Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cli arg to choose metal version #5392

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading