| 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, bool threadsafe=false)
| Creates a new texture. More...
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 553 of file allocator_vk.cc.

553 {
554 auto count = memory_properties_.memoryHeapCount;
555 std::vector<VmaBudget> budgets(count);
556 vmaGetHeapBudgets(allocator_.get(), budgets.data());
557 size_t total_usage = 0;
558 for (auto i = 0u; i < count; i++) {
559 const VmaBudget& budget = budgets[i];
560 total_usage += budget.usage;
561 }
562 return Bytes{static_cast<double>(total_usage)};
563 }
impeller::Bytes
AllocationSize< 1u > Bytes
Definition: allocation_size.h:151

## ◆ 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 180 of file allocator_vk.cc.

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

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

## ◆ ToVKImageUsageFlags()

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

Definition at line 206 of file allocator_vk.cc.

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

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