mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 23:04:07 +00:00
Makefile and RON converter parameters
This commit is contained in:
parent
0de28d1656
commit
df855bc2ff
@ -18,3 +18,5 @@ spirv = { package = "spirv_headers", version = "1" }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.6"
|
||||
ron = "0.5"
|
||||
serde = { version = "1", features = ["serde_derive"] }
|
||||
|
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
.PHONY: all clean
|
||||
|
||||
all: boids.metallib
|
||||
|
||||
clean:
|
||||
rm *.metal *.air *.metallib
|
||||
|
||||
%.metal: test-data/%.wgsl $(wildcard src/*.rs src/**/*.rs examples/*.rs)
|
||||
cargo run --example convert -- $< $@
|
||||
|
||||
%.air: %.metal
|
||||
xcrun -sdk macosx metal -c $< -mmacosx-version-min=10.11
|
||||
|
||||
%.metallib: %.air
|
||||
xcrun -sdk macosx metallib $< -o $@
|
@ -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();
|
||||
for (key, value) in params.metal_bindings {
|
||||
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) },
|
||||
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,
|
||||
};
|
||||
|
@ -13,8 +13,8 @@ use std::{
|
||||
};
|
||||
|
||||
|
||||
type FastHashMap<K, T> = HashMap<K, T, BuildHasherDefault<fxhash::FxHasher>>;
|
||||
type FastHashSet<K> = HashSet<K, BuildHasherDefault<fxhash::FxHasher>>;
|
||||
pub type FastHashMap<K, T> = HashMap<K, T, BuildHasherDefault<fxhash::FxHasher>>;
|
||||
pub type FastHashSet<K> = HashSet<K, BuildHasherDefault<fxhash::FxHasher>>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Header {
|
||||
|
7
test-data/boids.ron
Normal file
7
test-data/boids.ron
Normal file
@ -0,0 +1,7 @@
|
||||
(
|
||||
metal_bindings: {
|
||||
(set: 0, binding: 0): (buffer: Some(0), texture: None, sampler: None),
|
||||
(set: 0, binding: 1): (buffer: Some(1), texture: None, sampler: None),
|
||||
(set: 0, binding: 2): (buffer: Some(2), texture: None, sampler: None),
|
||||
}
|
||||
)
|
@ -30,7 +30,19 @@ fn convert_boids() {
|
||||
let module = load_wgsl("boids");
|
||||
{
|
||||
use naga::back::msl;
|
||||
let binding_map = msl::BindingMap::default();
|
||||
let mut binding_map = msl::BindingMap::default();
|
||||
binding_map.insert(
|
||||
msl::BindSource { set: 0, binding: 0 },
|
||||
msl::BindTarget { buffer: Some(0), texture: None, sampler: None },
|
||||
);
|
||||
binding_map.insert(
|
||||
msl::BindSource { set: 0, binding: 1 },
|
||||
msl::BindTarget { buffer: Some(1), texture: None, sampler: Some(1) },
|
||||
);
|
||||
binding_map.insert(
|
||||
msl::BindSource { set: 0, binding: 2 },
|
||||
msl::BindTarget { buffer: Some(2), texture: None, sampler: Some(1) },
|
||||
);
|
||||
let options = msl::Options {
|
||||
binding_map: &binding_map,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user