spv-in: UnsupportedInstruction(Type, Line) from shaderc debug info
I'm using wgpu 0.13.1 with naga 0.9.0 and compiling GLSL shaders to SPIR-V with shaderc 0.8.0. If I set_generate_debug_info() in shaderc options, naga fails to parse the input shader modules with a UnsupportedInstruction(Type, Line) error.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnsupportedInstruction(Type, Line)', /home/tari/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.13.1/src/backend/direct.rs:1106:45
stack backtrace:
0: rust_begin_unwind
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
2: core::result::unwrap_failed
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/result.rs:1749:5
3: core::result::Result<T,E>::unwrap
at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/result.rs:1065:23
4: <wgpu::backend::direct::Context as wgpu::Context>::device_create_shader_module
at /home/tari/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.13.1/src/backend/direct.rs:1106:30
5: wgpu::Device::create_shader_module
at /home/tari/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.13.1/src/lib.rs:2005:17
The code in wgpu this points at indicates parse() returned that error:
#[cfg(feature = "spirv")]
ShaderSource::SpirV(ref spv) => {
// Parse the given shader code and store its representation.
let options = naga::front::spv::Options {
adjust_coordinate_space: false, // we require NDC_Y_UP feature
strict_capabilities: true,
block_ctx_dump_prefix: None,
};
let parser = naga::front::spv::Parser::new(spv.iter().cloned(), &options);
let module = parser.parse().unwrap();
The SPIR-V assembly corresponding to the shader module that causes this error (a pretty simple vertex shader) looks like this:
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 10
; Bound: 32
; Schema: 0
OpCapability Shader
%2 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main" %_ %screenCoords %textureCoordinate %texCoords
%1 = OpString "shader.vert"
OpSource GLSL 450 %1 "// OpModuleProcessed entry-point main
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed entry-point main
#line 1
#version 450
layout(location = 0) in vec2 screenCoords;
layout(location = 1) in vec2 texCoords;
layout(location = 0) out vec2 textureCoordinate;
void main() {
gl_Position = vec4(screenCoords, 0, 1);
textureCoordinate = texCoords;
}
"
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %_ ""
OpName %screenCoords "screenCoords"
OpName %textureCoordinate "textureCoordinate"
OpName %texCoords "texCoords"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %screenCoords Location 0
OpDecorate %textureCoordinate Location 0
OpDecorate %texCoords Location 1
%void = OpTypeVoid
%4 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
%_ = OpVariable %_ptr_Output_gl_PerVertex Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%screenCoords = OpVariable %_ptr_Input_v2float Input
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_ptr_Output_v2float = OpTypePointer Output %v2float
%textureCoordinate = OpVariable %_ptr_Output_v2float Output
%texCoords = OpVariable %_ptr_Input_v2float Input
OpLine %1 8 11
%main = OpFunction %void None %4
%6 = OpLabel
OpLine %1 9 0
%20 = OpLoad %v2float %screenCoords
%23 = OpCompositeExtract %float %20 0
%24 = OpCompositeExtract %float %20 1
%25 = OpCompositeConstruct %v4float %23 %24 %float_0 %float_1
%27 = OpAccessChain %_ptr_Output_v4float %_ %int_0
OpStore %27 %25
OpLine %1 10 0
%31 = OpLoad %v2float %texCoords
OpStore %textureCoordinate %31
OpReturn
OpFunctionEnd
Without debug info, this is the shader module assembly (which doesn't cause an error):
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 10
; Bound: 31
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %4 "main" %13 %18 %28 %29
OpMemberDecorate %_struct_11 0 BuiltIn Position
OpMemberDecorate %_struct_11 1 BuiltIn PointSize
OpMemberDecorate %_struct_11 2 BuiltIn ClipDistance
OpMemberDecorate %_struct_11 3 BuiltIn CullDistance
OpDecorate %_struct_11 Block
OpDecorate %18 Location 0
OpDecorate %28 Location 0
OpDecorate %29 Location 1
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%_struct_11 = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%_ptr_Output__struct_11 = OpTypePointer Output %_struct_11
%13 = OpVariable %_ptr_Output__struct_11 Output
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%18 = OpVariable %_ptr_Input_v2float Input
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_ptr_Output_v2float = OpTypePointer Output %v2float
%28 = OpVariable %_ptr_Output_v2float Output
%29 = OpVariable %_ptr_Input_v2float Input
%4 = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %v2float %18
%22 = OpCompositeExtract %float %19 0
%23 = OpCompositeExtract %float %19 1
%24 = OpCompositeConstruct %v4float %22 %23 %float_0 %float_1
%26 = OpAccessChain %_ptr_Output_v4float %13 %int_0
OpStore %26 %24
%30 = OpLoad %v2float %29
OpStore %28 %30
OpReturn
OpFunctionEnd
Also getting same issue, but with SPIRV feature on
[features]
default = ["use_precompiled_spirv"]
use_precompiled_spirv = ["wgpu/spirv"]
[dependencies]
naga = "0.11.0"
wgpu = { version = "0.15.1" }
[2023-04-11T21:26:38Z DEBUG naga::front::spv] Store [3]
[2023-04-11T21:26:38Z DEBUG naga::front::spv] Load [4]
[2023-04-11T21:26:38Z DEBUG naga::front::spv] Load [4]
[2023-04-11T21:26:38Z DEBUG naga::front::spv] SampledImage [5]
[2023-04-11T21:26:38Z DEBUG naga::front::spv] Load [4]
[2023-04-11T21:26:38Z DEBUG naga::front::spv] ImageQueryLod [5]
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnsupportedInstruction(Function, ImageQueryLod)',
I am also seeing this when compiling HLSL shaders into Spir-V via dxc with debug-info