Skip to content

Commit 7c5b14d

Browse files
Alter compile_{f,d}xc to take Option<&CStr>
1 parent a6d3d13 commit 7c5b14d

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

wgpu-hal/src/dx12/device.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ impl super::Device {
262262
let source_name = stage
263263
.module
264264
.raw_name
265-
.as_ref()
266-
.and_then(|cstr| cstr.to_str().ok())
267-
.unwrap_or_default();
265+
.as_deref();
268266

269267
// Compile with DXC if available, otherwise fall back to FXC
270268
let (result, log_level) = if let Some(ref dxc_container) = self.dxc_container {

wgpu-hal/src/dx12/shader_compilation.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::auxil::dxgi::result::HResult;
1414
pub(super) fn compile_fxc(
1515
device: &super::Device,
1616
source: &str,
17-
source_name: &str,
17+
source_name: Option<&CStr>,
1818
raw_ep: &std::ffi::CString,
1919
stage_bit: wgt::ShaderStages,
2020
full_stage: String,
@@ -34,11 +34,7 @@ pub(super) fn compile_fxc(
3434
}
3535

3636
// If no name has been set, D3DCompile wants the null pointer.
37-
let source_name = if source_name.is_empty() {
38-
ptr::null()
39-
} else {
40-
source_name.as_ptr()
41-
};
37+
let source_name = source_name.map(|cstr| cstr.as_ptr()).unwrap_or(ptr::null());
4238

4339
let mut error = d3d12::Blob::null();
4440
let hr = unsafe {
@@ -140,7 +136,7 @@ mod dxc {
140136
pub(crate) fn compile_dxc(
141137
device: &crate::dx12::Device,
142138
source: &str,
143-
source_name: &str,
139+
source_name: Option<&CStr>,
144140
raw_ep: &str,
145141
stage_bit: wgt::ShaderStages,
146142
full_stage: String,
@@ -174,6 +170,8 @@ mod dxc {
174170
Err(e) => return (Err(e), log::Level::Error),
175171
};
176172

173+
let source_name = source_name.map(|cstr| cstr.to_str()).unwrap_or(&"");
174+
177175
let compiled = dxc_container.compiler.compile(
178176
&blob,
179177
source_name,

0 commit comments

Comments
 (0)