diff --git a/CHANGELOG.md b/CHANGELOG.md index c6765c0e0..f5263d40b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ TODO(wumpf): This is still work in progress. Should write a bit more about it. A `wgpu::ComputePass` recording methods (e.g. `wgpu::ComputePass:set_render_pipeline`) no longer impose a lifetime constraint passed in resources. -Furthermore, you can now opt out of `wgpu::ComputePass`'s lifetime dependency on its parent `wgpu::CommandEncoder` using `wgpu::ComputePass::forget_lifetime`: +Furthermore, you can now opt out of `wgpu::ComputePass`'s lifetime dependency on its parent `wgpu::CommandEncoder` using `wgpu::ComputePass::forget_lifetime`: ```rust fn independent_cpass<'enc>(encoder: &'enc mut wgpu::CommandEncoder) -> wgpu::ComputePass<'static> { let cpass: wgpu::ComputePass<'enc> = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default()); @@ -126,6 +126,7 @@ By @atlv24 in [#5383](https://github.com/gfx-rs/wgpu/pull/5383) #### Naga +- Added -D, --defines option to naga CLI to define preprocessor macros by @theomonnom in [#5859](https://github.com/gfx-rs/wgpu/pull/5859) - Added type upgrades to SPIR-V atomic support. Added related infrastructure. Tracking issue is [here](https://github.com/gfx-rs/wgpu/issues/4489). By @schell in [#5775](https://github.com/gfx-rs/wgpu/pull/5775). - Implement `WGSL`'s `unpack4xI8`,`unpack4xU8`,`pack4xI8` and `pack4xU8`. By @VlaDexa in [#5424](https://github.com/gfx-rs/wgpu/pull/5424) - Began work adding support for atomics to the SPIR-V frontend. Tracking issue is [here](https://github.com/gfx-rs/wgpu/issues/4489). By @schell in [#5702](https://github.com/gfx-rs/wgpu/pull/5702). diff --git a/naga-cli/src/bin/naga.rs b/naga-cli/src/bin/naga.rs index 090ca7047..4072d2d8a 100644 --- a/naga-cli/src/bin/naga.rs +++ b/naga-cli/src/bin/naga.rs @@ -132,6 +132,10 @@ struct Args { /// In bulk validation mode, these are all input files to be validated. #[argh(positional)] files: Vec, + + /// defines to be passed to the parser (only glsl is supported) + #[argh(option, short = 'D')] + defines: Vec, } /// Newtype so we can implement [`FromStr`] for `BoundsCheckPolicy`. @@ -285,6 +289,27 @@ impl FromStr for Overrides { } } +#[derive(Clone, Debug)] +struct Defines { + pairs: Vec<(String, String)>, +} + +impl FromStr for Defines { + type Err = String; + + fn from_str(s: &str) -> Result { + let mut pairs = vec![]; + for pair in s.split(',') { + let (name, value) = match pair.split_once('=') { + Some((name, value)) => (name, value), + None => (pair, ""), // Default to an empty string if no '=' is found + }; + pairs.push((name.trim().to_string(), value.trim().to_string())); + } + Ok(Defines { pairs }) + } +} + #[derive(Default)] struct Parameters<'a> { validation_flags: naga::valid::ValidationFlags, @@ -300,6 +325,7 @@ struct Parameters<'a> { hlsl: naga::back::hlsl::Options, input_kind: Option, shader_stage: Option, + defines: FastHashMap, } trait PrettyResult { @@ -393,6 +419,14 @@ fn run() -> anyhow::Result<()> { .flat_map(|o| &o.pairs) .cloned() .collect(); + + params.defines = args + .defines + .iter() + .flat_map(|o| &o.pairs) + .cloned() + .collect(); + params.spv_in = naga::front::spv::Options { adjust_coordinate_space: !args.keep_coordinate_space, strict_capabilities: false, @@ -611,7 +645,7 @@ fn parse_input(input_path: &Path, input: Vec, params: &Parameters) -> anyhow .parse( &naga::front::glsl::Options { stage: shader_stage.0, - defines: Default::default(), + defines: params.defines.clone(), }, &input, ) @@ -859,7 +893,7 @@ use codespan_reporting::{ termcolor::{ColorChoice, StandardStream}, }, }; -use naga::WithSpan; +use naga::{FastHashMap, WithSpan}; pub fn emit_annotated_error(ann_err: &WithSpan, filename: &str, source: &str) { let files = SimpleFile::new(filename, source);