Implement auditing of indirect RT dispatches

This commit is contained in:
baldurk
2024-12-05 13:31:35 +00:00
parent bdd479a5d4
commit 70c6dd32a2
4 changed files with 498 additions and 90 deletions
+2 -1
View File
@@ -338,7 +338,8 @@ struct LocalRootSigData
cbuffer RayIndirectDispatchCB REG(b0)
{
GPUAddress scratchBuffer;
GPUAddress destBuffer;
GPUAddress destBufferEnd;
uint commandSigDispatchOffset;
uint commandSigStride;
+23 -3
View File
@@ -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
@@ -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;
@@ -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);
}