Commit Graph

68 Commits

Author SHA1 Message Date
dan elksnitis
9a5a1b6f74 [shaders] minor include cleanup
#rb Jason.Hoerner
#rb Laura.Hermanns

[CL 26817718 by dan elksnitis in ue5-main branch]
2023-08-03 13:40:32 -04:00
jason hoerner
7f22080814 Shader Compiler: Made FShaderCompilerDefinitions private, to reduce code publicly visible in ShaderCore.h. For now, it's just marked deprecated for 5.4, but will be hidden more generally in 5.5.
#rnx
#rb yuriy.odonnell dan.elksnitis jason.nadro

[CL 26534998 by jason hoerner in ue5-main branch]
2023-07-22 06:35:10 -04:00
jason hoerner
e1fe70dbca Shader Compiler: GlobalBeginCompileShader define optimizations, plus a few other micro-optimizations, producing a 3.2x performance improvement.
* Major define optimization involves converting map of defines to use FName keys and variant values rather than strings -- this eliminates most of the cost of string hashing, allocation, and conversion.
* Lower overhead FHashTable used instead of TMap.
* An initial map of defines can optionally be provided globally.  Anything using an initial define can have its map index cached for optimized lookup when reading or writing.

Other micro-optimizations:
* Added Reserve calls for uniform buffer related maps, to eliminate map resizing / rehashing.  Saved around 15% perf (after define optimizations).
* Added a map for UB lookup, instead of iterating through the linked list.  Saved around 10% perf.

Non-optimization:  Sort the order in which uniform buffer variable names are searched in BuildShaderFileToUniformBufferMap, to create determinism in ShaderDebug data for A/B testing (previously order was dependent on global constructor order for UB definitions, which could vary arbitrarily with unrelated changes).

#jira UE-187334
#rnx
#rb dan.elksnitis jason.nadro yuriy.odonnell

[CL 26142884 by jason hoerner in ue5-main branch]
2023-06-21 03:26:02 -04:00
christopher waters
993a7ec191 Fixing shader error dumping:
- When checking if we should output debug info, the output won't always be successful
- When preprocessing the shader source, make sure the output buffer is cleared before we do anything to prevent doubling up the shader source on retries.

#rb dan.elksnitis

[CL 25857810 by christopher waters in ue5-main branch]
2023-06-07 16:52:24 -04:00
dan elksnitis
b083d56fb1 [shaders] partial backout of preprocessor optimizations. the reasons for the performance gain were incorrectly assessed and the additional cache is not providing any measurable gains, so removing it as unnecessary complexity.
#rb Jason.Nadro
#preflight 64779d234b0d5a1eb16000b3

[CL 25724429 by dan elksnitis in ue5-main branch]
2023-06-01 09:03:52 -04:00
dan elksnitis
459ef8ba65 [shader preprocessor] resubmit - optimizations
- keep a preprocessor-specific shared cache of loaded shader files in ANSI format similar to the one in ShaderCore but skipping the unnecessary additional load to widechar, along with the associated extra allocations and conversions, and stripping comments directly as part of the load
- for in-memory source contained in the environment, which can't use the above due to potential different contents of same-named includes across jobs, perform the widechar->ansichar conversion and comment strip in a single step rather than converting then stripping, to save an additional allocation of the full source

#rb Jason.Nadro
#rb Yuriy.ODonnell
#preflight 64775dca2e6c1a0737f6aaef

[CL 25702732 by dan elksnitis in ue5-main branch]
2023-05-31 11:08:31 -04:00
dan elksnitis
9b758ba87c [Backout] - CL25621499
#fyi dan.elksnitis
Original CL Desc
-----------------------------------------------------------------
[shader preprocessor] optimizations
- keep a preprocessor-specific shared cache of loaded shader files in ANSI format similar to the one in ShaderCore but skipping the unnecessary additional load to widechar, along with the associated extra allocations and conversions, and stripping comments directly as part of the load
- for in-memory source contained in the environment, which can't use the above due to potential different contents of same-named includes across jobs, perform the widechar->ansichar conversion and comment strip in a single step rather than converting then stripping, to save an additional allocation of the full source

#rb Jason.Nadro
#rb Yuriy.ODonnell
#preflight 646f74ac407983b99801c870

