UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderCore.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 ShaderCore.h: Shader core module definitions.
5=============================================================================*/
6
7#pragma once
8
11#include "Containers/Array.h"
14#include "Containers/Map.h"
17#include "CoreMinimal.h"
18#include "HAL/Platform.h"
19#include "HAL/UnrealMemory.h"
20#include "Logging/LogMacros.h"
22#include "Memory/SharedBuffer.h"
24#include "Misc/CString.h"
25#include "Misc/CoreStats.h"
26#include "Misc/EnumClassFlags.h"
27#include "Misc/Optional.h"
28#include "Misc/Paths.h"
29#include "Misc/SecureHash.h"
30#include "Misc/TVariant.h"
31#include "PixelFormat.h"
32#include "RHIDefinitions.h"
37#include "Stats/Stats.h"
38#include "Templates/Function.h"
39#include "Templates/PimplPtr.h"
43#include "UObject/NameTypes.h"
44#include "UObject/UnrealNames.h"
45#include "UniformBuffer.h"
46
47class Error;
54class FShaderPreprocessorUtilities;
55class FSHA1;
56class ITargetPlatform;
57
59
61bool operator<(const FShaderStatVariant& LHS, const FShaderStatVariant& RHS);
62
63namespace FShaderStatTagNames
64{
67}
68
70{
71public:
72 enum class EFlags : uint8
73 {
74 None = 0,
75 Hidden = 1 << 0, // If set this stat will not be shown to the user in the shader stats UI (i.e. stat is for internal use only)
76 };
81
82 FGenericShaderStat() = default;
83
84 friend FArchive& operator<<(FArchive& Ar, FGenericShaderStat& Stat) { Stat.StreamArchive(Ar); return Ar; }
85 bool operator==(const FGenericShaderStat& RHS) const;
86 bool operator<(const FGenericShaderStat& RHS) const;
88
90};
91
97#if UE_BUILD_DEBUG && (PLATFORM_UNIX)
99#else
101#endif
102
105
108
127
128// Shaders that have been loaded in memory (in a compressed form). Can also be called "preloaded" shaders.
130// Shaders that have been created as an RHI shader (i.e. exist in terms of underlying graphics API). Can also be called "used" shaders, although in theory some code may create but not use.
132// Shaders maps (essentially, material assets) that have been loaded in memory. This squarely correlates with the number of assets in memory (but assets can share SMs or have more than one SM - e.g. diff quality levels).
134// Shaders maps that has had RHI shaders created for them. This usually means that the asset referencing this shadermap was rendered at least in some pass.
136
138
142
144{
145 static_assert(12 == SF_NumFrequencies, "EShaderFrequency has a bad size.");
146
147 switch(ShaderFrequency)
148 {
157 }
159}
160
163
166
168extern RENDERCORE_API void CheckShaderHashCacheInclude(const FString& VirtualFilePath, EShaderPlatform ShaderPlatform, const FString& ShaderFormatName);
169
172
175
178
181
184
186{
187 // The rest of uint32 holding the bitfields can be left unitialized. Union with a uint32 serves to prevent that to be able to set the whole uint32 value
188 union
189 {
191 struct
192 {
195 };
196 };
197
199 : Packed(0)
200 {}
201
208
209 friend bool operator==(const FShaderTarget& X, const FShaderTarget& Y)
210 {
211 return X.Frequency == Y.Frequency && X.Platform == Y.Platform;
212 }
213
215 {
216 uint32 TargetFrequency = Target.Frequency;
217 uint32 TargetPlatform = Target.Platform;
218 Ar << TargetFrequency << TargetPlatform;
219 if (Ar.IsLoading())
220 {
221 Target.Packed = 0;
222 Target.Frequency = TargetFrequency;
223 Target.Platform = TargetPlatform;
224 }
225 return Ar;
226 }
227
229 {
231 }
232
234 {
236 }
237
238 friend inline uint32 GetTypeHash(FShaderTarget Target)
239 {
240 return ((Target.Frequency << SP_NumBits) | Target.Platform);
241 }
242};
244
245static_assert(sizeof(FShaderTarget) == sizeof(uint32), "FShaderTarget is expected to be bit-packed into a single uint32.");
246
248{
249 LooseData,
251 Sampler,
252 SRV,
253 UAV,
254
258
259 Num
260};
261
274
276{
277 return ParameterType == EShaderParameterType::BindlessSampler
278 || ParameterType == EShaderParameterType::BindlessSRV
279 || ParameterType == EShaderParameterType::BindlessUAV
280 ;
281}
282
284{
289 mutable bool bBound = false;
290
299
301 {
302 Ar << Allocation.BufferIndex << Allocation.BaseIndex << Allocation.Size << Allocation.bBound;
303 Ar << Allocation.Type;
304 return Ar;
305 }
306
307 friend inline bool operator==(const FParameterAllocation& A, const FParameterAllocation& B)
308 {
309 return
310 A.BufferIndex == B.BufferIndex && A.BaseIndex == B.BaseIndex && A.Size == B.Size && A.Type == B.Type && A.bBound == B.bBound;
311 }
312
313 friend inline bool operator!=(const FParameterAllocation& A, const FParameterAllocation& B)
314 {
315 return !(A == B);
316 }
317};
318
323{
324public:
325
328
333 RENDERCORE_API void AddParameterAllocation(FStringView ParameterName, uint16 BufferIndex, uint16 BaseIndex, uint16 Size, EShaderParameterType ParameterType);
335
338
341
346
348 void UpdateHash(FSHA1& HashState) const;
349
351 {
352 // Note: this serialize is used to pass between UE and the shader compile worker, recompile both when modifying
353 Ar << InParameterMap.ParameterMap;
354 return Ar;
355 }
356
358 {
359 ParameterMap.GenerateKeyArray(OutNames);
360 }
361
366
368};
369
371{
372 if (Ar.IsLoading())
373 {
374 // Filled in later in FShaderResourceTableMap::FixupOnLoad
375 Entry.UniformBufferMemberName = nullptr;
376 }
377 Ar << Entry.UniformBufferNameLength;
378 Ar << Entry.Type;
379 Ar << Entry.ResourceIndex;
380 return Ar;
381}
382
384{
385 Ar << Entry.StaticSlotName;
386 if (Ar.IsLoading())
387 {
389 }
390 Ar << *Entry.MemberNameBuffer.Get();
391 Ar << Entry.LayoutHash;
392 Ar << Entry.BindingFlags;
393 Ar << Entry.Flags;
394 return Ar;
395}
396
399
400// Simple wrapper for a uint64 bitfield; doesn't use TBitArray as it is fixed size and doesn't need dynamic memory allocations
402{
403public:
405 : Data(InData)
406 {
407 }
408
409 inline void Append(const FShaderCompilerFlags& In)
410 {
411 Data |= In.Data;
412 }
413
414 inline void Add(uint32 InFlag)
415 {
416 const uint64 FlagBit = (uint64)1 << (uint64)InFlag;
417 Data = Data | FlagBit;
418 }
419
420 inline void Remove(uint32 InFlag)
421 {
422 const uint64 FlagBit = (uint64)1 << (uint64)InFlag;
423 Data = Data & ~FlagBit;
424 }
425
426 inline bool Contains(uint32 InFlag) const
427 {
428 const uint64 FlagBit = (uint64)1 << (uint64)InFlag;
429 return (Data & FlagBit) == FlagBit;
430 }
431
432 inline void Iterate(TFunction<void(uint32)> Callback) const
433 {
434 uint64 Remaining = Data;
435 uint32 Index = 0;
436 while (Remaining)
437 {
438 if (Remaining & (uint64)1)
439 {
440 Callback(Index);
441 }
442 ++Index;
443 Remaining = Remaining >> (uint64)1;
444 }
445 }
446
448 {
449 Ar << F.Data;
450 return Ar;
451 }
452
453 inline uint64 GetData() const
454 {
455 return Data;
456 }
457
458private:
459 uint64 Data;
460};
461
482
487{
488public:
489 enum class EBindingType : uint8
490 {
491 Bindless,
493 Num
494 };
495
497 {
498 return Layouts[(uint8)BindingType];
499 }
501 {
502 Layouts[(uint8)BindingType] = InLayout;
503 }
504
505protected:
506
508};
509
517
519{
520public:
522 : Name(InName), MapIndex(INDEX_NONE)
523 {}
524
525 FString ToString() const
526 {
527 return Name.ToString();
528 }
529
530 operator FName() const
531 {
532 return Name;
533 }
534
535private:
536 FName Name;
537 int32 MapIndex;
538
540};
541
544{
545 // Map of the virtual file path -> content.
546 // The virtual file paths are the ones that USF files query through the #include "<The Virtual Path of the file>"
548
550
555
556 // Optional shader binding layout which can be used build the Uniform buffer map
558
559 // Serialized version of the shader binding layout which can be used during platform specific shader code generation and serialization
561
563
564 // Used for mobile platforms to allow per shader/material precision modes
566
569
572
584 RENDERCORE_API void SetDefine(const TCHAR* Name, const TCHAR* Value);
585 RENDERCORE_API void SetDefine(const TCHAR* Name, const FString& Value);
588 RENDERCORE_API void SetDefine(const TCHAR* Name, bool Value);
589 RENDERCORE_API void SetDefine(const TCHAR* Name, float Value);
590
592 RENDERCORE_API void SetDefine(FName Name, const FString& Value);
597
604
605 template <typename ValueType> void SetDefineIfUnset(const TCHAR* Name, ValueType Value)
606 {
608 if (!ContainsDefinition(NameKey))
609 {
611 }
612 }
613
614
615 // Sets a generic parameter which can be read in the various shader format backends to modify compilation
616 // behaviour. Intended to replace any usage of definitions after shader preprocessing.
617 template <typename ValueType> void SetCompileArgument(const TCHAR* Name, ValueType Value)
618 {
620 }
621
622 // Like above, but this overload takes in the define value variant explicitly.
627
628 // Helper to set both a define and a compile argument to the same value. Useful for various parameters which
629 // need to be consumed both by preprocessing and in the shader format backends to modify compilation behaviour.
630 template <typename ValueType> void SetDefineAndCompileArgument(const TCHAR* Name, ValueType Value)
631 {
634 }
635
636 // If a compile argument with the given name exists, returns true.
637 bool HasCompileArgument(const TCHAR* Name) const
638 {
639 if (CompileArgs.Contains(Name))
640 {
641 return true;
642 }
643 return false;
644 }
645
646 // If a compile argument with the given name exists and is of the specified type, returns its value. Otherwise,
647 // either the named argument doesn't exist or the type does not match, and the default value will be returned.
648 template <typename ValueType> ValueType GetCompileArgument(const TCHAR* Name, const ValueType& DefaultValue) const
649 {
651 if (StoredValue && StoredValue->IsType<ValueType>())
652 {
653 return StoredValue->Get<ValueType>();
654 }
655 return DefaultValue;
656 }
657
658 // If a compile argument with the given name exists and is of the specified type, its value will be assigned to OutValue
659 // and the function will return true. Otherwise, either the named argument doesn't exist or the type does not match, the
660 // OutValue will be left unmodified and the function will return false.
661 template <typename ValueType> bool GetCompileArgument(const TCHAR* Name, ValueType& OutValue) const
662 {
664 if (StoredValue && StoredValue->IsType<ValueType>())
665 {
666 OutValue = StoredValue->Get<ValueType>();
667 return true;
668 }
669 return false;
670 }
671
676
679
680 // Serializes the portions of the environment that are used as input to the backend compilation process (i.e. after all preprocessing)
682
684 {
685 // Note: this serialize is used to pass between UE and the shader compile worker, recompile both when modifying
686 Ar << Environment.IncludeVirtualPathToContentsMap;
687
688 // Note: skipping Environment.IncludeVirtualPathToSharedContentsMap, which is handled by FShaderCompileUtilities::DoWriteTasks in order to maintain sharing
689
690 Environment.SerializeEverythingButFiles(Ar);
691 return Ar;
692 }
693
695
697
698private:
699 RENDERCORE_API bool ContainsDefinition(FName Name) const;
700
703
705
706 FMemoryHasherBlake3* Hasher = nullptr;
707
709
711 TMap<FString, FString> UnusedStringDefinitions;
712};
713
714
716#define SET_SHADER_DEFINE(ENVIRONMENT, NAME, VALUE) \
717 do { \
718 static FShaderCompilerDefineNameCache Cache_##NAME(TEXT(#NAME)); \
719 (ENVIRONMENT).SetDefine(Cache_##NAME, VALUE); \
720 } while(0)
721
722#define SET_SHADER_DEFINE_AND_COMPILE_ARGUMENT(ENVIRONMENT, NAME, VALUE) \
723 do { \
724 static FShaderCompilerDefineNameCache Cache_##NAME(TEXT(#NAME)); \
725 (ENVIRONMENT).SetDefine(Cache_##NAME, VALUE); \
726 (ENVIRONMENT).SetCompileArgument(TEXT(#NAME), VALUE); \
727 } while(0)
728
729
734
736{
737 AttributeInputs = uint8('i'),
738 AttributeOutputs = uint8('o'),
740 Diagnostic = uint8('D'),
741 Features = uint8('x'),
742 Name = uint8('n'),
743 NativePath = uint8('P'),
744 ObjectFile = uint8('O'),
746 ResourceMasks = uint8('m'),
747 ShaderModel6 = uint8('6'),
748 SourceCode = uint8('c'),
749 UncompressedSize = uint8('U'),
750 UniformBuffers = uint8('u'),
751 Validation = uint8('V'),
752 VendorExtension = uint8('v'),
754 EntryPoint = uint8('e'),
756};
757
759{
760 None = 0,
761 GlobalUniformBuffer = 1 << 0,
762 BindlessResources = 1 << 1,
763 BindlessSamplers = 1 << 2,
764 RootConstants = 1 << 3,
765 NoDerivativeOps = 1 << 4,
766 ShaderBundle = 1 << 5,
767 DiagnosticBuffer = 1 << 6,
768};
770
771// if this changes you need to make sure all shaders get invalidated
783
784// Configuration for a different 'global constant buffer' register assignment.
785// Most compilers always force it to 0 or allow you to assign it, but some compilers do not.
792
794{
795 // for FindOptionalData() and AddOptionalData()
797
798 uint32 UAVMask; // Mask of UAVs bound
799};
800
801
803{
804 None = 0xff,
805
806 Low = 0u,
807 Normal,
808 High, // All global shaders have at least High priorty.
809 ExtraHigh, // Above high priority for shaders known to be slow
810 ForceLocal, // Force shader to skip distributed build and compile on local machine
811 Num,
812};
814
816{
817 switch (InPriority)
818 {
819 case EShaderCompileJobPriority::None: return TEXT("None");
820 case EShaderCompileJobPriority::Low: return TEXT("Low");
821 case EShaderCompileJobPriority::Normal: return TEXT("Normal");
822 case EShaderCompileJobPriority::High: return TEXT("High");
823 case EShaderCompileJobPriority::ExtraHigh: return TEXT("ExtraHigh");
824 case EShaderCompileJobPriority::ForceLocal: return TEXT("ForceLocal");
825 default: checkNoEntry(); return TEXT("");
826 }
827}
828
829
830// if this changes you need to make sure all shaders get invalidated
832{
833 None = 0,
834 WaveOps = 1 << 0,
835 SixteenBitTypes = 1 << 1,
836 TypedUAVLoadsExtended = 1 << 2,
837 Atomic64 = 1 << 3,
838 DiagnosticBuffer UE_DEPRECATED(5.5, "EShaderCodeFeatures::DiagnosticBuffer is superseded by EShaderResourceUsageFlags::DiagnosticBuffer") = 1 << 4,
839 BindlessResources = 1 << 5,
840 BindlessSamplers = 1 << 6,
841 StencilRef = 1 << 7,
842 BarycentricsSemantic = 1 << 8,
843};
845
847{
848 // for FindOptionalData() and AddOptionalData()
850
852};
853
854// if this changes you need to make sure all shaders get invalidated
856{
858
859 // We store the straight ANSICHAR zero-terminated string
860};
861
863{
865 // We store an array of FString objects
866};
867
869{
871 // We store FRHIShaderBindingLayout
872};
873
874// if this changes you need to make sure all shaders get invalidated
876{
877 // for FindOptionalData() and AddOptionalData()
879
882
889
891 {
892 return Ar << Extension.VendorId << Extension.Parameter;
893 }
894
896 {
897 return A.VendorId == B.VendorId && A.Parameter == B.Parameter;
898 }
899
901 {
902 return !(A == B);
903 }
904
905};
906
907
908inline FArchive& operator<<(FArchive& Ar, FShaderCodeValidationStride& ShaderCodeValidationStride)
909{
910 return Ar << ShaderCodeValidationStride.BindPoint << ShaderCodeValidationStride.Stride;
911}
912
917
922
945
951
956
958{
959 // for FindOptionalData() and AddOptionalData()
961 static constexpr uint16 StaticVersion = 0;
962
965
967 {
968 Ar << Extension.Version;
969 Ar << Extension.ShaderDiagnosticDatas;
970 return Ar;
971 }
972};
973
974#ifndef RENDERCORE_ATTRIBUTE_UNALIGNED
975// TODO find out if using GCC_ALIGN(1) instead of this new #define break on all kinds of platforms...
976#define RENDERCORE_ATTRIBUTE_UNALIGNED
977#endif
980
981// later we can transform that to the actual class passed around at the RHI level
983{
984 TConstArrayView<uint8> ShaderCode;
985
986public:
992
994 {
995 return ShaderCode.Num() - GetOptionalDataSize();
996 }
997
1002
1003 // for convenience
1004 template <class T>
1005 const T* FindOptionalData() const
1006 {
1007 return (const T*)FindOptionalData(T::Key, sizeof(T));
1008 }
1009
1010
1011 // @param InKey e.g. FShaderCodePackedResourceCounts::Key
1012 // @return 0 if not found
1014 {
1015 check(ValueSize);
1016
1017 const uint8* End = &ShaderCode[0] + ShaderCode.Num();
1018
1020
1021 const uint8* Start = End - LocalOptionalDataSize;
1022 // while searching don't include the optional data size
1023 End = End - sizeof(LocalOptionalDataSize);
1024 const uint8* Current = Start;
1025
1026 while(Current < End)
1027 {
1029 uint32 Size = *((const unaligned_uint32*)Current);
1030 Current += sizeof(Size);
1031
1032 if(Key == InKey && Size == ValueSize)
1033 {
1034 return Current;
1035 }
1036
1037 Current += Size;
1038 }
1039
1040 return 0;
1041 }
1042
1044 {
1045 check(ShaderCode.Num() >= 4);
1046
1047 const uint8* End = &ShaderCode[0] + ShaderCode.Num();
1048
1050
1051 const uint8* Start = End - LocalOptionalDataSize;
1052 // while searching don't include the optional data size
1053 End = End - sizeof(LocalOptionalDataSize);
1054 const uint8* Current = Start;
1055
1056 while(Current < End)
1057 {
1059 uint32 Size = *((const unaligned_uint32*)Current);
1060 Current += sizeof(Size);
1061
1062 if(Key == InKey)
1063 {
1064 return (ANSICHAR*)Current;
1065 }
1066
1067 Current += Size;
1068 }
1069
1070 return 0;
1071 }
1072
1073 // Returns nullptr and Size -1 if key was not found
1075 {
1076 check(ShaderCode.Num() >= 4);
1077
1078 const uint8* End = &ShaderCode[0] + ShaderCode.Num();
1079
1081
1082 const uint8* Start = End - LocalOptionalDataSize;
1083 // while searching don't include the optional data size
1084 End = End - sizeof(LocalOptionalDataSize);
1085 const uint8* Current = Start;
1086
1087 while (Current < End)
1088 {
1090 uint32 Size = *((const unaligned_uint32*)Current);
1091 Current += sizeof(Size);
1092
1093 if (Key == InKey)
1094 {
1095 OutSize = Size;
1096 return Current;
1097 }
1098
1099 Current += Size;
1100 }
1101
1102 OutSize = -1;
1103 return nullptr;
1104 }
1105
1107 {
1108 if(ShaderCode.Num() < sizeof(int32))
1109 {
1110 return 0;
1111 }
1112
1113 const uint8* End = &ShaderCode[0] + ShaderCode.Num();
1114
1116
1119
1120 return LocalOptionalDataSize;
1121 }
1122
1124 {
1125 return ShaderCode.Num() - GetOptionalDataSize();
1126 }
1127};
1128
1129class FShaderCode;
1130
1132
1134{
1135 struct FHeader
1136 {
1137 int32 UncompressedSize = 0; // full size of code array before compression
1138 int32 ShaderCodeSize = 0; // uncompressed size excluding optional data
1140 uint8 _Pad0 = 0;
1141 uint16 _Pad1 = 0;
1142 };
1143 // header is cloned into shared buffer to avoid needing to determine what offsets FArchive serialization wrote everything at
1144 // as such it needs explicitly initialized padding, so we ensure no additional padding was added by the compiler
1145 static_assert(std::has_unique_object_representations_v<FHeader>);
1146
1147 FSharedBuffer Header; // The above FHeader struct persisted in a shared buffer
1148 FSharedBuffer Code; // The bytecode buffer as constructed by FShaderCode::FinalizeShaderCode
1149 FCompressedBuffer Symbols; // Buffer containing the symbols for this bytecode; will be empty if symbols are disabled
1150
1151 friend class FShaderCode;
1153 friend FArchive& operator<<(FArchive& Ar, FShaderCodeResource& Resource);
1154
1155public:
1156
1157 /* Returns a uint8 array view representation of the Code FSharedBuffer, for compatibility's sake (much downstream
1158 * usage of shader code expects an array of uint8)
1159 */
1161 {
1162 return MakeConstArrayView(reinterpret_cast<const uint8*>(Code.GetData()), static_cast<int32>(Code.GetSize()));
1163 }
1164
1165 /* Return the buffer storing just the shader code for this resource */
1167 {
1168 return Code;
1169 }
1170
1171 /* Return the buffer storing the (compressed) symbols for this resource */
1173 {
1174 return Symbols;
1175 }
1176
1177 /* Returns a single composite buffer referencing both the header and code data to be cached. */
1179 {
1180 return FCompositeBuffer(Header, Code);
1181 }
1182
1183 /* Unpacks the given FSharedBuffer into separate header/code buffer views and returns them as a 2-segment composite buffer.
1184 * Note that this is required since when pushing a composite buffer to DDC it does not maintain the segment structure.
1185 */
1187 {
1189
1190 return FCompositeBuffer(
1191 MonolithicBuffer.MakeView(FullBufferView.Left(sizeof(FHeader)), MonolithicBuffer),
1192 MonolithicBuffer.MakeView(FullBufferView.RightChop(sizeof(FHeader)), MonolithicBuffer));
1193 }
1194
1195 /* Sets the Header and Code shared buffer references in this resource to the segments referenced
1196 * by the given composite buffer.
1197 */
1199 {
1200 check(CacheBuffer.GetSegments().Num() == 2);
1201 Header = CacheBuffer.GetSegments()[0];
1202 check(Header.GetSize() == sizeof(FHeader));
1203 Code = CacheBuffer.GetSegments()[1];
1204 Symbols = SymbolsBuffer;
1205 }
1206
1207 /* Populates the header for this code resource with the given sizes and frequency.
1208 * Note that this is done as a separate process from the construction of the Code buffer
1209 * as the shader frequency is only known by the owning job, and not stored in the FShaderCode.
1210 */
1212 {
1213 check(Code);
1214 FHeader HeaderData{ UncompressedSize, ShaderCodeSize, Frequency };
1215 Header = FSharedBuffer::Clone(&HeaderData, sizeof(HeaderData));
1216 }
1217
1218 /* Retrieves the uncompressed size of the shader code as stored in the FHeader buffer. */
1220 {
1221 check(Header);
1222 return reinterpret_cast<const FHeader*>(Header.GetData())->UncompressedSize;
1223 }
1224
1225 /* Retrieves the actual shader code size (excluding optional data) as stored in the FHeader buffer. */
1227 {
1228 check(Header);
1229 return reinterpret_cast<const FHeader*>(Header.GetData())->ShaderCodeSize;
1230 }
1231
1232 /* Retrieves the shader frequency as stored in the FHeader buffer. */
1234 {
1235 check(Header);
1236 return reinterpret_cast<const FHeader*>(Header.GetData())->Frequency;
1237 }
1238
1239};
1240
1242{
1243 // -1 if ShaderData was finalized
1244 mutable int32 OptionalDataSize;
1245 // access through class methods
1246 mutable TArray<uint8> ShaderCodeWithOptionalData;
1247
1248 mutable TArray<uint8> SymbolData;
1249
1250 mutable FShaderCodeResource ShaderCodeResource;
1251
1253 mutable int32 UncompressedSize;
1254
1256 mutable FName CompressionFormat;
1257
1259 FOodleDataCompression::ECompressor OodleCompressor;
1260
1263
1265 mutable int32 ShaderCodeSize;
1266
1267public:
1268
1270 : OptionalDataSize(0)
1271 , UncompressedSize(0)
1272 , CompressionFormat(NAME_None)
1273 , OodleCompressor(FOodleDataCompression::ECompressor::NotSet)
1274 , OodleLevel(FOodleDataCompression::ECompressionLevel::None)
1275 , ShaderCodeSize(0)
1276 {
1277 }
1278
1279 // converts code and symbols into shared buffer representations, optionally overriding the symbols buffer with the given input
1281 {
1282 if (OptionalDataSize != -1)
1283 {
1284 checkf(UncompressedSize == 0, TEXT("FShaderCode::FinalizeShaderCode() was called after compressing the code"));
1285 OptionalDataSize += sizeof(OptionalDataSize);
1286 ShaderCodeWithOptionalData.Append((const uint8*)&OptionalDataSize, sizeof(OptionalDataSize));
1287 OptionalDataSize = -1;
1288
1289 // sanity check: the override symbol buffer is only used currently when merging multiple code outputs into a single one, and in this
1290 // case we expect the symbols to be empty (as merging the symbols currently needs to be handled differently in each shader format)
1291 check(OverrideSymbolsBuffer.IsNull() || SymbolData.IsEmpty());
1292 ShaderCodeResource.Code = MakeSharedBufferFromArray(MoveTemp(ShaderCodeWithOptionalData));
1294 }
1295 }
1296
1298
1299 // Write access for regular microcode: Optional Data must be added AFTER regular microcode and BEFORE Finalize
1301 {
1302 checkf(OptionalDataSize != -1, TEXT("Tried to add ShaderCode after being finalized!"));
1303 checkf(OptionalDataSize == 0, TEXT("Tried to add ShaderCode after adding Optional data!"));
1304 return ShaderCodeWithOptionalData;
1305 }
1306
1308 {
1309 checkf(OptionalDataSize != -1, TEXT("Tried to add shader symbols after being finalized!"));
1310 return SymbolData;
1311 }
1312
1314 {
1315 checkf(OptionalDataSize != -1, TEXT("Tried to read uncompressed symbol data from bytecode after FinalizeShaderCode was called (which compresses the symbol data)"));
1316 return SymbolData;
1317 }
1318
1320 {
1321 // use the cached size whenever available
1322 if (ShaderCodeSize != 0)
1323 {
1324 return ShaderCodeSize;
1325 }
1326 else
1327 {
1329
1330 if (UncompressedSize != 0) // already compressed, get code size from resource
1331 {
1332 return ShaderCodeResource.GetShaderCodeSize();
1333 }
1334 else
1335 {
1336 // code buffer has been populated but not compressed, can still read additional fields from code buffer
1337 FShaderCodeReader Wrapper(ShaderCodeResource.GetCodeView());
1338 return Wrapper.GetShaderCodeSize();
1339 }
1340 }
1341 }
1342
1343 // for read access, can have additional data attached to the end. Can also be compressed
1345 {
1347
1348 return ShaderCodeResource.GetCodeView();
1349 }
1350
1351 bool IsCompressed() const
1352 {
1353 return UncompressedSize != 0;
1354 }
1355
1357 {
1358 return CompressionFormat;
1359 }
1360
1362 {
1363 return OodleCompressor;
1364 }
1365
1367 {
1368 return OodleLevel;
1369 }
1370
1372 {
1373 return UncompressedSize;
1374 }
1375
1376 // for convenience
1377 template <class T>
1378 void AddOptionalData(const T &In)
1379 {
1380 AddOptionalData(T::Key, (uint8*)&In, sizeof(T));
1381 }
1382
1383 // Note: we don't hash the optional attachments in GenerateOutputHash() as they would prevent sharing (e.g. many material share the save VS)
1384 // can be called after the non optional data was stored in ShaderData
1385 // @param Key uint8 to save memory so max 255, e.g. FShaderCodePackedResourceCounts::Key
1386 // @param Size >0, only restriction is that sum of all optional data values must be < 4GB
1387 void AddOptionalData(EShaderOptionalDataKey Key, const uint8* ValuePtr, uint32 ValueSize)
1388 {
1389 check(ValuePtr);
1390
1391 // don't add after Finalize happened
1392 check(OptionalDataSize >= 0);
1393
1394 ShaderCodeWithOptionalData.Add(uint8(Key));
1395 ShaderCodeWithOptionalData.Append((const uint8*)&ValueSize, sizeof(ValueSize));
1396 ShaderCodeWithOptionalData.Append(ValuePtr, ValueSize);
1397 OptionalDataSize += sizeof(uint8) + sizeof(ValueSize) + (uint32)ValueSize;
1398 }
1399
1400 // Note: we don't hash the optional attachments in GenerateOutputHash() as they would prevent sharing (e.g. many material share the save VS)
1401 // convenience, silently drops the data if string is too long
1402 // @param e.g. 'n' for the ShaderSourceFileName
1408
1409 // Populates FShaderCodeResource's header buffer and returns the fully populated resource struct
1411 {
1412 // shader code must be finalized prior to calling this function
1413 // the finalize process will have created the code FSharedBuffer on the resource already
1414 check(OptionalDataSize == -1);
1415
1416 // If the header is already populated, resource has already been finalized, early out
1417 if (ShaderCodeResource.Header)
1418 {
1419 // sanity check
1420 check(ShaderCodeResource.GetFrequency() == Frequency);
1421 return ShaderCodeResource;
1422 }
1423
1424 // Validate that compression settings used for this ShaderCode by the compilation process match what is expected
1427 {
1428 // we trust that SCWs also obeyed by the same CVar, so we expect a compressed shader code at this point
1429 // However, if we see an uncompressed shader, it perhaps means that SCW tried to compress it, but the result was worse than uncompressed.
1430 // Because of that we special-case NAME_None here
1432 {
1434 {
1435 UE_LOG(LogShaders, Fatal, TEXT("Shader %s is expected to be compressed with %s, but it is compressed with %s instead."),
1436 *OutputHash.ToString(),
1437 *ShaderCompressionFormat.ToString(),
1438 *GetCompressionFormat().ToString()
1439 );
1440 // unreachable
1441 return ShaderCodeResource;
1442 }
1443
1444 // assume uncompressed due to worse ratio than the compression
1445 UE_LOG(LogShaders, Verbose, TEXT("Shader %s is expected to be compressed with %s, but it arrived uncompressed (size=%d). Assuming compressing made it longer and storing uncompressed."),
1446 *OutputHash.ToString(),
1447 *ShaderCompressionFormat.ToString(),
1448 ShaderCodeWithOptionalData.Num()
1449 );
1450 }
1451 else if (ShaderCompressionFormat == NAME_Oodle)
1452 {
1453 // check if Oodle-specific settings match
1457
1459 {
1460 UE_LOG(LogShaders, Fatal, TEXT("Shader %s is expected to be compressed with Oodle compressor %d level %d, but it is compressed with compressor %d level %d instead."),
1461 *OutputHash.ToString(),
1462 static_cast<int32>(OodleCompressorSetting),
1463 static_cast<int32>(OodleLevelSetting),
1464 static_cast<int32>(GetOodleCompressor()),
1465 static_cast<int32>(GetOodleLevel())
1466 );
1467 // unreachable
1468 return ShaderCodeResource;
1469 }
1470 }
1471 }
1472
1473 // Shader library/shader map usage expects uncompressed size to be set to the full code buffer size if uncompressed; so we need to apply that
1474 // transformation here (and reverse it when populating from a FShaderCodeResource, see mirroring code in SetFromResource below)
1475 ShaderCodeResource.PopulateHeader(UncompressedSize == 0 ? static_cast<int32>(ShaderCodeResource.Code.GetSize()) : UncompressedSize, GetShaderCodeSize(), Frequency);
1476 return ShaderCodeResource;
1477 }
1478
1480 {
1481 ShaderCodeResource = MoveTemp(Resource);
1482 // Set the internal state of this FShaderCode to that of a finalized (and possibly compressed) ShaderCode object
1483 OptionalDataSize = -1;
1484 ShaderCodeSize = ShaderCodeResource.GetShaderCodeSize();
1485
1486 // as above, set UncompressedSize to 0 if not compressed, indicated by the resource uncompressed size matching the code buffer size.
1487 int32 ResourceUncompressedSize = ShaderCodeResource.GetUncompressedSize();
1489
1490 // already validated that compression settings matched when serializing the resource, so we can just initialize them to the known-correct values
1491 CompressionFormat = GetShaderCompressionFormat();
1492 GetShaderCompressionOodleSettings(OodleCompressor, OodleLevel);
1493 }
1494
1496};
1497
1503
1510extern RENDERCORE_API FString ParseVirtualShaderFilename(const FString& InFilename);
1511
1514
1517
1519extern RENDERCORE_API void LoadShaderSourceFileChecked(const TCHAR* VirtualFilePath, EShaderPlatform ShaderPlatform, FString& OutFileContents, const FName* ShaderPlatformName = nullptr);
1520
1524extern RENDERCORE_API void GetShaderIncludes(const TCHAR* EntryPointVirtualFilePath, const TCHAR* VirtualFilePath, TArray<FString>& IncludeVirtualFilePaths, EShaderPlatform ShaderPlatform, uint32 DepthLimit=100, const FName* ShaderPlatformName = nullptr);
1525extern RENDERCORE_API void GetShaderIncludes(const TCHAR* EntryPointVirtualFilePath, const TCHAR* VirtualFilePath, const FString& FileContents, TArray<FString>& IncludeVirtualFilePaths, EShaderPlatform ShaderPlatform, uint32 DepthLimit = 100, const FName* ShaderPlatformName = nullptr);
1526
1534extern RENDERCORE_API const class FSHAHash& GetShaderFileHash(const TCHAR* VirtualFilePath, EShaderPlatform ShaderPlatform);
1543 EShaderPlatform ShaderPlatform, FString* OutErrorMessage = nullptr);
1544
1549
1555
1558
1559extern RENDERCORE_API void VerifyShaderSourceFiles(EShaderPlatform ShaderPlatform);
1560
1561#if WITH_EDITOR
1562
1563class FShaderType;
1564class FVertexFactoryType;
1566
1567// Text to use as line terminator for HLSL files (may differ from platform LINE_TERMINATOR)
1568#define HLSL_LINE_TERMINATOR TEXT("\n")
1569
1575
1578 const TCHAR* SourceFilename,
1579 const TCHAR* ShaderTypeName,
1582
1584{
1585 inline bool operator()(const TCHAR* Name1, const TCHAR* Name2) const
1586 {
1587 return FCString::Strcmp(Name1, Name2) < 0;
1588 }
1589};
1590
1595
1596// Forward declarations
1600
1604 FPlatformTypeLayoutParameters LayoutParams,
1605 FString& OutKeyString,
1606 bool bIncludeSourceHashes = true);
1607
1610 TConstArrayView<FShaderPipelineTypeDependency> ShaderPipelineTypeDependencies,
1612 FPlatformTypeLayoutParameters LayoutParams,
1613 FString& OutKeyString,
1614 bool bIncludeSourceHashes = true);
1616 FShaderKeyGenerator& KeyGen,
1618 TConstArrayView<FShaderPipelineTypeDependency> ShaderPipelineTypeDependencies,
1620 FPlatformTypeLayoutParameters LayoutParams,
1621 bool bIncludeSourceHashes = true);
1622#endif // WITH_EDITOR
1623
1627FString RENDERCORE_API MakeInjectedShaderCodeBlock(const TCHAR* BlockName, const FString& CodeToInject);
1628
1629
1634
1637
1649
1650extern RENDERCORE_API void AddShaderSourceFileEntry(TArray<FString>& OutVirtualFilePaths, FString VirtualFilePath, EShaderPlatform ShaderPlatform, const FName* ShaderPlatformName = nullptr);
1651extern RENDERCORE_API void GetAllVirtualShaderSourcePaths(TArray<FString>& OutVirtualFilePaths, EShaderPlatform ShaderPlatform, const FName* ShaderPlatformName = nullptr);
constexpr auto MakeConstArrayView(OtherRangeType &&Other)
Definition ArrayView.h:904
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
FSharedBuffer MakeSharedBufferFromArray(TArray< T, Allocator > &&Array)
Definition SharedBuffer.h:915
#define GET_STATID(Stat)
Definition Stats.h:656
#define DECLARE_CYCLE_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:679
#define DECLARE_DWORD_ACCUMULATOR_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:684
#define DECLARE_FLOAT_ACCUMULATOR_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:683
#define DECLARE_MEMORY_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:687
SharedPointerInternals::TRawPtrProxy< ObjectType > MakeShareable(ObjectType *InObject)
Definition SharedPointer.h:1947
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define CSV_DECLARE_CATEGORY_MODULE_EXTERN(Module_API, CategoryName)
Definition CsvProfiler.h:80
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
#define X(Name, Desc)
Definition FormatStringSan.h:47
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define DECLARE_INTRINSIC_TYPE_LAYOUT(T)
Definition MemoryLayout.h:760
#define UE_PIXELFORMAT_TO_UINT8(argument)
Definition PixelFormat.h:268
EPixelFormat
Definition PixelFormat.h:16
EShaderFrequency
Definition RHIDefinitions.h:202
@ SF_Compute
Definition RHIDefinitions.h:208
@ SF_NumFrequencies
Definition RHIDefinitions.h:216
@ SF_NumBits
Definition RHIDefinitions.h:224
@ SF_RayGen
Definition RHIDefinitions.h:209
@ SF_RayCallable
Definition RHIDefinitions.h:212
@ SF_RayMiss
Definition RHIDefinitions.h:210
@ SF_RayHitGroup
Definition RHIDefinitions.h:211
@ SF_WorkGraphRoot
Definition RHIDefinitions.h:213
@ SF_WorkGraphComputeNode
Definition RHIDefinitions.h:214
@ SF_Pixel
Definition RHIDefinitions.h:206
EGpuVendorId
Definition RHIDefinitions.h:1006
EShaderPlatform
Definition RHIShaderPlatform.h:11
@ SP_NumBits
Definition RHIShaderPlatform.h:56
EShaderCodeFeatures
Definition ShaderCore.h:832
TStatId GetMemoryStatType(EShaderFrequency ShaderFrequency)
Definition ShaderCore.h:143
int32 RENDERCORE_ATTRIBUTE_UNALIGNED unaligned_int32
Definition ShaderCore.h:978
RENDERCORE_API void LoadShaderSourceFileChecked(const TCHAR *VirtualFilePath, EShaderPlatform ShaderPlatform, FString &OutFileContents, const FName *ShaderPlatformName=nullptr)
Definition ShaderCore.cpp:2827
bool operator==(const FShaderStatVariant &LHS, const FShaderStatVariant &RHS)
Definition ShaderCore.cpp:63
RENDERCORE_API bool ReplaceVirtualFilePathForShaderAutogen(FString &InOutVirtualFilePath, EShaderPlatform ShaderPlatform, const FName *InShaderPlatformName=nullptr)
Definition ShaderCore.cpp:2425
RENDERCORE_API const FSHAHash * TryGetShaderFileHash(const TCHAR *VirtualFilePath, EShaderPlatform ShaderPlatform, FString *OutErrorMessage=nullptr)
Definition ShaderCore.cpp:3293
RENDERCORE_API void CheckShaderHashCacheInclude(const FString &VirtualFilePath, EShaderPlatform ShaderPlatform, const FString &ShaderFormatName)
Definition ShaderCore.cpp:3512
constexpr int32 NumShaderCompileJobPriorities
Definition ShaderCore.h:813
RENDERCORE_API void GetAllVirtualShaderSourcePaths(TArray< FString > &OutVirtualFilePaths, EShaderPlatform ShaderPlatform, const FName *ShaderPlatformName=nullptr)
Definition ShaderCore.cpp:2208
RENDERCORE_API const TMap< FString, FString > & AllShaderSourceDirectoryMappings()
Definition ShaderCore.cpp:4060
RENDERCORE_API void InitializeShaderTypes()
Definition ShaderCore.cpp:3523
RENDERCORE_API const class FSHAHash & GetShaderFilesHash(const TArray< FString > &VirtualFilePaths, EShaderPlatform ShaderPlatform)
Definition ShaderCore.cpp:3353
EShaderResourceUsageFlags
Definition ShaderCore.h:759
RENDERCORE_API bool ReplaceVirtualFilePathForShaderPlatform(FString &InOutVirtualFilePath, EShaderPlatform ShaderPlatform)
Definition ShaderCore.cpp:2375
RENDERCORE_API void InitializeShaderHashCache()
Definition ShaderCore.cpp:3500
RENDERCORE_API FName GetShaderCompressionFormat()
Definition ShaderResource.cpp:47
EShaderParameterType
Definition ShaderCore.h:248
RENDERCORE_API void UpdateIncludeDirectoryForPreviewPlatform(EShaderPlatform PreviewPlatform, EShaderPlatform ActualPlatform)
Definition ShaderCore.cpp:3506
RENDERCORE_API void VerifyShaderSourceFiles(EShaderPlatform ShaderPlatform)
Definition ShaderCore.cpp:2246
RENDERCORE_API void GetShaderCompressionOodleSettings(FOodleDataCompression::ECompressor &OutCompressor, FOodleDataCompression::ECompressionLevel &OutLevel, const FName &ShaderFormat=NAME_None)
Definition ShaderResource.cpp:55
bool operator<(const FShaderStatVariant &LHS, const FShaderStatVariant &RHS)
Definition ShaderCore.cpp:89
RENDERCORE_API const class FSHAHash & GetShaderFileHash(const TCHAR *VirtualFilePath, EShaderPlatform ShaderPlatform)
Definition ShaderCore.cpp:3280
RENDERCORE_API void InvalidateShaderFileCacheEntry(const TCHAR *InVirtualFilePath, EShaderPlatform InShaderPlatform, const FName *InShaderPlatformName=nullptr)
Definition ShaderCore.cpp:3562
#define RENDERCORE_ATTRIBUTE_UNALIGNED
Definition ShaderCore.h:976
RENDERCORE_API bool AllowDebugViewmodes()
Definition ShaderCore.cpp:578
RENDERCORE_API FString ParseVirtualShaderFilename(const FString &InFilename)
Definition ShaderCore.cpp:2320
RENDERCORE_API void GetShaderIncludes(const TCHAR *EntryPointVirtualFilePath, const TCHAR *VirtualFilePath, TArray< FString > &IncludeVirtualFilePaths, EShaderPlatform ShaderPlatform, uint32 DepthLimit=100, const FName *ShaderPlatformName=nullptr)
Definition ShaderCore.cpp:3204
RENDERCORE_API void AddShaderSourceDirectoryMapping(const FString &VirtualShaderDirectory, const FString &RealShaderDirectory)
Definition ShaderCore.cpp:4070
bool IsParameterBindless(EShaderParameterType ParameterType)
Definition ShaderCore.h:275
FString RENDERCORE_API MakeInjectedShaderCodeBlock(const TCHAR *BlockName, const FString &CodeToInject)
Definition ShaderCore.cpp:3869
FArchive & operator<<(FArchive &Ar, FUniformResourceEntry &Entry)
Definition ShaderCore.h:370
EShaderParameterTypeMask
Definition ShaderCore.h:263
RENDERCORE_API FString GetShaderSourceFilePath(const FString &VirtualFilePath, TArray< struct FShaderCompilerError > *CompileErrors=nullptr)
Definition ShaderCore.cpp:2273
RENDERCORE_API void AddShaderSourceFileEntry(TArray< FString > &OutVirtualFilePaths, FString VirtualFilePath, EShaderPlatform ShaderPlatform, const FName *ShaderPlatformName=nullptr)
Definition ShaderCore.cpp:2190
uint32 RENDERCORE_ATTRIBUTE_UNALIGNED unaligned_uint32
Definition ShaderCore.h:979
RENDERCORE_API void AddShaderSourceSharedVirtualDirectory(const FString &VirtualShaderDirectory)
Definition ShaderCore.cpp:4109
EShaderOptionalDataKey
Definition ShaderCore.h:736
RENDERCORE_API void ResetAllShaderSourceDirectoryMappings()
Definition ShaderCore.cpp:4065
const TCHAR * ShaderCompileJobPriorityToString(EShaderCompileJobPriority InPriority)
Definition ShaderCore.h:815
EShaderCompileJobPriority
Definition ShaderCore.h:803
RENDERCORE_API void FlushShaderFileCache()
Definition ShaderCore.cpp:3548
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTempIfPossible(T &&Obj) noexcept
Definition UnrealTemplate.h:538
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
Definition CompositeBuffer.h:27
Definition CompressedBuffer.h:50
static CORE_API FCompressedBuffer Compress(const FCompositeBuffer &RawData)
Definition CompressedBuffer.cpp:1003
bool IsNull() const
Definition CompressedBuffer.h:115
Definition MemoryImageWriter.h:14
Definition MemoryImageWriter.h:78
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
Definition MemoryImage.h:49
Definition RHIShaderBindingLayout.h:72
Definition RefCounting.h:213
Definition SecureHash.h:314
Definition SecureHash.h:226
FString ToString() const
Definition SecureHash.h:242
Definition ShaderCore.h:487
EBindingType
Definition ShaderCore.h:490
FShaderBindingLayout Layouts[(uint8) EBindingType::Num]
Definition ShaderCore.h:507
void SetLayout(EBindingType BindingType, const FShaderBindingLayout &InLayout)
Definition ShaderCore.h:500
const FShaderBindingLayout & GetLayout(EBindingType BindingType) const
Definition ShaderCore.h:496
Definition ShaderCore.h:466
FRHIShaderBindingLayout RHILayout
Definition ShaderCore.h:469
Definition ShaderCore.h:983
const ANSICHAR * FindOptionalData(EShaderOptionalDataKey InKey) const
Definition ShaderCore.h:1043
int32 GetShaderCodeSize() const
Definition ShaderCore.h:1123
FShaderCodeReader(TConstArrayView< uint8 > InShaderCode)
Definition ShaderCore.h:987
uint32 GetActualShaderCodeSize() const
Definition ShaderCore.h:993
int32 GetOptionalDataSize() const
Definition ShaderCore.h:1106
const uint8 * FindOptionalDataAndSize(EShaderOptionalDataKey InKey, int32 &OutSize) const
Definition ShaderCore.h:1074
TConstArrayView< uint8 > GetOffsetShaderCode(int32 Offset)
Definition ShaderCore.h:998
const uint8 * FindOptionalData(EShaderOptionalDataKey InKey, uint8 ValueSize) const
Definition ShaderCore.h:1013
const T * FindOptionalData() const
Definition ShaderCore.h:1005
Definition ShaderCore.h:1134
FSharedBuffer GetCodeBuffer() const
Definition ShaderCore.h:1166
EShaderFrequency GetFrequency() const
Definition ShaderCore.h:1233
void PopulateHeader(int32 UncompressedSize, int32 ShaderCodeSize, EShaderFrequency Frequency)
Definition ShaderCore.h:1211
TConstArrayView< uint8 > GetCodeView() const
Definition ShaderCore.h:1160
void PopulateFromComposite(FCompositeBuffer CacheBuffer, FCompressedBuffer SymbolsBuffer)
Definition ShaderCore.h:1198
FCompositeBuffer GetCacheBuffer() const
Definition ShaderCore.h:1178
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FShaderCode &Code)
Definition ShaderCore.cpp:4212
int32 GetUncompressedSize() const
Definition ShaderCore.h:1219
int32 GetShaderCodeSize() const
Definition ShaderCore.h:1226
static FCompositeBuffer Unpack(FSharedBuffer MonolithicBuffer)
Definition ShaderCore.h:1186
FCompressedBuffer GetSymbolsBuffer() const
Definition ShaderCore.h:1172
Definition ShaderCore.h:1242
FName GetCompressionFormat() const
Definition ShaderCore.h:1356
const FShaderCodeResource & GetFinalizedResource(EShaderFrequency Frequency, FSHAHash OutputHash) const
Definition ShaderCore.h:1410
void SetFromResource(FShaderCodeResource &&Resource)
Definition ShaderCore.h:1479
friend RENDERCORE_API FArchive & operator<<(FArchive &Ar, FShaderCode &Output)
Definition ShaderCore.cpp:4212
int32 GetUncompressedSize() const
Definition ShaderCore.h:1371
TArray< uint8 > & GetSymbolWriteAccess()
Definition ShaderCore.h:1307
TConstArrayView< uint8 > GetSymbolReadView() const
Definition ShaderCore.h:1313
FShaderCode()
Definition ShaderCore.h:1269
TConstArrayView< uint8 > GetReadView() const
Definition ShaderCore.h:1344
bool IsCompressed() const
Definition ShaderCore.h:1351
void AddOptionalData(EShaderOptionalDataKey Key, const uint8 *ValuePtr, uint32 ValueSize)
Definition ShaderCore.h:1387
void AddOptionalData(const T &In)
Definition ShaderCore.h:1378
void AddOptionalData(EShaderOptionalDataKey Key, const ANSICHAR *InString)
Definition ShaderCore.h:1403
FOodleDataCompression::ECompressor GetOodleCompressor() const
Definition ShaderCore.h:1361
void FinalizeShaderCode(FCompressedBuffer OverrideSymbolsBuffer=FCompressedBuffer()) const
Definition ShaderCore.h:1280
TArray< uint8 > & GetWriteAccess()
Definition ShaderCore.h:1300
int32 GetShaderCodeSize() const
Definition ShaderCore.h:1319
FOodleDataCompression::ECompressionLevel GetOodleLevel() const
Definition ShaderCore.h:1366
Definition ShaderCompiler.h:347
Definition ShaderCore.h:519
FString ToString() const
Definition ShaderCore.h:525
FShaderCompilerDefineNameCache(const TCHAR *InName)
Definition ShaderCore.h:521
Definition ShaderCompilerDefinitions.h:24
Definition ShaderCore.h:402
void Iterate(TFunction< void(uint32)> Callback) const
Definition ShaderCore.h:432
friend FArchive & operator<<(FArchive &Ar, FShaderCompilerFlags &F)
Definition ShaderCore.h:447
void Add(uint32 InFlag)
Definition ShaderCore.h:414
bool Contains(uint32 InFlag) const
Definition ShaderCore.h:426
void Remove(uint32 InFlag)
Definition ShaderCore.h:420
void Append(const FShaderCompilerFlags &In)
Definition ShaderCore.h:409
FShaderCompilerFlags(uint64 InData=0)
Definition ShaderCore.h:404
uint64 GetData() const
Definition ShaderCore.h:453
Definition ShaderKeyGenerator.h:29
Definition ShaderCore.h:323
FShaderParameterMap()
Definition ShaderCore.h:326
void UpdateHash(FSHA1 &HashState) const
Definition Shader.cpp:201
RENDERCORE_API uint32 CountParametersOfType(EShaderParameterType InType) const
Definition ShaderCore.cpp:1119
RENDERCORE_API TOptional< FParameterAllocation > FindParameterAllocation(FStringView ParameterName) const
Definition ShaderCore.cpp:1047
TMap< FString, FParameterAllocation > ParameterMap
Definition ShaderCore.h:367
RENDERCORE_API void RemoveParameterAllocation(FStringView ParameterName)
Definition ShaderCore.cpp:1101
friend FArchive & operator<<(FArchive &Ar, FShaderParameterMap &InParameterMap)
Definition ShaderCore.h:350
RENDERCORE_API TArray< FStringView > GetAllParameterNamesOfType(EShaderParameterType InType) const
Definition ShaderCore.cpp:1106
RENDERCORE_API void VerifyBindingsAreComplete(const TCHAR *ShaderTypeName, FShaderTarget Target, const class FVertexFactoryType *InVertexFactoryType) const
Definition Shader.cpp:166
RENDERCORE_API TOptional< FParameterAllocation > FindAndRemoveParameterAllocation(FStringView ParameterName)
Definition ShaderCore.cpp:1065
RENDERCORE_API void AddParameterAllocation(FStringView ParameterName, uint16 BufferIndex, uint16 BaseIndex, uint16 Size, EShaderParameterType ParameterType)
Definition ShaderCore.cpp:1095
RENDERCORE_API bool ContainsParameterAllocation(FStringView ParameterName) const
Definition ShaderCore.cpp:1090
const TMap< FString, FParameterAllocation > & GetParameterMap() const
Definition ShaderCore.h:362
void GetAllParameterNames(TArray< FString > &OutNames) const
Definition ShaderCore.h:357
Definition ShaderParameterMetadata.h:136
Definition Shader.h:2111
Definition Shader.h:1931
Definition Shader.h:2040
Definition Shader.h:1238
Definition SharedBuffer.h:341
uint64 GetSize() const
Definition SharedBuffer.h:388
const void * GetData() const
Definition SharedBuffer.h:385
static CORE_API FSharedBuffer Clone(FMemoryView View)
Definition SharedBuffer.cpp:187
Definition VertexFactory.h:599
Definition VertexFactory.h:314
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_REWRITE bool IsEmpty() const
Definition Array.h:1133
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void Append(const TArray< OtherElementType, OtherAllocatorType > &Source)
Definition Array.h:2412
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition MemoryHasher.h:22
UE_FORCEINLINE_HINT ObjectType * Get() const
Definition SharedPointer.h:1065
Definition OodleDataCompression.cpp:28
ECompressor
Definition OodleDataCompression.h:49
ECompressionLevel
Definition OodleDataCompression.h:94
Definition ShaderCore.cpp:59
RENDERCORE_API const FName AnalysisArtifactsName
Definition ShaderCore.h:66
U16 Index
Definition radfft.cpp:71
Definition ShaderCore.h:70
friend FArchive & operator<<(FArchive &Ar, FGenericShaderStat &Stat)
Definition ShaderCore.h:84
FGenericShaderStat()=default
RENDERCORE_API void StreamArchive(FArchive &Ar)
Definition ShaderCore.cpp:140
bool operator==(const FGenericShaderStat &RHS) const
Definition ShaderCore.cpp:171
FName StatName
Definition ShaderCore.h:77
EFlags
Definition ShaderCore.h:73
FShaderStatVariant Value
Definition ShaderCore.h:78
EFlags Flags
Definition ShaderCore.h:79
FName TagName
Definition ShaderCore.h:80
bool operator<(const FGenericShaderStat &RHS) const
Definition ShaderCore.cpp:176
Definition ShaderCore.h:284
friend bool operator==(const FParameterAllocation &A, const FParameterAllocation &B)
Definition ShaderCore.h:307
friend bool operator!=(const FParameterAllocation &A, const FParameterAllocation &B)
Definition ShaderCore.h:313
friend FArchive & operator<<(FArchive &Ar, FParameterAllocation &Allocation)
Definition ShaderCore.h:300
bool bBound
Definition ShaderCore.h:289
uint16 Size
Definition ShaderCore.h:287
uint16 BaseIndex
Definition ShaderCore.h:286
uint16 BufferIndex
Definition ShaderCore.h:285
FParameterAllocation(uint16 InBufferIndex, uint16 InBaseIndex, uint16 InSize, EShaderParameterType InType)
Definition ShaderCore.h:292
EShaderParameterType Type
Definition ShaderCore.h:288
FParameterAllocation()=default
Definition MemoryLayout.h:799
Definition ShaderCore.h:847
EShaderCodeFeatures CodeFeatures
Definition ShaderCore.h:851
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:849
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:788
uint32 Slot
Definition ShaderCore.h:790
Definition ShaderCore.h:856
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:857
Definition ShaderCore.h:773
uint8 NumCBs
Definition ShaderCore.h:780
uint8 NumSamplers
Definition ShaderCore.h:778
uint8 NumSRVs
Definition ShaderCore.h:779
EShaderResourceUsageFlags UsageFlags
Definition ShaderCore.h:777
uint8 NumUAVs
Definition ShaderCore.h:781
Definition ShaderCore.h:794
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:796
uint32 UAVMask
Definition ShaderCore.h:798
Definition ShaderCore.h:869
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:870
Definition ShaderCore.h:863
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:864
Definition ShaderCore.h:924
static constexpr EShaderOptionalDataKey Key
Definition ShaderCore.h:926
uint16 Version
Definition ShaderCore.h:933
TArray< FShaderCodeValidationStride > ShaderCodeValidationStride
Definition ShaderCore.h:929
TArray< FShaderCodeValidationType > ShaderCodeValidationSRVType
Definition ShaderCore.h:930
TArray< FShaderCodeValidationUBSize > ShaderCodeValidationUBSize
Definition ShaderCore.h:932
TArray< FShaderCodeValidationType > ShaderCodeValidationUAVType
Definition ShaderCore.h:931
friend FArchive & operator<<(FArchive &Ar, FShaderCodeValidationExtension &Extension)
Definition ShaderCore.h:935
static constexpr uint16 StaticVersion
Definition ShaderCore.h:927
Definition RHIDefinitions.h:1746
uint16 BindPoint
Definition RHIDefinitions.h:1747
uint16 Stride
Definition RHIDefinitions.h:1748
Definition RHIDefinitions.h:1752
Definition RHIDefinitions.h:1758
Definition ShaderCore.h:876
EGpuVendorId VendorId
Definition ShaderCore.h:880
friend FArchive & operator<<(FArchive &Ar, FShaderCodeVendorExtension &Extension)
Definition ShaderCore.h:890
FParameterAllocation Parameter
Definition ShaderCore.h:881
FShaderCodeVendorExtension()=default
FShaderCodeVendorExtension(EGpuVendorId InVendorId, uint16 InBufferIndex, uint16 InBaseIndex, uint16 InSize, EShaderParameterType InType)
Definition ShaderCore.h:884
static const EShaderOptionalDataKey Key
Definition ShaderCore.h:878
friend bool operator!=(const FShaderCodeVendorExtension &A, const FShaderCodeVendorExtension &B)
Definition ShaderCore.h:900
friend bool operator==(const FShaderCodeVendorExtension &A, const FShaderCodeVendorExtension &B)
Definition ShaderCore.h:895
Definition ShaderCore.h:544
const ITargetPlatform * TargetPlatform
Definition ShaderCore.h:562
FShaderCompilerFlags CompilerFlags
Definition ShaderCore.h:551
TMap< uint32, uint8 > RenderTargetOutputFormatsMap
Definition ShaderCore.h:552
TMap< FString, FString > IncludeVirtualPathToContentsMap
Definition ShaderCore.h:547
FShaderResourceTableMap ResourceTableMap
Definition ShaderCore.h:553
void SetDefineAndCompileArgument(const TCHAR *Name, ValueType Value)
Definition ShaderCore.h:630
friend FArchive & operator<<(FArchive &Ar, FShaderCompilerEnvironment &Environment)
Definition ShaderCore.h:683
void SetDefineIfUnset(const TCHAR *Name, ValueType Value)
Definition ShaderCore.h:605
const FShaderBindingLayout * ShaderBindingLayout
Definition ShaderCore.h:557
void SetCompileArgument(const TCHAR *Name, TVariant< bool, float, int32, uint32, FString > Value)
Definition ShaderCore.h:623
ValueType GetCompileArgument(const TCHAR *Name, const ValueType &DefaultValue) const
Definition ShaderCore.h:648
FRHIShaderBindingLayout RHIShaderBindingLayout
Definition ShaderCore.h:560
bool GetCompileArgument(const TCHAR *Name, ValueType &OutValue) const
Definition ShaderCore.h:661
bool HasCompileArgument(const TCHAR *Name) const
Definition ShaderCore.h:637
void SetRenderTargetOutputFormat(uint32 RenderTargetIndex, EPixelFormat PixelFormat)
Definition ShaderCore.h:672
TMap< FString, FUniformBufferEntry > UniformBufferMap
Definition ShaderCore.h:554
RENDERCORE_API FShaderCompilerEnvironment()
Definition ShaderCore.cpp:1210
RENDERCORE_API void SetDefine(const TCHAR *Name, const TCHAR *Value)
Definition ShaderCore.cpp:1287
RENDERCORE_API void SerializeEverythingButFiles(FArchive &Ar)
Definition ShaderCore.cpp:1518
void SetCompileArgument(const TCHAR *Name, ValueType Value)
Definition ShaderCore.h:617
RENDERCORE_API FString GetDefinitionsAsCommentedCode() const
Definition ShaderCore.cpp:1266
RENDERCORE_API void SerializeCompilationDependencies(FArchive &Ar)
Definition ShaderCore.cpp:1539
TMap< FString, FThreadSafeSharedAnsiStringPtr > IncludeVirtualPathToSharedContentsMap
Definition ShaderCore.h:549
friend class FShaderPreprocessorUtilities
Definition ShaderCore.h:702
bool FullPrecisionInPS
Definition ShaderCore.h:565
Definition ShaderCore.h:947
FString Message
Definition ShaderCore.h:949
uint32 Hash
Definition ShaderCore.h:948
Definition ShaderCore.h:958
static constexpr uint16 StaticVersion
Definition ShaderCore.h:961
uint16 Version
Definition ShaderCore.h:964
TArray< FShaderDiagnosticData > ShaderDiagnosticDatas
Definition ShaderCore.h:963
static constexpr EShaderOptionalDataKey Key
Definition ShaderCore.h:960
friend FArchive & operator<<(FArchive &Ar, FShaderDiagnosticExtension &Extension)
Definition ShaderCore.h:966
Definition ShaderCore.h:511
TArray< FUniformResourceEntry > Resources
Definition ShaderCore.h:512
RENDERCORE_API void FixupOnLoad(const TMap< FString, FUniformBufferEntry > &UniformBufferMap)
Definition ShaderCore.cpp:1190
Definition ShaderCore.h:186
friend FArchive & operator<<(FArchive &Ar, FShaderTarget &Target)
Definition ShaderCore.h:214
FShaderTarget(EShaderFrequency InFrequency, EShaderPlatform InPlatform)
Definition ShaderCore.h:202
FShaderTarget()
Definition ShaderCore.h:198
uint32 Platform
Definition ShaderCore.h:194
EShaderPlatform GetPlatform() const
Definition ShaderCore.h:228
EShaderFrequency GetFrequency() const
Definition ShaderCore.h:233
friend bool operator==(const FShaderTarget &X, const FShaderTarget &Y)
Definition ShaderCore.h:209
uint32 Frequency
Definition ShaderCore.h:193
friend uint32 GetTypeHash(FShaderTarget Target)
Definition ShaderCore.h:238
uint32 Packed
Definition ShaderCore.h:190
Definition ShaderCore.h:731
virtual ~FSharedShaderCompilerEnvironment()=default
Definition MemoryLayout.h:108
Definition ShaderParameterMetadata.h:66
EUniformBufferBindingFlags BindingFlags
Definition ShaderParameterMetadata.h:77
ERHIUniformBufferFlags Flags
Definition ShaderParameterMetadata.h:80
FString StaticSlotName
Definition ShaderParameterMetadata.h:68
uint32 LayoutHash
Definition ShaderParameterMetadata.h:74
FThreadSafeNameBufferPtr MemberNameBuffer
Definition ShaderParameterMetadata.h:71
Definition ShaderParameterMetadata.h:51
const TCHAR * UniformBufferMemberName
Definition ShaderParameterMetadata.h:53
uint8 Type
Definition ShaderParameterMetadata.h:57
uint16 ResourceIndex
Definition ShaderParameterMetadata.h:59
uint8 UniformBufferNameLength
Definition ShaderParameterMetadata.h:55
static UE_FORCEINLINE_HINT int32 Strcmp(const CharType *String1, const CharType *String2)
Definition CString.h:1018
static int32 Strlen(const CharType *String)
Definition CString.h:1047
Definition TVariant.h:13
Definition Optional.h:131
Definition PimplPtr.h:50
Definition LightweightStats.h:416