mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
spv-out: configure source language in debug info
This commit is contained in:
parent
c8beade187
commit
eb18854b46
@ -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
|
||||
|
||||
|
@ -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<String>,
|
||||
language: naga::back::spv::SourceLanguage,
|
||||
}
|
||||
|
||||
fn parse_input(input_path: &Path, input: Vec<u8>, params: &Parameters) -> anyhow::Result<Parsed> {
|
||||
@ -593,16 +596,26 @@ fn parse_input(input_path: &Path, input: Vec<u8>, 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<u8>, 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<u8>, 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());
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
));
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user