| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Friends | List of all members
impeller::AllocatorVK Class Referencefinal

`#include <allocator_vk.h>`

Inheritance diagram for impeller::AllocatorVK:

## Public Member Functions
| ~AllocatorVK () override
Bytes | DebugGetHeapUsage () const override
Public Member Functions inherited from impeller::Allocator
virtual | ~Allocator ()
bool | IsValid () const
std::shared_ptr< DeviceBuffer > | CreateBuffer (const DeviceBufferDescriptor &desc)
std::shared_ptr< Texture > | CreateTexture (const TextureDescriptor &desc)
virtual uint16_t | MinimumBytesPerRow (PixelFormat format) const
| Minimum value for `row_bytes` on a Texture. The row bytes parameter of that method must be aligned to this value. More...
std::shared_ptr< DeviceBuffer > | CreateBufferWithCopy (const uint8_t *buffer, size_t length)
std::shared_ptr< DeviceBuffer > | CreateBufferWithCopy (const fml::Mapping &mapping)

## Static Public Member Functions
static int32_t | FindMemoryTypeIndex (uint32_t memory_type_bits_requirement, vk::PhysicalDeviceMemoryProperties &memory_properties)
| Select a matching memory type for the given [memory_type_bits_requirement], or -1 if none is found. More...
static vk::ImageUsageFlags | ToVKImageUsageFlags (PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)

## Friends
class | ContextVK

## Additional Inherited Members
Protected Member Functions inherited from impeller::Allocator
| Allocator ()

## Detailed Description

Definition at line 19 of file allocator_vk.h.

## Constructor & Destructor Documentation

## ◆ ~AllocatorVK()

impeller::AllocatorVK::~AllocatorVK | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ DebugGetHeapUsage()

Bytes impeller::AllocatorVK::DebugGetHeapUsage | ( |  | ) | const
| overridevirtual

Reimplemented from impeller::Allocator.

Definition at line 537 of file allocator_vk.cc.

537 {
538 auto count = memory_properties_.memoryHeapCount;
539 std::vector<VmaBudget> budgets(count);
540 vmaGetHeapBudgets(allocator_.get(), budgets.data());
541 size_t total_usage = 0;
542 for (auto i = 0u; i < count; i++) {
543 const VmaBudget& budget = budgets[i];
544 total_usage += budget.usage;
545 }
546 return Bytes{static_cast<double>(total_usage)};
547 }

## ◆ FindMemoryTypeIndex()

int32_t impeller::AllocatorVK::FindMemoryTypeIndex | ( | uint32_t | memory_type_bits_requirement,
|  | vk::PhysicalDeviceMemoryProperties & | memory_properties
| ) |  |
| static

Select a matching memory type for the given [memory_type_bits_requirement], or -1 if none is found.

This only returns memory types with deviceLocal allocations.

Definition at line 175 of file allocator_vk.cc.

177 {
178 int32_t type_index = -1;
179 vk::MemoryPropertyFlagBits required_properties =
180 vk::MemoryPropertyFlagBits::eDeviceLocal;
181
182 const uint32_t memory_count = memory_properties.memoryTypeCount;
183 for (uint32_t memory_index = 0; memory_index < memory_count; ++memory_index) {
184 const uint32_t memory_type_bits = (1 << memory_index);
185 const bool is_required_memory_type =
186 memory_type_bits_requirement & memory_type_bits;
187
188 const auto properties =
189 memory_properties.memoryTypes[memory_index].propertyFlags;
190 const bool has_required_properties =
191 (properties & required_properties) == required_properties;
192
193 if (is_required_memory_type && has_required_properties) {
194 return static_cast<int32_t>(memory_index);
195 }
196 }
197
198 return type_index;
199 }

Referenced by impeller::ImportVKDeviceMemoryFromAndroidHarwareBuffer(), and impeller::testing::TEST().

## ◆ ToVKImageUsageFlags()

vk::ImageUsageFlags impeller::AllocatorVK::ToVKImageUsageFlags | ( | PixelFormat | format,
|  | TextureUsageMask | usage,
|  | StorageMode | mode,
|  | bool | supports_memoryless_textures
| ) |  |
| static

Definition at line 201 of file allocator_vk.cc.

205 {
206 vk::ImageUsageFlags vk_usage;
207
208 switch (mode) {
209 case StorageMode::kHostVisible:
210 case StorageMode::kDevicePrivate:
211 break;
212 case StorageMode::kDeviceTransient:
213 if (supports_memoryless_textures) {
214 vk_usage |= vk::ImageUsageFlagBits::eTransientAttachment;
215 }
216 break;
217 }
218
219 if (usage & TextureUsage::kRenderTarget) {
220 if (PixelFormatIsDepthStencil(format)) {
221 vk_usage |= vk::ImageUsageFlagBits::eDepthStencilAttachment;
222 } else {
223 vk_usage |= vk::ImageUsageFlagBits::eColorAttachment;
224 vk_usage |= vk::ImageUsageFlagBits::eInputAttachment;
225 }
226 }
227
228 if (usage & TextureUsage::kShaderRead) {
229 vk_usage |= vk::ImageUsageFlagBits::eSampled;
230 }
231
232 if (usage & TextureUsage::kShaderWrite) {
233 vk_usage |= vk::ImageUsageFlagBits::eStorage;
234 }
235
236 if (mode != StorageMode::kDeviceTransient) {
237 // Add transfer usage flags to support blit passes only if image isn't
238 // device transient.
239 vk_usage |= vk::ImageUsageFlagBits::eTransferSrc |
240 vk::ImageUsageFlagBits::eTransferDst;
241 }
242
243 return vk_usage;
244 }

References impeller::PixelFormatIsDepthStencil().

Referenced by impeller::testing::TEST().

## Friends And Related Function Documentation

## ◆ ContextVK

friend class ContextVK
| friend

Definition at line 43 of file allocator_vk.h.

The documentation for this class was generated from the following files:

- impeller/renderer/backend/vulkan/allocator_vk.h
- impeller/renderer/backend/vulkan/allocator_vk.cc

impeller::TextureUsage::kShaderWrite
@ kShaderWrite
impeller::PixelFormatIsDepthStencil
constexpr bool PixelFormatIsDepthStencil(PixelFormat format)
Definition: formats_vk.h:393
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::TextureUsage::kShaderRead
@ kShaderRead
impeller::Bytes
AllocationSize< 1u > Bytes
Definition: allocation_size.h:151