[CL 25626032 by dan elksnitis in ue5-main branch]
2023-05-25 15:00:40 -04:00
dan elksnitis
c4e34c8b63 [shader preprocessor] optimizations
- keep a preprocessor-specific shared cache of loaded shader files in ANSI format similar to the one in ShaderCore but skipping the unnecessary additional load to widechar, along with the associated extra allocations and conversions, and stripping comments directly as part of the load
- for in-memory source contained in the environment, which can't use the above due to potential different contents of same-named includes across jobs, perform the widechar->ansichar conversion and comment strip in a single step rather than converting then stripping, to save an additional allocation of the full source

#rb Jason.Nadro
#rb Yuriy.ODonnell
#preflight 646f74ac407983b99801c870

[CL 25621499 by dan elksnitis in ue5-main branch]
2023-05-25 11:00:28 -04:00
dan elksnitis
f645f93588 [shaders] remove legacy preprocessor option & mcpp library
#rb Jason.Nadro
#preflight 6467bf0c2c0a5da0dcd7aaf2
#fyi Yuriy.ODonnell

[CL 25549427 by dan elksnitis in ue5-main branch]
2023-05-19 14:50:25 -04:00
dan elksnitis
b52faed5d5 [shaders]
- add new IShaderFormat API for separate preprocessing and compilation; backends can implement one or the other depending on the return value of SupportsIndependentPreprocessing
- add support for executing preprocessing in the cook process prior to job submission and constructing job input hashes based on preprocessed source (and a subset of the environment used as compile inputs). controlled by a cvar for now and disabled by default
- add a BaseShaderFormat class in ShaderCompilerCommon which implements common behaviour for output of debug data - note this function is only called for formats which support independent preprocessing, so is expected to be used only by formats which have been converted to use this API
- add new cvars for output of some additional shader debug data - 1. a txt file containing the input hash a.k.a. job cache key 2. a text file containing all diagnostic messages (errors and warnings) for the job
- minor change to how input hashes are constructed for pipeline jobs - sum hashes as 256-bit ints instead of adding to a buffer and re-hashing. faster and simpler, and also more collision resistant (sum of two well distributed hashes equally well distributed)

#rb Jason.Nadro
#rb Yuriy.ODonnell
#preflight 64512c88c86798f650b953d3

[CL 25317218 by dan elksnitis in ue5-main branch]
2023-05-03 10:17:48 -04:00
dan elksnitis
f2c9000b60 [shaders] deprecate GetDefinitions accessor on FShaderCompilerEnvironment; encapsulate internal usage of definitions object in friend classes and remove some superfluous code calling the function unnecessarily
#preflight 6425b46391589478cdab0c35
#rb Laura.Hermanns
#rb Sameer.Mirza

