Skip to content

Commit

Permalink
Pass encoders (#106)
Browse files Browse the repository at this point in the history
* introduce RenderPassEncoder, ComputePassEncoder and RayTracingPassEncoder

* pushDebugGroup/popDebugGroup

* add insertDebugMarker

* require no pass

* fix example

* add pushDebugGroup/popDebugGroup/insertDebugMarker to pass encoders

* fixes
  • Loading branch information
skallweitNV authored Nov 14, 2024
1 parent fcff089 commit aa89fde
Show file tree
Hide file tree
Showing 37 changed files with 1,107 additions and 582 deletions.
4 changes: 2 additions & 2 deletions examples/surface/example-surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class ExampleSurface : public ExampleBase
RenderPassDesc renderPass;
renderPass.colorAttachments = &colorAttachment;
renderPass.colorAttachmentCount = 1;
commandEncoder->beginRenderPass(renderPass);
commandEncoder->endRenderPass();
auto passEncoder = commandEncoder->beginRenderPass(renderPass);
passEncoder->end();
queue->submit(commandEncoder->finish());

surface->present();
Expand Down
111 changes: 64 additions & 47 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1642,11 +1642,72 @@ class ICommandBuffer : public ISlangUnknown
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) = 0;
};

class IPassEncoder : public ISlangUnknown
{
SLANG_COM_INTERFACE(0x159cd708, 0x4762, 0x4f30, {0xb5, 0x3f, 0xbe, 0x2a, 0xb5, 0x7d, 0x7c, 0x46});

public:
virtual SLANG_NO_THROW void SLANG_MCALL pushDebugGroup(const char* name, float rgbColor[3]) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL popDebugGroup() = 0;
virtual SLANG_NO_THROW void SLANG_MCALL insertDebugMarker(const char* name, float rgbColor[3]) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL end() = 0;
};

class IRenderPassEncoder : public IPassEncoder
{
SLANG_COM_INTERFACE(0x4f904e1a, 0xa5ed, 0x4496, {0xaa, 0xc6, 0xde, 0xcf, 0x68, 0x1e, 0x6c, 0x74});

public:
virtual SLANG_NO_THROW void SLANG_MCALL setRenderState(const RenderState& state) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL draw(const DrawArguments& args) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL drawIndexed(const DrawArguments& args) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL drawIndirect(
GfxCount maxDrawCount,
IBuffer* argBuffer,
Offset argOffset,
IBuffer* countBuffer = nullptr,
Offset countOffset = 0
) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL drawIndexedIndirect(
GfxCount maxDrawCount,
IBuffer* argBuffer,
Offset argOffset,
IBuffer* countBuffer = nullptr,
Offset countOffset = 0
) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL drawMeshTasks(GfxCount x, GfxCount y, GfxCount z) = 0;
};

class IComputePassEncoder : public IPassEncoder
{
SLANG_COM_INTERFACE(0x8479334f, 0xfb45, 0x471c, {0xb7, 0x75, 0x94, 0xa5, 0x76, 0x72, 0x32, 0xc8});

public:
virtual SLANG_NO_THROW void SLANG_MCALL setComputeState(const ComputeState& state) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL dispatchCompute(GfxCount x, GfxCount y, GfxCount z) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL dispatchComputeIndirect(IBuffer* argBuffer, Offset offset) = 0;
};

class IRayTracingPassEncoder : public IPassEncoder
{
SLANG_COM_INTERFACE(0x4fe41081, 0x819c, 0x4fdc, {0x80, 0x78, 0x40, 0x31, 0x9c, 0x01, 0xff, 0xad});

public:
virtual SLANG_NO_THROW void SLANG_MCALL setRayTracingState(const RayTracingState& state) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL
dispatchRays(GfxIndex rayGenShaderIndex, GfxCount width, GfxCount height, GfxCount depth) = 0;
};

