The code surrounding the link above looks like this:
auto uavBarrier = CD3DX12_RESOURCE_BARRIER::UAV(nullptr);
for (UINT i = 0; i < bottomLevelAccelerationStructureDescs.size(); i++)
{
pRaytracingCommandList->BuildRaytracingAccelerationStructure(&bottomLevelAccelerationStructureDescs[i], 0, nullptr);
}
pCommandList->ResourceBarrier(1, &uavBarrier);
pRaytracingCommandList->BuildRaytracingAccelerationStructure(&topLevelAccelerationStructureDesc, 0, nullptr);
Note the lack of a UAV barrier within the loop body. The bottomLevelAccelerationStructureDescs array contains descriptions for BLAS builds defined further up. Note that in line 811, the scratch memory assigned to each description in the array is the same, implying that these BLAS builds may not overlap on the GPU timeline or they will surely invoke a memory hazard.
The reason this code "works" currently is because even further up in line 727, the number of BLAS descriptions in this loop is hardcoded to 1. While the code works, it clearly wasn't intended to function this way, and its suggested to either remove the loop altogether, insert UAV barriers as needed, or allocate additional scratch storage so the BLAS builds operate in independent regions of a single scratch buffer.
https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingMiniEngineSample/ModelViewer.cpp#L848
The code surrounding the link above looks like this:
Note the lack of a UAV barrier within the loop body. The
bottomLevelAccelerationStructureDescs
array contains descriptions for BLAS builds defined further up. Note that in line 811, the scratch memory assigned to each description in the array is the same, implying that these BLAS builds may not overlap on the GPU timeline or they will surely invoke a memory hazard.The reason this code "works" currently is because even further up in line 727, the number of BLAS descriptions in this loop is hardcoded to 1. While the code works, it clearly wasn't intended to function this way, and its suggested to either remove the loop altogether, insert UAV barriers as needed, or allocate additional scratch storage so the BLAS builds operate in independent regions of a single scratch buffer.