1
1
use std:: ptr;
2
+ use std:: ffi:: CStr ;
2
3
3
4
pub ( super ) use dxc:: { compile_dxc, get_dxc_container, DxcContainer } ;
4
5
use winapi:: um:: d3dcompiler;
@@ -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 {
@@ -140,7 +137,7 @@ mod dxc {
140
137
pub ( crate ) fn compile_dxc (
141
138
device : & crate :: dx12:: Device ,
142
139
source : & str ,
143
- source_name : & str ,
140
+ source_name : Option < & CStr > ,
144
141
raw_ep : & str ,
145
142
stage_bit : wgt:: ShaderStages ,
146
143
full_stage : String ,
@@ -174,6 +171,8 @@ mod dxc {
174
171
Err ( e) => return ( Err ( e) , log:: Level :: Error ) ,
175
172
} ;
176
173
174
+ let source_name = source_name. map ( |cstr| cstr. to_str ( ) ) . unwrap_or ( & "" ) ;
175
+
177
176
let compiled = dxc_container. compiler . compile (
178
177
& blob,
179
178
source_name,
@@ -271,6 +270,7 @@ mod dxc {
271
270
// These are stubs for when the `dxc_shader_compiler` feature is disabled.
272
271
#[ cfg( not( feature = "dxc_shader_compiler" ) ) ]
273
272
mod dxc {
273
+ use std:: ffi:: CStr ;
274
274
use std:: path:: PathBuf ;
275
275
276
276
pub ( crate ) struct DxcContainer { }
@@ -288,7 +288,7 @@ mod dxc {
288
288
pub ( crate ) fn compile_dxc (
289
289
_device : & crate :: dx12:: Device ,
290
290
_source : & str ,
291
- _source_name : & str ,
291
+ _source_name : Option < & CStr > ,
292
292
_raw_ep : & str ,
293
293
_stage_bit : wgt:: ShaderStages ,
294
294
_full_stage : String ,
0 commit comments