-
Notifications
You must be signed in to change notification settings - Fork 68
Fixed preprocessor bug which caused incorrect handling of the -D option #984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,15 +58,20 @@ namespace nbl::wave | |
| // now define them as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D=32768" | ||
| // to match boost wave syntax | ||
| // 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 | ||
|
|
||
| for (const auto& define : preprocessOptions.extraDefines) | ||
| context.add_macro_definition(define.identifier.data() + core::string("=") + define.definition.data()); | ||
| { | ||
| const std::string macroDefinition = define.identifier.data() + core::string("=") + define.definition.data(); | ||
| const bool isMacroAdded = context.add_macro_definition(macroDefinition); | ||
| assert(isMacroAdded); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a duplicate should not be asserted, in this case silent fail is better you actually better just move |
||
| } | ||
|
|
||
| // preprocess | ||
| core::string resolvedString; | ||
| try | ||
| { | ||
| auto stream = std::stringstream(); | ||
| for (auto i= context.begin(); i!= context.end(); i++) | ||
| for (auto i = context.begin(); i != context.end(); i++) | ||
| stream << i->get_value(); | ||
| resolvedString = stream.str(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,6 +500,49 @@ class ShaderCompiler final : public IApplicationFramework | |
| opt.debugInfoFlags = bitflag<IShaderCompiler::E_DEBUG_INFO_FLAGS>(IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT); | ||
| opt.dxcOptions = std::span<std::string>(m_arguments); | ||
|
|
||
| // need this struct becuase fields of IShaderCompiler::SMacroDefinition are string views | ||
| struct SMacroDefinitionBuffer | ||
| { | ||
| std::string identifier; | ||
| std::string definition; | ||
| }; | ||
|
|
||
| core::vector<SMacroDefinitionBuffer> macroDefinitionBuffers; | ||
| core::vector<IShaderCompiler::SMacroDefinition> macroDefinitions; | ||
| { | ||
| for (const auto& argument : m_arguments) | ||
| { | ||
| if (argument.rfind("-D", 0) != 0) | ||
| continue; | ||
|
|
||
| std::string argumentTmp = argument.substr(2); | ||
|
|
||
| std::string identifier; | ||
| std::string definition; | ||
|
|
||
| const size_t equalPos = argumentTmp.find('='); | ||
| if (equalPos == std::string::npos) | ||
| { | ||
| identifier = argumentTmp; | ||
| definition = ""; | ||
|
Comment on lines
+523
to
+527
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it changes semantic of lack of
on |
||
| } | ||
| else | ||
| { | ||
| identifier = argumentTmp.substr(0, equalPos); | ||
| definition = argumentTmp.substr(equalPos + 1); | ||
| } | ||
|
|
||
| macroDefinitionBuffers.emplace_back(identifier, definition); | ||
| } | ||
|
|
||
| macroDefinitions.reserve(macroDefinitionBuffers.size()); | ||
|
|
||
| for (const auto& macroDefinitionBuffer : macroDefinitionBuffers) | ||
| macroDefinitions.emplace_back(macroDefinitionBuffer.identifier, macroDefinitionBuffer.definition); | ||
| } | ||
|
|
||
| opt.preprocessorOptions.extraDefines = macroDefinitions; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok but you forgot about |
||
|
|
||
| r.compiled = hlslcompiler->compileToSPIRV((const char*)shader->getContent()->getPointer(), opt); | ||
| r.ok = bool(r.compiled); | ||
| if (r.ok) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we suppose
define.definitionbeing a null span ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define.definitioncan be an empty string but not a null span