Skip to content

DXIL Modifying recursive payload does not work #3414

@DBouma

Description

@DBouma

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
}

Metadata

Metadata

Assignees

Labels

bugBug, regression, crash

Type

No type

Projects

Status

Triaged

Relationships

None yet

Development

No branches or pull requests

Issue actions