-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Precompiled shaders macro #8217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
ce14ac3
d974548
c1f9549
95491ce
9d52aca
80509c6
59db4c7
1dfc2b2
f7ecc4c
930b35b
309919a
bac4a48
12d5e26
a28790d
1a1d563
2f0293d
2229f05
11c9bca
662c76c
9d45fd9
78250d3
9c8988e
f12f60f
d1f1675
ed9934b
be1504d
038fb11
b66e991
5c03032
6b34506
0915522
fdfa221
cf98e44
507f3d4
d954714
f586710
10f31e0
9281184
9e41b07
f2a3620
113a75e
c860d50
5b9616e
6ea7ea7
a0f613b
c01e505
fc4e1c7
bedc327
dff0697
8344a81
537b32e
b06ce5e
1675170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,15 @@ impl Parse for PrecompileDxilArgs { | |
} | ||
} | ||
|
||
struct TempFolder { | ||
path: PathBuf, | ||
} | ||
impl Drop for TempFolder { | ||
fn drop(&mut self) { | ||
std::fs::remove_dir_all(&self.path).expect("Failed to remove temporary folder"); | ||
} | ||
} | ||
|
||
/// This is so we can conditionally hook into DXC depending on the target, which must be configured via #\[cfg] within the main program. | ||
/// Proc macros don't directly have access to the target configuration. Invoking naga unnecessarily shouldn't be *too* major, but | ||
/// compiling to macOS shouldn't require dxc be present. | ||
|
@@ -213,13 +222,17 @@ pub fn precompile_hlsl_to_dxil(input: TokenStream) -> TokenStream { | |
.to_string(), | ||
); | ||
std::fs::create_dir(&temporary_folder_location).expect("Failed to create temporary directory"); | ||
// Drop guard essentially | ||
let tempoary_folder = TempFolder { | ||
path: temporary_folder_location, | ||
}; | ||
|
||
// The naming matters for DXIL debug info. We don't want to give it a name that seems like something the | ||
// user might've specified, as that could cause confusion. | ||
let input_file = temporary_folder_location.join("__wgpu_inline.hlsl"); | ||
let input_file = tempoary_folder.path.join("__wgpu_inline.hlsl"); | ||
std::fs::write(&input_file, args.hlsl_code.as_bytes()) | ||
.expect("Failed to write to HLSL input file"); | ||
let temporary_file_location = temporary_folder_location.join("file.dxil"); | ||
let temporary_file_location = tempoary_folder.path.join("file.dxil"); | ||
let output = std::process::Command::new("dxc") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely need to make sure the errors when external tools aren't found are very good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the error messages slightly. You probably have a way you'd prefer to do it though |
||
.args([ | ||
"-T", | ||
|
@@ -238,8 +251,6 @@ pub fn precompile_hlsl_to_dxil(input: TokenStream) -> TokenStream { | |
panic!("DXC failed:\n{}", String::from_utf8(output.stderr).unwrap()); | ||
} | ||
let dxil = std::fs::read(temporary_file_location).expect("Failed to read DXC output file"); | ||
std::fs::remove_dir_all(temporary_folder_location) | ||
.expect("Failed to remove temporary directory"); | ||
quote! { | ||
&[#(#dxil),*] | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.