DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SER] Incomprehensible error from initializing const payload in a certain way and using it in Invoke

Open Hengoo opened this issue 1 year ago • 5 comments

Description

When creating a const payload via = {...} initialization and then use it to call Invoke you get a validation error that is quite unhelpful. I suspect from the way the error is written, that it is not something that is expected to be triggered via mistakes in hlsl code.

Note: This issue might be related to https://github.com/microsoft/DirectXShaderCompiler/issues/7760

Steps to Reproduce

// Disabled payload access qualifier just do hide a warning. It also fails with the same error when PAQ are enabled
struct Payload {
    float value;
};

[shader("raygeneration")]
void RayGen()
{
    RayDesc ray;
    // Removing the const fixes the validation error
    // Initializing p via an existing struct fixes the validation error
    const Payload p = {0.0};
    dx::HitObject obj = dx::HitObject::MakeMiss(0, 0, ray);
    // Removing this invoke fixes the validation error
    dx::HitObject::Invoke(obj, p);
}

-T lib_6_9 -disable-payload-qualifiers

https://godbolt.org/z/aT8hK9r4d

Actual Behavior

Compilation failed with Error message:

error: validation errors
Function: ?RayGen@@YAXXZ: error: Instructions must be of an allowed type.
note: at 'unreachable' in block '#0' of function '?RayGen@@YAXXZ'.
Validation failed.


Compiler returned: 5

I would expect an error message similar to (just an example error on a test function)

<source>:20:5: error: no matching function for call to 'test'
    test(p);
    ^~~~
<source>:6:6: note: candidate function not viable: 1st argument ('__restrict Payload') would lose restrict qualifier
void test(inout Payload p) {
     ^

Something that tells you what / where the mistake is.

Environment

  • DXC version: dxcompiler.dll: 1.9 - 1.8.2505.32 (https://github.com/microsoft/DirectXShaderCompiler/commit/b106a961d09221b3c5bdb37be45b679257da08b8); dxil.dll: 1.9(1.8.2505.32)

Hengoo avatar Sep 12 '25 15:09 Hengoo

@simoll - could you have first look at this please?

My initial guess here is that this is somewhat limited by the sorts of diagnostics that are possible during validation, but I'm not sure.

Also I wonder if https://github.com/microsoft/DirectXShaderCompiler/pull/7506 will improve some aspects of the error message.

damyanp avatar Sep 12 '25 15:09 damyanp

This code should be rejected during Sema. Cannot feed a const value into the [in]out payload param. Also see https://github.com/microsoft/DirectXShaderCompiler/issues/7760#issuecomment-3302628171

simoll avatar Sep 17 '25 11:09 simoll

https://godbolt.org/z/6KxdobT4s

This link shows the expected error. Not surprising but looks like this isn't a general "something goes wrong when const is passed as inout", it's a bit more specific.

V-FEXrt avatar Sep 26 '25 20:09 V-FEXrt

#7797 makes this fail during Sema. Since DXC uses all this special plumbing for builtin template/overload resolution, not entirely clear how this should be fixed proper.

simoll avatar Oct 01 '25 07:10 simoll

I'm inclined to say the error message generated by #7797 is sufficient for this issue. It highlights that the function overload isn't valid and given the teams focus on the upstream compiler, we don't want to spend huge amounts of effort untangling special casing in dxc

V-FEXrt avatar Oct 02 '25 00:10 V-FEXrt