fix: SG-43607: Bugfix/aces2 support#1288
Conversation
Signed-off-by: TJ Jackson <tj.jackson@dreamworks.com>
| searchBegin = match[0].second; | ||
| continue; | ||
| } | ||
|
|
There was a problem hiding this comment.
its not just else, in my case it was also happening on if. I think we should check all glsl keywords perhaps something like this
| static const std::unordered_set<std::string> glslKeywords = { | |
| "if", "else", "for", "while", "do", "switch", "case", | |
| "return", "break", "continue", "discard", "struct" | |
| }; | |
| while (std::regex_search(searchBegin, inout_glsl.cend(), match, functionStartRegex)) | |
| { | |
| // The regex can match "else if (...) {" as returnType=else, | |
| // functionName=if. Skip any match where the name is a | |
| // GLSL keyword. | |
| if (glslKeywords.count(match.str(2))) | |
| { | |
| searchBegin = match[0].second; | |
| continue; | |
| } |
There was a problem hiding this comment.
In the example GLSL you provided (thank you for that), functionsMissingLutAsParameter() is matching to the "else if (...) {" statements on line 98, and then returns "if" as a function that needs to have lut parameters passed to it. shaderAddLutAsParameter() then goes through and finds every instance of "if (,,,)" and inserts the LUT. An if statement on its own would not have triggered this behavior, as it would not have matched the functionStartRegex. As far as I'm aware, "else if" is the only two-word combination of GLSL keywords that could precede "(...) {", so that's why I limited my check to just that.
I'm fine adding checks for other GLSL keywords, if people would prefer that, it just may not be technically necessary.
Linked issues
#1275
Summarize your change.
Added a check to functionsMissingLutAsParameter() to avoid treating "else if" as a function definition.
Describe the reason for the change.
The logic added in my previous PR uses a regex to search for the start of functions. The regex roughly follows the format of "word word (...) {".
"else if (...) {" matches as a false positive, so if there is an "else if" block that references a LUT, the code will treat all insteads of "if (...)" as a function call that needs the LUT added as a parameter, and breaks the code.
To the best of my knowledge, "else if" may be the only combination of GLSL keywords that could match the regex as a false positive, so I just added logic to check if the first word matched is "else".
Describe what you have tested and on which operating system.
Tested it on Rocky Linux 9.7