CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUCommandBuffer.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Common.hpp"
11#include "Forward.hpp"
12
15
22
25
26#include <cstdint>
27#include <functional>
28
29namespace CeresEngine {
30
36 String name;
37
40 template<typename Processor> static constexpr void reflect(Processor&& RTTI) { CE_REFL_DATA(name); }
41 };
42
57
76
77 class CE_SCRIPT_EXPORT() GPUCommandBuffer : public TDeviceObject<GPUCommandBufferDescriptor> {
78 public:
80 using TDeviceObject::TDeviceObject;
81
85
89
90 public: // Events
94
95 public: // Drawing
107 virtual void bindResourceSet(GPUResourceSet& resourceSet, UInt32 firstSet = 0, Int32 offset = -1) = 0;
108
110 void bindResourceSet(const GPUResourceSetPtr& resourceSet, const UInt32 firstSet = 0, const Int32 offset = -1) { bindResourceSet(*resourceSet, firstSet, offset); }
111
117 virtual void bindVertexBuffer(GPUBuffer& vertexBuffer, UInt32 offset = 0, UInt32 slot = 0) = 0;
118
120 void bindVertexBuffer(const GPUBufferPtr& vertexBuffer, const UInt32 offset = 0, const UInt32 slot = 0) { bindVertexBuffer(*vertexBuffer, offset, slot); }
121
124 virtual void bindVertexBuffer(const GPUVertexBuffer& vertexBuffer);
125
131 virtual void bindIndexBuffer(GPUBuffer& indexBuffer, UInt32 offset = 0, IndexType indexType = IndexType::UInt32) = 0;
132
134 void bindIndexBuffer(const GPUBufferPtr& indexBuffer, const UInt32 offset = 0, const IndexType indexType = IndexType::UInt32) {
135 bindIndexBuffer(*indexBuffer, offset, indexType);
136 }
137
140 virtual void bindIndexBuffer(const GPUIndexBuffer& indexBuffer);
141
150 virtual void draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) = 0;
151
161 virtual void draw(GPUBuffer& buffer, UInt32 drawCount, UInt32 bufferOffset = 0, UInt32 stride = sizeof(GPUDrawIndirectCommand)) = 0;
162
164 void draw(const GPUIndirectBuffer& buffer, UInt32 drawCount, UInt32 stride = sizeof(GPUDrawIndirectCommand));
165
175 virtual void drawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) = 0;
176
187 virtual void drawIndexed(GPUBuffer& buffer, UInt32 drawCount, UInt32 bufferOffset = 0, UInt32 stride = sizeof(GPUDrawIndexedIndirectCommand)) = 0;
188
190 void drawIndexed(const GPUIndirectBuffer& buffer, UInt32 drawCount, UInt32 stride = sizeof(GPUDrawIndexedIndirectCommand));
191
200 virtual void dispatch(UInt32 groupCountX, UInt32 groupCountY, UInt32 groupCountZ) = 0;
201
202 public: // Dynamic States
209 CE_SCRIPT_EXPORT(property = "none")
210 virtual void setViewport(const Viewport& viewport);
211
221 virtual void setViewports(const SmallVector<Viewport, 16>& viewports) = 0;
222
231 CE_SCRIPT_EXPORT(property = "none")
232 virtual void setScissor(const Scissor& scissor);
233
244 virtual void setScissors(const SmallVector<Scissor, 16>& scissors) = 0;
245
246 public: // Ray-Tracing
247 void buildAccelerationStructures();
248 void buildAccelerationStructuresIndirect();
249
250 void copyAccelerationStructure();
251 void copyAccelerationStructureToMemory();
252 void copyMemoryToAccelerationStructure();
253 void writeAccelerationStructuresProperties();
254
255 void setRayTracingPipelineStackSize();
256
257 void traceRays();
258 void traceRaysIndirect();
259
260 public: // Mesh-shaders
266 virtual void drawMeshTasks(UInt32 groupCountX, UInt32 groupCountY, UInt32 groupCountZ) = 0;
267
275 virtual void drawMeshTasksIndirect(GPUBuffer& buffer, UInt64 offset, UInt32 drawCount, UInt32 stride) = 0;
276
292 virtual void drawMeshTasksIndirect(GPUBuffer& buffer, UInt64 offset, GPUBuffer& countBuffer, UInt64 countBufferOffset, uint32_t maxDrawCount, uint32_t stride) = 0;
293
294 public: // Buffer
313 virtual void updateBuffer(GPUBuffer& dstBuffer, std::uint64_t dstOffset, const void* data, std::uint16_t dataSize) = 0;
314
330 virtual void copyBuffer(GPUBuffer& dstBuffer, std::uint64_t dstOffset, GPUBuffer& srcBuffer, std::uint64_t srcOffset, std::uint64_t size) = 0;
331
346 virtual void fillBuffer(GPUBuffer& dstBuffer, std::uint64_t dstOffset, std::uint32_t value, std::uint64_t fillSize = ~0u) = 0;
347
348 public: // Image read, write & copy.
382 virtual void copyBufferFromImage(GPUBuffer& dstBuffer, std::uint64_t dstOffset, GPUImage& srcImage, const GPUImageRegion& srcImageRegion,
383 std::uint32_t rowStride = 0, std::uint32_t layerStride = 0) = 0;
384
405 virtual void copyImage(GPUImage& dstImage, const GPUImageLocation& dstLocation, GPUImage& srcImage, const GPUImageLocation& srcLocation,
406 const TExtent3<UInt32>& extent) = 0;
407
443 virtual void copyImageFromBuffer(GPUImage& dstImage, const GPUImageRegion& dstRegion, GPUBuffer& srcBuffer, std::uint64_t srcOffset,
444 std::uint32_t rowStride = 0, std::uint32_t layerStride = 0) = 0;
445
446 // TODO: Write docs.
447 virtual void resolveImage(GPUImage& dstImage, const GPUImageLocation& dstLocation, GPUImage& srcImage, const GPUImageLocation& srcLocation,
448 const TExtent3<UInt32>& extent) = 0;
449
451 virtual void clear(GPUImage& image) = 0;
452
461 virtual void generateMips(GPUImage& image) = 0;
462
483 virtual void generateMips(GPUImage& texture, const GPUImageSubresource& subresource) = 0;
484
485 public: // Synchronization
487 virtual void barrier(GPUImage& image, GPUImageLayout layout) = 0;
488
489 public: // Recording
496 virtual void begin() = 0;
497
504 virtual void end() = 0;
505
506 virtual void wait() = 0;
507
510 template<typename Func> decltype(auto) record(Func&& recorder) {
511 begin();
512 CE_SCOPE_EXIT { end(); };
513 return recorder();
514 }
515 };
516
517} // namespace CeresEngine
518
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
#define CE_SCOPE_EXIT
Definition ScopeExit.hpp:40
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUBuffer.hpp:124
Definition GPUCommandBuffer.hpp:77
virtual void bindIndexBuffer(const GPUIndexBuffer &indexBuffer)
Binds a index buffer for drawing.
GPUCommandBuffer & operator=(GPUCommandBuffer &&)=delete
Event< void()> didFinish
An event triggered whenever the command buffer has finished execution.
Definition GPUCommandBuffer.hpp:93
GPUCommandBuffer(const GPUCommandBuffer &)=delete
Deleted copy constructor.
GPUCommandBuffer & operator=(const GPUCommandBuffer &)=delete
void bindResourceSet(const GPUResourceSetPtr &resourceSet, const UInt32 firstSet=0, const Int32 offset=-1)
Definition GPUCommandBuffer.hpp:110
GPUCommandBuffer(GPUCommandBuffer &&)=delete
Deleted move constructor.
void bindVertexBuffer(const GPUBufferPtr &vertexBuffer, const UInt32 offset=0, const UInt32 slot=0)
Definition GPUCommandBuffer.hpp:120
virtual void bindVertexBuffer(const GPUVertexBuffer &vertexBuffer)
Binds a vertex buffer for drawing.
Definition GPUImage.hpp:331
Definition GPUBufferObject.hpp:169
Definition GPUBufferObject.hpp:314
A RenderAPI object that holds a set of resources that can be bound into shader.
Definition GPUResourceSet.hpp:735
Definition GPUBufferObject.hpp:126
Definition Common.hpp:62
Base template for the event class.
Definition Event.hpp:27
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
GPUImageLayout
Definition GPUImage.hpp:65
std::int32_t Int32
Definition DataTypes.hpp:21
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
Command buffer descriptor structure.
Definition GPUCommandBuffer.hpp:32
Structure specifying a draw indirect command.
Definition GPUCommandBuffer.hpp:59
UInt32 indexCount
The number of vertices to draw.
Definition GPUCommandBuffer.hpp:61
UInt32 firstInstance
The instance ID of the first instance to draw.
Definition GPUCommandBuffer.hpp:74
UInt32 instanceCount
The number of instances to draw.
Definition GPUCommandBuffer.hpp:64
UInt32 firstIndex
The base index within the index buffer.
Definition GPUCommandBuffer.hpp:67
Int32 vertexOffset
The value added to the vertex index before indexing into the vertex buffer.
Definition GPUCommandBuffer.hpp:71
Structure specifying a draw indirect command.
Definition GPUCommandBuffer.hpp:44
UInt32 vertexCount
The number of vertices to draw.
Definition GPUCommandBuffer.hpp:46
UInt32 firstInstance
The instance ID of the first instance to draw.
Definition GPUCommandBuffer.hpp:55
UInt32 firstVertex
The index of the first vertex to draw.
Definition GPUCommandBuffer.hpp:52
UInt32 instanceCount
The number of instances to draw.
Definition GPUCommandBuffer.hpp:49
Image location structure: MIP-map level and offset.
Definition GPUImage.hpp:120
Image region structure: Subresource (MIP-map level and array layer range), offset,...
Definition GPUImage.hpp:156
Image subresource descriptor which specifies the array layer and MIP-map level range of a image resou...
Definition GPUImage.hpp:77
Definition IndexType.hpp:20
Definition GPUGraphicsPipeline.hpp:281
Definition GPUGraphicsPipeline.hpp:214