class ICommandEncoder : public ISlangUnknown
{
SLANG_COM_INTERFACE(0x8ee39d55, 0x2b07, 0x4e61, {0x8f, 0x13, 0x1d, 0x6c, 0x01, 0xa9, 0x15, 0x43});

public:
virtual SLANG_NO_THROW IRenderPassEncoder* SLANG_MCALL beginRenderPass(const RenderPassDesc& desc) = 0;
virtual SLANG_NO_THROW IComputePassEncoder* SLANG_MCALL beginComputePass() = 0;
virtual SLANG_NO_THROW IRayTracingPassEncoder* SLANG_MCALL beginRayTracingPass() = 0;

virtual SLANG_NO_THROW void SLANG_MCALL
copyBuffer(IBuffer* dst, Offset dstOffset, IBuffer* src, Offset srcOffset, Size size) = 0;

Expand Down Expand Up @@ -1705,51 +1766,6 @@ class ICommandEncoder : public ISlangUnknown
virtual SLANG_NO_THROW void SLANG_MCALL
resolveQuery(IQueryPool* queryPool, GfxIndex index, GfxCount count, IBuffer* buffer, Offset offset) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL beginRenderPass(const RenderPassDesc& desc) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL endRenderPass() = 0;

virtual SLANG_NO_THROW void SLANG_MCALL setRenderState(const RenderState& state) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL draw(const DrawArguments& args) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL drawIndexed(const DrawArguments& args) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL drawIndirect(
GfxCount maxDrawCount,
IBuffer* argBuffer,
Offset argOffset,
IBuffer* countBuffer = nullptr,
Offset countOffset = 0
) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL drawIndexedIndirect(
GfxCount maxDrawCount,
IBuffer* argBuffer,
Offset argOffset,
IBuffer* countBuffer = nullptr,
Offset countOffset = 0
) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL drawMeshTasks(int x, int y, int z) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL beginComputePass() = 0;
virtual SLANG_NO_THROW void SLANG_MCALL endComputePass() = 0;

virtual SLANG_NO_THROW void SLANG_MCALL setComputeState(const ComputeState& state) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL dispatchCompute(int x, int y, int z) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL dispatchComputeIndirect(IBuffer* argBuffer, Offset offset) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL beginRayTracingPass() = 0;
virtual SLANG_NO_THROW void SLANG_MCALL endRayTracingPass() = 0;

virtual SLANG_NO_THROW void SLANG_MCALL setRayTracingState(const RayTracingState& state) = 0;

/// Issues a dispatch command to start ray tracing workload with a ray tracing pipeline.
/// `rayGenShaderIndex` specifies the index into the shader table that identifies the ray generation shader.
virtual SLANG_NO_THROW void SLANG_MCALL
dispatchRays(GfxIndex rayGenShaderIndex, GfxCount width, GfxCount height, GfxCount depth) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL buildAccelerationStructure(
const AccelerationStructureBuildDesc& desc,
IAccelerationStructure* dst,
Expand Down Expand Up @@ -1788,8 +1804,9 @@ class ICommandEncoder : public ISlangUnknown
setTextureState(texture, kEntireTexture, state);
}

virtual SLANG_NO_THROW void SLANG_MCALL beginDebugEvent(const char* name, float rgbColor[3]) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() = 0;
virtual SLANG_NO_THROW void SLANG_MCALL pushDebugGroup(const char* name, float rgbColor[3]) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL popDebugGroup() = 0;
virtual SLANG_NO_THROW void SLANG_MCALL insertDebugMarker(const char* name, float rgbColor[3]) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL writeTimestamp(IQueryPool* queryPool, GfxIndex queryIndex) = 0;

Expand Down
11 changes: 9 additions & 2 deletions src/command-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,25 @@ void CommandList::write(commands::SetTextureState&& cmd)
writeCommand(std::move(cmd));
}

void CommandList::write(commands::BeginDebugEvent&& cmd)
void CommandList::write(commands::PushDebugGroup&& cmd)
{
if (cmd.name)
cmd.name = (const char*)writeData(cmd.name, strlen(cmd.name) + 1);
writeCommand(std::move(cmd));
}

void CommandList::write(commands::EndDebugEvent&& cmd)
void CommandList::write(commands::PopDebugGroup&& cmd)
{
writeCommand(std::move(cmd));
}

void CommandList::write(commands::InsertDebugMarker&& cmd)
{
if (cmd.name)
cmd.name = (const char*)writeData(cmd.name, strlen(cmd.name) + 1);
writeCommand(std::move(cmd));
}

