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

## 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::testing::RendererDartTest::RenderDartToPlayground(), 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,
|  | 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::Geometry::ComputePositionGeometry(), impeller::TypographerContextSkia::CreateGlyphAtlas(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::VerticesGeometry::GetPositionBuffer(), impeller::VerticesGeometry::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 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] | cb | A 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] | 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::scene::CuboidGeometry::BindToCommand(), impeller::scene::UnlitMaterial::BindToCommand(), impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand(), impeller::scene::SkinnedVertexBufferGeometry::BindToCommand(), impeller::ColorSourceContents::DrawGeometry(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::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 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 195 of file host_buffer.cc.

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

References impeller::kHostBufferArenaSize.

Referenced by impeller::DlPlayground::OpenPlaygroundHere(), and 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/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