59 Commits

Author SHA1 Message Date
carl lloyd
906ea67138 Added missing entry for Metal 3.1 to GetMetalFamilyVersionString
#rb Mihnea.Balta
#jira UE-223695

[CL 37016311 by carl lloyd in 5.5 branch]
2024-10-10 08:16:49 -04:00
steve robb
7e54d6b019 Fixed wrong FString constructor being used to construct from a range.
#rb james.hopkin

[CL 34600674 by steve robb in ue5-main branch]
2024-06-24 06:49:39 -04:00
laura hermanns
a34925adb1 [Shaders] SPIRV-Tools pass rewrite (Re-introduced after backout of 34098261)
Interface variable scalar replacement pass rewrite (added as a new pass into spirv-opt, will replace existing one in future).

Things done so far:
- Rewritten to properly handle non-aggregate types and other tricky cases (both for Patch decorated variables and not)
- Matrix scalarization is now optional.
- More test cases added
- Path is now exposed as a command-line flag
- Fixed https://github.com/KhronosGroup/SPIRV-Tools/issues/4795

Few shaders contained loops, which were not unrolled, leading to the scalarization pass to fail. Loops were not unrolled due to "complex" condition expression. Those are changed to be accepted by the loop unroller (induction variable is the only lhs in the condition expression now).

This new pass is now always enabled for both Vulkan/GLES shaders for Android.
Multiple location remapping passes were removed: one was overriding another one results + not needed now due to arrays being removed by the scalarization pass.

#rb carl.lloyd, denys.mentiei
[FYI] Dmitriy.Dyomin, Allan.Bentham

[CL 34122278 by laura hermanns in ue5-main branch]
2024-06-05 09:24:38 -04:00
laura hermanns
434f0c3b84 [Backout] - CL34098261
[FYI] denys.mentiei
Original CL Desc
-----------------------------------------------------------------
[Shaders] SPIRV-Tools pass rewrite

Interface variable scalar replacement pass rewrite (added as a new pass into spirv-opt, will replace existing one in future).

Things done so far:
- Rewritten to properly handle non-aggregate types and other tricky cases (both for Patch decorated variables and not)
- Matrix scalarization is now optional.
- More test cases added
- Path is now exposed as a command-line flag
- Fixed https://github.com/KhronosGroup/SPIRV-Tools/issues/4795

Few shaders contained loops, which were not unrolled, leading to the scalarization pass to fail. Loops were not unrolled due to "complex" condition expression. Those are changed to be accepted by the loop unroller (induction variable is the only lhs in the condition expression now).

This new pass is now always enabled for both Vulkan/GLES shaders for Android.
Multiple location remapping passes were removed: one was overriding another one results + not needed now due to arrays being removed by the scalarization pass.

#rb carl.lloyd, Laura.Hermanns
[FYI] Dmitriy.Dyomin, Allan.Bentham

[CL 34107760 by laura hermanns in ue5-main branch]
2024-06-04 17:30:47 -04:00
denys mentiei
802971f9b4 [Shaders] SPIRV-Tools pass rewrite
Interface variable scalar replacement pass rewrite (added as a new pass into spirv-opt, will replace existing one in future).

Things done so far:
- Rewritten to properly handle non-aggregate types and other tricky cases (both for Patch decorated variables and not)
- Matrix scalarization is now optional.
- More test cases added
- Path is now exposed as a command-line flag
- Fixed https://github.com/KhronosGroup/SPIRV-Tools/issues/4795

Few shaders contained loops, which were not unrolled, leading to the scalarization pass to fail. Loops were not unrolled due to "complex" condition expression. Those are changed to be accepted by the loop unroller (induction variable is the only lhs in the condition expression now).

This new pass is now always enabled for both Vulkan/GLES shaders for Android.
Multiple location remapping passes were removed: one was overriding another one results + not needed now due to arrays being removed by the scalarization pass.

#rb carl.lloyd, Laura.Hermanns
[FYI] Dmitriy.Dyomin, Allan.Bentham

[CL 34100366 by denys mentiei in ue5-main branch]
2024-06-04 13:59:11 -04:00
laura hermanns
ca07d105fc [Shaders] Remove unused state in FShaderConductorContext and ignore unknown attributes in shader backends.
This adds "-Wno-unknown-attributes" to DXC backends and platform specific compiler argument to their respective backend.

#rnx
#rb Yuriy.ODonnell

[CL 33437776 by laura hermanns in ue5-main branch]
2024-05-03 17:13:42 -04:00
laura hermanns
7a0927103c [Shaders] Remove last remaining use case of DXC rewriter in MetalCompileShaderMSC and deprecate RewriteHlsl.
#rnx
#rb carl.lloyd, dan.elksnitis

[CL 33279539 by laura hermanns in ue5-main branch]
2024-04-26 17:10:10 -04:00
laura hermanns
623800cc99 [Shaders] Forward CFLAG_WarningsAsErrors to DXC compiler in SPIR-V backends.
This affects Vulkan, Metal, GLES, and SPIR-V based platform backends.
Warnings will not be treated as errors for intermediate shader code, such as the one generated by the HLSL rewriter for dead-code removal.

