Commit Graph

85 Commits

Author SHA1 Message Date
henrik karlsson
f027bfa856 [Core]
* Fixed compile errors when compiling .h files in isolation

#rb none

[CL 25865668 by henrik karlsson in ue5-main branch]
2023-06-08 02:30:27 -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
a21eb84e66 [shader preprocessor] implement #error directives
#rb Jason.Nadro
#preflight 644931ee1c2846595c0887c6

[CL 25199050 by dan elksnitis in ue5-main branch]
2023-04-26 11:23:31 -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
Joe Kirchoff
4d1c3ab0b8 Disable sndbs distribution for ShaderPreprocessor module
#rnx
#rb trivial
#preflight 63e41634ea7ad6869835614b

[CL 24083177 by Joe Kirchoff in ue5-main branch]
2023-02-08 16:42:12 -05:00
Jeremy Moore
3e7f174035 STB processor reemits line directives.
#preflight 63c838c902024f93d8dc9534

[CL 23760433 by Jeremy Moore in ue5-main branch]
2023-01-18 13:37:36 -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
dan elksnitis
7be75b5184 [shaders] fix missing closing " in stb header error msg (this path should not be hit but it's causing problems for IncludeTool static analyzer)
#rb trivial
#preflight none

[CL 23310769 by dan elksnitis in ue5-main branch]
2022-11-29 11:44:01 -05:00
dan elksnitis
4803fda014 [stb_preprocess]
- add handling of #pragma directives in macro definitions
- add handling of #pragma message to create diagnostic outputs
- add and update comments in preprocessor.h
- unifying memory allocation mechanisms between stb_ds, stb_alloc and preprocessor - allow configuring all functions performing memory allocation/freeing via macros which should be specified via a header whose include path is specified via the STB_CONFIG macro (this will be included in stb_common.h if defined)
- don't pass an stb_arena to the include resolution callback; this is unnecessary complexity (implementation can handle its own memory allocation as long as the resulting strings have the appropriate lifetime) and indeed the arena used was global (and so not threadsafe)
- expose function allowing external modification of error modes so we can disable the error case for preprocessor directives not being at the start of a line (and so handle the case where we #define a macro whose value is a #pragma, or any other string possibly containing a # that we want to pass unmodified to the output i.e. the case of #define COMPILER_DEFINE #define which we use to keep #defines in the preprocessed code for handling by the platform compilers)
- fix leak of pp diagnostic messages
- remove internal caches for include resolution; they are problematic since (a) they aren't threadsafe, and (b) the caching of resolved filenames based on the include path found in source is inherently problematic (can potentially cause issues with same-named files in different folders included via relative paths)
- strip all code related to explicit file loading and lists of include paths; this has no purpose for our use case. note this makes the callbacks for file load/unload and include resolve mandatory, comments in preprocessor.h updated to reflect this.
- fix a few other memory leaks

#preflight 638611a9fa053c489a54b2ec
#rb Yuriy.ODonnell

[CL 23305324 by dan elksnitis in ue5-main branch]
2022-11-29 09:34:03 -05:00
dan elksnitis
6aa37eca15 [shaders] additions & fixes to STB preprocessor for shader preprocessing. With the following all Lyra shaders compile and generate identical bytecode on PC SM5/6.
- add explicit extern "C" on preprocessor methods to allow linking from C++ code
- add custom callbacks for include path resolution and file loading/unloading
- add padding space following macro expansion ending with a > to work around DXC bug (not handling >> correctly if it occurs at the end of a templated type)
- adding explicit handling for HLSL infinity constant (1.#INF); the # character outside of a directive was previously putting the preprocessor into an error state
- change line directive output to use #line format rather than # (DXC is ok with the latter but minifier doesn't currently handle it), and also always include the filename (so when minifying don't have to be careful not to strip the line directive with the filename in it); this also matches mcpp behaviour
- adding const-correctness and casts where needed to avoid const casts/compile errors in calling C++ code and satisfy Mac/Intellisense compilers
- bugfix: parsing of '.' was immediately putting the scanning state machine into "number" mode resulting in skipped macro expansion in code of the form "var.MACRO.var2"/numbers; added extra state transitions and changing the default transition when encountering '.' to an explicit mode that can allow either transitioning to parsing identifiers or numbers depending on following characters.
- bugfix: macros with an empty parameter list were incorrectly terminating said list on expansion (adding extra rparens)
- bugfix: set file load mode as "callback" when callback used for loading, and check the mode in the free callbacks
- various minor changes to satisfy Clang code analysis

#preflight 637e3391e30d438849ddf902
#rb Yuriy.ODonnell

[CL 23249332 by dan elksnitis in ue5-main branch]
2022-11-23 09:58:24 -05:00
dan elksnitis
e01c10c613 [shaders] resubmit stb preprocessor code with static analysis fixes
#rb Jason.Nadro
#preflight 636d54ab1a66e7f73189e89f

[CL 23134601 by dan elksnitis in ue5-main branch]
2022-11-15 08:26:32 -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
dan elksnitis
3e268dcee4 [shaders] remove stb preprocessor code until static analysis errors can be addressed.
#rb trivial
#preflight skip

[CL 23057245 by dan elksnitis in ue5-main branch]
2022-11-09 12:33:30 -05:00
dan elksnitis
5e65aad0e3 [shaders] add initial version of stb preprocessor, using default data structure and alloc implementations (for now)
#preflight 636aa686f56cab38c7373c9f
#rb Jason.Nadro

[CL 23053497 by dan elksnitis in ue5-main branch]
2022-11-09 09:03:42 -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
bryan sefcik
892629fe83 Fixed some paths that got updated to include the full "ThirdParty" path.
#jira
#preflight 6320877bbc40358fa2995069

[CL 21997782 by bryan sefcik in ue5-main branch]
2022-09-13 21:48:33 -04:00