microsoft / microsoft/DirectXShaderCompiler

DXIL Modifying recursive payload does not work

Open
#3,414 3 comments 0 reactions 2 assignees View on GitHub

@tex3d is already working on this.

Since Jul 14, 2023.

bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.