Skip to content

DXIL Modifying recursive payload does not work #3414

Open

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
}

Activity

  1. Dredhog commented on Oct 1, 2021

    @Dredhog

    Gregory Roth (@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.

  2. llvm-beanz commented on Jul 14, 2023

    @llvm-beanz
    Collaborator

    The DXIL generation looks correct to me. We are generating a store to the payload so I'm unsure why this would fail.

    Tex Riddell (@tex3d), Gregory Roth (@pow2clk), any thoughts here?

    godbolt link

  3. moved this from For MSFT to Triaged in HLSL Triageon Apr 16, 2024
  4. added
    bug
    and removed
    needs-triage
    on Apr 16, 2024
  5. damyanp commented on Apr 16, 2024

    @damyanp
    Member

    Moving to Dormant. Tex Riddell (@tex3d) / Gregory Roth (@pow2clk), next step would be to look into llvm-beanz's question above. Darius Bouma (@DBouma) - if this is no longer an issue for you then please feel free to close this one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions