mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 09:34:09 +01:00
Makefile and RON converter parameters
This commit is contained in:
1 parent
0de28d1656
commit
df855bc2ff
6 files changed
+82
-12
No files matched your search
+43
-9
@@ -1,5 +1,24 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::{env, fs};
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Serialize, Deserialize)]
|
||||
struct BindSource {
|
||||
set: u32,
|
||||
binding: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct BindTarget {
|
||||
buffer: Option<u8>,
|
||||
texture: Option<u8>,
|
||||
sampler: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
struct Parameters {
|
||||
metal_bindings: naga::FastHashMap<BindSource, BindTarget>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
@@ -20,17 +39,32 @@ fn main() {
|
||||
|
||||
if args.len() <= 2 {
|
||||
println!("{:#?}", module);
|
||||
} else if args[2].ends_with(".metal") {
|
||||
return;
|
||||
}
|
||||
|
||||
let param_path = std::path::PathBuf::from(&args[1])
|
||||
.with_extension("ron");
|
||||
let params = match fs::read_to_string(param_path) {
|
||||
Ok(string) => ron::de::from_str(&string).unwrap(),
|
||||
Err(_) => Parameters::default(),
|
||||
};
|
||||
|
||||
if args[2].ends_with(".metal") {
|
||||
use naga::back::msl;
|
||||
let mut binding_map = msl::BindingMap::default();
|
||||
binding_map.insert(
|
||||
msl::BindSource { set: 0, binding: 0 },
|
||||
msl::BindTarget { buffer: None, texture: Some(1), sampler: None },
|
||||
);
|
||||
binding_map.insert(
|
||||
msl::BindSource { set: 0, binding: 1 },
|
||||
msl::BindTarget { buffer: None, texture: None, sampler: Some(1) },
|
||||
);
|
||||
for (key, value) in params.metal_bindings {
|
||||
binding_map.insert(
|
||||
msl::BindSource {
|
||||
set: key.set,
|
||||
binding: key.binding,
|
||||
},
|
||||
msl::BindTarget {
|
||||
buffer: value.buffer,
|
||||
texture: value.texture,
|
||||
sampler: value.sampler,
|
||||
},
|
||||
);
|
||||
}
|
||||
let options = msl::Options {
|
||||
binding_map: &binding_map,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user