shader-slang / slang

Making it easier to work with shaders
MIT License
1.8k stars 160 forks source link

SPIRV: Conflicting slots in tessellation control shader output #4540

Open n3b opened 1 week ago

n3b commented 1 week ago

When custom data added to constant function output that is expected to be accessible in evaluation (domain) shader, the wrong location is generated.

Decompiled GLSL generated by SPIRV-Cross:

layout(location = 0) out vec2 entryPointParam_main_gridPosition[4];
layout(location = 1) out vec2 entryPointParam_main_heightmap[4];
layout(location = 0) out uint entryPointParam_constants_instanceId;
ArielG-NV commented 1 week ago

It would be helpful if a shader that reproduces the described problem is shared

n3b commented 1 week ago

@ArielG-NV sorry about that, here is an example. The HscOut::instanceId is being bound to the same slot as the HsOut::pos.

struct HsOut
{
    float2 pos;
    float2 hm;
};

struct HscOut
{
    float EdgeTessFactor[4] : SV_TessFactor;
    float InsideTessFactor[2] : SV_InsideTessFactor;
    uint instanceId;
};

[domain("quad")]
[partitioning("integer")]
[outputtopology("triangle_ccw")]
[outputcontrolpoints(4)]
[patchconstantfunc("constants")]
HsOut main()
{
    HsOut o;
    o.pos = 1;
    o.hm = 2;
    return o;
}

HscOut constants()
{
    HscOut o;
    o.instanceId = 123;
    o.EdgeTessFactor[0] = 1;
    o.EdgeTessFactor[1] = 2;
    o.EdgeTessFactor[2] = 3;
    o.EdgeTessFactor[3] = 4;
    o.InsideTessFactor[0] = 0.5;
    o.InsideTessFactor[1] = 0.5;
    return o;
}
ArielG-NV commented 1 week ago

Thank you for passing along an example shader.