shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
3.17k stars 214 forks source link

Hitting assert due to NULL struct type layout #4451

Open chaoticbob opened 5 months ago

chaoticbob commented 5 months ago

The shader below triggers an assert in slang-ir-glsl-legalize.cpp:createGLSLGlobalVaryingsImpl() at 3 calls:

        // We need to recurse down into the individual fields,
        // and generate a variable for each of them.

        auto structTypeLayout = as<IRStructTypeLayout>(typeLayout);
        SLANG_ASSERT(structTypeLayout);
        RefPtr<ScalarizedTupleValImpl> tupleValImpl = new ScalarizedTupleValImpl();

CMD

slangc.exe -target spirv -lang slang -D__spirv__ -emit-spirv-directly -profile gs_6_0 -entry main shader.hlsl

Assert is at line 1678 using commit c3c1cb6776eacdc01ea5bc197b635471960994e4. I don't know enough about this part of the code to attempt a walk up the call stack to see where it's originating.

Shader

struct Empty { };

struct Base : Empty {
    float4 a  : AAA;
    float4 pos: SV_Position;
};

struct Derived : Base {
    float4 b  : BBB;
};

[maxvertexcount(2)]
void main(in line Derived inData[2], inout LineStream<Derived> outData)
{
    outData.Append(inData[0]);
    outData.RestartStrip();
}
jkwak-work commented 5 months ago

I got a wrong impression that the report was about a regression. But the issue can be reproduced with a build in March 2024.

Removing the regression label.

jkwak-work commented 5 months ago

This turned to be more of the inheritance problem that was pointed out on the other issues. When I ran the following shader, it didn't have any problem.

struct Base {
    float4 a  : AAA;
    float4 pos: SV_Position;
    float4 b  : BBB;
};

[maxvertexcount(2)]
void main(in line Base inData[2], inout LineStream<Base> outData)
{
    outData.Append(inData[0]);
    outData.RestartStrip();
}
jkwak-work commented 5 months ago

@swoods-nv I think we should close this for now and keep track it as a long term task, "Implement inheritance".