UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderPermutationUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "RHIGlobals.h"
7#include "ShaderPermutation.h"
8
10{
11 inline bool ShouldCompileWithWaveSize(const FShaderPermutationParameters& Parameters, int32 WaveSize)
12 {
13 if (WaveSize)
14 {
15 if (!RHISupportsWaveOperations(Parameters.Platform))
16 {
17 return false;
18 }
19
22 {
23 return false;
24 }
25 }
26
27 return true;
28 }
29
30 inline bool ShouldPrecacheWithWaveSize(const FShaderPermutationParameters& Parameters, int32 WaveSize)
31 {
32 if (WaveSize)
33 {
35 {
36 return false;
37 }
38 }
39
40 return true;
41 }
42
43 template <typename TDimension>
44 void FormatPermutationParameter(const typename TDimension::Type& E, FString& OutString, bool bFullNames, const TCHAR* Prefix);
45
46 inline void FormatPermutationDomain(const TShaderPermutationDomain<>& InShaderPermutationDomain, FString& OutString, bool bFullNames, const TCHAR* Prefix)
47 {
48 // Dummy
49 }
50
51 template <typename TDimension, typename... Ts>
53 {
54 const int32 Value = TDimension::ToDimensionValueId(InShaderPermutationDomain.template Get<TDimension>());
55 if (bFullNames)
56 {
57 if (!OutString.IsEmpty())
58 {
59 OutString.AppendChar(TEXT('\n'));
60 }
61
62 if (Prefix != nullptr)
63 {
64 OutString.Append(Prefix);
65 }
66
67 if (TDimension::IsMultiDimensional)
68 {
69 OutString.Appendf(TEXT("TShaderPermutationDomain[%d]"), TDimension::PermutationCount);
70 }
71
72 if (Prefix != nullptr)
73 {
74 const FString ExtendedPrefix = FString::Printf(TEXT("%s -> "), Prefix);
76 }
77 else
78 {
80 }
81 }
82 else
83 {
84 if (!OutString.IsEmpty())
85 {
86 OutString.AppendChar(TEXT(','));
87 }
89 }
90
92 }
93
94 template <typename TDimension>
95 void FormatPermutationParameter(const typename TDimension::Type& E, FString& OutString, bool bFullNames, const TCHAR* Prefix)
96 {
97 if constexpr (TDimension::IsMultiDimensional)
98 {
99 FormatPermutationDomain(E, OutString, bFullNames, Prefix);
100 }
101 else if constexpr (std::is_base_of_v<FShaderPermutationBool, TDimension>)
102 {
103 if (bFullNames)
104 {
105 OutString.Appendf(TEXT("%s (%s)"), TDimension::DefineName, !FShaderPermutationBool::ToDefineValue(E) ? TEXT("false") : TEXT("true"));
106 }
107 else
108 {
109 OutString.Appendf(TEXT("%d"), static_cast<int32>(FShaderPermutationBool::ToDefineValue(E)));
110 }
111 }
112 else
113 {
114 if (bFullNames)
115 {
116 OutString.Appendf(TEXT("%s (%d)"), TDimension::DefineName, static_cast<int32>(TDimension::ToDefineValue(E)));
117 }
118 else
119 {
120 OutString.Appendf(TEXT("%d"), static_cast<int32>(TDimension::ToDefineValue(E)));
121 }
122 }
123 }
124
125 template <typename DimensionType>
126 bool DoesDimensionContainValue(const typename DimensionType::Type& Value)
127 {
128 for (int32 PermutationId = 0; PermutationId < DimensionType::PermutationCount; ++PermutationId)
129 {
130 if (Value == DimensionType::FromDimensionValueId(PermutationId))
131 {
132 return true;
133 }
134 }
135 return false;
136 }
137}
#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
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool RHISupportsWaveOperations(const FStaticShaderPlatform Platform)
Definition DataDrivenShaderPlatformInfo.h:1232
FRHIGlobals GRHIGlobals
Definition RHIGlobals.cpp:6
static const uint32 GetMinimumWaveSize(const FStaticShaderPlatform Platform)
Definition DataDrivenShaderPlatformInfo.h:470
static const uint32 GetMaximumWaveSize(const FStaticShaderPlatform Platform)
Definition DataDrivenShaderPlatformInfo.h:476
Definition ShaderPermutationUtils.h:10
void FormatPermutationParameter(const typename TDimension::Type &E, FString &OutString, bool bFullNames, const TCHAR *Prefix)
Definition ShaderPermutationUtils.h:95
bool DoesDimensionContainValue(const typename DimensionType::Type &Value)
Definition ShaderPermutationUtils.h:126
bool ShouldCompileWithWaveSize(const FShaderPermutationParameters &Parameters, int32 WaveSize)
Definition ShaderPermutationUtils.h:11
void FormatPermutationDomain(const TShaderPermutationDomain<> &InShaderPermutationDomain, FString &OutString, bool bFullNames, const TCHAR *Prefix)
Definition ShaderPermutationUtils.h:46
bool ShouldPrecacheWithWaveSize(const FShaderPermutationParameters &Parameters, int32 WaveSize)
Definition ShaderPermutationUtils.h:30
int32 MaximumWaveSize
Definition RHIGlobals.h:505
static bool ToDefineValue(Type E)
Definition ShaderPermutation.h:68
Definition ShaderPermutation.h:27
const EShaderPlatform Platform
Definition ShaderPermutation.h:29
Definition ShaderPermutation.h:229