@@ -472,34 +472,6 @@ class ShaderCompiler final : public IApplicationFramework
472472 for (const auto & p : m_include_search_paths)
473473 includeFinder->addSearchPath (p, includeLoader);
474474
475- if (preprocessOnly)
476- {
477- CHLSLCompiler::SPreprocessorOptions opt = {};
478- opt.sourceIdentifier = sourceIdentifier;
479- opt.logger = m_logger.get ();
480- opt.includeFinder = includeFinder.get ();
481- opt.depfile = dep.enabled ;
482- opt.depfilePath = dep.path ;
483-
484- const char * codePtr = (const char *)shader->getContent ()->getPointer ();
485- std::string_view code (codePtr, std::strlen (codePtr));
486-
487- r.text = hlslcompiler->preprocessShader (std::string (code), shaderStage, opt, nullptr );
488- r.ok = !r.text .empty ();
489- r.view = r.text ;
490- return r;
491- }
492-
493- CHLSLCompiler::SOptions opt = {};
494- opt.stage = shaderStage;
495- opt.preprocessorOptions .sourceIdentifier = sourceIdentifier;
496- opt.preprocessorOptions .logger = m_logger.get ();
497- opt.preprocessorOptions .includeFinder = includeFinder.get ();
498- opt.preprocessorOptions .depfile = dep.enabled ;
499- opt.preprocessorOptions .depfilePath = dep.path ;
500- opt.debugInfoFlags = bitflag<IShaderCompiler::E_DEBUG_INFO_FLAGS>(IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT);
501- opt.dxcOptions = std::span<std::string>(m_arguments);
502-
503475 // need this struct becuase fields of IShaderCompiler::SMacroDefinition are string views
504476 struct SMacroDefinitionBuffer
505477 {
@@ -524,7 +496,7 @@ class ShaderCompiler final : public IApplicationFramework
524496 if (equalPos == std::string::npos)
525497 {
526498 identifier = argumentTmp;
527- definition = " " ;
499+ definition = " 1 " ;
528500 }
529501 else
530502 {
@@ -541,7 +513,35 @@ class ShaderCompiler final : public IApplicationFramework
541513 macroDefinitions.emplace_back (macroDefinitionBuffer.identifier , macroDefinitionBuffer.definition );
542514 }
543515
516+ if (preprocessOnly)
517+ {
518+ CHLSLCompiler::SPreprocessorOptions opt = {};
519+ opt.sourceIdentifier = sourceIdentifier;
520+ opt.logger = m_logger.get ();
521+ opt.includeFinder = includeFinder.get ();
522+ opt.depfile = dep.enabled ;
523+ opt.depfilePath = dep.path ;
524+ opt.extraDefines = macroDefinitions;
525+
526+ const char * codePtr = (const char *)shader->getContent ()->getPointer ();
527+ std::string_view code (codePtr, std::strlen (codePtr));
528+
529+ r.text = hlslcompiler->preprocessShader (std::string (code), shaderStage, opt, nullptr );
530+ r.ok = !r.text .empty ();
531+ r.view = r.text ;
532+ return r;
533+ }
534+
535+ CHLSLCompiler::SOptions opt = {};
536+ opt.stage = shaderStage;
537+ opt.preprocessorOptions .sourceIdentifier = sourceIdentifier;
538+ opt.preprocessorOptions .logger = m_logger.get ();
539+ opt.preprocessorOptions .includeFinder = includeFinder.get ();
540+ opt.preprocessorOptions .depfile = dep.enabled ;
541+ opt.preprocessorOptions .depfilePath = dep.path ;
544542 opt.preprocessorOptions .extraDefines = macroDefinitions;
543+ opt.debugInfoFlags = bitflag<IShaderCompiler::E_DEBUG_INFO_FLAGS>(IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT);
544+ opt.dxcOptions = std::span<std::string>(m_arguments);
545545
546546 r.compiled = hlslcompiler->compileToSPIRV ((const char *)shader->getContent ()->getPointer (), opt);
547547 r.ok = bool (r.compiled );
0 commit comments