diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d441c1a4..b0aee5d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,10 @@ Bottom level categories: - Added support for obtaining `AdapterInfo` from `Device`. By @sagudev in [#8807](https://github.com/gfx-rs/wgpu/pull/8807). - Added `Limits::or_worse_values_from`. By @atlv24 in [#8870](https://github.com/gfx-rs/wgpu/pull/8870). +#### Naga + +- Allow parsing shaders which make use of `SPV_KHR_non_semantic_info` for debug info. Also removes `naga::front::spv::SUPPORTED_EXT_SETS`. By @inner-daemons in #8827. + ### Bug Fixes #### General diff --git a/naga/src/front/spv/function.rs b/naga/src/front/spv/function.rs index 48b23e7c4..13bd90917 100644 --- a/naga/src/front/spv/function.rs +++ b/naga/src/front/spv/function.rs @@ -158,6 +158,18 @@ impl> super::Frontend { fun_inst.expect(1)?; break; } + spirv::Op::ExtInst => { + let _ = self.next()?; + let _ = self.next()?; + let set_id = self.next()?; + if Some(set_id) == self.ext_non_semantic_id { + for _ in 0..fun_inst.wc - 4 { + self.next()?; + } + } else { + return Err(Error::UnsupportedInstruction(self.state, fun_inst.op)); + } + } _ => { return Err(Error::UnsupportedInstruction(self.state, fun_inst.op)); } diff --git a/naga/src/front/spv/mod.rs b/naga/src/front/spv/mod.rs index 340d0594a..b7ebadf64 100644 --- a/naga/src/front/spv/mod.rs +++ b/naga/src/front/spv/mod.rs @@ -96,9 +96,9 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[ "SPV_EXT_descriptor_indexing", "SPV_EXT_shader_atomic_float_add", "SPV_KHR_16bit_storage", + "SPV_KHR_non_semantic_info", "SPV_KHR_fragment_shader_barycentric", ]; -pub const SUPPORTED_EXT_SETS: &[&str] = &["GLSL.std.450"]; #[derive(Copy, Clone)] pub struct Instruction { @@ -589,6 +589,7 @@ pub struct Frontend { layouter: Layouter, temp_bytes: Vec, ext_glsl_id: Option, + ext_non_semantic_id: Option, future_decor: FastHashMap, future_member_decor: FastHashMap<(spirv::Word, MemberIndex), Decoration>, lookup_member: FastHashMap<(Handle, MemberIndex), LookupMember>, @@ -656,6 +657,7 @@ impl> Frontend { layouter: Layouter::default(), temp_bytes: Vec::new(), ext_glsl_id: None, + ext_non_semantic_id: None, future_decor: FastHashMap::default(), future_member_decor: FastHashMap::default(), handle_sampling: FastHashMap::default(), @@ -1745,6 +1747,21 @@ impl> Frontend { inst.expect(5)?; self.parse_function(&mut module) } + Op::ExtInst => { + // Ignore the result type and result id + let _ = self.next()?; + let _ = self.next()?; + let set_id = self.next()?; + if Some(set_id) == self.ext_non_semantic_id { + // We've already skipped the instruction byte, result type, result id, and instruction set id + for _ in 0..inst.wc - 4 { + self.next()?; + } + Ok(()) + } else { + return Err(Error::UnsupportedInstruction(self.state, inst.op)); + } + } _ => Err(Error::UnsupportedInstruction(self.state, inst.op)), //TODO }?; } @@ -1848,10 +1865,17 @@ impl> Frontend { if left != 0 { return Err(Error::InvalidOperand); } - if !SUPPORTED_EXT_SETS.contains(&name.as_str()) { + if &name == "GLSL.std.450" { + self.ext_glsl_id = Some(result_id); + } else if &name == "NonSemantic.Shader.DebugInfo.100" { + // We completely ignore this extension. All related instructions are + // non-semantic and only for debug purposes, and the spec says they + // are ignorable. Many compilers (dxc, slang, etc) will emit these + // instructions depending on configuration. + self.ext_non_semantic_id = Some(result_id); + } else { return Err(Error::UnsupportedExtSet(name)); } - self.ext_glsl_id = Some(result_id); Ok(()) } diff --git a/naga/src/front/spv/next_block.rs b/naga/src/front/spv/next_block.rs index d3bc5db68..58b332555 100644 --- a/naga/src/front/spv/next_block.rs +++ b/naga/src/front/spv/next_block.rs @@ -1693,7 +1693,12 @@ impl> Frontend { let result_type_id = self.next()?; let result_id = self.next()?; let set_id = self.next()?; - if Some(set_id) != self.ext_glsl_id { + if Some(set_id) == self.ext_non_semantic_id { + for _ in 0..inst.wc - 4 { + self.next()?; + } + continue; + } else if Some(set_id) != self.ext_glsl_id { return Err(Error::UnsupportedExtInstSet(set_id)); } let inst_id = self.next()?; diff --git a/naga/tests/in/spv/non-semantic-debug.spvasm b/naga/tests/in/spv/non-semantic-debug.spvasm new file mode 100644 index 000000000..cec83e26e --- /dev/null +++ b/naga/tests/in/spv/non-semantic-debug.spvasm @@ -0,0 +1,44 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google spiregg; 0 +; Bound: 28 +; Schema: 0 + OpCapability Shader + OpExtension "SPV_KHR_non_semantic_info" + %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" + OpMemoryModel Logical GLSL450 + OpEntryPoint GLCompute %main "main" + OpExecutionMode %main LocalSize 1 1 1 + %3 = OpString "thing.hlsl" + %4 = OpString "[numthreads(1, 1, 1)] +void main() +{ +} +" + %5 = OpString "main" + %6 = OpString "" + %7 = OpString "__dxc_setup" + %8 = OpString "3f85295c" + %9 = OpString " -E main -T cs_6_0 -spirv -fspv-debug=vulkan-with-source -Fo out.spirv -Qembed_debug" + OpName %main "main" + %void = OpTypeVoid + %uint = OpTypeInt 32 0 + %uint_3 = OpConstant %uint 3 + %uint_1 = OpConstant %uint 1 + %uint_4 = OpConstant %uint 4 + %uint_5 = OpConstant %uint 5 + %uint_2 = OpConstant %uint 2 + %22 = OpTypeFunction %void + %11 = OpExtInst %void %1 DebugTypeFunction %uint_3 %void + %13 = OpExtInst %void %1 DebugSource %3 %4 + %14 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %13 %uint_5 + %18 = OpExtInst %void %1 DebugFunction %7 %11 %13 %uint_2 %uint_1 %14 %6 %uint_3 %uint_3 + %20 = OpExtInst %void %1 DebugEntryPoint %18 %14 %8 %9 + %main = OpFunction %void None %22 + %23 = OpLabel + %26 = OpExtInst %void %1 DebugScope %18 + %24 = OpExtInst %void %1 DebugFunctionDefinition %18 %main + %25 = OpExtInst %void %1 DebugLine %13 %uint_4 %uint_4 %uint_1 %uint_1 + OpReturn + %27 = OpExtInst %void %1 DebugNoScope + OpFunctionEnd diff --git a/naga/tests/out/wgsl/spv-non-semantic-debug.wgsl b/naga/tests/out/wgsl/spv-non-semantic-debug.wgsl new file mode 100644 index 000000000..beb39cf50 --- /dev/null +++ b/naga/tests/out/wgsl/spv-non-semantic-debug.wgsl @@ -0,0 +1,8 @@ +fn main_1() { + return; +} + +@compute @workgroup_size(1, 1, 1) +fn main() { + main_1(); +}