UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialIRModule.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5#include "MaterialShared.h"
6#include "Misc/MemStack.h"
7
8#if WITH_EDITOR
9
10// This class represents the intermediate representation (IR) of a material build.
11// The IRModule includes an IR value graph, produced through expression analysis,
12// as well as metadata on resource usage and reflection. The IR graph serves as an
13// abstract representation of the material and must be translated into a target backend
14// such as HLSL or specific Preshader opcodes for execution.
15//
16// This class is designed to be backend-agnostic, meaning it does not contain any
17// HLSL code nor does it configure a MaterialCompilationOutput instance. The data
18// stored within this class should be sufficient to enable translation to any supported
19// backend without requiring additional processing or validation.
21{
22public:
23 // Represents an error encountered during material processing.
24 struct FError
25 {
26 // The expression that caused the error.
28
29 // Description of the error.
30 FString Message;
31 };
32
33 // Stores information about the resources used by the translated material.
34 struct FStatistics
35 {
36 // Tracks external inputs used per frequency.
37 TBitArray<> ExternalInputUsedMask[MIR::NumStages];
38
39 // Number of vertex texture coordinates used.
41
42 // Number of pixel texture coordinates used.
44
45 // Dynamic particle parameter indices used by this material.
47 };
48
49 // An entry point is a sequence of instructions that evaluates a set of "output" instructions.
50 // A way to think of an entry point is as the "main scope" or the "body" of a C function.
51 // Each shader stage (Vertex, Pixel and Compute) gets its own entry point with one or more outputs.
52 // Other entry points are crated by user specified "local functions", such as custom outputs.
53 struct FEntryPoint
54 {
55 // This entry point's user name.
57
58 // The shader stage this entry point is intended to run in.
59 MIR::EStage Stage;
60
61 // The root block containing this entry point's instructions.
62 MIR::FBlock RootBlock;
63
64 // An array of terminal values this entry point evaluates.
66 };
67
68public:
71
72 // Clears the module, releasing all stored data.
73 void Empty();
74
75 // Returns the shader platform associated with this module.
76 EShaderPlatform GetShaderPlatform() const { return ShaderPlatform; }
77
78 // Returns the target platform interface associated with this module.
79 const ITargetPlatform* GetTargetPlatform() const { return TargetPlatform; };
80
81 // Returns the feature level associated with this module.
82 ERHIFeatureLevel::Type GetFeatureLevel() const { return FeatureLevel; }
83
84 // Returns the quality level associated with this module.
85 EMaterialQualityLevel::Type GetQualityLevel() const { return QualityLevel; }
86
87 // Returns the blend mode associated with this module.
88 EBlendMode GetBlendMode() const { return BlendMode; }
89
90 // Retrieves the material compilation output.
92
93 // Adds a new entry point with specified name, stage and expected number of evaluated output values.
95
96 // Returns the number of procedures inthe module.
97 int32 GetNumEntryPoints() const { return EntryPoints.Num(); }
98
99 // Gets the entry point of given Index previously added with AddEntryPoint().
100 FEntryPoint& GetEntryPoint(int32 Index) { return EntryPoints[Index]; }
101 const FEntryPoint& GetEntryPoint(int32 Index) const { return EntryPoints[Index]; }
102
103 // Sets the value of a material property for future reference.
104 void SetPropertyValue(EMaterialProperty Property, MIR::FValue* Value) { PropertyValues[Property] = Value; }
105
106 // Retrieves the value a meterial property is assigned to.
107 const MIR::FValue* GetPropertyValue(EMaterialProperty Property) const { return PropertyValues[Property]; }
108
109 // Returns a list of all environment define names this module requires to be enabled for shader compilation.
110 const TSet<FName>& GetEnvironmentDefines() const { return EnvironmentDefines; }
111
112 // Provides access to the translated material statistics.
113 const FStatistics& GetStatistics() const { return Statistics; }
114
115 // Provides mutable access to the translated material statistics.
116 FStatistics& GetStatistics() { return Statistics; }
117
118 // Retrieves parameter info for a given parameter ID.
119 const FMaterialParameterInfo& GetParameterInfo(uint32 ParameterId) const { return ParameterIdToData[ParameterId].Key; }
120
121 // Retrieves parameter metadata for a given parameter ID.
122 const FMaterialParameterMetadata& GetParameterMetadata(uint32 ParameterId) const { return ParameterIdToData[ParameterId].Value; }
123
124 // Find existing or add a material parameter collection -- may return INDEX_NONE if too many have already been added.
126
127 // Returns the list of material parameter collections used by this material.
128 TConstArrayView<UMaterialParameterCollection*> GetParameterCollections() const { return ParameterCollections; }
129
130 // Returns the array of HLSL-defined user-functions in the module.
132
133 // Flags a shading model as used by this material.
134 void AddShadingModel(EMaterialShadingModel InShadingModel);
135
136 // Returns the shading models used by this material.
137 FMaterialShadingModelField GetCompiledShadingModels() const { return this->ShadingModelsFromCompilation; }
138
139 // Returns true if the given property has a non default value. Similar to FHLSLMaterialTranslator::IsMaterialPropertyUsed.
140 bool IsMaterialPropertyUsed(EMaterialProperty InProperty) const;
141
142 // Stores a user-defined string and returns a view of it.
144
145 // Checks if the module is valid (i.e., contains no errors).
146 bool IsValid() const { return Errors.IsEmpty(); }
147
148 // Returns a list of errors encountered during processing.
149 TArrayView<const FError> GetErrors() const { return Errors; }
150
151 // Reports a translation error.
152 void AddError(UMaterialExpression* Expression, FString Message);
153
154 // Allocates a chunk of memory using the module's internal memory block, to be used
155 // by the user as they see fit.
156 // Note: The returned array has the same lifetime as this module.
157 void* Allocate(size_t Size, size_t Alignment) { return Allocator.Alloc(Size, Alignment); }
158
159 // Allocates an array of elements using the module's internal memory block, to be used
160 // by the user as they see fit.
161 // Note: The returned array has the same lifetime as this module.
162 template <typename T>
164 {
166 return { (T*)Allocate(sizeof(T) * Count, alignof(T)), Count };
167 }
168
169private:
170 // The chunk allocator used to contain child allocations (e.g., values, interned strings, etc)
172
173 // Target shader platform.
174 EShaderPlatform ShaderPlatform;
175
176 // Target platform interface.
177 const ITargetPlatform* TargetPlatform;
178
179 // Target feature level.
180 ERHIFeatureLevel::Type FeatureLevel;
181
182 // Target quality level.
183 EMaterialQualityLevel::Type QualityLevel;
184
185 // Target blend mode -- separate from UMaterial, as it may potentially overridden in a UMaterialInstance.
186 EBlendMode BlendMode;
187
188 // Compilation output data.
190
191 // List of all the IR values contained in this module.
193
194 // Array of entry points in this module.
196
197 // The final value assigned to each material property.
198 MIR::FValue* PropertyValues[MP_MAX];
199
200 // Compilation statistics.
201 FStatistics Statistics;
202
203 // Maps parameter info to IDs.
205
206 // Parameter metadata.
208
209 // Stores user-defined strings.
211
212 // Environment define names for shader compilation.
213 TSet<FName> EnvironmentDefines;
214
215 // Parameter collections used by this material.
216 TArray<UMaterialParameterCollection*> ParameterCollections;
217
218 // Array of HLSL-defined user-functions in the module.
220
223
224 // List of compilation errors.
225 TArray<FError> Errors;
226
227 friend MIR::FEmitter;
230};
231
232#endif // #if WITH_EDITOR
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
EBlendMode
Definition EngineTypes.h:245
EMaterialShadingModel
Definition EngineTypes.h:705
EShaderPlatform
Definition RHIShaderPlatform.h:11
EMaterialProperty
Definition SceneTypes.h:148
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MaterialShared.h:806
Definition MemStack.h:78
Definition ArrayView.h:139
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition MaterialExpression.h:150
Definition MaterialParameterCollection.h:79
Type
Definition SceneTypes.h:132
Type
Definition RHIFeatureLevel.h:20
EPropertyBagResult SetPropertyValue(const FPropertyBagPropertyDesc *Desc, void *Address, const T &InValue)
Definition PropertyBag.cpp:1155
EPropertyBagResult GetPropertyValue(const FPropertyBagPropertyDesc *Desc, const void *Address, T &OutValue)
Definition PropertyBag.cpp:761
UE_TRACE_API void GetStatistics(FStatistics &Out) UE_TRACE_IMPL()
U16 Index
Definition radfft.cpp:71
Definition MaterialParameters.h:33
Definition MaterialParameters.h:446
FMaterialParameterValue Value
Definition MaterialParameters.h:447
Definition EngineTypes.h:732
Definition IsTriviallyCopyAssignable.h:13