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

virtual ~HostBuffer ()
 
void SetLabel (std::string label)
 
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)
 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...
 
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)
 

Detailed Description

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

These are reset per-frame.

Definition at line 28 of file host_buffer.h.

Member Typedef Documentation

◆ EmplaceProc

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

Definition at line 105 of file host_buffer.h.

Constructor & Destructor Documentation

◆ ~HostBuffer()

impeller::HostBuffer::~HostBuffer ( )
virtualdefault

Member Function Documentation

◆ Create()

std::shared_ptr< HostBuffer > impeller::HostBuffer::Create ( const std::shared_ptr< Allocator > &  allocator)
static

Definition at line 20 of file host_buffer.cc.

21  {
22  return std::shared_ptr<HostBuffer>(new HostBuffer(allocator));
23 }

Referenced by ImGui_ImplImpeller_RenderDrawData(), impeller::scene::SceneContext::SceneContext(), 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)
inline

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

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

Definition at line 94 of file host_buffer.h.

94  {
95  return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
96  sizeof(BufferType), // size
97  alignof(BufferType) // alignment
98  );
99  }

Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::Geometry::ComputePositionUVGeometry(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::VerticesGeometry::GetPositionBuffer(), impeller::VerticesGeometry::GetPositionColorBuffer(), impeller::VerticesGeometry::GetPositionUVBuffer(), impeller::RuntimeEffectContents::Render(), and impeller::TextContents::Render().

◆ Emplace() [2/3]

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

Definition at line 41 of file host_buffer.cc.

43  {
44  auto [range, device_buffer] = EmplaceInternal(buffer, length, align);
45  if (!device_buffer) {
46  return {};
47  }
48  return BufferView{std::move(device_buffer), range};
49 }

◆ 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 59 of file host_buffer.cc.

61  {
62  auto [range, device_buffer] = EmplaceInternal(length, align, cb);
63  if (!device_buffer) {
64  return {};
65  }
66  return BufferView{std::move(device_buffer), range};
67 }

◆ 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 72 of file host_buffer.h.

73  {
74  const auto alignment =
75  std::max(alignof(StorageBufferType), DefaultUniformAlignment());
76  return Emplace(&buffer, // buffer
77  sizeof(StorageBufferType), // size
78  alignment // alignment
79  );
80  }

References impeller::DefaultUniformAlignment(), and Emplace().

Referenced by impeller::ComputeTessellator::Tessellate().

◆ 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 50 of file host_buffer.h.

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

References impeller::DefaultUniformAlignment(), and Emplace().

Referenced by impeller::scene::CuboidGeometry::BindToCommand(), impeller::scene::UnlitMaterial::BindToCommand(), impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand(), impeller::scene::SkinnedVertexBufferGeometry::BindToCommand(), impeller::SolidRRectBlurContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::Render(), impeller::ComputeTessellator::Tessellate(), and impeller::testing::TEST_P().

◆ GetStateForTest()

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

Retrieve internal buffer state for test expectations.

Definition at line 69 of file host_buffer.cc.

69  {
70  return HostBuffer::TestStateQuery{
71  .current_frame = frame_index_,
72  .current_buffer = current_buffer_,
73  .total_buffer_count = device_buffers_[frame_index_].size(),
74  };
75 }

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 189 of file host_buffer.cc.

189  {
190  // When resetting the host buffer state at the end of the frame, check if
191  // there are any unused buffers and remove them.
192  while (device_buffers_[frame_index_].size() > current_buffer_ + 1) {
193  device_buffers_[frame_index_].pop_back();
194  }
195 
196  offset_ = 0u;
197  current_buffer_ = 0u;
198  frame_index_ = (frame_index_ + 1) % kHostBufferArenaSize;
199 }

References impeller::kHostBufferArenaSize.

Referenced by impeller::EntityPlayground::OpenPlaygroundHere().

◆ SetLabel()

void impeller::HostBuffer::SetLabel ( std::string  label)

Definition at line 37 of file host_buffer.cc.

37  {
38  label_ = std::move(label);
39 }

The documentation for this class was generated from the following files:
impeller::DefaultUniformAlignment
constexpr size_t DefaultUniformAlignment()
Definition: platform.h:15
impeller::HostBuffer::Emplace
BufferView Emplace(const BufferType &buffer)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition: host_buffer.h:94
impeller::kHostBufferArenaSize
static const constexpr size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
Definition: host_buffer.h:22