| Flutter Impeller |

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
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, 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...
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< HostBuffer > | Create (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 107 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 21 of file host_buffer.cc.

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

Referenced by ImGui_ImplImpeller_RenderDrawData(), 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] | buffer | The buffer data.
  [in] | alignment | Minimum alignment of the data being emplaced.

Template Parameters

  BufferType | The type of the buffer data.

Returns
  The buffer view.

Definition at line 95 of file host_buffer.h.

96 {
97 return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
98 sizeof(BufferType), // size
99 std::max(alignment, alignof(BufferType)) // alignment
100 );
101 }

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::Geometry::ComputePositionGeometry(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::CreateVertexBuffer(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::DlVerticesGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::RuntimeEffectContents::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 44 of file host_buffer.cc.

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

## ◆ 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] | cb | A callback that will be passed a ptr to the underlying host buffer.

Returns
  The buffer view.

Definition at line 62 of file host_buffer.cc.

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

## ◆ 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] | uniform | The storage buffer to emplace onto the buffer.

Template Parameters

  StorageBufferType | The 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().

## ◆ 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] | uniform | The uniform struct to emplace onto the buffer.

Template Parameters

  UniformType | The 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::ColorSourceContents::DrawGeometry(), impeller::ClipContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ GetStateForTest()

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

Retrieve internal buffer state for test expectations.

Definition at line 72 of file host_buffer.cc.

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

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

208 {
209 // When resetting the host buffer state at the end of the frame, check if
210 // there are any unused buffers and remove them.
211 while (device_buffers_[frame_index_].size() > current_buffer_ + 1) {
212 device_buffers_[frame_index_].pop_back();
213 }
214
215 offset_ = 0u;
216 current_buffer_ = 0u;
217 frame_index_ = (frame_index_ + 1) % kHostBufferArenaSize;
218 }

References impeller::kHostBufferArenaSize.

Referenced by impeller::DisplayListToTexture(), impeller::AiksPlayground::OpenPlaygroundHere(), impeller::DlPlayground::OpenPlaygroundHere(), impeller::EntityPlayground::OpenPlaygroundHere(), and impeller::RenderToOnscreen().

## ◆ SetLabel()

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

Definition at line 40 of file host_buffer.cc.

40 {
41 label_ = std::move(label);
42 }

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

- impeller/core/host_buffer.h
- impeller/core/host_buffer.cc

impeller::HostBuffer::Emplace
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition: host_buffer.h:95
impeller::DefaultUniformAlignment
constexpr size_t DefaultUniformAlignment()
Definition: platform.h:14
impeller::kHostBufferArenaSize
static const constexpr size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
Definition: host_buffer.h:22