#rnx
#rb carl.lloyd, massimo.tristano

[CL 31645356 by laura hermanns in ue5-main branch]
2024-02-20 10:23:08 -05:00
carl lloyd
e8f8a7f3a0 Added support for Metal Shader Converter to Metal
- Disabled by default
    - Removed MetalDerivedData and moved shader compiler specific code to seperate files

#rb Laura.Hermanns
#jira UE-204112

[CL 31527482 by carl lloyd in ue5-main branch]
2024-02-15 13:52:17 -05:00
christopher waters
064dc45490 Removing extra '\0' from files output from ShaderConductor.
DxcCreateBlob apparently force adds this on creation of strings, so we need to account for that when creating a view of the result.

#rb dan.elksnitis, Laura.Hermanns

[CL 31311047 by christopher waters in ue5-main branch]
2024-02-08 18:28:52 -05:00
dan elksnitis
f230a0d2d0 [shaders] shaderconductorcontext improvements:
- add support to shaderconductor to load shader source from a FAnsiStringView
- remove internal string conversion helpers in favour of using FAnsiString
- don't make copies of input strings if they are provided in ANSI format

#rb Laura.Hermanns

[CL 30594203 by dan elksnitis in ue5-main branch]
2024-01-12 11:06:50 -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
laura hermanns
d6acdc4eab Make DXC compile arguments consistent between Vulkan backend and CompileDXC.bat script.
#jira UE-198594
#rb Dan.Elksnitis
#rnx

[CL 29569710 by laura hermanns in ue5-main branch]
2023-11-08 14:23:36 -05:00
serge bernier
9ce7402b1f Support INVARIANT on platform using DXC-SPIRV
-Add a new define to wrap the output semantic that we want to be post declare as precise.
-Modify DXC-SIRV to add the NoContraction decorator on precise output semantics.
-Modify spirv_glsl to post declare as precise output semantics
  -Example: out precise float4 gl_positon; will add precise gl_position; post declaration.

[REVIEW] [at]laura.hermanns

[CL 29338529 by serge bernier in ue5-main branch]
2023-11-01 19:14:21 -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
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
louisphilippe seguin
a11435338f Fix usage of const TCHAR* in the condition of checkf or ensureMsgf and test the strings for nullptr instead
#rb trivial
#rnx

[CL 27427505 by louisphilippe seguin in ue5-main branch]
2023-08-28 17:50:38 -04:00
jeannoe morissette
235b6cbfd3 VulkanRHI: Actually enable scalar_block_layout in raytracing and sm6 shaders to fix multiple alignment issues. Rename ReflectionSlot param to align with ShaderCommon code.
#rb carl.lloyd
#jira UE-171798
#rnx

[CL 27399055 by jeannoe morissette in ue5-main branch]
2023-08-25 22:19:15 -04:00
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
guillaume abadie
fb96324861 Adds bSupportsRealTypes=RuntimeDependent in Vulkan SM5 and SM6
#rb jeannoe.morissette
#jira UE-179496

[CL 26269642 by guillaume abadie in ue5-main branch]
2023-06-27 16:32:12 -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
Laura Hermanns
b8c526c389 DXC and SPIRV-Cross fixes to enable Substrate in D3D11:
- Support structured buffers in HLSL backend of SPIRV-Cross (PR #2143).
- Integrate SPIRV-Cross fix to forward opaque types in GLSL backend (PR #2110).
- Integrate SPIRV-Cross fix to use actual field offset to validate vec4 boundary alignment (#PR 2139).
- Integrate SPIRV-Cross fix to not restrict SV_RenderTargetArrayIndex to GS and MS (#PR 2138).
- Make SV_Position decoration as implicitly invariant optional (Used to address Z-fighting issues in Vulkan and Metal; Drastically impacts vertex shader performance on certain platforms).
- Don't force DXC for all shaders when r.Substrate is enabled.

#jira UE-174555
#rb Sebastien.Hillaire, Carl.Lloyd, Dan.Elksnitis
#fyi Brian.White, Jason.Nadro, JeaNoe.Morissette, Yuriy.Odonnell, Guillaume.Abadie
#preflight 6453d3df0e33f2d51d2b032e

[CL 25353473 by Laura Hermanns in ue5-main branch]
2023-05-05 09:21:36 -04:00
jeannoe morissette
efa00a9cb5 OpenGL: Avoid StorageImageWriteWithoutFormat SPIRV capability when compiling shaders for GL by adding a "-fvk_force_storage_image_format" flag that brings back old behavior (promote 3-component UAV to 4-component instead of using Unknown format). (author: Carl.Lloyd)
Broken since 24910389.

#rb Florin.Pascu,Carl.Lloyd
#fyi Laura.Hermanns,Dmitriy.Dyomin
#preflight 6442c73d0171aae0b1c6e85e
#jira UE-183868,UE-183432
#rnx

[CL 25149146 by jeannoe morissette in ue5-main branch]
2023-04-21 13:52:26 -04:00