Nebula
Loading...
Searching...
No Matches
commandbuffer.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10#include "ids/id.h"
11#include "util/stack.h"
12#include "coregraphics/config.h"
14#include "util/fixedarray.h"
15#include "coregraphics/config.h"
16#include "math/rectangle.h"
18#include "ids/idallocator.h"
19#include "coregraphics/memory.h"
20#include "math/vec4.h"
21
22namespace CoreGraphics
23{
24
25struct BufferId;
26struct TextureId;
27struct ResourceTableId;
28struct VertexLayoutId;
29class PrimitiveGroup;
30struct ShaderProgramId;
31struct BarrierId;
32struct EventId;
33struct PassId;
34struct PipelineId;
35struct BlasId;
36struct TlasId;
37
38struct TextureBarrierInfo;
39struct BufferBarrierInfo;
40struct AccelerationStructureBarrierInfo;
41
43{
44 NoQueries = 0x0
45 , Occlusion = 0x1
46 , Statistics = 0x2
47 , Timestamps = 0x4
48 , NumBits = 3
49};
52
64
67
76
78{
80 uint rowLength = 0; // for buffer to image copies
81 uint imageHeight = 0; // for buffer to image copies
82};
83
84#ifdef NEBULA_ENABLE_PROFILING
85struct FrameProfilingMarker
86{
88 Math::vec4 color;
89 Util::String name;
90 IndexT gpuBegin;
91 IndexT gpuEnd;
92 uint64_t start;
93 uint64_t duration;
95};
96#endif
97
98//------------------------------------------------------------------------------
102
104{
106 bool resetable : 1; // Allow buffers created from this pool to be resetable
107 bool shortlived : 1; // Hint if the buffers allocated from this pool will be short lived
108};
109
114
116{
117 bool subBuffer : 1; // create buffer to be executed on another command buffer (subBuffer must be 0 on the other buffer)
121
122#if NEBULA_GRAPHICS_DEBUG
123 const char* name;
124#endif
125
127 : subBuffer(false)
128 , pool(InvalidCmdBufferPoolId)
132 , name(nullptr)
133#endif
134 {};
135};
136
138{
139 bool submitOnce : 1;
142};
143
145{
146 bool allowRelease : 1; // release resources when clearing (don't use if buffer converges in size)
147};
148
154
157
161void DestroyCmdBuffer(const CmdBufferId id);
164
166void CmdBeginRecord(const CmdBufferId id, const CmdBufferBeginInfo& info);
168void CmdEndRecord(const CmdBufferId id);
169
171void CmdReset(const CmdBufferId id, const CmdBufferClearInfo& info);
172
174void CmdSetVertexBuffer(const CmdBufferId id, IndexT streamIndex, const CoreGraphics::BufferId& buffer, SizeT bufferOffset);
178void CmdSetIndexBuffer(const CmdBufferId id, const IndexType::Code indexType, const CoreGraphics::BufferId& buffer, SizeT bufferOffset);
181
183void CmdSetShaderProgram(const CmdBufferId id, const CoreGraphics::ShaderProgramId pro, bool bindGlobals = true);
187void CmdSetResourceTable(const CmdBufferId id, const CoreGraphics::ResourceTableId table, const IndexT slot, CoreGraphics::ShaderPipeline pipeline, uint32 numOffsets, uint32* offsets);
189void CmdPushConstants(const CmdBufferId id, ShaderPipeline pipeline, uint offset, uint size, const void* data);
193void CmdSetGraphicsPipeline(const CmdBufferId buf, const PipelineId pipeline);
195void CmdSetRayTracingPipeline(const CmdBufferId buf, const PipelineId pipeline);
196
198void CmdBarrier(
199 const CmdBufferId id,
203 const IndexT fromQueue = InvalidIndex,
204 const IndexT toQueue = InvalidIndex,
205 const char* name = nullptr
206);
208void CmdBarrier(
209 const CmdBufferId id,
214 const IndexT fromQueue = InvalidIndex,
215 const IndexT toQueue = InvalidIndex,
216 const char* name = nullptr
217);
219void CmdBarrier(
220 const CmdBufferId id,
225 const IndexT fromQueue = InvalidIndex,
226 const IndexT toQueue = InvalidIndex,
227 const char* name = nullptr
228);
230void CmdBarrier(
231 const CmdBufferId id,
236 const IndexT fromQueue = InvalidIndex,
237 const IndexT toQueue = InvalidIndex,
238 const char* name = nullptr
239);
241void CmdBarrier(
242 const CmdBufferId id,
249 const IndexT fromQueue = InvalidIndex,
250 const IndexT toQueue = InvalidIndex,
251 const char* name = nullptr
252);
253
255void CmdHandover(
256 const CmdBufferId from,
257 const CmdBufferId to,
262 const IndexT fromQueue = InvalidIndex,
263 const IndexT toQueue = InvalidIndex,
264 const char* name = nullptr
265);
266
267
269void CmdBarrier(const CmdBufferId id, const CoreGraphics::BarrierId barrier);
273void CmdWaitEvent(
274 const CmdBufferId id
275 , const EventId ev
276 , const CoreGraphics::PipelineStage waitStage
277 , const CoreGraphics::PipelineStage signalStage
278);
281
283void CmdBeginPass(const CmdBufferId id, const CoreGraphics::PassId pass);
285void CmdNextSubpass(const CmdBufferId id);
287void CmdEndPass(const CmdBufferId id);
289void CmdDraw(const CmdBufferId id, const CoreGraphics::PrimitiveGroup& pg);
291void CmdDraw(const CmdBufferId id, SizeT numInstances, const CoreGraphics::PrimitiveGroup& pg);
293void CmdDraw(const CmdBufferId id, SizeT numInstances, IndexT baseInstance, const CoreGraphics::PrimitiveGroup& pg);
295void CmdDrawIndirect(const CmdBufferId id, const CoreGraphics::BufferId buffer, IndexT bufferOffset, SizeT numDraws, SizeT stride);
297void CmdDrawIndirectIndexed(const CmdBufferId id, const CoreGraphics::BufferId buffer, IndexT bufferOffset, SizeT numDraws, SizeT stride);
299void CmdDispatch(const CmdBufferId id, int dimX, int dimY, int dimZ);
301void CmdResolve(const CmdBufferId id, const CoreGraphics::TextureId source, const CoreGraphics::TextureCopy sourceCopy, const CoreGraphics::TextureId dest, const CoreGraphics::TextureCopy destCopy);
303void CmdBuildBlas(const CmdBufferId id, const CoreGraphics::BlasId blas);
305void CmdBuildTlas(const CmdBufferId id, const CoreGraphics::TlasId tlas);
306
308{
309 struct Entry
310 {
311 CoreGraphics::DeviceAddress baseAddress;
312 CoreGraphics::DeviceSize entrySize;
314 };
315
317};
319void CmdRaysDispatch(const CmdBufferId id, const RayDispatchTable& table, int dimX, int dimY, int dimZ);
321void CmdDrawMeshlets(const CmdBufferId id, int dimX, int dimY, int dimZ);
322
324void CmdCopy(
325 const CmdBufferId id
326 , const CoreGraphics::TextureId fromTexture
328 , const CoreGraphics::TextureId toTexture
330);
332void CmdCopy(
333 const CmdBufferId id
334 , const CoreGraphics::TextureId fromTexture
336 , const CoreGraphics::BufferId toBuffer
338);
340void CmdCopy(
341 const CmdBufferId id
342 , const CoreGraphics::BufferId fromBuffer
344 , const CoreGraphics::BufferId toBuffer
346 , const SizeT size
347);
349void CmdCopy(
350 const CmdBufferId id
351 , const CoreGraphics::BufferId fromBuffer
353 , const CoreGraphics::TextureId toTexture
355);
357void CmdBlit(
358 const CmdBufferId id
359 , const CoreGraphics::TextureId fromTexture
360 , const CoreGraphics::TextureCopy& from
361 , const CoreGraphics::TextureId toTexture
362 , const CoreGraphics::TextureCopy& to
363);
364
366void CmdSetViewports(const CmdBufferId id, const Util::FixedArray<Math::rectangle<int>>& viewports);
370void CmdSetViewport(const CmdBufferId id, const Math::rectangle<int>& rect, int index);
372void CmdSetScissorRect(const CmdBufferId id, const Math::rectangle<int>& rect, int index);
374void CmdSetStencilRef(const CmdBufferId id, const uint frontRef, const uint backRef);
376void CmdSetStencilReadMask(const CmdBufferId id, const uint readMask);
378void CmdSetStencilWriteMask(const CmdBufferId id, const uint writeMask);
379
381void CmdUpdateBuffer(
382 const CmdBufferId id
383 , const CoreGraphics::BufferId buffer
384 , uint offset
385 , uint size
386 , const void* data
387);
388
393
398
399#if NEBULA_GRAPHICS_DEBUG
401void CmdBeginMarker(const CmdBufferId id, const Math::vec4& color, const char* name);
403void CmdEndMarker(const CmdBufferId id);
405void CmdInsertMarker(const CmdBufferId id, const Math::vec4& color, const char* name);
406#endif
407
410
411#if NEBULA_ENABLE_PROFILING
413bool CmdRecordsMarkers(const CmdBufferId id);
415Util::Array<CoreGraphics::FrameProfilingMarker>&& CmdMoveProfilingMarkers(const CmdBufferId id);
417uint CmdGetMarkerOffset(const CmdBufferId id);
418#endif
419
420#if NEBULA_GRAPHICS_DEBUG
421struct CmdMarkerScope
422{
423 const CmdBufferId id;
424
425 CmdMarkerScope(const CmdBufferId id, const Math::vec4& color, const char* name)
426 : id(id)
427 {
428 CoreGraphics::CmdBeginMarker(id, color, name);
429 }
430 ~CmdMarkerScope()
431 {
432 CoreGraphics::CmdEndMarker(this->id);
433 }
434};
435
436#endif
437
438#if NEBULA_GRAPHICS_DEBUG
439 #define N_CMD_SCOPE(buf, color, name) CoreGraphics::CmdMarkerScope __##cmdscope(buf, color, name)
440#else
441 #define N_CMD_SCOPE(x, y, z)
442#endif
443
444
445} // namespace CoreGraphics
446
Code
index types enum
Definition indextype.h:22
Defines a group of primitives as a subset of a vertex buffer and index buffer plus the primitive topo...
Definition primitivegroup.h:20
Code
enumeration
Definition primitivetopology.h:23
A 2d rectangle class.
Definition rectangle.h:20
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Nebula's stack class (a FILO container).
Definition stack.h:19
#define _DECL_ACQUIRE_RELEASE(ty)
Definition idallocator.h:88
#define ID_24_8_TYPE(x)
Definition id.h:132
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
void CmdStartPipelineQueries(const CmdBufferId id)
Start pipeline statistics.
Definition vkcommandbuffer.cc:1541
const CmdBufferId CreateCmdBuffer(const CmdBufferCreateInfo &info)
create new command buffer
Definition vkcommandbuffer.cc:143
void CmdUpdateBuffer(const CmdBufferId id, const CoreGraphics::BufferId buffer, uint offset, uint size, const void *data)
Update buffer using memory pointer in command buffer.
Definition vkcommandbuffer.cc:1503
void CmdSetStencilRef(const CmdBufferId id, const uint frontRef, const uint backRef)
Set the stencil reference values.
Definition vkcommandbuffer.cc:1465
void CmdDispatch(const CmdBufferId id, int dimX, int dimY, int dimZ)
Perform computation.
Definition vkcommandbuffer.cc:1112
void CmdSetViewport(const CmdBufferId id, const Math::rectangle< int > &rect, int index)
Sets a viewport for a certain index.
Definition vkcommandbuffer.cc:1433
void CmdSetShaderProgram(const CmdBufferId id, const CoreGraphics::ShaderProgramId pro, bool bindGlobals=true)
Set shader program.
Definition vkcommandbuffer.cc:440
void CmdBuildTlas(const CmdBufferId id, const CoreGraphics::TlasId tlas)
Build TLAS.
Definition vkcommandbuffer.cc:1165
void CmdDraw(const CmdBufferId id, const CoreGraphics::PrimitiveGroup &pg)
Draw primitives.
Definition vkcommandbuffer.cc:1053
void CmdDrawMeshlets(const CmdBufferId id, int dimX, int dimY, int dimZ)
Draw meshlets.
Definition vkcommandbuffer.cc:1214
void CmdPushConstants(const CmdBufferId id, ShaderPipeline pipeline, uint offset, uint size, const void *data)
Set push constants.
Definition vkcommandbuffer.cc:553
void CmdBeginPass(const CmdBufferId id, const CoreGraphics::PassId pass)
Begin pass.
Definition vkcommandbuffer.cc:1008
void CmdCopy(const CmdBufferId id, const CoreGraphics::TextureId fromTexture, const Util::Array< CoreGraphics::TextureCopy, 4 > &from, const CoreGraphics::TextureId toTexture, const Util::Array< CoreGraphics::TextureCopy, 4 > &to)
Copy between textures.
Definition vkcommandbuffer.cc:1224
void CmdSetPrimitiveTopology(const CmdBufferId id, const CoreGraphics::PrimitiveTopology::Code topo)
Set the type of topology used.
Definition vkcommandbuffer.cc:420
QueueType
Definition config.h:40
@ GraphicsQueueType
Definition config.h:41
void CmdSetStencilWriteMask(const CmdBufferId id, const uint writeMask)
Set the stencil write mask.
Definition vkcommandbuffer.cc:1493
void CmdEndOcclusionQueries(const CmdBufferId id)
End occlusion queries.
Definition vkcommandbuffer.cc:1527
void CmdWaitEvent(const CmdBufferId id, const EventId ev, const CoreGraphics::PipelineStage waitStage, const CoreGraphics::PipelineStage signalStage)
Signals an event.
Definition vkcommandbuffer.cc:974
void CmdSetStencilReadMask(const CmdBufferId id, const uint readMask)
Set the stencil read mask (compare mask(.
Definition vkcommandbuffer.cc:1483
void CmdBlit(const CmdBufferId id, const CoreGraphics::TextureId fromTexture, const CoreGraphics::TextureCopy &from, const CoreGraphics::TextureId toTexture, const CoreGraphics::TextureCopy &to)
Blit textures.
Definition vkcommandbuffer.cc:1358
void CmdBuildBlas(const CmdBufferId id, const CoreGraphics::BlasId blas)
Build BLAS.
Definition vkcommandbuffer.cc:1152
void CmdSetViewports(const CmdBufferId id, const Util::FixedArray< Math::rectangle< int > > &viewports)
Set viewport array.
Definition vkcommandbuffer.cc:1393
void CmdSetScissorRect(const CmdBufferId id, const Math::rectangle< int > &rect, int index)
Sets a scissor rect for a certain index.
Definition vkcommandbuffer.cc:1450
void CmdDrawIndirect(const CmdBufferId id, const CoreGraphics::BufferId buffer, IndexT bufferOffset, SizeT numDraws, SizeT stride)
Draw indirect, draws is the amount of draws in the buffer, and stride is the byte offset between each...
Definition vkcommandbuffer.cc:1092
void CmdSetResourceTable(const CmdBufferId id, const CoreGraphics::ResourceTableId table, const IndexT slot, CoreGraphics::ShaderPipeline pipeline, const Util::FixedArray< uint > &offsets)
Set resource table.
Definition vkcommandbuffer.cc:517
CmdPipelineBuildBits
Definition commandbuffer.h:54
void CmdBeginRecord(const CmdBufferId id, const CmdBufferBeginInfo &info)
begin recording to command buffer
Definition vkcommandbuffer.cc:298
const CmdBufferPoolId CreateCmdBufferPool(const CmdBufferPoolCreateInfo &info)
create new command buffer pool
Definition vkcommandbuffer.cc:104
void CmdReset(const CmdBufferId id, const CmdBufferClearInfo &info)
clear the command buffer to be empty
Definition vkcommandbuffer.cc:340
void CmdEndRecord(const CmdBufferId id)
end recording command buffer, it may be submitted after this is done
Definition vkcommandbuffer.cc:330
void CmdHandover(const CmdBufferId from, const CmdBufferId to, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage, const Util::FixedArray< TextureBarrierInfo, true > &textures, const Util::FixedArray< BufferBarrierInfo, true > &buffers, const IndexT fromQueue=InvalidIndex, const IndexT toQueue=InvalidIndex, const char *name=nullptr)
Handover.
Definition vkcommandbuffer.cc:810
void DeferredDestroyCmdBuffer(const CmdBufferId id)
Issue command buffer for deletion (happens when GPU is finished with it)
Definition vkcommandbuffer.cc:269
void CmdSetScissors(const CmdBufferId id, const Util::FixedArray< Math::rectangle< int > > &rects)
Set scissor array.
Definition vkcommandbuffer.cc:1414
void CmdResolve(const CmdBufferId id, const CoreGraphics::TextureId source, const CoreGraphics::TextureCopy sourceCopy, const CoreGraphics::TextureId dest, const CoreGraphics::TextureCopy destCopy)
Resolve MSAA source to non-MSAA target.
Definition vkcommandbuffer.cc:1122
void CmdStartOcclusionQueries(const CmdBufferId id)
Start occlusion queries.
Definition vkcommandbuffer.cc:1513
ShaderPipeline
Definition config.h:111
void CmdNextSubpass(const CmdBufferId id)
Progress to next subpass.
Definition vkcommandbuffer.cc:1031
void DestroyCmdBuffer(const CmdBufferId id)
Destroy the command buffer immediately (use with caution as buffer might be in use by GPU)
Definition vkcommandbuffer.cc:237
void CmdFinishQueries(const CmdBufferId id)
Finish queries.
void CmdDrawIndirectIndexed(const CmdBufferId id, const CoreGraphics::BufferId buffer, IndexT bufferOffset, SizeT numDraws, SizeT stride)
Draw indirect, draws is the amount of draws in the buffer, and stride is the byte offset between each...
Definition vkcommandbuffer.cc:1102
void CmdSetGraphicsPipeline(const CmdBufferId id)
Create (if necessary) and bind pipeline based on state thus far.
Definition vkcommandbuffer.cc:598
void CmdResetEvent(const CmdBufferId id, const CoreGraphics::EventId ev, const CoreGraphics::PipelineStage stage)
Signals an event.
Definition vkcommandbuffer.cc:997
ImageBits
Definition config.h:82
void CmdSetVertexBuffer(const CmdBufferId id, IndexT streamIndex, const CoreGraphics::BufferId &buffer, SizeT bufferOffset)
Set vertex buffer.
Definition vkcommandbuffer.cc:352
CmdBufferQueryBits
Definition commandbuffer.h:43
@ Occlusion
Definition commandbuffer.h:45
@ NoQueries
Definition commandbuffer.h:44
@ Statistics
Definition commandbuffer.h:46
@ NumBits
Definition commandbuffer.h:48
@ Timestamps
Definition commandbuffer.h:47
void CmdRaysDispatch(const CmdBufferId id, const RayDispatchTable &table, int dimX, int dimY, int dimZ)
Fire rays.
Definition vkcommandbuffer.cc:1178
void CmdEndPipelineQueries(const CmdBufferId id)
End pipeline statistics.
Definition vkcommandbuffer.cc:1555
void CmdSignalEvent(const CmdBufferId id, const CoreGraphics::EventId ev, const CoreGraphics::PipelineStage stage)
Signals an event.
Definition vkcommandbuffer.cc:963
void CmdSetVertexLayout(const CmdBufferId id, const CoreGraphics::VertexLayoutId &vl)
Set vertex layout.
Definition vkcommandbuffer.cc:368
BarrierDomain
Definition config.h:185
PipelineStage
Definition config.h:191
void CmdSetIndexBuffer(const CmdBufferId id, const IndexType::Code indexType, const CoreGraphics::BufferId &buffer, SizeT bufferOffset)
Set index buffer.
Definition vkcommandbuffer.cc:386
void DestroyCmdBufferPool(const CmdBufferPoolId pool)
destroy command buffer pool
Definition vkcommandbuffer.cc:134
void CmdEndPass(const CmdBufferId id)
End pass.
Definition vkcommandbuffer.cc:1043
void CmdBarrier(const CmdBufferId id, CoreGraphics::PipelineStage fromStage, CoreGraphics::PipelineStage toStage, CoreGraphics::BarrierDomain domain, const Util::FixedArray< TextureBarrierInfo, true > &textures, const IndexT fromQueue, const IndexT toQueue, const char *name)
Insert pipeline barrier.
Definition commandbuffer.cc:14
void CmdSetRayTracingPipeline(const CmdBufferId buf, const PipelineId pipeline)
Set ray tracing pipeline.
Definition vkcommandbuffer.cc:667
id
Definition resourceid.h:37
Compile time configuration options for the CoreGraphics subsystem.
#define NEBULA_GRAPHICS_DEBUG
Definition config.h:322
Graphics memory interface.
#define __ImplementEnumComparisonOperators(type)
#define __ImplementEnumBitOperators(type)
Definition barrier.h:21
Definition accelerationstructure.h:48
Definition commandbuffer.h:78
uint rowLength
Definition commandbuffer.h:80
uint offset
Definition commandbuffer.h:79
uint imageHeight
Definition commandbuffer.h:81
Definition buffer.h:23
Definition commandbuffer.h:138
bool submitDuringPass
Definition commandbuffer.h:140
bool submitOnce
Definition commandbuffer.h:139
bool resubmittable
Definition commandbuffer.h:141
Definition commandbuffer.h:145
bool allowRelease
Definition commandbuffer.h:146
Definition commandbuffer.h:116
CmdBufferQueryBits queryTypes
Definition commandbuffer.h:120
bool subBuffer
Definition commandbuffer.h:117
CmdBufferPoolId pool
Definition commandbuffer.h:118
CmdBufferCreateInfo()
Definition commandbuffer.h:126
QueueType usage
Definition commandbuffer.h:119
Definition commandbuffer.h:155
Definition commandbuffer.h:150
Util::Stack< CoreGraphics::FrameProfilingMarker > markerStack
Definition commandbuffer.h:151
Util::Array< CoreGraphics::FrameProfilingMarker > finishedMarkers
Definition commandbuffer.h:152
Definition commandbuffer.h:104
CoreGraphics::QueueType queue
Definition commandbuffer.h:105
bool resetable
Definition commandbuffer.h:106
bool shortlived
Definition commandbuffer.h:107
Definition commandbuffer.h:101
Definition event.h:24
Definition pass.h:28
Definition pipeline.h:16
Definition commandbuffer.h:310
ubyte numEntries
Definition commandbuffer.h:313
CoreGraphics::DeviceAddress baseAddress
Definition commandbuffer.h:311
CoreGraphics::DeviceSize entrySize
Definition commandbuffer.h:312
Definition commandbuffer.h:308
Entry missEntry
Definition commandbuffer.h:316
Entry hitEntry
Definition commandbuffer.h:316
Entry genEntry
Definition commandbuffer.h:316
Entry callableEntry
Definition commandbuffer.h:316
Definition resourcetable.h:95
struct for texture copies
Definition commandbuffer.h:70
ImageBits bits
Definition commandbuffer.h:74
uint mip
Definition commandbuffer.h:72
Math::rectangle< SizeT > region
Definition commandbuffer.h:71
uint layer
Definition commandbuffer.h:73
texture type
Definition texture.h:25
Definition accelerationstructure.h:98
Definition vertexlayout.h:16
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
static const int InvalidIndex
Definition types.h:54
#define N_BIT(x)
Definition types.h:59
unsigned char ubyte
Definition types.h:34
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
uint32_t uint32
Definition types.h:38
int IndexT
Definition types.h:48