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 committed Mar 15, 2024
1 parent 6a5418b commit 132e2c7
Showing 1 changed file with 31 additions and 0 deletions.
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 132e2c7

Please sign in to comment.