[CL 24870640 by dan elksnitis in ue5-main branch]
2023-03-31 09:55:19 -04:00
Matt Peters
6be2b0412d ShaderPreprocessor: Fix access violation due to reading off the end of the input text when the text contains an unterminated /* comment.
#jira UE-178273
#rnx
#rb charles.derousiers
#preflight 63f79630ef1b24bf940b32e0

[CL 24382270 by Matt Peters in ue5-main branch]
2023-02-23 11:44:33 -05:00
dan elksnitis
e5d2976d39 [shaders] fix msvc static analysis warning - enforce that loaded includes are non-empty when loading via stb file load callback.
#rb Yuriy.ODonnell
#preflight 6388f525303395f6c93adb67

[CL 23357182 by dan elksnitis in ue5-main branch]
2022-12-01 14:02:18 -05:00
dan elksnitis
93c67debf3 [shaders] move stb_ds and stb_alloc implementations to a .c file rather than using the single-header #define'd implementation pattern. IncludeTool doesn't like this.
#preflight 6388cb61cb3b75418301b20a
#rb Yuriy.ODonnell

[CL 23353516 by dan elksnitis in ue5-main branch]
2022-12-01 11:15:26 -05:00
dan elksnitis
8801f83bb2 [shaders] add support to run STB preprocessor instead of MCPP; add a cvar to disable this and instead use the legacy preprocessor (currently this is set to true - i.e. still using MCPP - by default)
#rb Yuriy.ODonnell
#rb Jason.Nadro
#preflight 6387663c3377450900c5522b

[CL 23350844 by dan elksnitis in ue5-main branch]
2022-12-01 09:27:13 -05:00
florin pascu
a945c1e0cb Remove ShaderPlatformToShaderFormatName
#rb Jason.Nadro, Jeremy.Moore
#preflight 637216e13248425305d19318

[CL 23116618 by florin pascu in ue5-main branch]
2022-11-14 07:59:15 -05:00
christopher waters
c6e9015a91 Cache uniform buffer definitions
- Remove shader platform specific info from uniform buffers, we can generate code with macros that translates to what each platform needs.
- With the per-platform differences removed, uniform buffer declarations (read: generated text) can be created once per shader parameter type that needs them instead of once per shader type's shader parameter type usage.
- FShaderType and FVertexFactoryType now hold a TSet of used uniform buffer names instead of a TMap that held potentially duplicated FStrings of uniform buffer defintions.
- Lists of uniform buffers are *potentially* different per platform, so the annoying CachedUniformBufferPlatform variables need to stick around for now.
- GenerateReferencedUniformBuffers renamed to GenerateReferencedUniformBufferNames and now populates a TSet instead of a TMap.
- ShaderType::AddReferencedUniformBufferIncludes renamed to ShaderType::AddUniformBufferIncludesToEnvironment which calls the shared UE::ShaderParameters::AddUniformBufferIncludesToEnvironment.
- CreateUniformBufferShaderDeclaration moved to UE::ShaderParameters::CreateUniformBufferShaderDeclaration and now returns its FString.
- CacheUniformBufferIncludes was removed since it was only populated values from CreateUniformBufferShaderDeclaration.
- Deprecated FShaderCompilerInput::SourceFilePrefix since nothing has populated it in 9 years.

#jira none
#rb dan.elksnitis, yuriy.odonnell
#preflight 63643e5ff233f06a127c11c1

[CL 22988611 by christopher waters in ue5-main branch]
2022-11-04 12:04:48 -04:00
Florin Pascu
f64fc575d2 Re-submiting with Mac fixes
Changed ShaderArchive, GlobalShaderCache, ShaderDebugInfo and Autogen to use ShaderPlatformName and not ShaderFormat when naming their output files.
#rb Jack.Porter, Chris.Waters, Mihnea.Balta, Jason.Nadro
#jira UE-120561
#preflight 62c31f6fc9410537282296c6

[CL 20937870 by Florin Pascu in ue5-main branch]
2022-07-04 19:06:33 -04:00
Florin Pascu
09cb19fcfd Backout 20871665 to fix Mac cook
#rb none
#jira none
#preflight 62be0c68d94b57687c3ff309

[CL 20904999 by Florin Pascu in ue5-main branch]
2022-06-30 17:41:55 -04:00
Florin Pascu
1844e8e514 Changed ShaderArchive, GlobalShaderCache, ShaderDebugInfo and Autogen to use ShaderPlatformName and not ShaderFormat when naming their output files.
#rb Jack.Porter, Chris.Waters, Mihnea.Balta, Jason.Nadro
#jira UE-120561
#preflight 62bbf93ae353c20ac2361d94

[CL 20871665 by Florin Pascu in ue5-main branch]
2022-06-29 04:19:06 -04:00
Jason Nadro
65a90154a6 Add scoped cpu markers to various D3D shader compiler functions to make this easier to profile when shader compilation is done in process.
#rb trivial
#jira none
#preflight 62389f8fec68595f3b78e9df

[CL 19453136 by Jason Nadro in ue5-main branch]
2022-03-21 12:17:22 -04:00
Lukas Hermanns
39181ee030 Undo //UE5/Main/Engine/Source/... changelist 17355504
#fyi Krzysztof.Narkowicz, Rolando.Caloca, Mihnea.Balta
#jira none
#rnx

[CL 17408288 by Lukas Hermanns in ue5-main branch]
2021-09-02 16:05:32 -04:00
Lukas Hermanns
42015c8185 Ensure escape characters are encoded correctly in '#line'-directives of shader preprocessor.
#rb Krzysztof.Narkowicz
#jira none
#rnx

[CL 17377839 by Lukas Hermanns in ue5-main branch]
2021-08-31 17:10:04 -04:00
Lukas Hermanns
83d05953f7 Enable '-fdiagnostics-format' option in DXC and emit asbolute file paths in '#line'-directives.
#rb Krzysztof.Narkowicz
#fyi Rolando.Caloca, Mihnea.Balta
#jira none
#rnx

[CL 17355504 by Lukas Hermanns in ue5-main branch]
2021-08-30 14:04:53 -04:00
guillaume abadie
0bb3821623 Allows SHADER_USE_PARAMETER_STRUCT() to submit all shader parameters in a single RHISetShaderParameter()
#rb yuriy.odonnell
#preflight 611d572d9db7df000134eb13


#ROBOMERGE-SOURCE: CL 17222098
#ROBOMERGE-BOT: (v855-17104924)

[CL 17222140 by guillaume abadie in ue5-main branch]
2021-08-18 16:55:41 -04:00