Skip to content

Commit ca783f8

Browse files
committed
address comments
1 parent 6da9c0b commit ca783f8

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/nbl/asset/utils/CWaveStringResolver.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ namespace nbl::wave
5959
// to match boost wave syntax
6060
// https://www.boost.org/doc/libs/1_82_0/libs/wave/doc/class_reference_context.html#:~:text=Maintain%20defined%20macros-,add_macro_definition,-bool%20add_macro_definition
6161

62-
for (const auto& define : preprocessOptions.extraDefines)
63-
{
64-
const std::string macroDefinition = define.identifier.data() + core::string("=") + define.definition.data();
65-
const bool isMacroAdded = context.add_macro_definition(macroDefinition);
66-
assert(isMacroAdded);
67-
}
68-
6962
// preprocess
7063
core::string resolvedString;
7164
try
7265
{
66+
for (const auto& define : preprocessOptions.extraDefines)
67+
{
68+
std::string macroDefinition(define.identifier);
69+
macroDefinition.push_back('=');
70+
macroDefinition.append(define.definition);
71+
context.add_macro_definition(macroDefinition);
72+
}
73+
7374
auto stream = std::stringstream();
7475
for (auto i = context.begin(); i != context.end(); i++)
7576
stream << i->get_value();
@@ -90,4 +91,4 @@ namespace nbl::wave
9091

9192
return resolvedString;
9293
}
93-
}
94+
}

tools/nsc/main.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)