init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
use naga::back::spv::PipelineOptions;
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
println!("cargo::rerun-if-changed=Cargo.lock");
|
||||
println!("cargo::rerun-if-changed=src/shader.wgsl");
|
||||
|
||||
let shader = std::fs::read_to_string("src/shader.wgsl").unwrap();
|
||||
|
||||
// Parse the source into a Module.
|
||||
let module: naga::Module = naga::front::wgsl::parse_str(&shader)
|
||||
.inspect_err(|e| e.emit_to_stderr_with_path(&shader, "src/shader.wgsl"))
|
||||
.expect("Failed to parse WGSL");
|
||||
// Validate the module.
|
||||
// Validation can be made less restrictive by changing the ValidationFlags.
|
||||
let module_info: naga::valid::ModuleInfo = naga::valid::Validator::new(
|
||||
naga::valid::ValidationFlags::all(),
|
||||
naga::valid::Capabilities::all(),
|
||||
)
|
||||
.subgroup_stages(naga::valid::ShaderStages::all())
|
||||
.subgroup_operations(naga::valid::SubgroupOperationSet::all())
|
||||
.validate(&module)
|
||||
.inspect_err(|e| e.emit_to_stderr_with_path(&shader, "src/shader.wgsl"))
|
||||
.unwrap();
|
||||
|
||||
// Translate the module.
|
||||
use naga::back::spv;
|
||||
let mut spv_out = vec![];
|
||||
let mut writer = spv::Writer::new(&spv::Options {
|
||||
lang_version: (1, 6),
|
||||
flags: spv::WriterFlags::DEBUG | spv::WriterFlags::PRINT_ON_TRACE_RAYS_FAIL,
|
||||
trace_ray_argument_validation: true,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap();
|
||||
writer
|
||||
.write(
|
||||
&module,
|
||||
&module_info,
|
||||
Some(&PipelineOptions {
|
||||
shader_stage: naga::ShaderStage::Compute,
|
||||
entry_point: "main".to_owned(),
|
||||
}),
|
||||
&None,
|
||||
&mut spv_out,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(
|
||||
"src/shader.spv",
|
||||
spv_out
|
||||
.into_iter()
|
||||
.flat_map(|f| f.to_le_bytes())
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user