Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Calling member function on raypayload causes cast<X>() argument of incompatible type error with PAQ #6464

Open
simco50 opened this issue Mar 26, 2024 · 4 comments
Labels
bug Bug, regression, crash crash DXC crashing or hitting an assert
Milestone

Comments

@simco50
Copy link

simco50 commented Mar 26, 2024

Description
When compiling the provided simple shader repro with SM6.7 or above (when PAQ is enabled by default) or with SM6.6 and compiling with -enable-payload-qualifiers, the compiler fails with an "Internal Compiler error".
It seems to be related to PAQ in combination with calling a member function on a raypayload that writes to a member.

Steps to Reproduce
Example in Compiler Explorer: https://godbolt.org/z/qqKedsWv9
Commandlines that reproduce the issue:

  • -T lib_6_7
  • -T lib_6_8
  • -T lib_6_6 -enable-payload-qualifiers

Actual Behavior
The output of the compiler:

Internal Compiler error: cast<X>() argument of incompatible type!
Compiler returned: 29

Environment

  • DXC version dxcompiler.dll: 1.8 - 1.8.2403.36 (9c2b82878); dxil.dll: 1.8(101.8.2403.21)
  • Host Operating System: Win11 - 22631.3296
@simco50 simco50 added bug Bug, regression, crash needs-triage Awaiting triage labels Mar 26, 2024
@llvm-beanz
Copy link
Collaborator

A few bits of extra context. This reproduces back to DXC 1.7.2207 when targeting SM 6.7, so it is not a new regression. The call stack for the exception throw is:

An exception is being thrown from here, because a member function is being accessed but the code assumes all member accesses are field declarations.

This exposes a flaw in the implementation for payload access qualifiers. It incorrectly assumes all member expressions are accessing field declarations whereas here we're accessing a member function declaration.

@damyanp
Copy link
Member

damyanp commented Mar 27, 2024

Slightly reduced repro: https://godbolt.org/z/bnb9feMv6 - this repro doesn't have any payload qualifiers at all, although passing -enable-payload-qualifiers does trigger it.

Looks like this would affect someone trying to migrate from lib_6_6 to lib_6_7.

@damyanp damyanp moved this to Triaged in HLSL Triage Mar 27, 2024
@damyanp damyanp added this to the Backlog milestone Mar 27, 2024
@damyanp damyanp added crash DXC crashing or hitting an assert and removed needs-triage Awaiting triage labels Mar 27, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in HLSL Roadmap Mar 27, 2024
@devshgraphicsprogramming
Copy link

devshgraphicsprogramming commented Mar 31, 2025

I've ran into this recently with SPIR-V output as well

struct [raypayload] PrimaryPayload
{
    using generator_t = nbl::hlsl::random::Pcg;

    // alpha is quantized to 10 bits
    bool nextDiscard(const uint32_t quantAlpha)
    {
        const uint32_t bitpattern = pcg()>>22;
        return bitpattern > quantAlpha;
    }

    bool nextDiscard(const float32_t alpha)
    {
        const uint32_t bitpattern = pcg();
        const float32_t xi = (float32_t(bitpattern)+0.5f)/float32_t(0xFFFFFFFF);
        return xi > alpha;
    }

    float32_t3  worldNormal : read(caller) : write(closesthit);
    float32_t   rayDistance : read(caller) : write(closesthit, miss);
    generator_t pcg         : read(anyhit) : write(caller,anyhit);
    MaterialId  materialId  : read(caller) : write(closesthit);

};

as soon as I added a method to a payload struct

devshgraphicsprogramming pushed a commit to Devsh-Graphics-Programming/Nabla-Examples-and-Tests that referenced this issue Mar 31, 2025
@devshgraphicsprogramming

You can, however put a struct with a method as a member variable in the payload. That works.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Bug, regression, crash crash DXC crashing or hitting an assert
Projects
Status: New
Status: Triaged
Development

No branches or pull requests

4 participants