DXIL Modifying recursive payload does not work
When doing recursions in a closest hit shader, modifying the inout payload does not seem to update the payload. However creating a new payload and assigning it with the incoming payload for recursions does work.
Note that this behavior only happens on dxil, on spirv this seems to work fine.
#define RECURSION_DEPTH 30
#define BUGGED 1
struct Payload {
uint4 data0;
};
RaytracingAccelerationStructure tlas : register(t0, space0);
[shader("closesthit")] void
main(inout Payload payload, in BuiltInTriangleIntersectionAttributes attribs) {
float3 dir = WorldRayDirection();
RayDesc ray;
ray.Origin = WorldRayOrigin() + dir * RayTCurrent();
ray.TMin = 0.1;
ray.Direction = float3(dir.x, dir.y, -dir.z);
ray.TMax = 1000.0;
#if BUGGED
payload.data0 += uint4(1,1,1,1);
if (payload.data0.x < RECURSION_DEPTH) {
TraceRay(tlas,
RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_CULL_BACK_FACING_TRIANGLES |
0, // flags
0xff, // instance inclusion mask
0, // RayContributionToHitGroupIndex
1, // MultiplierForGeometryContributionToHitGroupIndex
0, // MissShaderIndex
ray, payload);
}
#else
Payload new_payload;
new_payload = payload;
new_payload.data0 += uint4(1,1,1,1);
if (new_payload.data0.x < RECURSION_DEPTH) {
TraceRay(tlas,
RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_CULL_BACK_FACING_TRIANGLES |
0, // flags
0xff, // instance inclusion mask
0, // RayContributionToHitGroupIndex
1, // MultiplierForGeometryContributionToHitGroupIndex
0, // MissShaderIndex
ray, new_payload);
payload = new_payload;
}
#endif
}
@pow2clk hope you can help, would it be possible to evaluate and bump the priority on this case?
At Unity we're getting reports from our users about this after updating DXC to the latest release, this is a regression that can cause visual differences and even freezes.
The DXIL generation looks correct to me. We are generating a store to the payload so I'm unsure why this would fail.
@tex3d, @pow2clk, any thoughts here?
Moving to Dormant. @tex3d / @pow2clk, next step would be to look into llvm-beanz's question above. @DBouma - if this is no longer an issue for you then please feel free to close this one. Thanks!