void CommandList::write(commands::WriteTimestamp&& cmd)
{
retainResource(cmd.queryPool);
Expand Down
32 changes: 20 additions & 12 deletions src/command-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
x(DeserializeAccelerationStructure) \
x(SetBufferState) \
x(SetTextureState) \
x(BeginDebugEvent) \
x(EndDebugEvent) \
x(PushDebugGroup) \
x(PopDebugGroup) \
x(InsertDebugMarker) \
x(WriteTimestamp) \
x(ExecuteCallback)
// clang-format on
Expand Down Expand Up @@ -181,9 +182,9 @@ struct DrawIndexedIndirect

struct DrawMeshTasks
{
int x;
int y;
int z;
GfxCount x;
GfxCount y;
GfxCount z;
};

struct BeginComputePass
Expand All @@ -199,9 +200,9 @@ struct SetComputeState

struct DispatchCompute
{
int x;
int y;
int z;
GfxCount x;
GfxCount y;
GfxCount z;
};

struct DispatchComputeIndirect
Expand Down Expand Up @@ -279,15 +280,21 @@ struct SetTextureState
ResourceState state;
};

struct BeginDebugEvent
struct PushDebugGroup
{
const char* name;
float rgbColor[3];
};

struct EndDebugEvent
struct PopDebugGroup
{};

struct InsertDebugMarker
{
const char* name;
float rgbColor[3];
};

struct WriteTimestamp
{
IQueryPool* queryPool;
Expand Down Expand Up @@ -396,8 +403,9 @@ class CommandList : public RefObject
void write(commands::DeserializeAccelerationStructure&& cmd);
void write(commands::SetBufferState&& cmd);
void write(commands::SetTextureState&& cmd);
void write(commands::BeginDebugEvent&& cmd);
void write(commands::EndDebugEvent&& cmd);
void write(commands::PushDebugGroup&& cmd);
void write(commands::PopDebugGroup&& cmd);
void write(commands::InsertDebugMarker&& cmd);
void write(commands::WriteTimestamp&& cmd);
void write(commands::ExecuteCallback&& cmd);

Expand Down
14 changes: 10 additions & 4 deletions src/cpu/cpu-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class CommandExecutor
void cmdDeserializeAccelerationStructure(const commands::DeserializeAccelerationStructure& cmd);
void cmdSetBufferState(const commands::SetBufferState& cmd);
void cmdSetTextureState(const commands::SetTextureState& cmd);
void cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd);
void cmdEndDebugEvent(const commands::EndDebugEvent& cmd);
void cmdPushDebugGroup(const commands::PushDebugGroup& cmd);
void cmdPopDebugGroup(const commands::PopDebugGroup& cmd);
void cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd);
void cmdWriteTimestamp(const commands::WriteTimestamp& cmd);
void cmdExecuteCallback(const commands::ExecuteCallback& cmd);
};
Expand Down Expand Up @@ -316,12 +317,17 @@ void CommandExecutor::cmdSetTextureState(const commands::SetTextureState& cmd)
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd)
void CommandExecutor::cmdPushDebugGroup(const commands::PushDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdEndDebugEvent(const commands::EndDebugEvent& cmd)
void CommandExecutor::cmdPopDebugGroup(const commands::PopDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd)
{
SLANG_UNUSED(cmd);
}
Expand Down
14 changes: 10 additions & 4 deletions src/cuda/cuda-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class CommandExecutor
void cmdDeserializeAccelerationStructure(const commands::DeserializeAccelerationStructure& cmd);
void cmdSetBufferState(const commands::SetBufferState& cmd);
void cmdSetTextureState(const commands::SetTextureState& cmd);
void cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd);
void cmdEndDebugEvent(const commands::EndDebugEvent& cmd);
void cmdPushDebugGroup(const commands::PushDebugGroup& cmd);
void cmdPopDebugGroup(const commands::PopDebugGroup& cmd);
void cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd);
void cmdWriteTimestamp(const commands::WriteTimestamp& cmd);
void cmdExecuteCallback(const commands::ExecuteCallback& cmd);
};
Expand Down Expand Up @@ -432,12 +433,17 @@ void CommandExecutor::cmdSetTextureState(const commands::SetTextureState& cmd)
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd)
void CommandExecutor::cmdPushDebugGroup(const commands::PushDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdEndDebugEvent(const commands::EndDebugEvent& cmd)
void CommandExecutor::cmdPopDebugGroup(const commands::PopDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd)
{
SLANG_UNUSED(cmd);
}
Expand Down
14 changes: 10 additions & 4 deletions src/d3d11/d3d11-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class CommandExecutor
void cmdDeserializeAccelerationStructure(const commands::DeserializeAccelerationStructure& cmd);
void cmdSetBufferState(const commands::SetBufferState& cmd);
void cmdSetTextureState(const commands::SetTextureState& cmd);
void cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd);
void cmdEndDebugEvent(const commands::EndDebugEvent& cmd);
void cmdPushDebugGroup(const commands::PushDebugGroup& cmd);
void cmdPopDebugGroup(const commands::PopDebugGroup& cmd);
void cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd);
void cmdWriteTimestamp(const commands::WriteTimestamp& cmd);
void cmdExecuteCallback(const commands::ExecuteCallback& cmd);

