5 #ifndef FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
6 #define FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
12 #include <type_traits>
28 static std::shared_ptr<HostBuffer>
Create(
29 const std::shared_ptr<Allocator>& allocator,
30 const std::shared_ptr<const IdleWaiter>& idle_waiter,
31 size_t minimum_uniform_alignment);
45 template <
class UniformType,
46 class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
48 const auto alignment =
50 return Emplace(
reinterpret_cast<const void*
>(&uniform),
67 class StorageBufferType,
68 class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
70 const StorageBufferType& buffer) {
71 const auto alignment =
74 sizeof(StorageBufferType),
90 template <
class BufferType,
91 class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
93 size_t alignment = 0) {
94 return Emplace(
reinterpret_cast<const void*
>(&buffer),
96 std::max(alignment,
alignof(BufferType))
139 [[nodiscard]] std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
140 EmplaceInternal(
const void* buffer,
size_t length);
142 std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
143 EmplaceInternal(
size_t length,
size_t align,
const EmplaceProc& cb);
145 std::tuple<Range, std::shared_ptr<DeviceBuffer>,
DeviceBuffer*>
146 EmplaceInternal(
const void* buffer,
size_t length,
size_t align);
148 size_t GetLength()
const {
return offset_; }
154 [[nodiscard]]
bool MaybeCreateNewBuffer();
156 const std::shared_ptr<DeviceBuffer>& GetCurrentBuffer()
const;
160 explicit HostBuffer(
const std::shared_ptr<Allocator>& allocator,
161 const std::shared_ptr<const IdleWaiter>& idle_waiter,
162 size_t minimum_uniform_alignment);
168 std::shared_ptr<Allocator> allocator_;
169 std::shared_ptr<const IdleWaiter> idle_waiter_;
172 size_t current_buffer_ = 0u;
174 size_t frame_index_ = 0u;
175 size_t minimum_uniform_alignment_ = 0u;
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
size_t GetMinimumUniformAlignment() const
Retrieve the minimum uniform buffer alignment in bytes.
TestStateQuery GetStateForTest()
Retrieve internal buffer state for test expectations.
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment)
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 constexpr const size_t kHostBufferArenaSize
Approximately the same size as the max frames in flight.
Test only internal state.
size_t total_buffer_count