UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialIRTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
6#include "MaterialValueType.h"
8
9#if WITH_EDITOR
10
11namespace MIR
12{
13
14// Represents the top-level kind of a type.
15enum class ETypeKind : uint8
16{
17 Poison, // An invalid or error type.
18 Void, // The void type, representing no value.
19 Primitive, // A numeric, vector, or matrix type (e.g. float, float4, float4x4).
20 Aggregate, // A material aggregate.
21
22 // Opaque Objects
23
24 ShadingModel, // Dynamically specified material shading model.
25 Texture, // A texture object.
26 RuntimeVirtualTexture, // A runtime virtual texture object.
27 ParameterCollection, // Material parameter collection object.
28 SubstrateData, // Substrate-specific data structure.
29 VTPageTableResult, // A virtual texture page table lookup result.
30};
31
32// Returns the string representation of a ETypeKind.
33const TCHAR* TypeKindToString(ETypeKind Kind);
34
35// Primitive types of a single scalar.
36// Note: These are listed in precision order. Converting one to the other is then simply performed taking the max EScalarKind.
37enum class EScalarKind : uint8
38{
39 Bool, // Boolean type (true/false).
40 Int, // 32-bit signed integer type.
41 Float, // 32-bit floating-point type.
42 Double, // Large World Coordinates type.
43};
44
45// Returns whether the specified scalar kind supports arithmetic operators (plus, minus, etc).
47
48// Returns whether the specified scalar kind is a floating point type (float, LWC).
50
51// Returns the string representation of specified scalar kind.
53
54// Describes a primitive type (scalar, vector, or matrix).
55struct FPrimitive
56{
57 // The underlying scalar data type (e.g. Bool, Int, Float).
59
60 // Number of rows. For a vector, this is the number of elements. For a scalar, this is 1.
61 int8 NumRows;
62
63 // Number of columns. For a vector or scalar, this is 1. For a matrix, this is > 1.
64 int8 NumColumns;
65
66 // If true, this represents an LWC inverse matrix. Only supported for EScalarKind::LWC and 4x4 dimensions.
68
69 // Returns whether this primitive type is arithmetic (it supports arithmetic operations like addition).
70 bool IsArithmetic() const { return ScalarKindIsArithmetic(ScalarKind); }
71
72 // Returns whether this type is a primitive scalar (1x1).
73 bool IsScalar() const { return NumComponents() == 1; }
74
75 // Returns whether this primitive type is a column vector (rows > 1, columns = 1).
76 bool IsRowVector() const { return NumRows == 1 && NumColumns > 1; }
77
78 // Returns whether this primitive type is a row vector (rows = 1, columns > 1).
79 bool IsColumnVector() const { return NumRows > 1 && NumColumns == 1; }
80
81 // Returns whether this primitive type is a matrix (rows > 1, columns > 1).
82 bool IsMatrix() const { return NumRows > 1 && NumColumns > 1; }
83
84 // Returns whether this is a boolean primitive type (of any dimension).
85 bool IsBoolean() const { return ScalarKind == EScalarKind::Bool; }
86
87 // Returns whether this is a single boolean scalar.
88 bool IsBoolScalar() const { return IsBoolean() && IsScalar(); }
89
90 // Returns whether this is an integer primitive type (of any dimension).
91 bool IsInteger() const { return ScalarKind == EScalarKind::Int; }
92
93 // Returns whether this is a float primitive type (of any dimension).
94 bool IsFloat() const { return ScalarKind == EScalarKind::Float; }
95
96 // Returns whether this is an LWC primitive type (of any dimension).
97 bool IsDouble() const { return ScalarKind == EScalarKind::Double; }
98
99 // Returns whether this is any floating point primitive type (e.g. float, LWC).
100 bool IsAnyFloat() const { return ScalarKindIsAnyFloat(ScalarKind); }
101
102 // Returns the total number of scalar components in this primitive type.
103 int32 NumComponents() const { return NumRows * NumColumns; }
104
105 // Returns a new FType with the same dimensions but a different scalar kind.
107
108 // Returns the scalar FType corresponding to this primitive's scalar kind.
109 FType ToScalar() const;
110
111 // Returns a vector FType with the given number of rows and this primitive's scalar kind.
112 FType ToVector(int NumColumns) const;
113
114 bool operator==(const FPrimitive& Other) const = default;
115 bool operator!=(const FPrimitive& Other) const = default;
116};
117
118// Describes a complete type within the material IR. This can be a primitive, an aggregate
119// (struct), an opaque object (e.g., a texture), or a special type like Poison or Void.
120// Note: This struct is lightweight and intended to be passed by value.
121struct FType
122{
123 // Returns the FType corresponding to a given UE::Shader::FType.
124 static FType FromShaderType(const UE::Shader::FType& InShaderType);
125
126 // Returns the FType corresponding to a given EMaterialValueType.
127 static FType FromMaterialValueType(EMaterialValueType Type);
128
129 // Returns the FType corresponding to a given EMaterialParameterType.
131
132 // Returns the poison type, which represents an error or invalid type.
133 static FType MakePoison();
134
135 // Returns the void type, which represents the absence of a value.
136 static FType MakeVoid();
137
138 // Returns a scalar type of the given scalar kind.
139 static FType MakeScalar(EScalarKind InScalarKind) { return MakePrimitive(InScalarKind, 1, 1); }
140
141 // Returns a scalar type representing a boolean value.
142 static FType MakeBoolScalar() { return MakeScalar(EScalarKind::Bool); }
143
144 // Returns a scalar type representing a integer value.
145 static FType MakeIntScalar() { return MakeScalar(EScalarKind::Int); }
146
147 // Returns a scalar type representing a single precision floating point value.
148 static FType MakeFloatScalar() { return MakeScalar(EScalarKind::Float); }
149
150 // Returns a scalar type representing a double precision floating point value.
151 static FType MakeDoubleScalar() { return MakeScalar(EScalarKind::Double); }
152
153 // Returns a row-major vector type of the given scalar kind and number of columns.
154 static FType MakeVector(EScalarKind InScalarKind, int NumColumns) { return MakePrimitive(InScalarKind, 1, NumColumns); }
155
156 // Returns a row-major vector type of boolean values with the specified number of columns.
157 static FType MakeBoolVector(int NumColumns) { return MakeVector(EScalarKind::Bool, NumColumns); }
158
159 // Returns a row-major vector type of integer values with the specified number of columns.
160 static FType MakeIntVector(int NumColumns) { return MakeVector(EScalarKind::Int, NumColumns); }
161
162 // Returns a row-major vector type of single precision floating point values with the specified number of columns.
163 static FType MakeFloatVector(int NumColumns) { return MakeVector(EScalarKind::Float, NumColumns); }
164
165 // Returns a row-major vector type of double precision floating point values with the specified number of columns.
166 static FType MakeDoubleVector(int NumColumns) { return MakeVector(EScalarKind::Double, NumColumns); }
167
168 // Creates an integer primitive type with given dimensions.
169 static FType MakeInt(int NumRows, int NumColumns) { return MakePrimitive(EScalarKind::Int, NumRows, NumColumns); }
170
171 // Creates a single precision float primitive type with given dimensions.
172 static FType MakeFloat(int NumRows, int NumColumns) { return MakePrimitive(EScalarKind::Float, NumRows, NumColumns); }
173
174 // Creates a double precision float primitive type with given dimensions.
175 static FType MakeDouble(int NumRows, int NumColumns) { return MakePrimitive(EScalarKind::Double, NumRows, NumColumns); }
176
177 // Returns a primitive type with the given kind and dimensions.
178 // Double inverse matrix flag is only supported for EScalarKind::Double and 4x4 dimensions.
179 static FType MakePrimitive(EScalarKind InScalarKind, int NumRows, int NumColumns, bool bIsDoubleInverseMatrix = false);
180
181 // Returns the aggregate type associated with the given material aggregate definition.
182 static FType MakeAggregate(const UMaterialAggregate* Aggregate);
183
184 // Returns the Material Parameter Collection object type.
185 static FType MakeParameterCollection();
186
187 // Returns the Material Shading Model object type.
188 static FType MakeShadingModel();
189
190 // Returns the Texture object type.
191 static FType MakeTexture();
192
193 // Returns the RuntimeVirtualTexture object type.
194 static FType MakeRuntimeVirtualTexture();
195
196 // Returns the SubstrateData object type.
197 static FType MakeSubstrateData();
198
199 // Returns the VTPageTableResult object type.
200 static FType MakeVTPageTableResult();
201
202 // Returns the this type name spelling (e.g. float4x4).
203 FString GetSpelling() const;
204
205 // Checks if this type is of the specified kind.
206 bool Is(ETypeKind InKind) const { return Kind == InKind; }
207
208 // Returns the high-level kind of this type.
209 ETypeKind GetKind() const { return Kind; }
210
211 // Returns whether this is the poison type, indicating an error.
212 bool IsPoison() const { return Kind == ETypeKind::Poison; }
213
214 // Returns whether this is the void type.
215 bool IsVoid() const { return Kind == ETypeKind::Void; }
216
217 // Returns true if the given type is a primitive that supports arithmetic operations.
218 bool IsPrimitive() const { return Is(ETypeKind::Primitive); }
219
220 // Returns true if the given type is a primitive that supports arithmetic operations.
221 bool IsArithmetic() const { return Is(ETypeKind::Primitive) && Primitive.IsArithmetic(); }
222
223 // Returns true if the given type is a primitive with a boolean scalar kind.
224 bool IsBoolean() const { return Is(ETypeKind::Primitive) && Primitive.IsBoolean(); }
225
226 // Returns true if the given type is a primitive with an integer scalar kind.
227 bool IsInteger() const { return Is(ETypeKind::Primitive) && Primitive.IsInteger(); }
228
229 // Returns true if the given type is a primitive with a float scalar kind.
230 bool IsFloat() const { return Is(ETypeKind::Primitive) && Primitive.IsFloat(); }
231
232 // Returns true if the given type is a primitive with an LWC scalar kind.
233 bool IsDouble() const { return IsPrimitive() && Primitive.IsDouble(); }
234
235 // Returns true if the given type is a primitive with any float-based scalar kind (e.g. float, LWC).
236 bool IsAnyFloat() const { return Is(ETypeKind::Primitive) && Primitive.IsAnyFloat(); }
237
238 // Returns true if the given type is a scalar primitive.
239 bool IsScalar() const { return Is(ETypeKind::Primitive) && Primitive.IsScalar(); }
240
241 // Returns true if the given type is a boolean scalar primitive.
242 bool IsBoolScalar() const { return Is(ETypeKind::Primitive) && Primitive.IsBoolScalar(); }
243
244 // Returns true if the given type is a vector primitive.
245 bool IsVector() const { return Is(ETypeKind::Primitive) && Primitive.IsRowVector(); }
246
247 // Returns whether this type is a Material Parameter Collection object.
248 bool IsParameterCollection() const { return Kind == ETypeKind::ParameterCollection; }
249
250 // Returns true if the given type is a matrix primitive.
251 bool IsMatrix() const { return Is(ETypeKind::Primitive) && Primitive.IsMatrix(); }
252
253 // Returns whether this type is a Texture object.
254 bool IsTexture() const { return Kind == ETypeKind::Texture; }
255
256 // Returns whether this type is a RuntimeVirtualTexture object.
257 bool IsRuntimeVirtualTexture() const { return Kind == ETypeKind::RuntimeVirtualTexture; }
258
259 // Returns whether this type is a SubstrateData object.
260 bool IsSubstrateData() const { return Kind == ETypeKind::SubstrateData; }
261
262 // Returns whether this type is a VTPageTableResult object.
263 bool IsVTPageTableResult() const { return Kind == ETypeKind::VTPageTableResult; }
264
265 // Returns the primitive type information. It asserts that this type is primitive.
266 FPrimitive GetPrimitive() const { check(Is(ETypeKind::Primitive)); return Primitive; }
267
268 // If this is a primitive type, returns its primitive info. Otherwise, returns None.
270
271 // If this is a scalar type, returns its primitive info. Otherwise, returns None.
272 TOptional<FPrimitive> AsScalar() const { return IsScalar() ? Primitive : TOptional<FPrimitive>{}; }
273
274 // If this is a vector type, returns its primitive info. Otherwise, returns None.
275 TOptional<FPrimitive> AsVector() const { return IsVector() ? Primitive : TOptional<FPrimitive>{}; }
276
277 // If this is a matrix type, returns its primitive info. Otherwise, returns None.
279
280 // If this is an aggregate type, returns a pointer to the UMaterialAggregate definition. Otherwise, returns nullptr.
281 const UMaterialAggregate* AsAggregate() const { return Is(ETypeKind::Aggregate) ? Aggregate : nullptr; }
282
283 // Converts this type to a corresponding UE::Shader::EValueType.
285
286 // Conversion to bool, returns false if the type is Poison, true otherwise.
287 operator bool() const { return Kind != ETypeKind::Poison; }
288
289 bool operator==(FType Other) const;
290 bool operator!=(FType Other) const { return !operator==(Other); }
291
292private:
293 union
294 {
295 // The primitive type information.
297
298 // Pointer to the material aggregate.
300 };
301
302 // Identifies the high-level kind of this type.
303 ETypeKind Kind : 8;
304};
305
306// To avoid the compiler adding automatic padding, we must make sure that its size is a multiple of maximum alignment.
307static_assert(sizeof(MIR::FType) % alignof(void*) == 0);
308static_assert(sizeof(MIR::FType) == 16);
309
310} // namespace MIR
311
312#endif // #if WITH_EDITOR
#define check(expr)
Definition AssertionMacros.h:314
FloatPixel MakeFloat(const uint8 *rgb)
Definition BlockCodingHelpers.cpp:222
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
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
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
EMaterialParameterType
Definition MaterialParameters.h:187
EMaterialValueType
Definition MaterialValueType.h:15
const bool
Definition NetworkReplayStreaming.h:178
bool IsInteger(EPixelFormat PixelFormat)
Definition PixelFormat.h:343
FIntVector4 ToVector(int32 Value)
Definition SystemTextures.cpp:1240
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition MaterialAggregate.h:82
Definition MaterialExpression.h:36
Definition RuntimeVirtualTexture.h:231
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
EValueType
Definition ShaderTypes.h:94
ETypeKind
Definition SemanticTypes.h:92
Definition Optional.h:131
Definition ShaderTypes.h:181