Skip to content

Commit

Permalink
Implement auditing of indirect RT dispatches
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed Dec 5, 2024
1 parent bdd479a commit 70c6dd3
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 88 deletions.
3 changes: 2 additions & 1 deletion renderdoc/data/hlsl/hlsl_cbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ struct LocalRootSigData

cbuffer RayIndirectDispatchCB REG(b0)
{
GPUAddress scratchBuffer;
GPUAddress destBuffer;
GPUAddress destBufferEnd;

uint commandSigDispatchOffset;
uint commandSigStride;
Expand Down
26 changes: 23 additions & 3 deletions renderdoc/data/hlsl/raytracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,24 @@ void PatchTable(uint byteOffset)
}

// Each SV_GroupId corresponds to one shader record to patch
[numthreads(RECORD_PATCH_THREADS, 1, 1)] void RENDERDOC_PatchRayDispatchCS(uint3 dispatchThread
[numthreads(RECORD_PATCH_THREADS, 1, 1)] void RENDERDOC_PatchShaderTableCS(uint3 dispatchThread
: SV_DispatchThreadID) {
if(dispatchThread.x < shaderrecord_count)
PatchTable(shaderrecord_stride * dispatchThread.x);
}
};

// Each SV_GroupId corresponds to one shader record to patch
[numthreads(RECORD_PATCH_THREADS, 1, 1)] void RENDERDOC_CopyShaderTableCS(uint3 dispatchThread
: SV_DispatchThreadID) {
if(dispatchThread.x < shaderrecord_count)
{
for(uint b = 0; b < shaderrecord_stride;)
{
b = CopyData(patchSource, patchDest, shaderrecord_stride * dispatchThread.x, b,
shaderrecord_stride);
}
}
};

// define these structs in hlsl for simplicity

Expand Down Expand Up @@ -327,7 +340,7 @@ GPUAddress AlignRecordAddress(GPUAddress x)
numCommands = min(numCommands, applicationCountBuffer.Load(0));
}

GPUAddress outputBufferLocation = scratchBuffer;
GPUAddress outputBufferLocation = destBuffer;
uint dispatchIndex = 0;

PatchingExecute execute = (PatchingExecute)0xccddeeff;
Expand Down Expand Up @@ -443,6 +456,13 @@ GPUAddress AlignRecordAddress(GPUAddress x)
patchedExecuteArguments.Store(commandSigDispatchOffset + commandOffset + 6 * 16, raw.b);
}

// check for buffer overrun
if(!lessEqual(outputBufferLocation, destBufferEnd))
{
// error! don't patch, this will fail. Needs to be caught by auditing
dispatchIndex = 0;
}

// store the number of patching indirect dispatches we'll do, up to 4 per the application's number
internalExecuteCount.Store(0, dispatchIndex);
}
Expand Down
Loading

0 comments on commit 70c6dd3

Please sign in to comment.