Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
impeller::AllocatorVK Class Referencefinal

#include <allocator_vk.h>

Inheritance diagram for impeller::AllocatorVK:
impeller::Allocator

Public Member Functions

 ~AllocatorVK () override
 
size_t DebugGetHeapUsage () const
 
- Public Member Functions inherited from impeller::Allocator
virtual ~Allocator ()
 
bool IsValid () const
 
std::shared_ptr< DeviceBufferCreateBuffer (const DeviceBufferDescriptor &desc)
 
std::shared_ptr< TextureCreateTexture (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.
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (const uint8_t *buffer, size_t length)
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (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.
 
static vk::ImageUsageFlags ToVKImageUsageFlags (PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
 

Private Member Functions

std::shared_ptr< DeviceBufferOnCreateBuffer (const DeviceBufferDescriptor &desc) override
 
std::shared_ptr< TextureOnCreateTexture (const TextureDescriptor &desc) override
 
ISize GetMaxTextureSizeSupported () const override
 
void DebugTraceMemoryStatistics () const override
 Write debug memory usage information to the dart timeline in debug and profile modes.
 

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()

size_t impeller::AllocatorVK::DebugGetHeapUsage ( ) const

Definition at line 512 of file allocator_vk.cc.

512 {
513 auto count = memory_properties_.memoryHeapCount;
514 std::vector<VmaBudget> budgets(count);
515 vmaGetHeapBudgets(allocator_.get(), budgets.data());
516 size_t total_usage = 0;
517 for (auto i = 0u; i < count; i++) {
518 const VmaBudget& budget = budgets[i];
519 total_usage += budget.usage;
520 }
521 // Convert bytes to MB.
522 total_usage *= 1e-6;
523 return total_usage;
524}
int count
const T & get() const

◆ DebugTraceMemoryStatistics()

void impeller::AllocatorVK::DebugTraceMemoryStatistics ( ) const
overrideprivatevirtual

Write debug memory usage information to the dart timeline in debug and profile modes.

This is only supported on the Vulkan backend.

Reimplemented from impeller::Allocator.

Definition at line 526 of file allocator_vk.cc.

526 {
527#ifdef IMPELLER_DEBUG
528 FML_TRACE_COUNTER("flutter", "AllocatorVK",
529 reinterpret_cast<int64_t>(this), // Trace Counter ID
530 "MemoryBudgetUsageMB", DebugGetHeapUsage());
531#endif // IMPELLER_DEBUG
532}
size_t DebugGetHeapUsage() const
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)
Definition trace_event.h:85

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

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

◆ GetMaxTextureSizeSupported()

ISize impeller::AllocatorVK::GetMaxTextureSizeSupported ( ) const
overrideprivatevirtual

Implements impeller::Allocator.

Definition at line 169 of file allocator_vk.cc.

169 {
170 return max_texture_size_;
171}

◆ OnCreateBuffer()

std::shared_ptr< DeviceBuffer > impeller::AllocatorVK::OnCreateBuffer ( const DeviceBufferDescriptor desc)
overrideprivatevirtual

Implements impeller::Allocator.

Definition at line 460 of file allocator_vk.cc.

461 {
462 vk::BufferCreateInfo buffer_info;
463 buffer_info.usage = vk::BufferUsageFlagBits::eVertexBuffer |
464 vk::BufferUsageFlagBits::eIndexBuffer |
465 vk::BufferUsageFlagBits::eUniformBuffer |
466 vk::BufferUsageFlagBits::eStorageBuffer |
467 vk::BufferUsageFlagBits::eTransferSrc |
468 vk::BufferUsageFlagBits::eTransferDst;
469 buffer_info.size = desc.size;
470 buffer_info.sharingMode = vk::SharingMode::eExclusive;
471 auto buffer_info_native =
472 static_cast<vk::BufferCreateInfo::NativeType>(buffer_info);
473
474 VmaAllocationCreateInfo allocation_info = {};
475 allocation_info.usage = ToVMAMemoryUsage();
476 allocation_info.preferredFlags = static_cast<VkMemoryPropertyFlags>(
477 ToVKBufferMemoryPropertyFlags(desc.storage_mode));
478 allocation_info.flags =
479 ToVmaAllocationBufferCreateFlags(desc.storage_mode, desc.readback);
480 if (created_buffer_pool_ && desc.storage_mode == StorageMode::kHostVisible &&
481 !desc.readback) {
482 allocation_info.pool = staging_buffer_pool_.get().pool;
483 }
484
485 VkBuffer buffer = {};
486 VmaAllocation buffer_allocation = {};
487 VmaAllocationInfo buffer_allocation_info = {};
488 auto result = vk::Result{::vmaCreateBuffer(allocator_.get(), //
489 &buffer_info_native, //
490 &allocation_info, //
491 &buffer, //
492 &buffer_allocation, //
493 &buffer_allocation_info //
494 )};
495
496 if (result != vk::Result::eSuccess) {
497 VALIDATION_LOG << "Unable to allocate a device buffer: "
498 << vk::to_string(result);
499 return {};
500 }
501
502 return std::make_shared<DeviceBufferVK>(
503 desc, //
504 context_, //
505 UniqueBufferVMA{BufferVMA{allocator_.get(), //
506 buffer_allocation, //
507 vk::Buffer{buffer}}}, //
508 buffer_allocation_info //
509 );
510}
static const uint8_t buffer[]
GAsyncResult * result
static constexpr vk::Flags< vk::MemoryPropertyFlagBits > ToVKBufferMemoryPropertyFlags(StorageMode mode)
static VmaAllocationCreateFlags ToVmaAllocationBufferCreateFlags(StorageMode mode, bool readback)
static constexpr VmaMemoryUsage ToVMAMemoryUsage()
fml::UniqueObject< BufferVMA, BufferVMATraits > UniqueBufferVMA
Definition vma.h:98
#define VALIDATION_LOG
Definition validation.h:73
VkFlags VkMemoryPropertyFlags

◆ OnCreateTexture()

std::shared_ptr< Texture > impeller::AllocatorVK::OnCreateTexture ( const TextureDescriptor desc)
overrideprivatevirtual

Implements impeller::Allocator.

Definition at line 433 of file allocator_vk.cc.

434 {
435 if (!IsValid()) {
436 return nullptr;
437 }
438 auto device_holder = device_holder_.lock();
439 if (!device_holder) {
440 return nullptr;
441 }
442 auto context = context_.lock();
443 if (!context) {
444 return nullptr;
445 }
446 auto source = std::make_shared<AllocatedTextureSourceVK>(
447 ContextVK::Cast(*context).GetResourceManager(), //
448 desc, //
449 allocator_.get(), //
450 device_holder->GetDevice(), //
451 supports_memoryless_textures_ //
452 );
453 if (!source->IsValid()) {
454 return nullptr;
455 }
456 return std::make_shared<TextureVK>(context_, std::move(source));
457}
static ContextVK & Cast(Context &base)
std::shared_ptr< ResourceManagerVK > GetResourceManager() const
SkBitmap source
Definition examples.cpp:28

◆ ToVKImageUsageFlags()

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

Definition at line 199 of file allocator_vk.cc.

203 {
204 vk::ImageUsageFlags vk_usage;
205
206 switch (mode) {
209 break;
211 if (supports_memoryless_textures) {
212 vk_usage |= vk::ImageUsageFlagBits::eTransientAttachment;
213 }
214 break;
215 }
216
219 vk_usage |= vk::ImageUsageFlagBits::eDepthStencilAttachment;
220 } else {
221 vk_usage |= vk::ImageUsageFlagBits::eColorAttachment;
222 vk_usage |= vk::ImageUsageFlagBits::eInputAttachment;
223 }
224 }
225
227 vk_usage |= vk::ImageUsageFlagBits::eSampled;
228 }
229
231 vk_usage |= vk::ImageUsageFlagBits::eStorage;
232 }
233
234 if (mode != StorageMode::kDeviceTransient) {
235 // Add transfer usage flags to support blit passes only if image isn't
236 // device transient.
237 vk_usage |= vk::ImageUsageFlagBits::eTransferSrc |
238 vk::ImageUsageFlagBits::eTransferDst;
239 }
240
241 return vk_usage;
242}
uint32_t uint32_t * format
constexpr bool PixelFormatIsDepthStencil(PixelFormat format)
Definition formats_vk.h:392
static void usage(char *argv0)

Friends And Related Symbol 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: