Commit Graph

303 Commits

Author SHA1 Message Date
yuriy odonnell
57397e6c36 Add CPU profiler scope to UE::ShaderCompilerCommon::RemoveDeadCode
#rb none

[CL 28744091 by yuriy odonnell in ue5-main branch]
2023-10-13 04:02:29 -04:00
yuriy odonnell
355a38075e Fix compile error on linux/mac due to indexing arrays with char type
#rb none

[CL 28699927 by yuriy odonnell in ue5-main branch]
2023-10-11 23:46:03 -04:00
yuriy odonnell
dd72ffe26c ShaderMinifier - Optimize BuildLineBreakMap, SkipUntilNonIdentifierCharacter, ExtractIdentifiers and few other bits
* Generate line directive map during parsing
* Use xxhash instead of cityhash
* Avoid FStringView operator [] in ExtractIdentifiers
* Use TArray Reset instead of Empty where appropriate
* Vectorize SkipUntilNonIdentifierCharacter
* Vectorize ExtractBlock
* Vectorize line ending search
* Use FString directly instead of FStringBuilderBase for the final output to avoid a copy

#rb christopher.waters
#rb jason.hoerner

[CL 28699609 by yuriy odonnell in ue5-main branch]
2023-10-11 23:32:28 -04:00
christopher waters
0403f2caa0 Always set the HLSL version and don't assume the default is 2018.
#rb David.Harvey, Yuriy.Odonnell

[CL 28692390 by christopher waters in ue5-main branch]
2023-10-11 19:52:44 -04:00
laura hermanns
0320f2f528 D3D11 cross-compilation fixes:
- Patch HLSL to support SV_DepthGreaterEqual and SV_DepthLessEqual.
- Maintain order of shader input/output variables in cross-compiled HLSL.

#rb Jason.Nadro
#jira UE-186066, UE-192125
#rnx

[CL 28633421 by laura hermanns in ue5-main branch]
2023-10-10 15:30:19 -04:00
christopher waters
0121d81804 Fixing crash that was hidden by hardcoded namespaces.
[CL 28495033 by christopher waters in ue5-main branch]
2023-10-05 08:27:30 -04:00
christopher waters
b9351620ad HlslParser
- Adding ability to 'forward declare' symbols per platform.
- Removes hardcoded symbols in HlslParser.cpp
- Converting a few array/string input types to views.

#rb dan.elksnitis

[CL 28494936 by christopher waters in ue5-main branch]
2023-10-05 08:26:39 -04:00
yuriy odonnell
eb793d3fb5 ShaderMinifier - Use inline implementations of string view Equals and StartsWith
* Also use TEXTVIEW instead of TEXT where possible
* ~1.5x speedup

#rb dan.elksnitis

[CL 28494884 by yuriy odonnell in ue5-main branch]
2023-10-05 08:26:07 -04:00
jason hoerner
bca274f611 Shader Compiler: CleanupUniformBufferCodeNew minor fix to account for escaped quotes in text. Continue string parsing if character before quote is a backslash. Note that there are no escaped quotes in any existing .usf or .ush file at the moment, so I don't think the bug should have caused any issues.
#rnx
#rb dan.elksnitis jason.nadro

[CL 28494850 by jason hoerner in ue5-main branch]
2023-10-05 08:25:49 -04:00
christopher waters
9b84b8accd Fixing enum handling in the shader minifier. Since the enum elements weren't marked as reachable identifiers, the minifier was considering the whole enum block unused.
#rb yuriy.odonnell

[CL 28438918 by christopher waters in ue5-main branch]
2023-10-03 19:32:26 -04:00
yuriy odonnell
d635588f1b ShaderMinifier - Don't skip keyword blocks when building ChunksByIdentifier (temporary workaround for an issue introduced in 28384399)
#rb christopher.waters

[CL 28417897 by yuriy odonnell in ue5-main branch]
2023-10-03 12:08:28 -04:00
yuriy odonnell
86d5bb7306 ShaderMinifier - Add basic support for global operator overloads
#rb christopher.waters

[CL 28417810 by yuriy odonnell in ue5-main branch]
2023-10-03 12:06:47 -04:00
christopher waters
c1487a0042 Adding typedef support to ShaderMinifier.
- Before this, every typedef and the code using them was being included in the final source.
- This was primarily affecting Bindless Resources where all bindless resources were included in the minified code even if they weren't used.

#rb yuriy.odonnell

[CL 28365749 by christopher waters in ue5-main branch]
2023-09-30 11:10:06 -04:00
jason hoerner
6f67025ccc Shader Compiler: Optimized version of CleanupUniformBufferCode, called during preprocessing. New version is 3.8x faster, producing a 19% overall speedup in ConditionalPreprocessShader. Processes the shader in a single pass, scanning for potential compound identifiers (symbol tokens connected by dots and optional whitespace), then checking if they match known uniform buffer members. A few optimizations improve the speed of checking if an identifier matches, including an early out based on identifier length and start character, followed by organizing uniform buffers and their members by length, requiring only a small subset of members to be tested. Parsing uniform buffer definitions was also optimized to avoid memory allocation.
Doesn't produce bit identical preprocessed output, as it compacts whitespace from compound identifiers before testing them, whereas the original implementation compacts whitespace after matching.  Compacting first makes testing more efficient and simpler, since it doesn't need to take into account whitespace.  For A/B validation, I did add temporary debug code that stored and reverted un-matched identifiers, mimicking the old behavior, and it was identical across the board.

#rnx
#rb dan.elksnitis chris.waters jason.nadro

