@@ -166,12 +166,10 @@ static void populate_arguments_with_type_conversion(std::vector<std::wstring> &a
166
166
167
167
static DxcCompilationResult dxcCompile (const CHLSLCompiler* compiler, nbl::asset::impl::DXC* dxc, std::string& source, LPCWSTR* args, uint32_t argCount, const CHLSLCompiler::SOptions& options)
168
168
{
169
- // Append Commandline options into source only if debugInfoFlags will emit source
170
- auto sourceEmittingFlags =
171
- CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT |
172
- CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT |
173
- CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_NON_SEMANTIC_BIT;
174
- if ((options.debugInfoFlags .value & sourceEmittingFlags) != CHLSLCompiler::E_DEBUG_INFO_FLAGS::EDIF_NONE)
169
+ // Emit compile flags as a #pragma directive
170
+ // "#pragma wave dxc_compile_flags allows" intended use is to be able to recompile a shader with the same* flags as initial compilation
171
+ // mainly meant to be used while debugging in RenderDoc.
172
+ // * (except "-no-nbl-builtins")
175
173
{
176
174
std::ostringstream insertion;
177
175
insertion << " #pragma wave dxc_compile_flags( " ;
@@ -303,50 +301,32 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
303
301
core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV (const char * code, const IShaderCompiler::SCompilerOptions& options) const
304
302
{
305
303
auto hlslOptions = option_cast (options);
306
-
304
+ auto logger = hlslOptions. preprocessorOptions . logger ;
307
305
if (!code)
308
306
{
309
- hlslOptions. preprocessorOptions . logger .log (" code is nullptr" , system::ILogger::ELL_ERROR);
307
+ logger.log (" code is nullptr" , system::ILogger::ELL_ERROR);
310
308
return nullptr ;
311
309
}
312
310
std::vector<std::string> dxc_compile_flags = {};
313
- IShader::E_SHADER_STAGE stageOverrideFromPragma = IShader::ESS_UNKNOWN ;
314
- auto newCode = preprocessShader (code, stageOverrideFromPragma , hlslOptions.preprocessorOptions , dxc_compile_flags);
311
+ IShader::E_SHADER_STAGE stage = options. stage ;
312
+ auto newCode = preprocessShader (code, stage , hlslOptions.preprocessorOptions , dxc_compile_flags);
315
313
316
314
// Suffix is the shader model version
317
- // TODO: Figure out a way to get the shader model version automatically
318
- //
319
- // We can't get it from the DXC library itself, as the different versions and the parsing
320
- // use a weird lexer based system that resolves to a hash, and all of that is in a scoped variable
321
- // (lib/DXIL/DxilShaderModel.cpp:83)
322
- //
323
- // Another option is trying to fetch it from the commandline tool, either from parsing the help message
324
- // or from brute forcing every -T option until one isn't accepted
325
- //
326
315
std::wstring targetProfile (SHADER_MODEL_PROFILE);
327
- IShader::E_SHADER_STAGE stage = options.stage ;
328
- if (stageOverrideFromPragma != IShader::ESS_UNKNOWN)
329
- {
330
- // Shader Stage was overriden using #pragma
331
- // #pragma wave shaderStage overrides all other definitions of shader stage, such as
332
- // -T argument (passed here as options.stage)
333
- // shader stage inferred from file extension in asset namespace
334
- stage = stageOverrideFromPragma;
335
- }
336
316
337
317
std::vector<std::wstring> arguments = {};
338
318
if (dxc_compile_flags.size () || hlslOptions.dxcOptions .size ()) { // #pragma dxc_compile_flags takes priority
339
- populate_arguments_with_type_conversion (arguments, dxc_compile_flags, hlslOptions. preprocessorOptions . logger );
319
+ populate_arguments_with_type_conversion (arguments, dxc_compile_flags, logger);
340
320
}
341
321
else if (hlslOptions.dxcOptions .size ()) { // second in order of priority is command line arguments
342
- populate_arguments_with_type_conversion (arguments, hlslOptions.dxcOptions , hlslOptions. preprocessorOptions . logger );
322
+ populate_arguments_with_type_conversion (arguments, hlslOptions.dxcOptions , logger);
343
323
}
344
324
else { // lastly default arguments
345
325
346
326
// Set profile two letter prefix based on stage
347
327
auto stageStr = ShaderStageToString (stage);
348
328
if (!stageStr) {
349
- hlslOptions. preprocessorOptions . logger .log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
329
+ logger.log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
350
330
return nullptr ;
351
331
}
352
332
targetProfile.replace (0 , 2 , stageStr);
@@ -381,8 +361,8 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
381
361
arguments.push_back (L" -fspv-debug=vulkan-with-source" );
382
362
}
383
363
384
- try_upgrade_shader_stage (arguments, stageOverrideFromPragma );
385
- try_upgrade_hlsl_version (arguments);
364
+ try_upgrade_shader_stage (arguments, stage, logger );
365
+ try_upgrade_hlsl_version (arguments, logger );
386
366
387
367
uint32_t argc = arguments.size ();
388
368
LPCWSTR* argsArray = new LPCWSTR[argc];
@@ -408,7 +388,7 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
408
388
409
389
// Optimizer step
410
390
if (hlslOptions.spirvOptimizer )
411
- outSpirv = hlslOptions.spirvOptimizer ->optimize (outSpirv.get (), hlslOptions. preprocessorOptions . logger );
391
+ outSpirv = hlslOptions.spirvOptimizer ->optimize (outSpirv.get (), logger);
412
392
413
393
return core::make_smart_refctd_ptr<asset::ICPUShader>(std::move (outSpirv), stage, IShader::E_CONTENT_TYPE::ECT_SPIRV, hlslOptions.preprocessorOptions .sourceIdentifier .data ());
414
394
}
0 commit comments