shader-slang / slang

Making it easier to work with shaders
MIT License
1.94k stars 166 forks source link

SPIRV output with debuginfo invalid #3437

Closed farnoy closed 6 months ago

farnoy commented 7 months ago

When invoking $ slangc -I src/shaders -g -entry main -target spirv -o shader.spv -- shader.slang, the produced shader is invalid because of this:

$ spirv-val shader.spv
error: line 586: All OpVariable instructions in a function must be the first instructions in the first block.
  %1554 = OpVariable %_ptr_Function_bool Function %false

Dissassembling the segment reveals:

       %main = OpFunction %void None %5 # line 578
         %22 = OpLabel
       %1676 = OpVariable %_ptr_Function_int Function
       %1675 = OpVariable %_ptr_Function_uint Function
       %1674 = OpVariable %_ptr_Function_uint Function
       %1673 = OpVariable %_ptr_Function_uint Function
       %1672 = OpVariable %_ptr_Function_uint Function
       %1738 = OpExtInst %void %2 DebugNoLine
       %1554 = OpVariable %_ptr_Function_bool Function %false # line 586
       %1556 = OpVariable %_ptr_Function_uint Function

It seems that OpExtInst cannot go in the middle of OpVariable declarations at the start of each function. The workaround is to remove -g.

I'm trying to change my pipeline to compile directly from slang to spv in order to get slang source lines displayed in nsight, so the workaround is not satisfactory.

pmistryNV commented 7 months ago

@farnoy can you attach a shader that I use to reproduce the bug?

pmistryNV commented 6 months ago

@farnoy can you attach a shader that I use to reproduce the bug?

Gentle reminder. If I can't replicate the bug, I would be closing this. If you have a reference shader kindly share.

csyonghe commented 6 months ago

You need to use -emit-spirv-directly for -g to work properly. Closing this issue since this is a GLSLang bug.

farnoy commented 6 months ago

Sorry about the delay. Switching to direct SPIRV sounds like the way forward so I'll try that. IIRC, I was primarily blocked on the scalar block layout being unavailable with -emit-spirv-directly, but it looks like it was fixed very recently:

StructuredBuffer<float3, ScalarDataLayout> scalarBuffer;
csyonghe commented 6 months ago

You are right. The recent fix allows you to control layout per buffer. There is also a global -force-glsl-scalar-layout that applies to all buffers.