1
+ use std:: ffi:: CStr ;
1
2
use std:: ptr;
2
3
3
4
pub ( super ) use dxc:: { compile_dxc, get_dxc_container, DxcContainer } ;
@@ -14,7 +15,7 @@ use crate::auxil::dxgi::result::HResult;
14
15
pub ( super ) fn compile_fxc (
15
16
device : & super :: Device ,
16
17
source : & str ,
17
- source_name : & str ,
18
+ source_name : Option < & CStr > ,
18
19
raw_ep : & std:: ffi:: CString ,
19
20
stage_bit : wgt:: ShaderStages ,
20
21
full_stage : String ,
@@ -34,11 +35,7 @@ pub(super) fn compile_fxc(
34
35
}
35
36
36
37
// 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
- } ;
38
+ let source_name = source_name. map ( |cstr| cstr. as_ptr ( ) ) . unwrap_or ( ptr:: null ( ) ) ;
42
39
43
40
let mut error = d3d12:: Blob :: null ( ) ;
44
41
let hr = unsafe {
@@ -86,6 +83,7 @@ pub(super) fn compile_fxc(
86
83
// The Dxc implementation is behind a feature flag so that users who don't want to use dxc can disable the feature.
87
84
#[ cfg( feature = "dxc_shader_compiler" ) ]
88
85
mod dxc {
86
+ use std:: ffi:: CStr ;
89
87
use std:: path:: PathBuf ;
90
88
91
89
// Destructor order should be fine since _dxil and _dxc don't rely on each other.
@@ -140,7 +138,7 @@ mod dxc {
140
138
pub ( crate ) fn compile_dxc (
141
139
device : & crate :: dx12:: Device ,
142
140
source : & str ,
143
- source_name : & str ,
141
+ source_name : Option < & CStr > ,
144
142
raw_ep : & str ,
145
143
stage_bit : wgt:: ShaderStages ,
146
144
full_stage : String ,
@@ -174,6 +172,10 @@ mod dxc {
174
172
Err ( e) => return ( Err ( e) , log:: Level :: Error ) ,
175
173
} ;
176
174
175
+ let source_name = source_name
176
+ . and_then ( |cstr| cstr. to_str ( ) . ok ( ) )
177
+ . unwrap_or ( "" ) ;
178
+
177
179
let compiled = dxc_container. compiler . compile (
178
180
& blob,
179
181
source_name,
@@ -271,6 +273,7 @@ mod dxc {
271
273
// These are stubs for when the `dxc_shader_compiler` feature is disabled.
272
274
#[ cfg( not( feature = "dxc_shader_compiler" ) ) ]
273
275
mod dxc {
276
+ use std:: ffi:: CStr ;
274
277
use std:: path:: PathBuf ;
275
278
276
279
pub ( crate ) struct DxcContainer { }
@@ -288,7 +291,7 @@ mod dxc {
288
291
pub ( crate ) fn compile_dxc (
289
292
_device : & crate :: dx12:: Device ,
290
293
_source : & str ,
291
- _source_name : & str ,
294
+ _source_name : Option < & CStr > ,
292
295
_raw_ep : & str ,
293
296
_stage_bit : wgt:: ShaderStages ,
294
297
_full_stage : String ,
0 commit comments