microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.11k stars 698 forks source link

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

Open raaavioli opened 7 months ago

raaavioli commented 7 months ago

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,l:'5',n:'0',o:'HLSL+source+%231',t:'0')),k:42.60918253079506,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:dxc_1_7_2308,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:hlsl,libs:!(),options:'-pack_optimized+-nologo+-spirv+-fspv-target-env%3Dvulkan1.1+%22-E+main%22+-T+gs_6_6',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+DXC+1.7.2308+(Editor+%231)',t:'0')),header:(),k:41.948115516397436,l:'4',m:50,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'DXC+(trunk)',editorid:1,fontScale:14,fontUsePx:'0',j:2,wrap:'1'),l:'5',n:'0',o:'Output+of+DXC+1.7.2308+(Compiler+%232)',t:'0')),header:(),l:'4',m:50,n:'0',o:'',s:0,t:'0')),k:57.3908174692049,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

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

sudonatalie commented 7 months ago

@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).