Repository navigation
Fix conditional directives in GLSL macro arguments - #3750
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3442.
Keep directive operands unexpanded while collecting macro arguments, and preserve their newline boundaries for the existing rescan. This lets
#ifdef FOOinsideOGRE_UNIFORMS(...)test the macro name even whenFOOexpands to an empty value,0,1, or another macro. Ordinary argument macros still expand.Count preserved newlines before padding the expansion so following shader statements keep their source line numbers. Stabilize changed borrowed rescan results before advancing to the next pass: forwarded wrappers and rescans that return a slice of the previous buffer must outlive their argument/source storage.
Six regression tests cover
#ifdef,#ifndef,#if defined(FOO)and#elif defined(FOO)with direct and forwarded wrappers (80 combinations), ordinary type expansion, declaration order, following source line numbers, and the borrowed-source rescan lifetime. A passing multiline/repeated-argument control protects existing source-line behavior.Validation on Linux with GCC 12 / CMake 3.25:
Test_Ogre: 172 passed, 2 skipped; unchanged baseline: 165 passed, 2 skipped. The six regressions fail on the audited base, while the new multiline control passes.glslangValidator -S vertaccepts four shaders preprocessed using the realOgreUnifiedShader.h/GLSL_GL3Support.glsl: GLSL 330 and GLES 300, each withFOOdefined as0or undefined.git diff --checkpasses.The native test build enables sample resource configuration and disables tools, language bindings, ImGui and the GLES2 render-system build. Windows/macOS execution and GPU visual tests were not run locally.
Related work: draft #1314 addresses extension-condition passthrough for #614 and shares the preprocessor/test files. Its changes to
HandleIf,HandleDirectiveandParseare separate from this fix toMacro::Expand,ExpandMacroandGetArgument. At draft headf77b471, its hunks in both shared files apply cleanly to the audited base and this candidate. The complete older draft already needs updates in its other files; compatibility will need rechecking if that draft changes or lands.