Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
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.
 
size_t GetMinimumUniformAlignment () const
 Retrieve the minimum uniform buffer alignment in bytes.
 
void Reset ()
 Resets the contents of the HostBuffer to nothing so it can be reused.
 
TestStateQuery GetStateForTest ()
 Retrieve internal buffer state for test expectations.
 

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, std::shared_ptr< const GpuSubmissionTracker > submission_tracker=nullptr)
 

Detailed Description

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

These are reset per-frame.

The buffers of an arena entry are reused kHostBufferArenaSize resets after they were written. Nothing guarantees that few frames are in flight, so with a [GpuSubmissionTracker] the reuse is made safe. Entries whose GPU work has not completed by the time they come up for reuse are kept alive off to the side and replaced with fresh allocations.

Definition at line 35 of file host_buffer.h.

Member Typedef Documentation

◆ EmplaceProc

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

Definition at line 114 of file host_buffer.h.

Constructor & Destructor Documentation

◆ ~HostBuffer()

impeller::HostBuffer::~HostBuffer ( )

Definition at line 50 of file host_buffer.cc.

50 {
51 if (idle_waiter_) {
52 // Since we hold on to DeviceBuffers we should make sure they aren't being
53 // used while we are deleting the HostBuffer.
54 idle_waiter_->WaitIdle();
55 }
56};

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,
std::shared_ptr< const GpuSubmissionTracker submission_tracker = nullptr 
)
static

Definition at line 21 of file host_buffer.cc.

25 {
26 return std::shared_ptr<HostBuffer>(
27 new HostBuffer(allocator, idle_waiter, minimum_uniform_alignment,
28 std::move(submission_tracker)));
29}
std::shared_ptr< ImpellerAllocator > allocator

References allocator.

Referenced by impeller::ContentContext::ContentContext(), impeller::testing::DrawCompressedTextureGolden(), impeller::testing::DrawManuallyMippedTextureGolden(), impeller::testing::FlushTestContentContext::FlushTestContentContext(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::RendererDartTest::RenderDartToPlayground(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), 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 102 of file host_buffer.h.

103 {
104 return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
105 sizeof(BufferType), // size
106 std::max(alignment, alignof(BufferType)) // alignment
107 );
108 }
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.

References Emplace().

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::Geometry::ComputePositionGeometry(), impeller::ContentContext::ContentContext(), impeller::DlAtlasGeometry::CreateBlendVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateBlendVertexBuffer(), impeller::DlAtlasGeometry::CreateSimpleVertexBuffer(), impeller::DrawImageRectAtlasGeometry::CreateSimpleVertexBuffer(), impeller::CreateVertexBuffer(), Emplace(), EmplaceStorageBuffer(), impeller::RuntimeEffectContents::EmplaceUniform(), EmplaceUniform(), impeller::ShadowVertices::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionBuffer(), impeller::DlVerticesGeometry::GetPositionUVColorBuffer(), impeller::TextContents::Render(), impeller::testing::TEST_P(), and impeller::UpdateAtlasBitmap().

◆ Emplace() [2/3]

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

Definition at line 58 of file host_buffer.cc.

60 {
61 auto [range, device_buffer, raw_device_buffer] =
62 EmplaceInternal(buffer, length, align);
63 if (device_buffer) {
64 return BufferView(std::move(device_buffer), range);
65 } else if (raw_device_buffer) {
66 return BufferView(raw_device_buffer, range);
67 } else {
68 return {};
69 }
70}
size_t length

References length.

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

86 {
87 auto [range, device_buffer, raw_device_buffer] =
88 EmplaceInternal(length, align, cb);
89 if (device_buffer) {
90 return BufferView(std::move(device_buffer), range);
91 } else if (raw_device_buffer) {
92 return BufferView(raw_device_buffer, range);
93 } else {
94 return {};
95 }
96}

References length.

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

80 {
81 const auto alignment =
82 std::max(alignof(StorageBufferType), GetMinimumUniformAlignment());
83 return Emplace(&buffer, // buffer
84 sizeof(StorageBufferType), // size
85 alignment // alignment
86 );
87 }
size_t GetMinimumUniformAlignment() const
Retrieve the minimum uniform buffer alignment in bytes.

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

57 {
58 const auto alignment =
59 std::max(alignof(UniformType), GetMinimumUniformAlignment());
60 return Emplace(reinterpret_cast<const void*>(&uniform), // buffer
61 sizeof(UniformType), // size
62 alignment // alignment
63 );
64 }

References Emplace(), and GetMinimumUniformAlignment().

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

◆ GetMinimumUniformAlignment()

size_t impeller::HostBuffer::GetMinimumUniformAlignment ( ) const

Retrieve the minimum uniform buffer alignment in bytes.

Definition at line 282 of file host_buffer.cc.

282 {
283 return minimum_uniform_alignment_;
284}

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

◆ GetStateForTest()

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

Retrieve internal buffer state for test expectations.

Definition at line 98 of file host_buffer.cc.

98 {
99 return HostBuffer::TestStateQuery{
100 .current_frame = frame_index_,
101 .current_buffer = current_buffer_,
102 .total_buffer_count = device_buffers_[frame_index_].size(),
103 };
104}

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

234 {
235 // When resetting the host buffer state at the end of the frame, check if
236 // there are any unused buffers and remove them.
237 while (device_buffers_[frame_index_].size() > current_buffer_ + 1) {
238 device_buffers_[frame_index_].pop_back();
239 }
240
241 if (submission_tracker_) {
242 // Everything submitted so far may reference this entry's buffers.
243 entry_stamps_[frame_index_] = submission_tracker_->LatestSubmission();
244 }
245
246 offset_ = 0u;
247 current_buffer_ = 0u;
248 frame_index_ = (frame_index_ + 1) % kHostBufferArenaSize;
249
250 if (!submission_tracker_) {
251 return;
252 }
253 uint64_t completed = submission_tracker_->CompletedThrough();
254
255 // Release retired buffers the GPU has completed with.
256 std::erase_if(retired_buffers_, [completed](const auto& retired) {
257 return retired.first <= completed;
258 });
259
260 if (entry_stamps_[frame_index_] <= completed) {
261 return;
262 }
263
264 // The GPU may still be reading the next entry's buffers. Retire them and
265 // start the entry over with a fresh allocation, since reusing them would
266 // race the reads of an incomplete earlier frame.
267 DeviceBufferDescriptor desc;
268 desc.size = kAllocatorBlockSize;
269 desc.storage_mode = StorageMode::kHostVisible;
270 std::shared_ptr<DeviceBuffer> buffer = allocator_->CreateBuffer(desc);
271 if (!buffer) {
272 VALIDATION_LOG << "Failed to replace an in-flight host buffer entry.";
273 return;
274 }
275 retired_buffers_.emplace_back(entry_stamps_[frame_index_],
276 std::move(device_buffers_[frame_index_]));
277 device_buffers_[frame_index_].clear();
278 device_buffers_[frame_index_].push_back(std::move(buffer));
279 entry_stamps_[frame_index_] = 0;
280}
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
constexpr size_t kAllocatorBlockSize
static const constexpr size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
Definition host_buffer.h:23
#define VALIDATION_LOG
Definition validation.h:91

References impeller::kAllocatorBlockSize, impeller::kHostBufferArenaSize, impeller::kHostVisible, impeller::DeviceBufferDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, and VALIDATION_LOG.

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


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