GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
buffers.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_GRAPHICS_BUFFERS_HPP
5#define GREM_GRAPHICS_BUFFERS_HPP
6
8
20#include <GREM/core/math.hpp>
26
27#include <cstddef> // std::nullptr_t
28#include <utility> // std::move
29
30namespace grem::graphics {
31
32class Device; // Forward declaration, to avoid a circular include of Device.hpp.
33struct TextureImplementation; // Forward declaration, to avoid including Texture.hpp.
34
35struct UniformBufferImplementation;
36struct StorageBufferImplementation;
37struct BufferSetImplementation;
38struct InstanceBufferImplementation;
39struct DrawCommandBufferImplementation;
40struct UnorderedDrawCommandBufferImplementation;
41
42namespace detail {
43
44class BufferSetBase; // Forward declaration.
45class StorageBufferBase; // Forward declaration.
46
47class UniformBufferBase {
48public:
57 [[nodiscard]] SharedPointer<UniformBufferImplementation> lock() const {
58 flush();
59 return implementation;
60 }
61
70 [[nodiscard]] UniformBufferImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
71 return implementation.get();
72 }
73
82 [[nodiscard]] const UniformBufferImplementation* get() const noexcept {
83 return implementation.get();
84 }
85
86protected:
87 GREM_API(graphics) UniformBufferBase(Device& device, BufferLayoutReference bufferLayout, size_t bufferSize, size_t textureParameterCount);
88
89 GREM_API(graphics)
90 void upload(Span<const byte> newParameterValuesBytes, Span<SharedPointer<TextureImplementation>> newTextures, Span<const ParameterDescription> parameterDescriptions);
91
92 GREM_API(graphics) void flush() const;
93
94private:
95 friend BufferSetImplementation;
96 friend BufferSetBase;
97 friend StorageBufferBase;
98
99 SharedPointer<UniformBufferImplementation> implementation{};
100};
101
102class StorageBufferBase {
103public:
112 [[nodiscard]] SharedPointer<StorageBufferImplementation> lock() const {
113 flush();
114 return implementation;
115 }
116
125 [[nodiscard]] StorageBufferImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
126 return implementation.get();
127 }
128
137 [[nodiscard]] const StorageBufferImplementation* get() const noexcept {
138 return implementation.get();
139 }
140
141protected:
142 GREM_API(graphics) StorageBufferBase(Device& device, BufferLayoutReference bufferLayout, size_t elementSize);
143
144 GREM_API(graphics) void upload(StridedSpan<const byte> elementsData, size_t elementSize);
145 GREM_API(graphics) void write(uint32_t elementOffset, StridedSpan<const byte> elementsData, size_t elementSize);
146 GREM_API(graphics) void flush() const;
147
148private:
149 friend BufferSetImplementation;
150 friend BufferSetBase;
151 friend UniformBufferBase;
152
153 SharedPointer<StorageBufferImplementation> implementation{};
154};
155
156class BufferSetBase {
157public:
166 [[nodiscard]] SharedPointer<BufferSetImplementation> lock() const {
167 flush();
168 return implementation;
169 }
170
179 [[nodiscard]] BufferSetImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
180 return implementation.get();
181 }
182
191 [[nodiscard]] const BufferSetImplementation* get() const noexcept {
192 return implementation.get();
193 }
194
195protected:
196 GREM_API(graphics) BufferSetBase(Device& device, BufferLayoutReference bufferSetLayout, Allocation<SharedPointer<void>> buffers);
197
198 GREM_API(graphics) void setBuffer(size_t bufferIndex, SharedPointer<void> newBuffer);
199 GREM_API(graphics) void setBuffers(Span<SharedPointer<void>> newBuffers);
200
201 GREM_API(graphics)
202 void uploadToUniformBuffer(size_t bufferIndex, Span<const byte> newParameterValuesBytes, Span<SharedPointer<TextureImplementation>> newTextures,
203 Span<const ParameterDescription> parameterDescriptions);
204
205 GREM_API(graphics)
206 void uploadToStorageBuffer(size_t bufferIndex, StridedSpan<const byte> elementsData, size_t elementSize);
207
208 GREM_API(graphics)
209 void writeToStorageBuffer(size_t bufferIndex, uint32_t elementOffset, StridedSpan<const byte> elementsData, size_t elementSize);
210
211 GREM_API(graphics) void flush() const;
212
213 [[nodiscard]] static SharedPointer<void> getBufferHandle(const UniformBufferBase& uniformBuffer) {
214 return uniformBuffer.implementation;
215 }
216
217 [[nodiscard]] static SharedPointer<void> getBufferHandle(const StorageBufferBase& storageBuffer) {
218 return storageBuffer.implementation;
219 }
220
221private:
222 friend UniformBufferBase;
223 friend StorageBufferBase;
224
225 SharedPointer<BufferSetImplementation> implementation{};
226};
227
228class InstanceBufferBase {
229public:
238 GREM_API(graphics) void clear();
239
245 [[nodiscard]] GREM_API(graphics) uint32_t size() const noexcept;
246
252 [[nodiscard]] bool empty() const noexcept {
253 return size() == 0;
254 }
255
264 [[nodiscard]] SharedPointer<InstanceBufferImplementation> lock() const {
265 flush();
266 return implementation;
267 }
268
277 [[nodiscard]] InstanceBufferImplementation* get() const noexcept {
278 return implementation.get();
279 }
280
281protected:
282 GREM_API(graphics) InstanceBufferBase(Device& device, size_t instanceSize);
283
284 [[nodiscard]] GREM_API(graphics) uint32_t append(StridedSpan<const byte> instancesData, size_t instanceSize);
285
286 GREM_API(graphics) void flush() const;
287
288private:
289 SharedPointer<InstanceBufferImplementation> implementation{};
290};
291
292class DrawCommandBufferBase {
293public:
302 GREM_API(graphics) void clear();
303
312 [[nodiscard]] SharedPointer<DrawCommandBufferImplementation> lock() const {
313 flush();
314 return implementation;
315 }
316
325 [[nodiscard]] DrawCommandBufferImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
326 return implementation.get();
327 }
328
337 [[nodiscard]] const DrawCommandBufferImplementation* get() const noexcept {
338 return implementation.get();
339 }
340
341protected:
342 GREM_API(graphics) DrawCommandBufferBase(Device& device);
343
344 GREM_API(graphics)
345 void append(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceOffset, uint32_t instanceCount);
346
347 GREM_API(graphics) void flush() const;
348
349private:
350 SharedPointer<DrawCommandBufferImplementation> implementation{};
351};
352
353class UnorderedDrawCommandBufferBase {
354public:
363 GREM_API(graphics) void clear();
364
373 [[nodiscard]] SharedPointer<UnorderedDrawCommandBufferImplementation> lock() const {
374 flush();
375 return implementation;
376 }
377
386 [[nodiscard]] UnorderedDrawCommandBufferImplementation* get() noexcept { // NOLINT(readability-make-member-function-const)
387 return implementation.get();
388 }
389
398 [[nodiscard]] const UnorderedDrawCommandBufferImplementation* get() const noexcept {
399 return implementation.get();
400 }
401
402protected:
403 GREM_API(graphics) UnorderedDrawCommandBufferBase(Device& device);
404
405 GREM_API(graphics)
406 void insert(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceOffset, uint32_t instanceCount);
407
408 GREM_API(graphics) void flush() const;
409
410private:
411 SharedPointer<UnorderedDrawCommandBufferImplementation> implementation{};
412};
413
414} // namespace detail
415
425template <typename ParameterStruct, ConstantString Name>
426class UniformBuffer : public detail::UniformBufferBase {
427public:
429
431 using parameters_type = ParameterStruct;
432
435
438
440 static constexpr CStringView NAME = Name;
441
453 explicit UniformBuffer(Device& device)
454 : detail::UniformBufferBase(device, LAYOUT_REFERENCE, detail::PARAMETER_VALUES_BYTES_SIZE<ParameterStruct>, detail::PARAMETER_TEXTURES_COUNT<ParameterStruct>) {}
455
467 void upload(const ParameterStruct& newParameterValues) {
468 alignas(sizeof(float) * 4) Array<byte, detail::PARAMETER_VALUES_BYTES_SIZE<ParameterStruct>> bytes;
469 Array<SharedPointer<TextureImplementation>, detail::PARAMETER_TEXTURES_COUNT<ParameterStruct>> textures{};
470 size_t byteOffset = 0;
471 size_t textureIndex = 0;
472 meta::forEachField(newParameterValues, [&]<typename Wrapper>(const Wrapper& parameter) -> void { //
473 detail::alignParameter(byteOffset, detail::PARAMETER_TYPE_OF_PARAMETER_WRAPPER<Wrapper>, detail::ARRAY_ELEMENT_COUNT_OF_PARAMETER_WRAPPER<Wrapper>);
474 detail::writeParameter(bytes.data() + byteOffset, parameter);
475 detail::skipParameter(byteOffset, detail::PARAMETER_TYPE_OF_PARAMETER_WRAPPER<Wrapper>, detail::ARRAY_ELEMENT_COUNT_OF_PARAMETER_WRAPPER<Wrapper>);
476 detail::writeParameterTextures(textures.data() + textureIndex, parameter);
477 textureIndex += detail::TEXTURE_COUNT_OF_PARAMETER_WRAPPER<Wrapper>;
478 });
479 detail::UniformBufferBase::upload(bytes, textures, detail::PARAMETER_DESCRIPTIONS<ParameterStruct>);
480 }
481};
482
492template <typename FieldStruct, ConstantString Name>
493class StorageBuffer : public detail::StorageBufferBase {
494public:
495 static_assert(field_struct<FieldStruct>);
496
498 using fields_type = FieldStruct;
499
502
505
507 static constexpr CStringView NAME = Name;
508
519 explicit StorageBuffer(Device& device)
520 : detail::StorageBufferBase(device, LAYOUT_REFERENCE, sizeof(FieldStruct)) {}
521
534 detail::StorageBufferBase::upload(as_strided_bytes(newElements), sizeof(FieldStruct));
535 }
536
550 void write(uint32_t elementOffset, StridedSpan<const FieldStruct> newElements) {
551 detail::StorageBufferBase::write(elementOffset, as_strided_bytes(newElements), sizeof(FieldStruct));
552 }
553
567 void write(uint32_t elementIndex, const FieldStruct& newElement) {
568 detail::StorageBufferBase::write(elementIndex, as_strided_bytes(StridedSpan{&newElement, 1}), sizeof(FieldStruct));
569 }
570};
571
579template <typename... Buffers>
580class BufferSet : public detail::BufferSetBase {
581public:
583 static constexpr BufferSetLayout<Buffers...> LAYOUT{};
584
587
589 static constexpr CStringView NAME = static_cast<BufferSetLayoutReference>(LAYOUT).name;
590
592 using buffer_types = meta::TypeList<Buffers...>;
593
605 explicit BufferSet(Device& device)
606 : BufferSetBase(device, LAYOUT_REFERENCE, {getBufferHandle(Buffers{device})...}) {}
607
625 BufferSet(Device& device, std::nullptr_t nullPointer)
626 : BufferSetBase(device, LAYOUT_REFERENCE, Allocation<SharedPointer<void>>(sizeof...(Buffers), nullptr)) {
627 (void)nullPointer;
628 }
629
642 explicit BufferSet(Device& device, const Buffers&... buffers)
643 : BufferSetBase(device, LAYOUT_REFERENCE, {getBufferHandle(buffers)...}) {}
644
663 template <typename Buffer>
664 void setBuffer(std::nullptr_t nullPointer) requires(meta::type_list_contains_v<buffer_types, Buffer>) {
665 (void)nullPointer;
666 detail::BufferSetBase::setBuffer(meta::type_list_index_v<buffer_types, Buffer>, nullptr);
667 }
668
682 template <typename Buffer>
684 detail::BufferSetBase::setBuffer(meta::type_list_index_v<buffer_types, Buffer>, getBufferHandle(buffer));
685 }
686
702 void setBuffers(std::nullptr_t nullPointer) {
703 (void)nullPointer;
704 Array<SharedPointer<void>, sizeof...(Buffers)> newBuffers{};
705 detail::BufferSetBase::setBuffers(newBuffers);
706 }
707
718 void setBuffers(const Buffers&... buffers) {
719 Array<SharedPointer<void>, sizeof...(Buffers)> newBuffers{getBufferHandle(buffers)...};
720 detail::BufferSetBase::setBuffers(newBuffers);
721 }
722
737 template <typename Buffer>
738 void upload(const typename Buffer::parameters_type& newParameterValues) requires(meta::type_list_contains_v<buffer_types, Buffer>) {
739 using ParameterStruct = typename Buffer::parameters_type;
740 alignas(sizeof(float) * 4) Array<byte, detail::PARAMETER_VALUES_BYTES_SIZE<ParameterStruct>> bytes;
741 Array<SharedPointer<TextureImplementation>, detail::PARAMETER_TEXTURES_COUNT<ParameterStruct>> textures{};
742 size_t byteOffset = 0;
743 size_t textureIndex = 0;
744 meta::forEachField(newParameterValues, [&]<typename Wrapper>(const Wrapper& parameter) -> void { //
745 detail::alignParameter(byteOffset, detail::PARAMETER_TYPE_OF_PARAMETER_WRAPPER<Wrapper>, detail::ARRAY_ELEMENT_COUNT_OF_PARAMETER_WRAPPER<Wrapper>);
746 detail::writeParameter(bytes.data() + byteOffset, parameter);
747 detail::skipParameter(byteOffset, detail::PARAMETER_TYPE_OF_PARAMETER_WRAPPER<Wrapper>, detail::ARRAY_ELEMENT_COUNT_OF_PARAMETER_WRAPPER<Wrapper>);
748 detail::writeParameterTextures(textures.data() + textureIndex, parameter);
749 textureIndex += detail::TEXTURE_COUNT_OF_PARAMETER_WRAPPER<Wrapper>;
750 });
751 uploadToUniformBuffer(meta::type_list_index_v<buffer_types, Buffer>, bytes, textures, detail::PARAMETER_DESCRIPTIONS<ParameterStruct>);
752 }
753
768 template <typename Buffer>
770 uploadToStorageBuffer(meta::type_list_index_v<buffer_types, Buffer>, as_strided_bytes(newElements), sizeof(typename Buffer::fields_type));
771 }
772
789 template <typename Buffer>
791 writeToStorageBuffer(meta::type_list_index_v<buffer_types, Buffer>, elementOffset, as_strided_bytes(newElements), sizeof(typename Buffer::fields_type));
792 }
793
810 template <typename Buffer>
811 void write(uint32_t elementIndex, const typename Buffer::fields_type& newElement) requires(meta::type_list_contains_v<buffer_types, Buffer>) {
812 writeToStorageBuffer(meta::type_list_index_v<buffer_types, Buffer>, elementIndex, as_strided_bytes(StridedSpan{&newElement, 1}), sizeof(typename Buffer::fields_type));
813 }
814};
815
824template <typename Instance>
825class InstanceBuffer : public detail::InstanceBufferBase {
826public:
827 static_assert(field_struct<Instance>);
828
830 using instance_type = Instance;
831
837 explicit InstanceBuffer(Device& device)
838 : detail::InstanceBufferBase(device, sizeof(Instance)) {}
839
854 return detail::InstanceBufferBase::append(as_strided_bytes(instances), sizeof(Instance));
855 }
856
870 uint32_t push(const Instance& instance) {
871 return detail::InstanceBufferBase::append(as_strided_bytes(StridedSpan{&instance, 1}), sizeof(Instance));
872 }
873};
874
882template <typename Mesh>
884
885template <typename Vertex, typename Index, typename Parameters, typename Instance>
886class DrawCommandBuffer<graphics::Mesh<Vertex, Index, Parameters, Instance>> : public detail::DrawCommandBufferBase {
887public:
890
896 explicit DrawCommandBuffer(Device& device)
897 : detail::DrawCommandBufferBase(device) {}
898
919 void append(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceOffset, uint32_t instanceCount) requires(!same_as<Instance, NoInstance>) {
920 detail::DrawCommandBufferBase::append(shaderPipeline.lock(), mesh.lock(), instanceOffset, instanceCount);
921 }
922
945 void append(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceOffset, uint32_t instanceCount) requires(!same_as<Instance, NoInstance>) {
946 detail::DrawCommandBufferBase::append(shaderPipeline, mesh.lock(), instanceOffset, instanceCount);
947 }
948
972 void append(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceOffset, uint32_t instanceCount)
974 detail::DrawCommandBufferBase::append(std::move(shaderPipelineHandle), std::move(meshHandle), instanceOffset, instanceCount);
975 }
976
990 void append(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceCount) requires(same_as<Instance, NoInstance>) {
991 detail::DrawCommandBufferBase::append(shaderPipeline.lock(), mesh.lock(), 0, instanceCount);
992 }
993
1009 void append(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceCount) requires(same_as<Instance, NoInstance>) {
1010 detail::DrawCommandBufferBase::append(shaderPipeline, mesh.lock(), 0, instanceCount);
1011 }
1012
1029 void append(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceCount)
1031 detail::DrawCommandBufferBase::append(std::move(shaderPipelineHandle), std::move(meshHandle), 0, instanceCount);
1032 }
1033
1053 void push(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceIndex) requires(!same_as<Instance, NoInstance>) {
1054 detail::DrawCommandBufferBase::append(shaderPipeline.lock(), mesh.lock(), instanceIndex, 1);
1055 }
1056
1078 void push(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceIndex) requires(!same_as<Instance, NoInstance>) {
1079 detail::DrawCommandBufferBase::append(shaderPipeline, mesh.lock(), instanceIndex, 1);
1080 }
1081
1104 void push(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceIndex)
1106 detail::DrawCommandBufferBase::append(std::move(shaderPipelineHandle), std::move(meshHandle), instanceIndex, 1);
1107 }
1108
1121 void push(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh) requires(same_as<Instance, NoInstance>) {
1122 detail::DrawCommandBufferBase::append(shaderPipeline.lock(), mesh.lock(), 0, 1);
1123 }
1124
1139 void push(std::nullptr_t shaderPipeline, const mesh_type& mesh) requires(same_as<Instance, NoInstance>) {
1140 detail::DrawCommandBufferBase::append(shaderPipeline, mesh.lock(), 0, 1);
1141 }
1142
1159 detail::DrawCommandBufferBase::append(std::move(shaderPipelineHandle), std::move(meshHandle), 0, 1);
1160 }
1161};
1162
1175template <typename Mesh>
1177
1178template <typename Vertex, typename Index, typename Parameters, typename Instance>
1179class UnorderedDrawCommandBuffer<graphics::Mesh<Vertex, Index, Parameters, Instance>> : public detail::UnorderedDrawCommandBufferBase {
1180public:
1183
1190 : detail::UnorderedDrawCommandBufferBase(device) {}
1191
1212 void insertRange(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceOffset, uint32_t instanceCount)
1214 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline.lock(), mesh.lock(), instanceOffset, instanceCount);
1215 }
1216
1239 void insertRange(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceOffset, uint32_t instanceCount) requires(!same_as<Instance, NoInstance>) {
1240 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline, mesh.lock(), instanceOffset, instanceCount);
1241 }
1242
1267 void insertRange(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceOffset,
1268 uint32_t instanceCount) requires(!same_as<Instance, NoInstance>) {
1269 detail::UnorderedDrawCommandBufferBase::insert(std::move(shaderPipelineHandle), std::move(meshHandle), instanceOffset, instanceCount);
1270 }
1271
1285 void insertRange(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceCount) requires(same_as<Instance, NoInstance>) {
1286 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline.lock(), mesh.lock(), 0, instanceCount);
1287 }
1288
1304 void insertRange(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceCount) requires(same_as<Instance, NoInstance>) {
1305 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline, mesh.lock(), 0, instanceCount);
1306 }
1307
1325 void insertRange(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceCount)
1327 detail::UnorderedDrawCommandBufferBase::insert(std::move(shaderPipelineHandle), std::move(meshHandle), 0, instanceCount);
1328 }
1329
1349 void insert(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh, uint32_t instanceIndex) requires(!same_as<Instance, NoInstance>) {
1350 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline.lock(), mesh.lock(), instanceIndex, 1);
1351 }
1352
1374 void insert(std::nullptr_t shaderPipeline, const mesh_type& mesh, uint32_t instanceIndex) requires(!same_as<Instance, NoInstance>) {
1375 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline, mesh.lock(), instanceIndex, 1);
1376 }
1377
1401 void insert(SharedPointer<ShaderPipelineImplementation> shaderPipelineHandle, SharedPointer<MeshImplementation> meshHandle, uint32_t instanceIndex)
1403 detail::UnorderedDrawCommandBufferBase::insert(std::move(shaderPipelineHandle), std::move(meshHandle), instanceIndex, 1);
1404 }
1405
1418 void insert(const ShaderPipeline<mesh_type>& shaderPipeline, const mesh_type& mesh) requires(same_as<Instance, NoInstance>) {
1419 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline.lock(), mesh.lock(), 0, 1);
1420 }
1421
1436 void insert(std::nullptr_t shaderPipeline, const mesh_type& mesh) requires(same_as<Instance, NoInstance>) {
1437 detail::UnorderedDrawCommandBufferBase::insert(shaderPipeline, mesh.lock(), 0, 1);
1438 }
1439
1457 detail::UnorderedDrawCommandBufferBase::insert(std::move(shaderPipelineHandle), std::move(meshHandle), 0, 1);
1458 }
1459};
1460
1461} // namespace grem::graphics
1462
1463#endif
Definition Allocation.hpp:25
Definition Buffer.hpp:28
Definition SharedPointer.hpp:65
Definition StridedSpan.hpp:427
static constexpr BufferSetLayout< Buffers... > LAYOUT
Definition buffers.hpp:583
BufferSet(Device &device, const Buffers &... buffers)
Create a new buffer set from a set of existing buffers.
Definition buffers.hpp:642
void setBuffers(const Buffers &... buffers)
Assign an existing set of buffers to the buffer set.
Definition buffers.hpp:718
static constexpr BufferLayoutReference LAYOUT_REFERENCE
Definition buffers.hpp:586
meta::TypeList< Buffers... > buffer_types
Buffer type list of the buffer set.
Definition buffers.hpp:592
BufferSet(Device &device, std::nullptr_t nullPointer)
Create an empty set of buffers that is invalid until all of its buffers have been reassigned.
Definition buffers.hpp:625
void setBuffer(const Buffer &buffer)
Assign an existing buffer to a slot in the buffer set.
Definition buffers.hpp:683
BufferSet(Device &device)
Create a new set of empty buffers.
Definition buffers.hpp:605
void write(uint32_t elementIndex, const typename Buffer::fields_type &newElement)
Upload a new element to the buffer at a specific index, overriding any element that previously occupi...
Definition buffers.hpp:811
static constexpr CStringView NAME
Definition buffers.hpp:589
void setBuffer(std::nullptr_t nullPointer)
Remove a buffer from the set, making the set invalid until all of its buffers have been reassigned.
Definition buffers.hpp:664
void write(uint32_t elementOffset, StridedSpan< const typename Buffer::fields_type > newElements)
Upload new elements to a storage buffer in the buffer set at a specific offset, overriding any data t...
Definition buffers.hpp:790
void setBuffers(std::nullptr_t nullPointer)
Reset the buffer set to an empty set that is invalid until all of its buffers have been reassigned.
Definition buffers.hpp:702
void upload(StridedSpan< const typename Buffer::fields_type > newElements)
Upload a new array of data to a storage buffer in the buffer set, overriding any previous contents.
Definition buffers.hpp:769
void upload(const typename Buffer::parameters_type &newParameterValues)
Upload new parameter values to a uniform buffer in the buffer set for the next shader invocation that...
Definition buffers.hpp:738
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
void append(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceOffset, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:919
void append(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1029
graphics::Mesh< Vertex, Index, Parameters, Instance > mesh_type
Mesh type of the buffer.
Definition buffers.hpp:889
void push(std::nullptr_t shaderPipeline, const mesh_type &mesh)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1139
DrawCommandBuffer(Device &device)
Create a new empty buffer set up to contain draw commands.
Definition buffers.hpp:896
void push(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1158
void append(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:990
void push(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceIndex)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1053
void append(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceOffset, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:972
void push(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceIndex)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1104
void push(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1121
void append(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1009
void push(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceIndex)
Append a draw command to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1078
void append(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceOffset, uint32_t instanceCount)
Append a sequence of draw commands to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:945
Resource handle with shared ownership of a GPU memory buffer with copy-on-write value semantics conta...
Definition buffers.hpp:883
InstanceBuffer(Device &device)
Create a new empty buffer set up to contain the specified element type.
Definition buffers.hpp:837
uint32_t push(const Instance &instance)
Append an instance to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:870
uint32_t append(StridedSpan< const Instance > instances)
Append an array of instances to the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:853
Instance instance_type
Instance type of the buffer.
Definition buffers.hpp:830
Generic abstraction of a GPU vertex array object and its associated buffers.
Definition Mesh.hpp:209
Linked GPU shader pipeline.
Definition shaders.hpp:1508
StorageBuffer(Device &device)
Create a new empty buffer set up to contain the specified element type.
Definition buffers.hpp:519
FieldStruct fields_type
Field struct type of the buffer.
Definition buffers.hpp:498
void write(uint32_t elementIndex, const FieldStruct &newElement)
Upload a new element to the buffer at a specific index, overriding any element that previously occupi...
Definition buffers.hpp:567
void write(uint32_t elementOffset, StridedSpan< const FieldStruct > newElements)
Upload new elements to the buffer at a specific offset, overriding any data that previously occupied ...
Definition buffers.hpp:550
static constexpr BufferLayoutReference LAYOUT_REFERENCE
Definition buffers.hpp:504
static constexpr CStringView NAME
Definition buffers.hpp:507
void upload(StridedSpan< const FieldStruct > newElements)
Upload a new array of data to the buffer, overriding any previous contents.
Definition buffers.hpp:533
static constexpr StorageBufferLayout< VolumeFields, Name > LAYOUT
Definition buffers.hpp:501
UniformBuffer(Device &device)
Create a new buffer set up to contain the specified parameters, starting with uninitialized values.
Definition buffers.hpp:453
static constexpr CStringView NAME
Definition buffers.hpp:440
static constexpr UniformBufferLayout< Parameters, Name > LAYOUT
Definition buffers.hpp:434
ParameterStruct parameters_type
Parameter struct type of the buffer.
Definition buffers.hpp:431
void upload(const ParameterStruct &newParameterValues)
Upload new parameter values to the buffer for the next shader invocation that reads from it.
Definition buffers.hpp:467
static constexpr BufferLayoutReference LAYOUT_REFERENCE
Definition buffers.hpp:437
void insertRange(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1285
void insert(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceIndex)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1374
void insert(std::nullptr_t shaderPipeline, const mesh_type &mesh)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1436
void insertRange(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1325
void insert(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceIndex)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1349
void insertRange(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1304
void insertRange(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceOffset, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1267
void insert(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1456
void insertRange(std::nullptr_t shaderPipeline, const mesh_type &mesh, uint32_t instanceOffset, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1239
void insertRange(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh, uint32_t instanceOffset, uint32_t instanceCount)
Insert a sequence of draw commands into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1212
void insert(const ShaderPipeline< mesh_type > &shaderPipeline, const mesh_type &mesh)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1418
UnorderedDrawCommandBuffer(Device &device)
Create a new empty buffer set up to contain draw commands.
Definition buffers.hpp:1189
void insert(SharedPointer< ShaderPipelineImplementation > shaderPipelineHandle, SharedPointer< MeshImplementation > meshHandle, uint32_t instanceIndex)
Insert a draw command into the buffer, growing the buffer capacity if necessary.
Definition buffers.hpp:1401
graphics::Mesh< Vertex, Index, Parameters, Instance > mesh_type
Mesh type of the buffer.
Definition buffers.hpp:1182
Resource handle with shared ownership of a GPU memory buffer with copy-on-write value semantics conta...
Definition buffers.hpp:1176
Concept that checks if a type is a valid field struct type for a shader-read buffer.
Definition FieldDescription.hpp:123
Concept that checks if a type is a valid parameter struct type for a shader-read buffer.
Definition ParameterDescription.hpp:318
Definition concepts.hpp:35
Definition buffer_layouts.hpp:20
constexpr void forEachField(Aggregate &&value, auto fn)
Execute a function for each field of an aggregate.
Definition metaprogramming.hpp:1297
constexpr std::size_t type_list_index_v
Index of the first occurence of a specific type in a specialization of meta::TypeList.
Definition metaprogramming.hpp:509
constexpr bool type_list_contains_v
Whether a specialization of meta::TypeList contains a specific type.
Definition metaprogramming.hpp:475
StridedSpan(R &&range) -> StridedSpan< std::remove_reference_t< decltype(*std::data(range))>, DYNAMIC_EXTENT, sizeof(std::remove_reference_t< decltype(*std::data(range))>)>
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
auto as_strided_bytes(StridedSpan< T, N, S > s) noexcept
Definition StridedSpan.hpp:725
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635
Definition Array.hpp:20
constexpr pointer data() noexcept
Definition Array.hpp:79
Generic type-erased read-only reference to a buffer or buffer set layout.
Definition buffer_layouts.hpp:43
Type-erased read-only reference to a BufferSetLayout.
Definition buffer_layouts.hpp:37
Layout description of a BufferSet.
Definition buffer_layouts.hpp:168
Type-erased read-only reference to a StorageBufferLayout.
Definition buffer_layouts.hpp:29
Layout description of a StorageBuffer.
Definition buffer_layouts.hpp:125
Type-erased read-only reference to a UniformBufferLayout.
Definition buffer_layouts.hpp:23
Layout description of a UniformBuffer.
Definition buffer_layouts.hpp:106
Compile-time list of types.
Definition metaprogramming.hpp:347