UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialShaderType.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 MaterialShader.h: Material shader definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "Shader.h"
10#include "GlobalShader.h"
11
13#define IMPLEMENT_MATERIAL_SHADER_TYPE(TemplatePrefix,ShaderClass,SourceFilename,FunctionName,Frequency) \
14 IMPLEMENT_SHADER_TYPE( \
15 TemplatePrefix, \
16 ShaderClass, \
17 SourceFilename, \
18 FunctionName, \
19 Frequency \
20 );
21
22class FMaterial;
32enum EBlendMode : int;
33enum EMaterialShadingModel : int;
35#if WITH_EDITOR
37#endif
38
39
41
42
44
46extern ENGINE_API FString GetShadingModelFieldString(FMaterialShadingModelField ShadingModels, const FShadingModelToStringDelegate& Delegate, const FString& Delimiter = " ");
47
50
52extern ENGINE_API FString GetBlendModeString(EBlendMode BlendMode);
53
54#if WITH_EDITOR
56 const FMaterialShaderMapId& ShaderMapId,
57 const FMaterialShaderParameters& ShaderParameters,
60
63 FMaterialShaderMapId& ShaderMapId,
64 FMaterialShaderParameters& ShaderParameters);
65
66// Alternate arguments for RecordOrEmitMaterialShaderMapKey: Support being called with const&
67// when emitting or saving.
70 const FMaterialShaderMapId& ShaderMapId,
71 const FMaterialShaderParameters& ShaderParameters);
74 FMaterialShaderMapId& ShaderMapId,
75 FMaterialShaderParameters&& ShaderParameters)
76{
77 RecordOrEmitMaterialShaderMapKey(Context, ShaderMapId, ShaderParameters);
78}
79#endif
80
83
90
95{
96public:
125
126 IMPLEMENT_SHADER_TYPE_CONSTRUCTOR(FMaterialShaderType, EShaderTypeForDynamicCast::Material, TEXT("material shader"));
127
128#if WITH_EDITOR
136 int32 PermutationId,
137 const FMaterial* Material,
138 const FMaterialShaderMapId& ShaderMapId,
141 EShaderPermutationFlags PermutationFlags,
143 const FString& DebugGroupName,
144 const TCHAR* DebugDescription,
145 const TCHAR* DebugExtension
146 ) const;
147
148 static void BeginCompileShaderPipeline(
152 EShaderPermutationFlags PermutationFlags,
153 const FMaterial* Material,
154 const FMaterialShaderMapId& ShaderMapId,
156 const FShaderPipelineType* ShaderPipeline,
158 const FString& DebugGroupName,
159 const TCHAR* DebugDescription,
160 const TCHAR* DebugExtension
161 );
162
169 const FUniformExpressionSet& UniformExpressionSet,
170 const FSHAHash& MaterialShaderMapHash,
172 const FShaderPipelineType* ShaderPipeline,
173 const FString& InDebugDescription
174 ) const;
175#endif // WITH_EDITOR
176
184
186
187#if WITH_EDITOR
194#endif // WITH_EDITOR
195};
196
220
222{
226
227 inline FMaterialShaders() : ShaderMap(nullptr), Pipeline(nullptr) { FMemory::Memzero(Shaders); }
228
230 {
231 if (Pipeline)
232 {
234 return true;
235 }
236 return false;
237 }
238
239 template<typename ShaderType>
241 {
243 if (Shader)
244 {
245 checkSlow(Shader->GetFrequency() == InFrequency);
246 OutShader = TShaderRef<ShaderType>(static_cast<ShaderType*>(Shader), *ShaderMap);
247 // FTypeLayoutDesc::operator== doesn't work correctly in all cases, when dealing with inline/templated types
248 //checkfSlow(OutShader.GetType()->GetLayout().IsDerivedFrom(StaticGetTypeLayoutDesc<ShaderType>()), TEXT("Invalid cast of shader type '%s' to '%s'"),
249 // OutShader.GetType()->GetName(),
250 // StaticGetTypeLayoutDesc<ShaderType>().Name);
251 return true;
252 }
253 return false;
254 }
255
256 template<typename ShaderType>
258 {
260 if (Shader)
261 {
262 checkSlow(Shader->GetFrequency() == InFrequency);
263 check(OutShader); // make sure output isn't null, if we have the shader
264 *OutShader = TShaderRef<ShaderType>(static_cast<ShaderType*>(Shader), *ShaderMap);
265 // FTypeLayoutDesc::operator== doesn't work correctly in all cases, when dealing with inline/templated types
266 //checkfSlow(OutShader.GetType()->GetLayout().IsDerivedFrom(StaticGetTypeLayoutDesc<ShaderType>()), TEXT("Invalid cast of shader type '%s' to '%s'"),
267 // OutShader.GetType()->GetName(),
268 // StaticGetTypeLayoutDesc<ShaderType>().Name);
269 return true;
270 }
271 return false;
272 }
273
274 template<typename ShaderType> inline bool TryGetVertexShader(TShaderRef<ShaderType>& OutShader) const { return TryGetShader(SF_Vertex, OutShader); }
275 template<typename ShaderType> inline bool TryGetPixelShader(TShaderRef<ShaderType>& OutShader) const { return TryGetShader(SF_Pixel, OutShader); }
276 template<typename ShaderType> inline bool TryGetGeometryShader(TShaderRef<ShaderType>& OutShader) const { return TryGetShader(SF_Geometry, OutShader); }
277 template<typename ShaderType> inline bool TryGetMeshShader(TShaderRef<ShaderType>& OutShader) const { return TryGetShader(SF_Mesh, OutShader); }
278 template<typename ShaderType> inline bool TryGetComputeShader(TShaderRef<ShaderType>& OutShader) const { return TryGetShader(SF_Compute, OutShader); }
279
280 template<typename ShaderType> inline bool TryGetVertexShader(TShaderRef<ShaderType>* OutShader) const { return TryGetShader(SF_Vertex, OutShader); }
281 template<typename ShaderType> inline bool TryGetPixelShader(TShaderRef<ShaderType>* OutShader) const { return TryGetShader(SF_Pixel, OutShader); }
282 template<typename ShaderType> inline bool TryGetGeometryShader(TShaderRef<ShaderType>* OutShader) const { return TryGetShader(SF_Geometry, OutShader); }
283 template<typename ShaderType> inline bool TryGetMeshShader(TShaderRef<ShaderType>* OutShader) const { return TryGetShader(SF_Mesh, OutShader); }
284 template<typename ShaderType> inline bool TryGetComputeShader(TShaderRef<ShaderType>* OutShader) const { return TryGetShader(SF_Compute, OutShader); }
285};
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#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
#define DECLARE_DELEGATE_RetVal_OneParam(ReturnValueType, DelegateName, Param1Type)
Definition DelegateCombinations.h:54
EBlendMode
Definition EngineTypes.h:245
EMaterialShadingModel
Definition EngineTypes.h:705
void UpdateMaterialShaderCompilingStats(const FMaterial *Material)
Definition MaterialShader.cpp:725
ENGINE_API void DumpMaterialStats(EShaderPlatform Platform)
Definition MaterialShader.cpp:4159
ENGINE_API FString GetBlendModeString(EBlendMode BlendMode)
Definition MaterialShader.cpp:205
ENGINE_API FString GetShadingModelFieldString(FMaterialShadingModelField ShadingModels, const FShadingModelToStringDelegate &Delegate, const FString &Delimiter=" ")
Definition MaterialShader.cpp:177
FString GetShadingModelString(EMaterialShadingModel ShadingModel)
Definition MaterialShader.cpp:123
EShaderFrequency
Definition RHIDefinitions.h:202
@ SF_Compute
Definition RHIDefinitions.h:208
@ SF_NumFrequencies
Definition RHIDefinitions.h:216
@ SF_Vertex
Definition RHIDefinitions.h:203
@ SF_Mesh
Definition RHIDefinitions.h:204
@ SF_Geometry
Definition RHIDefinitions.h:207
@ SF_Pixel
Definition RHIDefinitions.h:206
EShaderPlatform
Definition RHIShaderPlatform.h:11
EShaderCompileJobPriority
Definition ShaderCore.h:803
EShaderPermutationFlags
Definition ShaderPermutation.h:19
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GlobalShader.h:87
Definition MaterialShared.h:1194
Definition MaterialShared.h:1518
Definition MaterialShaderType.h:95
static bool ShouldCompilePipeline(const FShaderPipelineType *ShaderPipelineType, EShaderPlatform Platform, const FMaterialShaderParameters &MaterialParameters, EShaderPermutationFlags Flags)
Definition MaterialShader.cpp:1970
bool ShouldCompilePermutation(EShaderPlatform Platform, const FMaterialShaderParameters &MaterialParameters, int32 PermutationId, EShaderPermutationFlags Flags) const
Definition MaterialShader.cpp:1965
IMPLEMENT_SHADER_TYPE_CONSTRUCTOR(FMaterialShaderType, EShaderTypeForDynamicCast::Material, TEXT("material shader"))
Definition MaterialShared.h:2058
Definition SecureHash.h:226
Definition ShaderCompilerJobTypes.h:152
Definition ShaderCompilerJobTypes.h:331
Definition ShaderKeyGenerator.h:29
Definition Shader.h:2476
Definition Shader.h:2273
Definition Shader.h:1931
Definition Shader.h:2182
Definition Shader.h:1238
EShaderFrequency GetFrequency() const
Definition Shader.h:1460
Definition Shader.h:829
Definition MaterialShared.h:666
Definition VertexFactory.h:314
Definition Array.h:670
Definition RefCounting.h:454
Definition Shader.h:1021
Definition MaterialShared.h:1181
Definition MaterialShaderType.h:98
const FUniformExpressionSet & UniformExpressionSet
Definition MaterialShaderType.h:99
CompiledShaderInitializerType(const FShaderType *InType, int32 InPermutationId, const FShaderCompilerOutput &CompilerOutput, const FUniformExpressionSet &InUniformExpressionSet, const FSHAHash &InMaterialShaderMapHash, const FShaderPipelineType *InShaderPipeline, const FVertexFactoryType *InVertexFactoryType, const FString &InDebugDescription)
Definition MaterialShaderType.h:102
const FString DebugDescription
Definition MaterialShaderType.h:100
Definition MaterialShaderType.h:198
const FShaderType * AddShaderType(int32 InPermutationId=0)
Definition MaterialShaderType.h:215
const FShaderType * ShaderType[SF_NumFrequencies]
Definition MaterialShaderType.h:200
FMaterialShaderTypes()
Definition MaterialShaderType.h:203
const FShaderType * AddShaderType(const FShaderType *InType, int32 InPermutationId=0)
Definition MaterialShaderType.h:205
const FShaderPipelineType * PipelineType
Definition MaterialShaderType.h:199
int32 PermutationId[SF_NumFrequencies]
Definition MaterialShaderType.h:201
Definition MaterialShaderType.h:222
bool TryGetPixelShader(TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:275
bool TryGetVertexShader(TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:280
bool TryGetPipeline(FShaderPipelineRef &OutPipeline) const
Definition MaterialShaderType.h:229
FMaterialShaders()
Definition MaterialShaderType.h:227
bool TryGetPixelShader(TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:281
bool TryGetGeometryShader(TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:276
bool TryGetComputeShader(TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:284
bool TryGetShader(EShaderFrequency InFrequency, TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:257
bool TryGetGeometryShader(TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:282
bool TryGetMeshShader(TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:277
bool TryGetMeshShader(TShaderRef< ShaderType > *OutShader) const
Definition MaterialShaderType.h:283
bool TryGetShader(EShaderFrequency InFrequency, TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:240
FShaderPipeline * Pipeline
Definition MaterialShaderType.h:224
bool TryGetVertexShader(TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:274
FShader * Shaders[SF_NumFrequencies]
Definition MaterialShaderType.h:225
const FShaderMapBase * ShaderMap
Definition MaterialShaderType.h:223
bool TryGetComputeShader(TShaderRef< ShaderType > &OutShader) const
Definition MaterialShaderType.h:278
Definition EngineTypes.h:732
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
Definition Shader.h:1610
Definition ShaderCore.h:544
Definition ShaderCompilerCore.h:491
Definition ShaderCore.h:731