Expand Down Expand Up @@ -658,12 +659,17 @@ void CommandExecutor::cmdSetTextureState(const commands::SetTextureState& cmd)
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd)
void CommandExecutor::cmdPushDebugGroup(const commands::PushDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdEndDebugEvent(const commands::EndDebugEvent& cmd)
void CommandExecutor::cmdPopDebugGroup(const commands::PopDebugGroup& cmd)
{
SLANG_UNUSED(cmd);
}

void CommandExecutor::cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd)
{
SLANG_UNUSED(cmd);
}
Expand Down
22 changes: 18 additions & 4 deletions src/d3d12/d3d12-command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class CommandRecorder
void cmdDeserializeAccelerationStructure(const commands::DeserializeAccelerationStructure& cmd);
void cmdSetBufferState(const commands::SetBufferState& cmd);
void cmdSetTextureState(const commands::SetTextureState& cmd);
void cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd);
void cmdEndDebugEvent(const commands::EndDebugEvent& cmd);
void cmdPushDebugGroup(const commands::PushDebugGroup& cmd);
void cmdPopDebugGroup(const commands::PopDebugGroup& cmd);
void cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd);
void cmdWriteTimestamp(const commands::WriteTimestamp& cmd);
void cmdExecuteCallback(const commands::ExecuteCallback& cmd);

Expand Down Expand Up @@ -1166,7 +1167,7 @@ void CommandRecorder::cmdSetTextureState(const commands::SetTextureState& cmd)
m_stateTracking.setTextureState(checked_cast<TextureImpl*>(cmd.texture), cmd.subresourceRange, cmd.state);
}

void CommandRecorder::cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd)
void CommandRecorder::cmdPushDebugGroup(const commands::PushDebugGroup& cmd)
{
auto beginEvent = m_device->m_BeginEventOnCommandList;
if (beginEvent)
Expand All @@ -1179,7 +1180,7 @@ void CommandRecorder::cmdBeginDebugEvent(const commands::BeginDebugEvent& cmd)
}
}

void CommandRecorder::cmdEndDebugEvent(const commands::EndDebugEvent& cmd)
void CommandRecorder::cmdPopDebugGroup(const commands::PopDebugGroup& cmd)
{
auto endEvent = m_device->m_EndEventOnCommandList;
if (endEvent)
Expand All @@ -1188,6 +1189,19 @@ void CommandRecorder::cmdEndDebugEvent(const commands::EndDebugEvent& cmd)
}
}

void CommandRecorder::cmdInsertDebugMarker(const commands::InsertDebugMarker& cmd)
{
auto setMarker = m_device->m_SetMarkerOnCommandList;
if (setMarker)
{
UINT64 color = 0xff000000;
color |= uint8_t(cmd.rgbColor[0] * 255.0f) << 16;
color |= uint8_t(cmd.rgbColor[1] * 255.0f) << 8;
color |= uint8_t(cmd.rgbColor[2] * 255.0f);
setMarker(m_cmdList, color, cmd.name);
}
}

void CommandRecorder::cmdWriteTimestamp(const commands::WriteTimestamp& cmd)
{
auto queryPool = checked_cast<QueryPoolImpl*>(cmd.queryPool);
Expand Down
Loading

0 comments on commit aa89fde

Please sign in to comment.