KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.98k stars 823 forks source link

HLSL: Hull shader miswrites to SV_Position #1207

Open Themaister opened 6 years ago

Themaister commented 6 years ago
struct HSConstantOut
{
    float EdgeTess[3] : SV_TessFactor;
    float InsideTess : SV_InsideTessFactor;
};

struct HSOut
{
    float4 pos : SV_Position;
    float2 uv : TEXCOORD0;
};

struct VertexOutput
{
    float4 pos : SV_Position;
    float2 uv : TEXCOORD0;
};

[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("PatchHS")]
HSOut hs_main(InputPatch<VertexOutput, 3> p, uint i : SV_OutputControlPointID)
{
    HSOut output;
    output.pos = p[i].pos;
    output.uv = p[i].uv;
    return output;
}

HSConstantOut PatchHS(InputPatch<VertexOutput, 3> patch)
{
    HSConstantOut output;
    output.EdgeTess[0] = 1.0f + patch[0].uv;
    output.EdgeTess[1] = 1.0f + patch[1].uv;
    output.EdgeTess[2] = 1.0f + patch[2].uv;
    output.InsideTess = 1.0f + patch[0].uv;
    return output;
}

Emits:

              30:     29(int) Constant 0
              89:     88(ptr) AccessChain 85(@entryPointOutput.pos) 30
                              Store 89 87

gl_Position must be accessed by gl_InvocationID here, it works for the TEXCOORD0 output.

johnkslang commented 6 years ago

I tried this with

glslangValidator -Od -D -e hs_main -H t.tesc

and got the following. It is off by one from your results, but also indexes @entryPointOutput.pos with the InvocationId. So, want to start by making sure you're up to date, and we are discussing the same options/stage.

                              Decorate 76(i) BuiltIn InvocationId
              86:     10(int) Load 76(i)
              87:     32(ptr) AccessChain 78(flattenTemp) 30
              90:     89(ptr) AccessChain 85(@entryPointOutput.pos) 86
                              Store 90 88
dustin-lunarg commented 6 years ago

This may be the same issue reported in #1181. The constant 0 issue was fixed with #1183.