113 Commits

Author SHA1 Message Date
dan elksnitis
c4deae64ff [shaders] bytecode sharing between shader and shadermap DDC buckets
- create utility classes (serialization context objects) which allow serialization of shader code blobs independently of "shader object" (i.e. whatever type of thing we're pushing to the cache, shader job or shader map) structure
- commonize bytecode format in cache entries for shadermap and shader DDC (FShaderCodeResource struct)
- rework per-shader caching to use the serialization helpers to separate serialization of job output struct data and bytecode
- rework material and global shadermap DDC serialization to use the serialization helpers to separate serialization of shadermap structural data and bytecode

#rb Laura.Hermanns, Zousar.Shaker
#jira UE-196556

(resubmit with monolithic build fix)

[CL 36153164 by dan elksnitis in 5.5 branch]
2024-09-10 13:06:22 -04:00
huw bowles
c81d47b8e9 [ShaderPreprocessor] Parse line directives. Apply line number and filename to parser state so that subsequent errors will have line numbers with offsets applied from line directives.
[ComputeFramework] Treat preprocessor issues as warnings if compile succeeded, otherwise errors, which is the standard rule.
[PCG] Adapt error summary to whatever line information is available in the error (if any).

#rb dan.elksnitis, Jeremy.Moore, Laura.Hermanns, wyatt.marvil
#rnx

[CL 35362997 by huw bowles in ue5-main branch]
2024-08-07 04:05:17 -04:00
dan elksnitis
857e446f3b [shaders] fix preprocessor infinite loop caused by '[at]' being considered part of the identifier character class, but not being handled properly by copy_and_filter_macro (it appears the RADC compiler from which this code originated allowed [at] in identifiers, but our UE SIMD optimizations missed this quirk. since it's not a valid identifier character in HLSL I opted to just remove it from the character class.
#rb Jason.Nadro, Laura.Hermanns
#jira UE-219735

[CL 35353119 by dan elksnitis in ue5-main branch]
2024-08-06 17:12:57 -04:00
jason hoerner
fc1f7e0bf1 Shader Preprocessor: Fix bug where the pointer to the preprocessed text buffer isn't updated when reallocated while appending string printing code. This hadn't been hit before, because we reserve a large (1.25 MB) buffer to begin with, so encountering the bug requires a shader that uses string printing (itself rare), and of an extremely precise length (within a few KB of the reserve size, so there isn't slack to absorb the appended code).
#rnx
#rb dan.elksnitis

[CL 35346815 by jason hoerner in ue5-main branch]
2024-08-06 13:59:01 -04:00
steve robb
f40be2d759 Fixed some 'deprecated' FString usage.
#rb james.hopkin

[CL 34603027 by steve robb in ue5-main branch]
2024-06-24 09:25:50 -04:00
marc audy
5acacec5d3 Move PVS silencing to correct line
#rnx

[CL 32819753 by marc audy in ue5-main branch]
2024-04-09 01:01:18 -04:00
dan elksnitis
4189be13af [shaders] silence static analysis warning from PVS studio (it doesn't like sizeof(*a) but IMO this is perfectly valid)
#rb Marc.Audy

[CL 32759331 by dan elksnitis in ue5-main branch]
2024-04-05 10:26:28 -04:00
dan elksnitis
765e6b79d6 [shaders] add support in stb_preprocess for #warning directives, and log warnings emitted by preprocessing
#rb Laura.Hermanns

[CL 32700527 by dan elksnitis in ue5-main branch]
2024-04-03 12:12:03 -04:00
dan elksnitis
be2a80c92b [shaders/stb_preprocess] stb preprocessor bug fixes:
- fix line number mismatches caused due to multiline macro arguments by keeping leading/trailing whitespaces in cases of multiple lines encountered in a single macro argument (single line macro args still have whitespace trimmed as this is needed for token pasting)
- avoid early out preventing parsing of "defined" builtin macro outside of #if conditions; this allows using defined in #define directives (among other places)

#rb Yuriy.ODonnell

[CL 32051438 by dan elksnitis in ue5-main branch]
2024-03-06 09:07:22 -05:00
christopher waters
15bede992d Entire engine compiling with -DisableUnity -IncludeHeaders
[CL 31778133 by christopher waters in ue5-main branch]
2024-02-23 16:51:32 -05:00
henrik karlsson
e75785aaf0 [ShaderPreprocessor]
* Reverted change that should never have checked in that disabled sse opts

[CL 31651792 by henrik karlsson in ue5-main branch]
2024-02-20 13:57:20 -05:00
henrik karlsson
9983643fb9 Compile error fixes for iwyu when compiling UnrealEditor
#rb christopher.waters (and phil.pizlo for verse files)


#changelist validated
#virtualized

[CL 31228054 by henrik karlsson in ue5-main branch]
2024-02-06 15:28:47 -05:00
dan elksnitis
a9037b25ed [shaders]
- add FShaderSource class which wraps source as populated by preprocessing and subsequently accessed by compilation and other debug features; this class automatically inserts zeroed padding such that 16-byte-wide SIMD string comparison operations do not require a non-SIMD tail to process any overhang.
- add typedefs for the string/view/character types and update preprocessing code to use these typedefs instead of the explicit types
- add explicit if constexprs in minifier code around char width to disable simd optimizations for char width != 2 (and subsequently skip the non-simd tail if char width == 2 since FShaderSource automatically adds the required padding)

#rb Jason.Nadro, Yuriy.ODonnell

[CL 30358137 by dan elksnitis in ue5-main branch]
2023-12-15 15:28:27 -05:00
jason hoerner
903ff2eea7 Shader preprocessor: Fix for ASAN failure -- need to add SSE padding to substitution text generated for TEXT macros.
#jira UE-202569
#rnx
#rb dan.elksnitis

[CL 30331769 by jason hoerner in ue5-main branch]
2023-12-14 16:35:09 -05:00
dan elksnitis
6ed653a189 [shaders] further preprocessing cleanup
- move sequence of preprocessing steps out of ShaderPreprocessor module and into UE::ShaderCompilerCommon::ExecuteShaderPreprocessingSteps; the former is now explicitly just the low-level preprocessor lib
- add an implementation of PreprocessShader in FBaseShaderFormat so backends which have no custom code to execute as part of preprocessing can just automatically inherit this implementation, and fix up such backends to eliminate now-unnecessary overrides

#rb christopher.waters, Laura.Hermanns

[CL 30178136 by dan elksnitis in ue5-main branch]
2023-12-07 08:55:41 -05:00
dan elksnitis
c1f33c7a82 [shaders] debug usf/direct compile cleanup
- never append the environment defines as commented code to the source used for further preprocessing/compilation; instead only append it to the debug USF
- strip comments after loading the debug usf in direct compile mode as some backends expect comments to have already been removed and the extra ones we add to the debug dump cause them to barf
- change all #if 0s in the debug usf to block comments instead so the above can strip them (said backends also don't like preprocessor directives left in the file)

#rb Jason.Nadro, rob.krajcarski

[CL 30161438 by dan elksnitis in ue5-main branch]
2023-12-06 13:32:32 -05:00
dan elksnitis
cc7c2c54f4 [shaders] shader format preprocessing cleanup & refactoring
- move uniform buffer cleanup and dead stripping into ShaderPreprocessor module's PreprocessShader function
- add "required symbols" to compiler input struct to specify additional symbols to keep during minification aside from those specified by the entrypoint; modify API such that both an entry point string and additional symbols can be specified (to avoid each backend needing to manually parse the compound RT entry point string)
- make use of ModifyShaderCompilerInput in all backends to set additional defines and required symbols on input struct up front; only use the AdditionalDefines map in cases where it's actually necessary
- remove the various per-platform defines for enabling minifier, no longer required now that this has been rolled out for all backends
- fix SCW directcompile mode; this had rotted due to pieces of the FShaderCompilerEnvironment having been added that weren't explicitly serialized to either cmdline or in the shader source. this now serializes as a base64 string written inside the USF containing all portions of the environment required for compilation (using the same serialization function as is used to write/read the SCW input file)
- use a debug flag for indicating we're in "direct compile" mode and should load the debug USF off disk, rather than the poorly named "bSkipPreprocessedCache" (this name is both inaccurate and also confusing due to the addition of the preprocessed job cache)
- modify platform "force wave32" mechanism to use a pragma directive to set a compiler define, instead of doing string replacement in the preprocessed source
- add a view version of the RT entrypoint parsing to use in preprocessing, note that other paths still need to construct fstrings due to further manipulation so keeping the FString path around too
- clean up backends manually checking the "directcompile" cmdline arg

#rb christopher.waters, Yuriy.ODonnell
#rb Chris.Waters
#rb Laura.Hermanns

[CL 30023082 by dan elksnitis in ue5-main branch]
2023-11-30 15:56:34 -05:00
marc audy
399bcf9971 Disable PVS warning V758
Silence V570 false positives for bit field assignments
Silence various other PVS warnings
#rnx

[CL 29706746 by marc audy in ue5-main branch]
2023-11-14 00:29:43 -05:00
josh adams
92f54ebbbc - Worked around crash in shader preprocessor on mac
#rb Jason.Hoerner

[CL 29612445 by josh adams in ue5-main branch]
2023-11-09 17:28:23 -05:00
jason hoerner
92db7f3070 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]
2023-11-07 18:01:37 -05:00
jason hoerner
9852294945 Shader Preprocessor: ASAN bug fix for stack use after return for undef_map identifiers, by enabling arena allocation. Strip out whitespace on blank lines -- doesn't measurably affect perf, and could improve deduplication or avoid certain shader invalidations, and makes stripped source more readable. Fix bug where line numbers aren't incremented when exiting the scanning loop on an identifier.
#jira UE-198065
#rnx
#rb dan.elksnitis yuriy.odonnell

[CL 29100213 by jason hoerner in ue5-main branch]
2023-10-25 16:04:13 -04:00
jason hoerner
0e18ea7e81 Shader Preprocessor: Roll TEXT macro substitution into the C preprocessor step, via custom macro callback feature, making it effectively free. Saves 3% overall on preprocess, but also represents a simplification by reducing the number of unique preprocess passes.
#jira UE-198496
#rnx
#rb dan.elksnitis yuriy.odonnell jason.nadro

[CL 29100104 by jason hoerner in ue5-main branch]
2023-10-25 16:01:11 -04:00
jason hoerner
a518725896 Shader Preprocessor optimization: Support for loading include preprocess dependencies in bulk, and drastically reduced string processing, memory allocation, and map overhead. Roughly 7x faster, saving 12% in low level preprocessor, or 5% overall.
Flattened include dependencies are generated during include scanning at startup, basically for free (perf difference was well below noise).  Bulk dependencies reduce round trips to the shader cache (which require mutex locks), and are indexed by the ANSI text exactly as it appears in the include directive in the source files, allowing a faster case sensitive hash, and avoiding the need for expensive path string operations.  Anything found in a bulk dependency is stored in an array that parallels the dependency array, rather than a map.  Includes stored in IncludeVirtualPathToSharedContentsMap also use an array.

Noting that our string classes (FString) are already case insensitive by default, some unnecessary case conversions were removed.  The separate map of "seen" shaders was also removed, as we can just use the LoadedIncludesCache map for the same purpose.  Where possible, existing ANSI strings are referenced, avoiding dynamic allocation.

#jira UE-197213
#rnx
#rb yuriy.odonnell jason.nadro

[CL 29095249 by jason hoerner in ue5-main branch]
2023-10-25 13:58:15 -04:00
jason hoerner
bae18a5cc0 Shader Preprocessor platform specific compile error / warning fixes. Unused branch label on non-SSE platforms, char array index, conversion of 255 to char in SSE vector initialization (used by unsigned compare intrinsic so code was correct), strcpy_s not supported on some platforms -- switched to strncpy.
#rnx

[CL 28835617 by jason hoerner in ue5-main branch]
2023-10-17 07:01:26 -04:00
jason hoerner
8074c3b4b1 Shader Preprocessor: Add padding for SSE reads as actual zeroes, rather than capacity padding. Capacity padding doesn't work for compiler workers some of the time.
[CL 28834349 by jason hoerner in ue5-main branch]
2023-10-17 05:19:24 -04:00