microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Conflicting input locations with -pack_optimized in geometry shaders
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
Compiling a geometry shader with multiple texcoord attributes and -pack-optimized after dxc 1.7.2207 all the way up to trunk generates overlapping locations.
The behaviour seems to be caused by the non-interleaved implementation of the packed attributes.
triangle GS_IN In[3] as input, where GS_IN is:
struct GS_IN
{
float4 Pos : SV_POSITION;
float4 UV0_UV1 : TEXCOORD0;
float4 COLOR : TEXCOORD1;
};
Then UV0_UV1 specifically will appear 3 times in the input stream, and thus occupy 3 locations of 4 components. But pack-optimized does not seem to consider the size of the geometry shader input array properly, so COLOR needs to be at earliest on location 4, but it ends up overlapping with UV0_UV1.
Steps to Reproduce
Godbolt link
Toggle "BROKEN" define on/off. By adding -Vd, note the generated spirv in the broken case has Location 1 duplicated. The "non-broken" case explicitly bypasses the -pack_optimized by requiring explicit locations, it works as well to just remove -pack_optimized.
Actual Behavior
fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpEntryPoint-08721] Entry-point has conflicting input location assignment at location 1, component 0
OpEntryPoint Geometry %main "main" %gl_Position %in_var_TEXCOORD0 %in_var_TEXCOORD1 %gl_Position_0 %in_var_TEXCOORD0_0 %in_var_TEXCOORD0_1 %in_var_TEXCOORD1_0 %in_var_TEXCOORD1_1
Expected Behaviour
Correctly generated location decorations when using -pack_optimized in geometry shaders.
Environment
- DXC version 1.7.2207 -> trunk
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Godbolt example with dxc and -pack_optimized, then inspect the generated SPIR-V decorations for the geometry shader inputs. The fix is complete when the arrayed UV0_UV1 inputs and COLOR receive non-overlapping locations, and validation no longer reports conflicting assignments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100