From 7c5b14d12a9245aaf258bf818441b93950a89a61 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 13 Jun 2024 23:57:57 -0700 Subject: [PATCH] Alter compile_{f,d}xc to take `Option<&CStr>` --- wgpu-hal/src/dx12/device.rs | 4 +--- wgpu-hal/src/dx12/shader_compilation.rs | 12 +++++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 5625dfca3b6..7064ac42dc1 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -262,9 +262,7 @@ impl super::Device { let source_name = stage .module .raw_name - .as_ref() - .and_then(|cstr| cstr.to_str().ok()) - .unwrap_or_default(); + .as_deref(); // Compile with DXC if available, otherwise fall back to FXC let (result, log_level) = if let Some(ref dxc_container) = self.dxc_container { diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index b4afe492b76..2e42fe2e3df 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -14,7 +14,7 @@ use crate::auxil::dxgi::result::HResult; pub(super) fn compile_fxc( device: &super::Device, source: &str, - source_name: &str, + source_name: Option<&CStr>, raw_ep: &std::ffi::CString, stage_bit: wgt::ShaderStages, full_stage: String, @@ -34,11 +34,7 @@ pub(super) fn compile_fxc( } // If no name has been set, D3DCompile wants the null pointer. - let source_name = if source_name.is_empty() { - ptr::null() - } else { - source_name.as_ptr() - }; + let source_name = source_name.map(|cstr| cstr.as_ptr()).unwrap_or(ptr::null()); let mut error = d3d12::Blob::null(); let hr = unsafe { @@ -140,7 +136,7 @@ mod dxc { pub(crate) fn compile_dxc( device: &crate::dx12::Device, source: &str, - source_name: &str, + source_name: Option<&CStr>, raw_ep: &str, stage_bit: wgt::ShaderStages, full_stage: String, @@ -174,6 +170,8 @@ mod dxc { Err(e) => return (Err(e), log::Level::Error), }; + let source_name = source_name.map(|cstr| cstr.to_str()).unwrap_or(&""); + let compiled = dxc_container.compiler.compile( &blob, source_name,