Skip to content

Commit

Permalink
add cli arg to choose metal version
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Cleavelin authored and teoxoy committed Mar 15, 2024
1 parent e04a9f4 commit a63bec8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ By @cwfitzgerald in [#5325](https://github.com/gfx-rs/wgpu/pull/5325).
- Cache the sample count to keep `get_texture_format_features` cheap. By @Dinnerbone in [#5346](https://github.com/gfx-rs/wgpu/pull/5346)
- Mark `DEPTH32FLOAT_STENCIL8` as supported in GLES. By @Dinnerbone in [#5370](https://github.com/gfx-rs/wgpu/pull/5370)

#### Naga

- Allow user to select which MSL version to use via `--metal-version` with Naga CLI. By @pcleavelin in [#5392](https://github.com/gfx-rs/wgpu/pull/5392)

### Bug Fixes

#### General
Expand Down
31 changes: 31 additions & 0 deletions naga-cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ struct Args {
#[argh(option)]
shader_model: Option<ShaderModelArg>,

/// the metal version to use, for example, 1.0, 1.1, 1.2, etc.
#[argh(option)]
metal_version: Option<MslVersionArg>,

/// if the selected frontends/backends support coordinate space conversions,
/// disable them
#[argh(switch)]
Expand Down Expand Up @@ -174,6 +178,30 @@ impl FromStr for GlslProfileArg {
}
}

/// Newtype so we can implement [`FromStr`] for a Metal Language Version.
#[derive(Clone, Debug)]
struct MslVersionArg((u8, u8));

impl FromStr for MslVersionArg {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut iter = s.split('.');

let check_value = |iter: &mut core::str::Split<_>| {
iter.next()
.ok_or_else(|| format!("Invalid value for --metal-version: {s}"))?
.parse::<u8>()
.map_err(|err| format!("Invalid value for --metal-version: '{s}': {err}"))
};

let major = check_value(&mut iter)?;
let minor = check_value(&mut iter)?;

Ok(Self((major, minor)))
}
}

#[derive(Default)]
struct Parameters<'a> {
validation_flags: naga::valid::ValidationFlags,
Expand Down Expand Up @@ -287,6 +315,9 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
if let Some(ref model) = args.shader_model {
params.hlsl.shader_model = model.0;
}
if let Some(ref version) = args.metal_version {
params.msl.lang_version = version.0;
}
params.keep_coordinate_space = args.keep_coordinate_space;

params.dot.cfg_only = args.dot_cfg_only;
Expand Down

0 comments on commit a63bec8

Please sign in to comment.