Flutter Impeller
impeller::HostBuffer Class Reference

#include <host_buffer.h>

Classes

struct  TestStateQuery
 Test only internal state. More...
 

Public Types

using EmplaceProc = std::function< void(uint8_t *buffer)>
 

Public Member Functions

 ~HostBuffer ()
 
template<class UniformType , class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
BufferView EmplaceUniform (const UniformType &uniform)
 Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected. More...
 
template<class StorageBufferType , class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
BufferView EmplaceStorageBuffer (const StorageBufferType &buffer)
 Emplace storage buffer data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected. More...
 
template<class BufferType , class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
BufferView Emplace (const BufferType &buffer, size_t alignment=0)
 Emplace non-uniform data (like contiguous vertices) onto the host buffer. More...
 
BufferView Emplace (const void *buffer, size_t length, size_t align)
 
BufferView Emplace (size_t length, size_t align, const EmplaceProc &cb)
 Emplaces undefined data onto the managed buffer and gives the caller a chance to update it using the specified callback. The buffer is guaranteed to have enough space for length bytes. It is the responsibility of the caller to not exceed the bounds of the buffer returned in the EmplaceProc. More...
 
size_t GetMinimumUniformAlignment () const
 Retrieve the minimum uniform buffer alignment in bytes. More...
 
void Reset ()
 Resets the contents of the HostBuffer to nothing so it can be reused. More...
 
TestStateQuery GetStateForTest ()
 Retrieve internal buffer state for test expectations. More...
 

Static Public Member Functions

