|
1 | 1 | #![allow(unexpected_cfgs)]
|
| 2 | +use naga::{ |
| 3 | + back::wgsl::WriterFlags, |
| 4 | + valid::{ValidationFlags, Validator}, |
| 5 | +}; |
2 | 6 | use quote::quote;
|
3 | 7 |
|
4 | 8 | #[derive(Debug, serde::Deserialize)]
|
@@ -91,19 +95,35 @@ fn wgsl(spv_filepath: impl AsRef<std::path::Path>, destination: impl AsRef<std::
|
91 | 95 | });
|
92 | 96 | let opts = naga::front::spv::Options::default();
|
93 | 97 | let module = naga::front::spv::parse_u8_slice(&bytes, &opts).unwrap();
|
94 |
| - let mut validator = |
95 |
| - naga::valid::Validator::new(Default::default(), naga::valid::Capabilities::empty()); |
96 |
| - let info = validator.validate(&module).unwrap_or_else(|e| { |
97 |
| - panic!( |
98 |
| - "Could not validate '{}': {e}", |
99 |
| - spv_filepath.as_ref().display(), |
100 |
| - ) |
101 |
| - }); |
102 |
| - let wgsl = |
103 |
| - naga::back::wgsl::write_string(&module, &info, naga::back::wgsl::WriterFlags::empty()) |
104 |
| - .unwrap(); |
| 98 | + let mut wgsl = String::new(); |
| 99 | + let mut panic_msg: Option<String> = None; |
| 100 | + for (vflags, name) in [ |
| 101 | + (ValidationFlags::empty(), "empty"), |
| 102 | + (ValidationFlags::all(), "all"), |
| 103 | + ] { |
| 104 | + let mut validator = Validator::new(vflags, Default::default()); |
| 105 | + match validator.validate(&module) { |
| 106 | + Err(e) => { |
| 107 | + panic_msg = Some(format!( |
| 108 | + "Could not validate '{}' with WGSL validation flags {name}: {}", |
| 109 | + spv_filepath.as_ref().display(), |
| 110 | + e.emit_to_string(&wgsl) |
| 111 | + )); |
| 112 | + } |
| 113 | + Ok(i) => { |
| 114 | + wgsl = naga::back::wgsl::write_string(&module, &i, WriterFlags::empty()).unwrap(); |
| 115 | + } |
| 116 | + }; |
| 117 | + } |
| 118 | + |
105 | 119 | let destination = destination.as_ref().with_extension("wgsl");
|
106 | 120 | std::fs::write(destination, wgsl).unwrap();
|
| 121 | + if let Some(msg) = panic_msg { |
| 122 | + panic!( |
| 123 | + "{msg}\nWGSL was written to {}", |
| 124 | + spv_filepath.as_ref().display() |
| 125 | + ); |
| 126 | + } |
107 | 127 | }
|
108 | 128 |
|
109 | 129 | pub struct RenderlingPaths {
|
|
0 commit comments