Flutter Impeller
impeller::Allocator Class Referenceabstract

An object that allocates device memory. More...

#include <allocator.h>

Inheritance diagram for impeller::Allocator:
impeller::AllocatorGLES impeller::AllocatorMTL impeller::AllocatorVK impeller::testing::TestAllocator

Public Member Functions

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. More...
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (const uint8_t *buffer, size_t length)
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (const fml::Mapping &mapping)
 
virtual ISize GetMaxTextureSizeSupported () const =0
 
virtual void DebugTraceMemoryStatistics () const
 Write debug memory usage information to the dart timeline in debug and profile modes. More...
 

Protected Member Functions

 Allocator ()
 
virtual std::shared_ptr< DeviceBufferOnCreateBuffer (const DeviceBufferDescriptor &desc)=0
 
virtual std::shared_ptr< TextureOnCreateTexture (const TextureDescriptor &desc)=0
 

Detailed Description

An object that allocates device memory.

Definition at line 22 of file allocator.h.

Constructor & Destructor Documentation

◆ ~Allocator()

impeller::Allocator::~Allocator ( )
virtualdefault

◆ Allocator()

impeller::Allocator::Allocator ( )
protecteddefault

Member Function Documentation

◆ CreateBuffer()

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBuffer ( const DeviceBufferDescriptor desc)

Definition at line 44 of file allocator.cc.

45  {
46  return OnCreateBuffer(desc);
47 }

References OnCreateBuffer().

Referenced by CreateBufferWithCopy(), and impeller::scene::Geometry::MakeFromFlatbuffer().

◆ CreateBufferWithCopy() [1/2]

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBufferWithCopy ( const fml::Mapping &  mapping)

Definition at line 39 of file allocator.cc.

40  {
41  return CreateBufferWithCopy(mapping.GetMapping(), mapping.GetSize());
42 }

References CreateBufferWithCopy().

◆ CreateBufferWithCopy() [2/2]

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBufferWithCopy ( const uint8_t *  buffer,
size_t  length 
)

Definition at line 18 of file allocator.cc.

20  {
21  DeviceBufferDescriptor desc;
22  desc.size = length;
23  desc.storage_mode = StorageMode::kHostVisible;
24  auto new_buffer = CreateBuffer(desc);
25 
26  if (!new_buffer) {
27  return nullptr;
28  }
29 
30  auto entire_range = Range{0, length};
31 
32  if (!new_buffer->CopyHostBuffer(buffer, entire_range)) {
33  return nullptr;
34  }
35 
36  return new_buffer;
37 }

References CreateBuffer(), impeller::kHostVisible, impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

Referenced by CreateBufferWithCopy().

◆ CreateTexture()

std::shared_ptr< Texture > impeller::Allocator::CreateTexture ( const TextureDescriptor desc)

Definition at line 49 of file allocator.cc.

50  {
51  const auto max_size = GetMaxTextureSizeSupported();
52  if (desc.size.width > max_size.width || desc.size.height > max_size.height) {
53  VALIDATION_LOG << "Requested texture size " << desc.size
54  << " exceeds maximum supported size of " << max_size;
55  return nullptr;
56  }
57 
58  if (desc.mip_count > desc.size.MipCount()) {
59  VALIDATION_LOG << "Requested mip_count " << desc.mip_count
60  << " exceeds maximum supported for size " << desc.size;
61  TextureDescriptor corrected_desc = desc;
62  corrected_desc.mip_count = desc.size.MipCount();
63  return OnCreateTexture(corrected_desc);
64  }
65 
66  return OnCreateTexture(desc);
67 }

References GetMaxTextureSizeSupported(), impeller::TSize< T >::height, impeller::TextureDescriptor::mip_count, impeller::TSize< T >::MipCount(), OnCreateTexture(), impeller::TextureDescriptor::size, VALIDATION_LOG, and impeller::TSize< T >::width.

Referenced by impeller::DeviceBuffer::AsTexture(), impeller::EntityPassTarget::Flip(), impeller::scene::Skin::GetJointsTexture(), impeller::RenderTarget::SetupDepthStencilAttachments(), impeller::scene::UnpackTextureFromFlatbuffer(), and impeller::WrapTextureWithRenderTarget().

◆ DebugTraceMemoryStatistics()

virtual void impeller::Allocator::DebugTraceMemoryStatistics ( ) const
inlinevirtual

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

This is only supported on the Vulkan backend.

Definition at line 51 of file allocator.h.

51 {};

◆ GetMaxTextureSizeSupported()

virtual ISize impeller::Allocator::GetMaxTextureSizeSupported ( ) const
pure virtual

Implemented in impeller::testing::TestAllocator.

Referenced by CreateTexture().

◆ IsValid()

bool impeller::Allocator::IsValid ( ) const

◆ MinimumBytesPerRow()

uint16_t impeller::Allocator::MinimumBytesPerRow ( PixelFormat  format) const
virtual

Minimum value for row_bytes on a Texture. The row bytes parameter of that method must be aligned to this value.

Definition at line 69 of file allocator.cc.

69  {
70  return BytesPerPixelForPixelFormat(format);
71 }

References impeller::BytesPerPixelForPixelFormat().

◆ OnCreateBuffer()

virtual std::shared_ptr<DeviceBuffer> impeller::Allocator::OnCreateBuffer ( const DeviceBufferDescriptor desc)
protectedpure virtual

Implemented in impeller::testing::TestAllocator.

Referenced by CreateBuffer().

◆ OnCreateTexture()

virtual std::shared_ptr<Texture> impeller::Allocator::OnCreateTexture ( const TextureDescriptor desc)
protectedpure virtual

Implemented in impeller::testing::TestAllocator.

Referenced by CreateTexture().


The documentation for this class was generated from the following files:
impeller::Allocator::GetMaxTextureSizeSupported
virtual ISize GetMaxTextureSizeSupported() const =0
impeller::Allocator::OnCreateTexture
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::Allocator::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition: allocator.cc:44
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:448
impeller::Allocator::CreateBufferWithCopy
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition: allocator.cc:18
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::Allocator::OnCreateBuffer
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0