diff --git a/Cargo.lock b/Cargo.lock index 3c16a737f0..763f6855de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2006,9 +2006,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", @@ -3553,9 +3553,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3563,9 +3563,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -3590,9 +3590,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3600,9 +3600,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -3613,9 +3613,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-bindgen-test" @@ -4612,18 +4612,18 @@ checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zerocopy" -version = "0.7.15" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ba595b9f2772fbee2312de30eeb80ec773b4cb2f1e8098db024afadda6c06f" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.15" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "772666c41fb6dceaf520b564b962d738a8e1a83b41bd48945f50837aed78bb1d" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 4ad43cc165..5226a8b29e 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -238,12 +238,7 @@ impl super::Device { .as_ref() .map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("{e}")))?; - let source_name = stage - .module - .raw_name - .as_ref() - .and_then(|cstr| cstr.to_str().ok()) - .unwrap_or_default(); + let source_name = stage.module.raw_name.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 0057b0e85e..30d809e61e 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -1,3 +1,4 @@ +use std::ffi::CStr; use std::ptr; pub(super) use dxc::{compile_dxc, get_dxc_container, DxcContainer}; @@ -13,8 +14,8 @@ use crate::auxil::dxgi::result::HResult; pub(super) fn compile_fxc( device: &super::Device, - source: &String, - source_name: &str, + source: &str, + source_name: Option<&CStr>, raw_ep: &std::ffi::CString, stage_bit: wgt::ShaderStages, full_stage: String, @@ -32,13 +33,17 @@ pub(super) fn compile_fxc( { compile_flags |= d3dcompiler::D3DCOMPILE_DEBUG | d3dcompiler::D3DCOMPILE_SKIP_OPTIMIZATION; } + + // If no name has been set, D3DCompile wants the null pointer. + let source_name = source_name.map(|cstr| cstr.as_ptr()).unwrap_or(ptr::null()); + let mut error = d3d12::Blob::null(); let hr = unsafe { profiling::scope!("d3dcompiler::D3DCompile"); d3dcompiler::D3DCompile( source.as_ptr().cast(), source.len(), - source_name.as_ptr().cast(), + source_name.cast(), ptr::null(), ptr::null_mut(), raw_ep.as_ptr(), @@ -78,6 +83,7 @@ pub(super) fn compile_fxc( // The Dxc implementation is behind a feature flag so that users who don't want to use dxc can disable the feature. #[cfg(feature = "dxc_shader_compiler")] mod dxc { + use std::ffi::CStr; use std::path::PathBuf; // Destructor order should be fine since _dxil and _dxc don't rely on each other. @@ -132,7 +138,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, @@ -166,6 +172,10 @@ mod dxc { Err(e) => return (Err(e), log::Level::Error), }; + let source_name = source_name + .and_then(|cstr| cstr.to_str().ok()) + .unwrap_or(""); + let compiled = dxc_container.compiler.compile( &blob, source_name, @@ -263,6 +273,7 @@ mod dxc { // These are stubs for when the `dxc_shader_compiler` feature is disabled. #[cfg(not(feature = "dxc_shader_compiler"))] mod dxc { + use std::ffi::CStr; use std::path::PathBuf; pub(crate) struct DxcContainer {} @@ -280,7 +291,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,