microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.08k stars 686 forks source link

[SPIR-V] `found unregistered decl` when using out-of-line static member + member function #6787

Open FoggyMist opened 3 months ago

FoggyMist commented 3 months ago

Description I am unable to use out-of-line initialized static member of a structure. Possibly related issues: https://github.com/microsoft/DirectXShaderCompiler/issues/5563 and https://github.com/microsoft/DirectXShaderCompiler/issues/5916

Steps to Reproduce Following code does not compile (https://godbolt.org/z/xza9oobrf):

// compiled with -T ps_6_6 -E PSMain -spirv

struct PSInput
{
    static const uint Val;
    int Func() { return 8 + Val + Bonus(); }
    int Bonus() { return 11; }
};

static const uint PSInput::Val = 3;

float4 PSMain(PSInput input) : SV_Target0
{
    return float4(float(input.Func()), 0.0f, 0.0f, 0.0f);
}

Actual Behavior

<source>:5:23: fatal error: found unregistered decl Val
    static const uint Val;
                      ^
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Compiler returned: 5

Val at the end of first line is added in DXC 1.8.x, it is not present in older versions.

Environment

Additional notes Doing any of the following makes the code compile:

damyanp commented 3 months ago

No repro if -spirv removed from compiler args.

FoggyMist commented 3 months ago

No repro if -spirv removed from compiler args.

What do you mean?

  1. Does the code compile after removing -spirv? => You cannot reproduce the compilation failure? It works fine for DXIL, I have mentioned as a possible clue, not a prerequisite. Sorry if it was confusing, I will update the description.
  2. Does the code fail to compile after removing -spirv? => You cannot reproduce what I have noted?

Anyway, it would be nice to be able to compile with the flag.

s-perron commented 3 months ago

I think he is just doing triage, to see who will need to look at it. If it is only an issue with targeting spir-v, then it will be directed to some on my team. We will take a look at it at some point.