5 #ifndef FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
6 #define FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
13 #include <type_traits>
30 static std::shared_ptr<HostBuffer>
Create(
31 const std::shared_ptr<Allocator>& allocator,
32 const std::shared_ptr<const IdleWaiter>& idle_waiter);
46 template <
class UniformType,
47 class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
49 const auto alignment =
51 return Emplace(
reinterpret_cast<const void*
>(&uniform),
68 class StorageBufferType,
69 class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
71 const StorageBufferType& buffer) {
72 const auto alignment =
75 sizeof(StorageBufferType),
91 template <
class BufferType,
92 class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
94 size_t alignment = 0) {
95 return Emplace(
reinterpret_cast<const void*
>(&buffer),
97 std::max(alignment,
alignof(BufferType))
137 [[nodiscard]] std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
138 EmplaceInternal(
const void* buffer,
size_t length);
140 std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
141 EmplaceInternal(
size_t length,
size_t align,
const EmplaceProc& cb);
143 std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
144 EmplaceInternal(
const void* buffer,
size_t length,
size_t align);
146 size_t GetLength()
const {
return offset_; }
152 [[nodiscard]]
bool MaybeCreateNewBuffer();
154 const std::shared_ptr<DeviceBuffer>& GetCurrentBuffer()
const;
158 explicit HostBuffer(
const std::shared_ptr<Allocator>& allocator,
159 const std::shared_ptr<const IdleWaiter>& idle_waiter);
165 std::shared_ptr<Allocator> allocator_;
166 std::shared_ptr<const IdleWaiter> idle_waiter_;
169 size_t current_buffer_ = 0u;
171 size_t frame_index_ = 0u;
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
TestStateQuery GetStateForTest()
Retrieve internal buffer state for test expectations.
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
BufferView EmplaceStorageBuffer(const StorageBufferType &buffer)
Emplace storage buffer data onto the host buffer. Ensure that backend specific uniform alignment requ...
std::function< void(uint8_t *buffer)> EmplaceProc
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter)
static constexpr const size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
constexpr size_t DefaultUniformAlignment()
Test only internal state.
size_t total_buffer_count