[CL 28313553 by jason hoerner in ue5-main branch]
2023-09-28 07:08:47 -04:00
dan elksnitis
4515e3b5f4 [shaders] add debug dump option to output "detailed" shader source, including the output of the preprocessing step unmodified, the stripped version used for hashing, and whatever the final source passed to the compiler is (can differ from the stripped version if further modifications are applied as part of the compile step). this is only done if the preprocessed job cache is enabled; otherwise (and if this cvar is disabled) the single output will either be the compiler-step-modified source if it exists, or the output of the preprocessing step.
#rb Jason.Hoerner

[CL 28274493 by dan elksnitis in ue5-main branch]
2023-09-27 11:02:18 -04:00
christopher waters
7f66db7ffc Shader preprocessing optimizations:
- Removing system calls from UniformBuffer parsing and processing.
- When searching for uses of a UniformBuffer, start after the end of the UniformBuffer declaration.
- Simplifying the code around UniformBuffer reference cleanup
- Cuts time in CleanupUniformBufferCode by 50-75% based on how large the shader is.

#jira UE-195103
#rb dan.elksnitis, jason.hoerner

[CL 28172021 by christopher waters in ue5-main branch]
2023-09-23 05:43:20 -04:00
christopher waters
bb0a274b8c Reworking UniformBuffer code generation to not use an intermediate struct
- When generating Uniform Buffer HLSL code, a 'static const struct {} Name' was created which has been causing compiler issues off and on for years.
- When RemoveUniformBuffersFromSource removed said struct, it parsed the struct's structure to figure out how to translate UniformBuffer.Member into UniformBuffer_Member in code that accessed Uniform Buffers.
- Now, instead of a struct, a "UniformBuffer <Name>" declaration is created and filled with mappings from "UniformBuffer.Member" into the correct code.
- This allows ConstantBuffer objects to be used differently from cbuffer where the former generates "UniformBuffer.Member" and the latter generates "UniformBuffer_Member"
- This also allows resources to always be translated to "UniformBuffer_Member"
- Shader define 'PLATFORM_SUPPORTS_UB_STRUCT' is now 'PLATFORM_SUPPORTS_CONSTANTBUFFER_OBJECT' and will be set on shader formats that support ConstantBuffer<> objects.
- Removed lots of unused code from BindlessResources.ush

#jira UE-195103
#rb dan.elksnitis, jeannoe.morissette

[CL 28058373 by christopher waters in ue5-main branch]
2023-09-20 17:33:36 -04:00
tom holmes
0c53e701a0 Improve ShaderSymbols.info file generation in multicook scenarios
Dedupe info where multiple workers built same shader

#rb Ben.Woodhouse
#tests local runs, compare of farm built files attached in bug

[CL 27995633 by tom holmes in ue5-main branch]
2023-09-19 10:46:28 -04:00
laura hermanns
f9b3974ab9 Platform-specific DXC improvements:
- Avoid explicit FMA instructions in platform-specific GLSL to let backend-compiler decide when to use them.
- Fix code refelction when using SPIR-V directly with backend-compiler.
- Define preset of SPIR-V optimization passes to reduce nested expressions "preset(relax-nested-expr)".

#rb Serge.Bernier, Brian.White
[FYI] Graeme.Thornton, Jason.Nadro, Carl.Lloyd, Florin.Pascu, Michael.WAnderson
#jira UE-195236, UE-194869

[CL 27994871 by laura hermanns in ue5-main branch]
2023-09-19 10:25:17 -04:00
laura hermanns
d7fff598d5 Allow passing custom SPIV-V optimization passes to ShaderConductor. This allows us to control more fine-grained what optimization passes work best for certain render passes on different platforms.
#rb Serge.Bernier
[FYI] Carl.Lloyd, JeanNoe.Morissette
#rnx

[CL 27880727 by laura hermanns in ue5-main branch]
2023-09-14 11:39:49 -04:00
christopher waters
5dc4ce553d Removing redundant line directives from Shader Minifier.
#rb yuriy.odonnell

[CL 27872540 by christopher waters in ue5-main branch]
2023-09-14 05:20:23 -04:00
graham wihlidal
811135f653 RDNA ISA parser improvements and fixes
[FYI] rune.stubbe, brian.karis

[CL 27697998 by graham wihlidal in ue5-main branch]
2023-09-07 20:34:04 -04:00
graham wihlidal
7f36ea203a Added two missing MIMG instructions to RDNA2_ISA.h
[CL 27697990 by graham wihlidal in ue5-main branch]
2023-09-07 20:33:59 -04:00
graham wihlidal
987e25e552 Renamed NoImplicitDerivatives -> NoDerivativeOps to also handle the explicit derivative cases, and cleaned up cflag naming
#rb rune.stubbe
[FYI] dan.elksnitis

[CL 27697881 by graham wihlidal in ue5-main branch]
2023-09-07 20:30:26 -04:00
graham wihlidal
3295fddd4f Implemented RDNA 1 & 2 ISA parser to optionally detect if a compute shader has any need for implicit derivatives (image sample, ddx, ddy, etc.). Certain shaders can be marked with CFLAG_ExplicitDerivatives, indicating the shaders prefer to handle derivatives explicitly, and this instructs the shader compiler - on supporting platforms - to parse the compiled ISA and look if any instructions requiring implicit derivatives are present. If none are found, the shader is decorated with NoImplicitDerivatives, indicating it is safe to ignore shading quads, etc..
#rb jason.nadro, luke.thatcher, dan.elksnitis
[FYI] brian.karis, rune.stubbe

[CL 27697142 by graham wihlidal in ue5-main branch]
2023-09-07 20:10:55 -04:00