Skip to content

Commit a6d3d13

Browse files
workingjubileejanhohenheimBrezak
committed
Do not feed &"" to D3DCompile
A recent change by rustc, now in 1.79-stable, makes empty str constants point to the same location: 0x01. This is an optimization of sorts, not stable behavior. Code must not rely on constants having stable addresses nor should it pass &"" to APIs expecting CStrs or NULL addresses. D3DCompile will segfault if you give it such a pointer, or worse: read random garbage addresses! Pass the NULL pointer to D3DCompile if wgpu lacks a decent CString. refs: - https://learn.microsoft.com/en-us/windows/win32/api/d3dcompiler/nf-d3dcompiler-d3dcompile Co-authored-by: Jan Hohenheim <[email protected]> Co-authored-by: Brezak <[email protected]>
1 parent d7a35ec commit a6d3d13

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

wgpu-hal/src/dx12/shader_compilation.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ pub(super) fn compile_fxc(
3232
{
3333
compile_flags |= d3dcompiler::D3DCOMPILE_DEBUG | d3dcompiler::D3DCOMPILE_SKIP_OPTIMIZATION;
3434
}
35+
36+
// 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+
};
42+
3543
let mut error = d3d12::Blob::null();
3644
let hr = unsafe {
3745
profiling::scope!("d3dcompiler::D3DCompile");
3846
d3dcompiler::D3DCompile(
3947
source.as_ptr().cast(),
4048
source.len(),
41-
source_name.as_ptr().cast(),
49+
source_name.cast(),
4250
ptr::null(),
4351
ptr::null_mut(),
4452
raw_ep.as_ptr(),

0 commit comments

Comments
 (0)