diff --git a/CHANGELOG.md b/CHANGELOG.md index c58f5894d..2a463c89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216). #### Naga - Accept only `vec3` (not `vecN`) for the `cross` built-in. By @ErichDonGubler in [#6171](https://github.com/gfx-rs/wgpu/pull/6171). +- Configure `SourceLanguage` when enabling debug info in SPV-out. By @kvark in [#6256](https://github.com/gfx-rs/wgpu/pull/6256) #### General diff --git a/naga-cli/src/bin/naga.rs b/naga-cli/src/bin/naga.rs index d97d96de7..e28519cb0 100644 --- a/naga-cli/src/bin/naga.rs +++ b/naga-cli/src/bin/naga.rs @@ -465,6 +465,7 @@ fn run() -> anyhow::Result<()> { let Parsed { mut module, input_text, + language, } = parse_input(input_path, input, ¶ms)?; // Include debugging information if requested. @@ -477,6 +478,7 @@ fn run() -> anyhow::Result<()> { params.spv_out.debug_info = Some(naga::back::spv::DebugInfo { source_code: input_text, file_name: input_path, + language, }) } else { eprintln!( @@ -579,6 +581,7 @@ fn run() -> anyhow::Result<()> { struct Parsed { module: naga::Module, input_text: Option, + language: naga::back::spv::SourceLanguage, } fn parse_input(input_path: &Path, input: Vec, params: &Parameters) -> anyhow::Result { @@ -593,16 +596,26 @@ fn parse_input(input_path: &Path, input: Vec, params: &Parameters) -> anyhow .context("Unable to determine --input-kind from filename")?, }; - let (module, input_text) = match input_kind { - InputKind::Bincode => (bincode::deserialize(&input)?, None), - InputKind::SpirV => { - naga::front::spv::parse_u8_slice(&input, ¶ms.spv_in).map(|m| (m, None))? - } + Ok(match input_kind { + InputKind::Bincode => Parsed { + module: bincode::deserialize(&input)?, + input_text: None, + language: naga::back::spv::SourceLanguage::Unknown, + }, + InputKind::SpirV => Parsed { + module: naga::front::spv::parse_u8_slice(&input, ¶ms.spv_in)?, + input_text: None, + language: naga::back::spv::SourceLanguage::Unknown, + }, InputKind::Wgsl => { let input = String::from_utf8(input)?; let result = naga::front::wgsl::parse_str(&input); match result { - Ok(v) => (v, Some(input)), + Ok(v) => Parsed { + module: v, + input_text: Some(input), + language: naga::back::spv::SourceLanguage::WGSL, + }, Err(ref e) => { let message = anyhow!( "Could not parse WGSL:\n{}", @@ -631,8 +644,8 @@ fn parse_input(input_path: &Path, input: Vec, params: &Parameters) -> anyhow }; let input = String::from_utf8(input)?; let mut parser = naga::front::glsl::Frontend::default(); - ( - parser + Parsed { + module: parser .parse( &naga::front::glsl::Options { stage: shader_stage.0, @@ -649,12 +662,11 @@ fn parse_input(input_path: &Path, input: Vec, params: &Parameters) -> anyhow error.emit_to_writer_with_path(&mut writer, &input, filename); std::process::exit(1); }), - Some(input), - ) + input_text: Some(input), + language: naga::back::spv::SourceLanguage::GLSL, + } } - }; - - Ok(Parsed { module, input_text }) + }) } fn write_output( @@ -833,7 +845,11 @@ fn bulk_validate(args: Args, params: &Parameters) -> anyhow::Result<()> { let path = Path::new(&input_path); let input = fs::read(path)?; - let Parsed { module, input_text } = match parse_input(path, input, params) { + let Parsed { + module, + input_text, + language: _, + } = match parse_input(path, input, params) { Ok(parsed) => parsed, Err(error) => { invalid.push(input_path.clone()); diff --git a/naga/src/back/spv/mod.rs b/naga/src/back/spv/mod.rs index 91407561a..32bd1fcec 100644 --- a/naga/src/back/spv/mod.rs +++ b/naga/src/back/spv/mod.rs @@ -16,7 +16,7 @@ mod selection; mod subgroup; mod writer; -pub use spirv::Capability; +pub use spirv::{Capability, SourceLanguage}; use crate::arena::{Handle, HandleVec}; use crate::proc::{BoundsCheckPolicies, TypeResolution}; @@ -89,6 +89,7 @@ impl IdGenerator { pub struct DebugInfo<'a> { pub source_code: &'a str, pub file_name: &'a std::path::Path, + pub language: SourceLanguage, } /// A SPIR-V block to which we are still adding instructions. diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index 488371558..678dcb424 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -1967,7 +1967,7 @@ impl Writer { source_file_id, }); self.debugs.append(&mut Instruction::source_auto_continued( - spirv::SourceLanguage::Unknown, + debug_info.language, 0, &debug_info_inner, )); diff --git a/naga/tests/snapshots.rs b/naga/tests/snapshots.rs index 0e285e7b0..936203986 100644 --- a/naga/tests/snapshots.rs +++ b/naga/tests/snapshots.rs @@ -358,6 +358,10 @@ fn check_targets( let debug_info = source_code.map(|code| naga::back::spv::DebugInfo { source_code: code, file_name: name.as_ref(), + // wgpu#6266: we technically know all the information here to + // produce the valid language but it's not too important for + // validation purposes + language: naga::back::spv::SourceLanguage::Unknown, }); if targets.contains(Targets::SPIRV) { diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 181da3d88..6c3bfc5ed 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -769,6 +769,7 @@ impl super::Device { temp_options.debug_info = Some(naga::back::spv::DebugInfo { source_code: &debug.source_code, file_name: debug.file_name.as_ref().as_ref(), + language: naga::back::spv::SourceLanguage::WGSL, }) } if !stage.zero_initialize_workgroup_memory { @@ -1742,6 +1743,7 @@ impl crate::Device for super::Device { .map(|d| naga::back::spv::DebugInfo { source_code: d.source_code.as_ref(), file_name: d.file_name.as_ref().as_ref(), + language: naga::back::spv::SourceLanguage::WGSL, }); if !desc.runtime_checks { naga_options.bounds_check_policies = naga::proc::BoundsCheckPolicies {