@@ -83,7 +83,7 @@ DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::impl:
83
83
if ((options.debugInfoFlags .value & sourceEmittingFlags) != CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_NONE)
84
84
{
85
85
std::ostringstream insertion;
86
- insertion << " // #pragma compile_flags " ;
86
+ insertion << " #pragma compile_flags " ;
87
87
88
88
std::wstring_convert<std::codecvt_utf8<wchar_t >, wchar_t > conv;
89
89
for (uint32_t arg = 0 ; arg < argCount; arg ++)
@@ -204,11 +204,11 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
204
204
return resolvedString;
205
205
}
206
206
207
- // std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
208
- // {
209
- // std::vector<LPCWSTR > extra_dxc_compile_flags = {};
210
- // return preprocessShader(code, stage, extra_dxc_compile_flags, preprocessOptions);
211
- // }
207
+ std::string CHLSLCompiler::preprocessShader (std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
208
+ {
209
+ std::vector<std::string > extra_dxc_compile_flags = {};
210
+ return preprocessShader (std::move ( code) , stage, extra_dxc_compile_flags, preprocessOptions);
211
+ }
212
212
213
213
core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV (const char * code, const IShaderCompiler::SCompilerOptions& options) const
214
214
{
@@ -238,41 +238,47 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
238
238
// Set profile two letter prefix based on stage
239
239
switch (stage)
240
240
{
241
- case asset::IShader::ESS_VERTEX:
242
- targetProfile.replace (0 , 2 , L" vs" );
243
- break ;
244
- case asset::IShader::ESS_TESSELLATION_CONTROL:
245
- targetProfile.replace (0 , 2 , L" ds" );
246
- break ;
247
- case asset::IShader::ESS_TESSELLATION_EVALUATION:
248
- targetProfile.replace (0 , 2 , L" hs" );
249
- break ;
250
- case asset::IShader::ESS_GEOMETRY:
251
- targetProfile.replace (0 , 2 , L" gs" );
252
- break ;
253
- case asset::IShader::ESS_FRAGMENT:
254
- targetProfile.replace (0 , 2 , L" ps" );
255
- break ;
256
- case asset::IShader::ESS_COMPUTE:
257
- targetProfile.replace (0 , 2 , L" cs" );
258
- break ;
259
- case asset::IShader::ESS_TASK:
260
- targetProfile.replace (0 , 2 , L" as" );
261
- break ;
262
- case asset::IShader::ESS_MESH:
263
- targetProfile.replace (0 , 2 , L" ms" );
264
- break ;
265
- default :
266
- hlslOptions.preprocessorOptions .logger .log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
267
- return nullptr ;
241
+ case asset::IShader::ESS_VERTEX:
242
+ targetProfile.replace (0 , 2 , L" vs" );
243
+ break ;
244
+ case asset::IShader::ESS_TESSELLATION_CONTROL:
245
+ targetProfile.replace (0 , 2 , L" ds" );
246
+ break ;
247
+ case asset::IShader::ESS_TESSELLATION_EVALUATION:
248
+ targetProfile.replace (0 , 2 , L" hs" );
249
+ break ;
250
+ case asset::IShader::ESS_GEOMETRY:
251
+ targetProfile.replace (0 , 2 , L" gs" );
252
+ break ;
253
+ case asset::IShader::ESS_FRAGMENT:
254
+ targetProfile.replace (0 , 2 , L" ps" );
255
+ break ;
256
+ case asset::IShader::ESS_COMPUTE:
257
+ targetProfile.replace (0 , 2 , L" cs" );
258
+ break ;
259
+ case asset::IShader::ESS_TASK:
260
+ targetProfile.replace (0 , 2 , L" as" );
261
+ break ;
262
+ case asset::IShader::ESS_MESH:
263
+ targetProfile.replace (0 , 2 , L" ms" );
264
+ break ;
265
+ default :
266
+ hlslOptions.preprocessorOptions .logger .log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
267
+ return nullptr ;
268
268
};
269
269
270
-
270
+ std::wstring* arg_storage = NULL ;
271
271
std::vector<LPCWSTR> arguments;
272
- if (dxc_compile_flags.size ()) {
272
+
273
+ if (dxc_compile_flags.size ()) { // #pragma wave overrides compile flags
274
+ size_t arg_size = dxc_compile_flags.size ();
273
275
arguments = {};
274
- for (size_t i = 0 ; i < dxc_compile_flags.size (); i++)
275
- arguments.push_back (LPCWSTR (dxc_compile_flags[i].c_str ()));
276
+ arguments.reserve (arg_size);
277
+ arg_storage = new std::wstring[arg_size]; // prevent deallocation before shader compilation
278
+ for (size_t i = 0 ; i < dxc_compile_flags.size (); i++) {
279
+ arg_storage[i] = std::wstring (dxc_compile_flags[i].begin (), dxc_compile_flags[i].end ());
280
+ arguments.push_back (arg_storage[i].c_str ());
281
+ }
276
282
}
277
283
else {
278
284
arguments = {
@@ -315,11 +321,14 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
315
321
this ,
316
322
m_dxcCompilerTypes,
317
323
newCode,
318
- & arguments[ 0 ] ,
324
+ arguments. data () ,
319
325
arguments.size (),
320
326
hlslOptions
321
327
);
322
328
329
+ if (arg_storage)
330
+ delete[] arg_storage;
331
+
323
332
if (!compileResult.objectBlob )
324
333
{
325
334
return nullptr ;
@@ -341,4 +350,6 @@ void CHLSLCompiler::insertIntoStart(std::string& code, std::ostringstream&& ins)
341
350
{
342
351
code.insert (0u , ins.str ());
343
352
}
353
+
354
+
344
355
#endif
0 commit comments