static std::shared_ptr< HostBufferCreate (const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
 

Detailed Description

The host buffer class manages one more 1024 Kb blocks of device buffer allocations.

These are reset per-frame.

Definition at line 26 of file host_buffer.h.

Member Typedef Documentation

◆ EmplaceProc

using impeller::HostBuffer::EmplaceProc = std::function<void(uint8_t* buffer)>

Definition at line 104 of file host_buffer.h.

Constructor & Destructor Documentation

◆ ~HostBuffer()

impeller::HostBuffer::~HostBuffer ( )

Definition at line 45 of file host_buffer.cc.

45  {
46  if (idle_waiter_) {
47  // Since we hold on to DeviceBuffers we should make sure they aren't being
48  // used while we are deleting the HostBuffer.
49  idle_waiter_->WaitIdle();
50  }
51 };

Member Function Documentation

◆ Create()

std::shared_ptr< HostBuffer > impeller::HostBuffer::Create ( const std::shared_ptr< Allocator > &  allocator,
const std::shared_ptr< const IdleWaiter > &  idle_waiter,
size_t  minimum_uniform_alignment 
)
static

Definition at line 21 of file host_buffer.cc.

24  {
25  return std::shared_ptr<HostBuffer>(
26  new HostBuffer(allocator, idle_waiter, minimum_uniform_alignment));
27 }

Referenced by impeller::testing::FlushTestContentContext::FlushTestContentContext(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::RendererDartTest::RenderDartToPlayground(), and impeller::testing::TEST_P().

◆ Emplace() [1/3]

template<class BufferType , class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
BufferView impeller::HostBuffer::Emplace ( const BufferType &  buffer,
size_t  alignment = 0 
)
inline

Emplace non-uniform data (like contiguous vertices) onto the host buffer.

Parameters
[in]bufferThe buffer data.
[in]alignmentMinimum alignment of the data being emplaced.
Template Parameters
BufferTypeThe type of the buffer data.
Returns
The buffer view.

Definition at line 92 of file host_buffer.h.

93  {
94  return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
95  sizeof(BufferType), // size
96  std::max(alignment, alignof(BufferType)) // alignment
97  );
98  }
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition: host_buffer.h:92

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::Geometry::ComputePositionGeometry(), impeller::ContentContext::ContentContext(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateSimpleVertexBuffer(), impeller::CreateVertexBuffer(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::RuntimeEffectContents::EmplaceVulkanUniform(), impeller::DlVerticesGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::TextContents::Render(), impeller::Tessellator::TessellateConvex(), and impeller::UpdateAtlasBitmap().

◆ Emplace() [2/3]

BufferView impeller::HostBuffer::Emplace ( const void *  buffer,
size_t  length,
size_t  align 
)

Definition at line 53 of file host_buffer.cc.

55  {
56  auto [range, device_buffer, raw_device_buffer] =
57  EmplaceInternal(buffer, length, align);
58  if (device_buffer) {
59  return BufferView(std::move(device_buffer), range);
60  } else if (raw_device_buffer) {
61  return BufferView(raw_device_buffer, range);
62  } else {
63  return {};
64  }
65 }

◆ Emplace() [3/3]

BufferView impeller::HostBuffer::Emplace ( size_t  length,
size_t  align,
const EmplaceProc cb 
)

Emplaces undefined data onto the managed buffer and gives the caller a chance to update it using the specified callback. The buffer is guaranteed to have enough space for length bytes. It is the responsibility of the caller to not exceed the bounds of the buffer returned in the EmplaceProc.

Parameters
[in]cbA callback that will be passed a ptr to the underlying host buffer.
Returns
The buffer view.

Definition at line 79 of file host_buffer.cc.

81  {
82  auto [range, device_buffer, raw_device_buffer] =
83  EmplaceInternal(length, align, cb);
84  if (device_buffer) {
85  return BufferView(std::move(device_buffer), range);
86  } else if (raw_device_buffer) {
87  return BufferView(raw_device_buffer, range);
88  } else {
89  return {};
90  }
91 }

◆ EmplaceStorageBuffer()

template<class StorageBufferType , class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
BufferView impeller::HostBuffer::EmplaceStorageBuffer ( const StorageBufferType &  buffer)
inline

Emplace storage buffer data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected.

Parameters
[in]uniformThe storage buffer to emplace onto the buffer.
Template Parameters
StorageBufferTypeThe type of the shader storage buffer.
Returns
The buffer view.

Definition at line 69 of file host_buffer.h.

70  {
71  const auto alignment =
72  std::max(alignof(StorageBufferType), GetMinimumUniformAlignment());
73  return Emplace(&buffer, // buffer
74  sizeof(StorageBufferType), // size
75  alignment // alignment
76  );
77  }
size_t GetMinimumUniformAlignment() const
Retrieve the minimum uniform buffer alignment in bytes.
Definition: host_buffer.cc:241

References Emplace(), and GetMinimumUniformAlignment().

◆ EmplaceUniform()

template<class UniformType , class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
BufferView impeller::HostBuffer::EmplaceUniform ( const UniformType &  uniform)
inline

Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected.

Parameters
[in]uniformThe uniform struct to emplace onto the buffer.
Template Parameters
UniformTypeThe type of the uniform struct.
Returns
The buffer view.

Definition at line 47 of file host_buffer.h.

47  {
48  const auto alignment =
49  std::max(alignof(UniformType), GetMinimumUniformAlignment());
50  return Emplace(reinterpret_cast<const void*>(&uniform), // buffer
51  sizeof(UniformType), // size
52  alignment // alignment
53  );
54  }

References Emplace(), and GetMinimumUniformAlignment().

Referenced by impeller::ColorSourceContents::DrawGeometry(), ImGui_ImplImpeller_RenderDrawData(), impeller::TextContents::Render(), impeller::ClipContents::Render(), impeller::RenderClipRestore(), and impeller::testing::TEST_P().

◆ GetMinimumUniformAlignment()

size_t impeller::HostBuffer::GetMinimumUniformAlignment ( ) const

Retrieve the minimum uniform buffer alignment in bytes.

Definition at line 241 of file host_buffer.cc.

241  {
242  return minimum_uniform_alignment_;
243 }

Referenced by impeller::BulkUpdateAtlasBitmap(), EmplaceStorageBuffer(), EmplaceUniform(), and impeller::UpdateAtlasBitmap().

◆ GetStateForTest()

HostBuffer::TestStateQuery impeller::HostBuffer::GetStateForTest ( )

Retrieve internal buffer state for test expectations.

Definition at line 93 of file host_buffer.cc.

93  {
94  return HostBuffer::TestStateQuery{
95  .current_frame = frame_index_,
96  .current_buffer = current_buffer_,
97  .total_buffer_count = device_buffers_[frame_index_].size(),
98  };
99 }

References impeller::HostBuffer::TestStateQuery::current_frame.

◆ Reset()

void impeller::HostBuffer::Reset ( )

Resets the contents of the HostBuffer to nothing so it can be reused.

Definition at line 229 of file host_buffer.cc.

229  {
230  // When resetting the host buffer state at the end of the frame, check if
231  // there are any unused buffers and remove them.
232  while (device_buffers_[frame_index_].size() > current_buffer_ + 1) {
233  device_buffers_[frame_index_].pop_back();
234  }
235 
236  offset_ = 0u;
237  current_buffer_ = 0u;
238  frame_index_ = (frame_index_ + 1) % kHostBufferArenaSize;
239 }
static constexpr const size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
Definition: host_buffer.h:20

References impeller::kHostBufferArenaSize.

Referenced by ImGui_ImplImpeller_RenderDrawData(), and impeller::EntityPlayground::OpenPlaygroundHere().


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