Shader Preprocessor: Fix preprocessing for shader asserts. Need to preprocess the contents of TEXT macros to handle __FILE__ macros, or other possible macro generated text.

#rnx
#rb dan.elksnitis

[CL 29538506 by jason hoerner in ue5-main branch]
This commit is contained in:
jason hoerner
2023-11-07 18:01:37 -05:00
parent 540ba6901f
commit 92db7f3070
3 changed files with 41 additions and 6 deletions

View File

@@ -702,8 +702,14 @@ bool InnerPreprocessShaderStb(
macro_definition** StbDefines = nullptr;
FShaderPreprocessorUtilities::PopulateDefines(Environment, AdditionalDefines, &MacroArena, StbDefines);
arrput(StbDefines, pp_define_custom_macro(&MacroArena, ShaderPrintTextIdentifier));
arrput(StbDefines, pp_define_custom_macro(&MacroArena, ShaderPrintAssertIdentifier));
// The substitution text generated by custom macros gets run through the preprocessor afterwards, but in some cases we want to
// run the arguments through the preprocessor before as well. The TEXT macro needs this to handle things like TEXT(__FILE__),
// where the __FILE__ macro needs to be expanded before the custom macro handler is called, so we pass "1" to enable running
// the preprocessor first. By contrast, for shader asserts, we must NOT run the preprocessor on the arguments first, because
// the assert macro sets a state flag which modifies behavior of TEXT macros inside the assert. Asserts store their TEXT tokens
// outside the shader for printing in code when an assert is triggered, while ShaderPrint stores TEXT in the shader itself.
arrput(StbDefines, pp_define_custom_macro(&MacroArena, ShaderPrintTextIdentifier, 1));
arrput(StbDefines, pp_define_custom_macro(&MacroArena, ShaderPrintAssertIdentifier, 0));
PRAGMA_ENABLE_DEPRECATION_WARNINGS