mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
[naga-cli] add --defines options for the glsl parser (#5859)
This commit is contained in:
1 parent
6405dcf611
commit
0f6abc99ee
2 files changed
+38
-3
No files matched your search
+2
-1
@@ -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).
|
||||
|
||||
@@ -132,6 +132,10 @@ struct Args {
|
||||
/// In bulk validation mode, these are all input files to be validated.
|
||||
#[argh(positional)]
|
||||
files: Vec<String>,
|
||||
|
||||
/// defines to be passed to the parser (only glsl is supported)
|
||||
#[argh(option, short = 'D')]
|
||||
defines: Vec<Defines>,
|
||||
}
|
||||
|
||||
/// 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<Self, Self::Err> {
|
||||
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<InputKind>,
|
||||
shader_stage: Option<ShaderStage>,
|
||||
defines: FastHashMap<String, String>,
|
||||
}
|
||||
|
||||
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<u8>, 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<E: Error>(ann_err: &WithSpan<E>, filename: &str, source: &str) {
|
||||
let files = SimpleFile::new(filename, source);
|
||||
|
||||
Reference in new issue
Block a user