| 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
| ~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...
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, const std::shared_ptr< const IdleWaiter > &idle_waiter)

## 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 | ( |  | ) |

Definition at line 40 of file host_buffer.cc.

40 {
41 if (idle_waiter_) {
42 // Since we hold on to DeviceBuffers we should make sure they aren't being
43 // used while we are deleting the HostBuffer.
44 idle_waiter_->WaitIdle();
45 }
46 };

## 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
| ) |  |
| static

Definition at line 21 of file host_buffer.cc.

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

Referenced by 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] | 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 93 of file host_buffer.h.

94 {
95 return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
96 sizeof(BufferType), // size
97 std::max(alignment, alignof(BufferType)) // alignment
98 );
99 }
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:93

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::Geometry::ComputePositionGeometry(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::CreateVertexBuffer(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::RuntimeEffectContents::EmplaceVulkanUniform(), impeller::Tessellator::GenerateLineStrip(), 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 48 of file host_buffer.cc.

50 {
51 auto [range, device_buffer, raw_device_buffer] =
52 EmplaceInternal(buffer, length, align);
53 if (device_buffer) {
54 return BufferView(std::move(device_buffer), range);
55 } else if (raw_device_buffer) {
56 return BufferView(raw_device_buffer, range);
57 } else {
58 return {};
59 }
60 }

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

76 {
77 auto [range, device_buffer, raw_device_buffer] =
78 EmplaceInternal(length, align, cb);
79 if (device_buffer) {
80 return BufferView(std::move(device_buffer), range);
81 } else if (raw_device_buffer) {
82 return BufferView(raw_device_buffer, range);
83 } else {
84 return {};
85 }
86 }

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

71 {
72 const auto alignment =
73 std::max(alignof(StorageBufferType), DefaultUniformAlignment());
74 return Emplace(&buffer, // buffer
75 sizeof(StorageBufferType), // size
76 alignment // alignment
77 );
78 }
impeller::DefaultUniformAlignment
constexpr size_t DefaultUniformAlignment()
Definition: platform.h:14

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

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

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

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

## ◆ GetStateForTest()

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

Retrieve internal buffer state for test expectations.

Definition at line 88 of file host_buffer.cc.

88 {
89 return HostBuffer::TestStateQuery{
90 .current_frame = frame_index_,
91 .current_buffer = current_buffer_,
92 .total_buffer_count = device_buffers_[frame_index_].size(),
93 };
94 }

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

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

References impeller::kHostBufferArenaSize.

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

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

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