microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[SPIR-V] Conflicting input locations with -pack_optimized in geometry shaders

raaavioli opened this issue · comments

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

@raaavioli Thanks for reporting, we'll take a look. If it goes back to 1.7.2207, I think that's the first release in which the SPIR-V backend supported optimized signature packing (#4361).