UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialIR.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
10#include "Shader/Preshader.h"
11
12#if WITH_EDITOR
13
15
17
18namespace MIR
19{
20
21// A simple string view without constructors, to be used inside FValues.
23{
24 const TCHAR* Ptr; // The string characters
25 int32 Len; // The string length (excluding null byte)
26
27 FStringView ToView() const { return { Ptr, Len }; }
28 FString ToString() const { return FString{ ToView() }; }
29 operator FStringView() const { return ToView(); }
30 FSimpleStringView& operator=(FStringView View) { Ptr = View.GetData(); Len = View.Len(); return *this; }
31};
32
33// Identifies the block of execution in which an instruction runs.
34// Note: If you introduce a new stage, make sure you update EValueFlags accordingly.
35enum EStage
36{
41};
42
43// Returns the string representation of given stage.
44const TCHAR* LexToString(EStage Stage);
45
46// A collection of bit flags for a specific Value instance.
47enum class EValueFlags : uint8
48{
49 None = 0,
50
51 // Value has been analyzed for the vertex stage.
53
54 // Value has been analyzed for the pixel stage.
55 AnalyzedForStagePixel = 1 << 1,
56
57 // Value has been analyzed for the compute stage.
59
60 // Value has been analyzed in some stage.
61 AnalyzedInAnyStage = 1 << 3,
62
63 // Whether to substitute abstract tokens like "<PREV>" in code expressions of InlineHLSL instructions.
64 SubstituteTags = 1 << 4,
65
66 // Whether 'FInlineHLSL::Code' field is used. Otherwise, 'ExternalCodeDeclaration' is used.
67 HasDynamicHLSLCode = 1 << 5,
68
69 // External code declaration must emit the secondary definition for the DDX derivative.
70 DerivativeDDX = 1 << 6,
71
72 // External code declaration must emit the secondary definition for the DDY derivative.
73 DerivativeDDY = 1 << 7,
74};
75
77
78// A collection of graph properties used by a value.
79//
80// If a graph property is true, it means that either the value itself makes has of that
81// property, or one of its dependencies (direct or indirect) has it. This entails these
82// flags are automatically propagated to all dependant values (values that depend on a given one).
83// As an example, if "ReadsPixelNormal" is true on a specific value it means that either
84// that value itself or some other upstream value that value is dependent on reads
85// the pixel normal.
86enum class EGraphProperties : uint8
87{
88 None = 0,
89
90 // Some value reads the pixel normal.
91 ReadsPixelNormal = 1 << 0,
92};
93
95
96// Enumeration of all different structs deriving from FValue. Used for dynamic casting.
97enum EValueKind
98{
99 // Values
100
101 VK_Poison,
110
111 // Instructions
112
114
118 VK_Branch,
120 VK_Scalar,
127 VK_Nop,
128 VK_Call,
131
133};
134
135// Returns the string representation of given value kind.
136const TCHAR* LexToString(EValueKind Kind);
137
138// Values
139
140// Base entity of all IR graph nodes.
141//
142// An IR module is a graph of values, connected by their "uses" relations. The graph of IR
143// values is built by the `MaterialIRModuleBuilder` as the result of crawling through and
144// analyizing the MaterialExpression graph contained in the translated Material. During
145// this processing, IR values are emitted, and linked together. After the graph is
146// constructed, it is itself analyzed: the builder will call `FMaterialIRValueAnalyzer::Analyze()`
147// in each active* (i.e. truly used) value in the graph, making sure a value is analyzed only
148// after its dependencies have been analyzed.
149// A few notes:
150// - FValues are automatically zero-initialized.
151// - FValues are intended to be simple and inert data records. They cannot have non-trivia
152// ctor, dtor or copy operators.
153// - The ModuleBuilder relies on this property to efficiently hashing values so that it
154// will reuse the same value instance instead of creating multiple instances of the
155// same computation (for a more efficient output shader).
156// - All values have a MIR type.
157// - Pure FValue instances are values that do not have other dependencies (called "uses").
158// - If a value has some other value as dependency, it means that it is the result of a
159// calculation on those values. Values that have dependencies are Instructions (they
160// derive from FInstruction).
161struct FValue
162{
163 // The runtime type this value has.
164 FType Type;
165
166 // Used to discern the concrete C++ type of this value (e.g. Subscript)
167 EValueKind Kind : 8;
168
169 // Set of fundamental flags true for this value.
171
172 // The set of properties that are true for this value. Some flags might have been
173 // set but some upstream dependency leading to this value and not this value directly.
174 // See `EGraphProperties` for more information.
176
177 // Returns whether this value has been analyzed for specified stage.
178 bool IsAnalyzed(EStage State) const;
179
180 // Returns whether specified flags are true for this value.
181 bool HasFlags(EValueFlags InFlags) const;
182
183 // Enables the specified flags without affecting others.
185
186 // Disables the specified flags without affecting others.
187 void ClearFlags(EValueFlags InFlags);
188
189 // Returns whether specified properties are true for this value.
190 bool HasSubgraphProperties(EGraphProperties Properties) const;
191
192 // Enables specified properties for this value.
194
195 // Returns the size in bytes of this value instance.
196 uint32 GetSizeInBytes() const;
197
198 // Gets the immutable array of all this value uses.
199 // An use is another value referenced by this one (e.g. the operands of a binary expression).
200 // Returns the immutable array of uses.
202
203 // Gets the immutable array of this value uses filtered for a specific stage stage.
204 //
205 // Returns the immutable array of uses.
206 TConstArrayView<FValue*> GetUsesForStage(MIR::EStage Stage) const;
207
208 // Returns whether this value is of specified kind.
209 bool IsA(EValueKind InKind) const { return Kind == InKind; }
210
211 // Returns whether this value is poison.
212 bool IsPoison() const { return Kind == VK_Poison; }
213
214 // Returns whether this value is a constant boolean with value true.
215 bool IsTrue() const;
216
217 // Returns whether this value is a constant boolean with value false.
218 bool IsFalse() const;
219
220 // Returns whether this value is boolean and all components are true.
221 bool AreAllTrue() const;
222
223 // Returns whether this value is boolean and all components are false.
224 bool AreAllFalse() const;
225
226 // Returns whether this value is arithmetic and all components are exactly zero.
227 bool AreAllExactlyZero() const;
228
229 // Returns whether this value is arithmetic and all components are approximately zero.
230 bool AreAllNearlyZero() const;
231
232 // Returns whether this value is arithmetic and all components are exactly one.
233 bool AreAllExactlyOne() const;
234
235 // Returns whether this value is arithmetic and all components are approximately one.
236 bool AreAllNearlyOne() const;
237
238 // Returns whether this value exactly equals Other.
239 bool Equals(const FValue* Other) const;
240
241 // Returns whether this value equals the given constant scalar.
242 bool EqualsConstant(float Value) const;
243
244 // Returns whether this value equals the given constant vector.
245 bool EqualsConstant(FVector4f Value) const;
246
247 // Returns the UTexture or URuntimeVirtualTexture object if this value is of type FTextureObject or FRuntimeVirtualTextureObject. Returns null otherwise.
248 UObject* GetTextureObject() const;
249
250 // Returns the uniform parameter index if this value is of type FTextureObject, FRuntimeVirtualTextureObject, or FUniformParameter. Returns INDEX_NONE otherwise.
252
253 // Tries to cast this value to specified type T and returns the casted pointer, if possible (nullptr otherwise).
254 template <typename T>
255 T* As() { return IsA(T::TypeKind) ? static_cast<T*>(this) : nullptr; }
256
257 // Tries to cast this value to specified type T and returns the casted pointer, if possible (nullptr otherwise).
258 template <typename T>
259 const T* As() const { return IsA(T::TypeKind) ? static_cast<const T*>(this) : nullptr; }
260};
261
262// Tries to cast a value to a derived type.
263// If specified value is not null, it tries to cast this value T and returns it. Otherwise, it returns null.
264template <typename T>
265T* As(FValue* Value)
266{
267 return Value && Value->IsA(T::TypeKind) ? static_cast<T*>(Value) : nullptr;
268}
269
270// Tries to cast a value to a derived type.
271// If specified value is not null, it tries to cast this value T and returns it. Otherwise, it returns null.
272template <typename T>
273const T* As(const FValue* Value)
274{
275 return Value && Value->IsA(T::TypeKind) ? static_cast<const T*>(Value) : nullptr;
276}
277
278// Casts a value to an instruction.
279// If specified value is not null, it tries to cast this value to an instruction and returns it. Otherwise, it returns null.
281
282// Casts a value to an instruction.
283// If specified value is not null, it tries to cast this value to an instruction and returns it. Otherwise, it returns null.
284const FInstruction* AsInstruction(const FValue* Value);
285
286template <EValueKind TTypeKind>
287struct TValue : FValue
288{
289 static constexpr EValueKind TypeKind = TTypeKind;
290};
291
292// A placeholder for an invalid value.
293//
294// A poison value represents an invalid value. It is produced by the emitter when an
295// invalid operation is performed. Poison values can be passed as arguments to other operations,
296// but they are "contagious": any instruction emitted with a poison value as an argument
297// will itself produce a poison value.
298struct FPoison : TValue<VK_Poison>
299{
300 static FPoison* Get();
301};
302
303// The integer type used inside MIR.
304using TInteger = int64_t;
305
306// The floating point type used inside MIR.
307using TFloat = float;
308
309// The double precision / LWC floating point type used inside MIR.
310using TDouble = double;
311
312// A constant value.
313//
314// A constant represents a translation-time known scalar primitive value. Operations on
315// constant values can be folded by the builder, that is they can be evaluated statically
316// while the builder constructs the IR graph of an input material.
317struct FConstant : TValue<VK_Constant>
318{
319 union
320 {
321 bool Boolean;
325 };
326
327 // Returns the constant value of given type T. The type must be bool, integral or floating point.
328 template <typename T>
329 T Get() const
330 {
331 if constexpr (std::is_same_v<T, bool>)
332 {
333 return Boolean;
334 }
335 else if constexpr (std::is_integral_v<T>)
336 {
337 return Integer;
338 }
339 else if constexpr (std::is_floating_point_v<T>)
340 {
341 return Float;
342 }
343 else
344 {
345 check(false && "unexpected type T.");
346 }
347 }
348};
349
350// Specifies the axis for computing screen-space derivatives.
351//
352// This enum is used to indicate whether a partial derivative should be taken
353// along the X or Y screen-space direction, corresponding to HLSL's ddx and ddy
354// functions.
355enum class EDerivativeAxis
356{
357 X, // Corresponding to d/dx
358 Y, // Corresponding to d/dy
359};
360
361// Specify the source expression type of a derivative, useful for generating actionable user facing errors if derivatives
362// are used where not allowed (vertex shader).
363enum class EDerivativeSource
364{
365 Derivative, // DDX or DDY expression
366 TextureSampleBias, // TextureSample expression with MipBias option selected
367 AnalyticDerivative, // Generated during calculation of an analytic derivative
368};
369
370// Enumeration of all supported material external inputs.
371enum class EExternalInput
372{
373 None,
374
375 TexCoord0,
376 TexCoord1,
377 TexCoord2,
378 TexCoord3,
379 TexCoord4,
380 TexCoord5,
381 TexCoord6,
382 TexCoord7,
383 WorldPosition_Absolute, // (LWC) WPT_Default Absolute World Position, including Material Shader Offsets
384 WorldPosition_AbsoluteNoOffsets, // (LWC) WPT_ExcludeAllShaderOffsets Absolute World Position, excluding Material Shader Offsets
385 WorldPosition_CameraRelative, // (float) WPT_CameraRelative Camera Relative World Position, including Material Shader Offsets
386 WorldPosition_CameraRelativeNoOffsets, // (float) WPT_CameraRelativeNoOffsets Camera Relative World Position, excluding Material Shader Offsets
391
400 WorldPosition_Absolute_Ddx, // LWC (cast from float on load)
401 WorldPosition_AbsoluteNoOffsets_Ddx, // LWC (cast from float on load)
408
417 WorldPosition_Absolute_Ddy, // LWC (cast from float on load)
418 WorldPosition_AbsoluteNoOffsets_Ddy, // LWC (cast from float on load)
425
426 // Ranges of External inputs with derivatives. There must be an equal number of value, ddx, and ddy variations. TexCoord0 must remain first,
427 // as code that translates texture coordinate indices to external input ID and back assumes this.
433
440 GlobalDistanceField, // Flag to mark that global distance fields are used, for value analyzer step. Doesn't generate code.
441 DynamicParticleParameterIndex, // UserData stores the parameter index.
442 CompilingPreviousFrame, // Boolean value bCompilingPreviousFrame, set when compiling the vertex shader WorldPositionOffsets for the previous frame.
443
444 Count,
445};
446
447// The number of external input derivative groups (value, ddx, ddy).
448static constexpr int32 ExternalInputWithDerivativesGroups = 3;
449
450// Number of external inputs with derivatives
451static constexpr int32 ExternalInputWithDerivativesNum = (int32)EExternalInput::WithDerivatives_LastVal - (int32)EExternalInput::WithDerivatives_First + 1;
452
453// Maximum number of supported texture coordinates.
454static constexpr int32 TexCoordMaxNum = 8;
455
456// Returns the string representation of given external input.
458
459// Returns the given external input type.
461
462// Returns whether the given external input needs to generate non-trivial derivative expressions.
464
465// Translate an input ID to a derivative variation
467
468// Converts the given texture coordinate index to its corresponding external input mapping.
469MIR::EExternalInput TexCoordIndexToExternalInput(int32 TexCoordIndex);
470
471// Returns the index of the specified texture coordinates external input.
473
474// Returns whether the given external is a texture coordinate.
476
477// Returns whether the given external is a texture coordinate ddx.
479
480// Returns whether the given external is a texture coordinate ddy.
482
483// Returns whether the given external is a texture coordinate, a ddx or ddy.
485
486// Returns whether the given external is a world position, including a ddx or ddy.
488
489// It represents an external input (like texture coordinates) value.
490struct FExternalInput : TValue<VK_ExternalInput>
491{
493 uint32 UserData; // Optional user data for certain external input types
494};
495
496// It represents a Material Parameter Collection object value.
497struct FMaterialParameterCollection : TValue<VK_MaterialParameterCollection>
498{
500
501 // Index of this collection in the list of collections referenced by the material.
502 // Note: This field is automatically set by the builder.
504};
505
506// It represents a texture object value.
507struct FTextureObject : TValue<VK_TextureObject>
508{
509 // The texture object.
511
512 // The sampler type associated to this texture object.
513 EMaterialSamplerType SamplerType;
514
515 // Index of this parameter in the uniform expression set.
516 // Note: This field is automatically set by the builder.
518};
519
520// It represents a runtime virtual texture (RVT) object value. Those *do not* extend UTexture so they have their own MIR value.
521struct FRuntimeVirtualTextureObject : TValue<VK_RuntimeVirtualTextureObject>
522{
523 // The runtime virtual texture object.
525
526 // The sampler type associated to this RVT object.
527 EMaterialSamplerType SamplerType;
528
529 // Field to explicitly assign a VT stack layer index (INDEX_NONE if unset). Regular VTs are assigned these indices automatically.
530 int32 VTLayerIndex : 16;
531
532 // Field to explicitly assign a VT page table index. Regular VTs are assigned these indices automatically.
534
535 // Index of this parameter in the uniform expression set.
536 // Note: This field is automatically set by the builder.
538};
539
540// It represents a material uniform parameter.
541struct FUniformParameter: TValue<VK_UniformParameter>
542{
543 // Index of the parameter as registered in the module.
545
546 // Eventual sampler type to use to sample this parameter's texture (if it is one).
547 EMaterialSamplerType SamplerType;
548
549 // Field to explicitly assign a VT stack layer index (INDEX_NONE if unset). Regular VTs are assigned these indices automatically.
550 int32 VTLayerIndex : 16;
551
552 // Field to explicitly assign a VT page table index. Regular VTs are assigned these indices automatically.
554
555 // Index of this parameter in the uniform expression set
556 // Note: This field is automatically set by the builder.
558};
559
560enum class EScreenTexture : uint8
561{
563 UserSceneTexture,
566 SceneDepthWithoutWater,
568};
569
570// Reference to various types of full screen textures accessible by expressions. These
571// generally involve custom code to set data in the compilation output, extensive validation
572// logic, and HLSL generation deferred to the analyzer for the case of UserSceneTextures.
573struct FScreenTexture : TValue<VK_ScreenTexture>
574{
576 union
577 {
580 };
581 FName UserSceneTexture;
582};
583
584struct FShadingModel : TValue<VK_ShadingModel>
585{
587};
588
589/*------------------------------------ Instructions ------------------------------------*/
590
591// A block of instructions.
592//
593// A block is a sequence of instructions in order of execution. Blocks are organized in a
594// tree-like structure, used to model blocks nested inside other blocks.
595struct FBlock
596{
597 // This block's parent block, if any. If this is null, this is a *root block.
598 FBlock* Parent;
599
600 // The linked-list head of the instructions contained in this block.
601 // Links are contained in the FInstruction::Next field.
603
604 // Depth of this block in the tree structure (root blocks have level zero).
605 int32 Level;
606
607 // Finds and returns the common block between this and Other, if any. It returns null
608 // if no common block was found.
609 // Note: This has O(n) complexity, where n is the maximum depth of the tree structure.
610 FBlock* FindCommonParentWith(MIR::FBlock* Other);
611};
612
613//
615{
616 // The next instruction executing after this one.
618
619 // This instruction parent block.
620 FBlock* Block;
621
622 // How many users (i.e., dependencies) this instruction has.
624
625 // The number of users processed during instruction graph linking in each entry point.
626 // Note: This information combined with NumUsers is used by the builder to push instructions
627 // in the appropriate block automatically.
629};
630
631// Base struct of an instruction value.
632//
633// An instruction is a value in a well defined order of evaluation.
634// Instructions have a parent block and are organized in a linked list: the Next field
635// indicates the instruction that will execute immediately after this one.
636// Since the material shader has multiple stages, the same instruction can belong to two
637// different graphs of execution, which explains why all fields in this structure have
638// a different possible value per stage.
639//
640// Note: All fields in this struct are not expected to be set by the user when emitting
641// an instruction, and are instead automatically populated by the builder.
642struct FInstruction : FValue
643{
644 // Array of linkage information (how this instruction is connected inside the IR graph)
645 // for each entry point registered in the module.
647
648 // Returns the block in which the dependency with specified index should execute.
650
651 // Returns the next instruction in specified entry point.
652 FInstruction* GetNext(int32 EntryPointIndex) const { return Linkage[EntryPointIndex].Next; }
653
654 // Returns the number of user sin specified entry point.
655 uint32 GetNumUsers(int32 EntryPointIndex) const { return Linkage[EntryPointIndex].NumUsers; }
656
657 // Returns the block this instruction belongs to in specified entry point.
658 const FBlock* GetBlock(int32 EntryPointIndex) const { return Linkage[EntryPointIndex].Block; }
659
660};
661
662template <EValueKind TTypeKind, uint32 TNumStaticUses = 0>
664{
665 // The kind of this instruction.
666 static constexpr EValueKind TypeKind = TTypeKind;
667
668 // The number of values this instruction uses statically. Some instructions have a
669 // dynamic number of uses, in which case NumStaticUses is 0.
670 static constexpr uint32 NumStaticUses = TNumStaticUses;
671};
672
673// An aggregate of other values.
674//
675// A dimensional is a fixed array of other values. This value is used to model vectors and matrices.
676struct FComposite : TInstruction<VK_Composite, 0>
677{
678 // Returns the constant array of component values.
679 TConstArrayView<FValue*> GetComponents() const;
680
681 // Returns the mutable array of component values.
683
684 // Returns whether all components are constant (i.e., they're instances of FConstant).
685 bool AreComponentsConstant() const;
686};
687
688template <int TSize>
689struct TComposite : FComposite
690{
691 FValue* Components[TSize];
692};
693
694// Instruction that sets material attribute (i.e., "BaseColor") to its value.
695struct FSetMaterialOutput : TInstruction<VK_SetMaterialOutput, 1>
696{
697 // The value this material attribute should be set to.
698 FValue* Arg;
699
700 // The material attribute to set.
702};
703
704// Inline HLSL instruction.
705//
706// A value that is the result of an arbitrary snippet of HLSL code.
707//
708// Note: See BaseMaterialExpressions.ini file.
709struct FInlineHLSL : TInstruction<VK_InlineHLSL, 0>
710{
711 static constexpr int32 MaxNumArguments = 16;
712
713 // Array of argument values.
714 FValue* Arguments[MaxNumArguments];
715
716 // Number of arguments from another expression node.
718
719 union
720 {
721 // The declaration this instruction refers to.
723
724 // The arbitrary inlined HLSL code snippet
726 };
727};
728
729// Material IR representation of the FSubstrateData shader parameter to transition legacy materials into Substrate.
730struct FPromoteSubstrateParameter : TInstruction<VK_PromoteSubstrateParameter, 4>
731{
732 // Extra IR values for tangent and normal vectors that are transformed into world-space specifically for Substrate conversion.
734
735 // IR values for all property arguments that forwarded to the Substrate conversion function.
737
738 // Specifies what Substrate BSDF to select, default or unlit.
739 bool bIsUnlit;
740};
741
742// Operator enumeration.
743//
744// Note: If you modify this enum, update the implementations of the helper functions below.
745enum EOperator
746{
747 O_Invalid,
748
749 // Unary
751
752 // Unary operators
754 UO_Negate, // Arithmetic negation: negate(5) -> -5
755 UO_Not, // Logical negation: not(true) -> false
756
757 // Unary intrinsics
758 UO_Abs,
759 UO_ACos,
761 UO_ACosh,
762 UO_ASin,
764 UO_ASinh,
765 UO_ATan,
767 UO_ATanh,
768 UO_Ceil,
769 UO_Cos,
770 UO_Cosh,
773 UO_Floor,
774 UO_Frac,
776 UO_IsInf,
777 UO_IsNan,
778 UO_Length,
784 UO_Round,
785 UO_Rsqrt,
787 UO_Sign,
788 UO_Sin,
789 UO_Sinh,
790 UO_Sqrt,
791 UO_Tan,
792 UO_Tanh,
795
797
798 // Binary comparisons
805
806 // Binary logical
807 BO_And,
808 BO_Or,
809
810 // Binary arithmetic
811 BO_Add,
815 BO_Divide,
816 BO_Modulo,
821
822 // Binary intrinsics
823 BO_ATan2,
825 BO_Cross,
827 BO_Dot,
828 BO_Fmod,
829 BO_Max,
830 BO_Min,
831 BO_Pow,
832 BO_Step,
833
835
836 // Ternary intrinsics
838 TO_Lerp,
839 TO_Select,
841
843};
844
845// Whether the given operator identifies a comparison operation (e.g., ">=", "==").
847
848// Whether the given operator identifies a unary operator.
850
851// Whether the given operator identifies a binary operator.
853
854// Whether the given operator identifies a ternary operator.
856
857// Returns the arity of the operator (the number of arguments it take, 1, 2 or 3).
859
860// Returns the string representation of the given operator.
861const TCHAR* LexToString(EOperator Op);
862
863// A mathematical operator instruction.
864//
865// This instruction identifies a built-in operation on one, two or three argument values.
866struct FOperator : TInstruction<VK_Operator, 3>
867{
868 // The first argument of the operation. This value is never null.
869 FValue* AArg;
870
871 // The second argument of the operation. This value is null for unary operators.
872 FValue* BArg;
873
874 // The third argument of the operation. This value is null for unary and binary operators.
875 FValue* CArg;
876
877 // It identifies which supported operation to carry.
878 EOperator Op;
879};
880
881// A branch instruction.
882//
883// This instruction evaluates to one or another argument based on whether a third boolean
884// condition argument is true or false. The builder will automatically place as many
885// instructions as possible in the true/false inner blocks whilst respecting dependency
886// requirements. This is done in an effort to avoid the unnecessary computation of the
887// input value that was not selected by the condition.
888struct FBranch : TInstruction<VK_Branch, 3>
889{
890 // The boolean condition argument used to forward the "true" or "false" argument.
892
893 // Value this branch evaluates to when the condition is true.
895
896 // Value this branch evaluates to when the condition is false.
898
899 // The inner block (in each module entry point) the subgraph evaluating `TrueArg` should be placed in.
901
902 // The inner block (in each module entry point) the subgraph evaluating `FalseArg` should be placed in.
904};
905
906// A subscript instruction.
907//
908// This instruction is used to pull the inner value making a compound one. For example,
909// it is used to extract an individual component of a vector value.
910struct FSubscript : TInstruction<VK_Subscript, 1>
911{
912 // The argument to subscript.
913 FValue* Arg;
914
915 // The subscript index, i.e. the index of the component to extract.
916 int32 Index;
917};
918
919// A scalar construction instruction.
920//
921// This instruction constructs a scalar from another (of possibly a different scalar kind).
922struct FScalar : TInstruction<VK_Scalar, 1>
923{
924 // The initializing argument value.
925 FValue* Arg;
926};
927
928// What texture gather mode to use in a texture read instruction (none indicates a sample).
929enum class ETextureReadMode
930{
931 // Gather the four red components in a 2x2 pixel block.
932 GatherRed,
933
934 // Gather the four green components in a 2x2 pixel block.
936
937 // Gather the four blue components in a 2x2 pixel block.
939
940 // Gather the four alpha components in a 2x2 pixel block.
942
943 // Texture gather with automatically calculated mip level
944 MipAuto,
945
946 // Texture gather with user specified mip level
947 MipLevel,
948
949 // Texture gather with automatically calculated mip level plus user specified bias
950 MipBias,
951
952 // Texture gather using automatically caluclated mip level based on user provided partial derivatives
954};
955
956// Returns the string representation of given mode.
958
959// This instruction performs texture read operaation (sample or gather).
960struct FTextureRead : TInstruction<VK_TextureRead, 6>
961{
962 // The texture object to sample. Can be FTextureObject or FUniformParameter.
964
965 // The texture coordinate at which to sample.
966 FValue* TexCoord;
967
968 // Optional. The mip index to sample, if any provided.
969 FValue* MipValue;
970
971 // Optional. The analytical partial derivative of the coordinates along the X axis.
973
974 // Optional. The analytical partial derivative of the coordinates along the Y axis.
976
977 // Only required for virtual textures. Must point to FVTPageTableRead value.
979
980 // The mip value mode to use for sampling.
982
983 // The sampler source mode to use for sampling.
985
986 // The sampler type to use for sampling.
987 EMaterialSamplerType SamplerType : 8;
988
989 // Used for VTs whether anisotropic filtering is used or not.
990 bool bUseAnisoSampler : 1;
991};
992
993// This instruction reads a virtual texture (VT) page table and is allocated alongside VT sampling instructions.
994struct FVTPageTableRead : TInstruction<VK_VTPageTableRead, 5>
995{
996 // The texture object to load the page table for.
998
999 // The texture coordinate at which to sample.
1000 FValue* TexCoord;
1001
1002 // Optional. The analytical partial derivative of the coordinates along the X axis.
1004
1005 // Optional. The analytical partial derivative of the coordinates along the Y axis.
1007
1008 // Used with TMVM_MipBias and TMVM_MipLevel.
1009 FValue* MipValue;
1010
1011 // Index of the virtual texture slot. This is determined in the analysis stage.
1012 int32 VTStackIndex : 16;
1013
1014 // Index of the VT page table. This is determined in the analysis stage.
1016
1017 // Texture address mode for U axis.
1018 TextureAddress AddressU : 8;
1019
1020 // Texture address mode for V axis.
1021 TextureAddress AddressV : 8;
1022
1023 // Specifies the sampler function to read the page table, i.e. TextureLoadVirtualPageTable(), TextureLoadVirtualPageTableGrad(), or TextureLoadVirtualPageTableLevel().
1024 ETextureMipValueMode MipValueMode : 4;
1025
1026 // Enables VT texture sampling feedback
1027 bool bEnableFeedback : 1;
1028
1029 // Determines whether adaptive or regular VT page table loads will be emitted, i.e. TextureLoadVirtualPageTable*() or TextureLoadVirtualPageTableAdaptive*().
1030 bool bIsAdaptive : 1;
1031};
1032
1033// Utility value for selecting a different value based on the execution stage.
1034struct FStageSwitch : TInstruction<VK_StageSwitch, 1>
1035{
1036 // The argument for to be bypassed in each stage.
1037 FValue* Args[NumStages];
1038
1039 // Use the specified value argument in the pixel stage, and another specified
1040 // argument for other stages.
1041 void SetArgs(FValue* PixelStageArg, FValue* OtherStagesArg);
1042};
1043
1044// Instruction that maps to hardware ddx()/ddy().
1045//
1046// Note: This is only available in stages that support hardware derivatives (e.g. pixel shader)
1047struct FHardwarePartialDerivative : TInstruction<VK_HardwarePartialDerivative, 1>
1048{
1049 // The value argument of ddx()/ddy()
1050 FValue* Arg;
1051
1052 // The direction of partial derivative
1054
1055 // The source expression that generated this partial derivative (for error reporting)
1057};
1058
1059// A "no operation" instruction is a dummy instruction used to perform analysis on a value (and its dependencies)
1060// but not push it to the list of instructions in a block.
1061// A NOP instructions should effectively bahave as the default value of Arg type.
1062struct FNop : TInstruction<VK_Nop, 1>
1063{
1064 FValue* Arg;
1065};
1066
1067// Kind of user-specified function.
1068enum class FFunctionKind
1069{
1070 HLSL,
1071};
1072
1073// Describes a function parameter.
1074struct FFunctionParameter
1075{
1076 // The parameter name (used as identifier).
1077 FName Name;
1078
1079 // The parameter type.
1080 FType Type;
1081};
1082
1083// Maximum number of parameters a user function can have.
1084constexpr uint32 MaxNumFunctionParameters = 32;
1085
1086// Defines a user-specified function.
1087struct FFunction
1088{
1089 // The kind of function this is.
1090 FFunctionKind Kind;
1091
1092 // This function's name (could be used as identifier).
1094
1095 // The function return value type
1096 FType ReturnType;
1097
1098 // Number of input-only parameters.
1100
1101 // Number of input-output parameters.
1103
1104 // Total number of parameters (input-only + input-output + output-only)
1106
1107 // A module-unique id assigned to this function to disambiguate it with other functions with identical name.
1108 uint16 UniqueId;
1109
1110 // The parameters this function has (in order: input-only, then input-output, finally output-only).
1112
1113 // Returns the number of output parameters (input-output + output-only).
1115
1116 // Returns the input-output/output-only parameter with given index.
1117 const FFunctionParameter& GetOutputParameter(uint32 Index) const { return Parameters[Index + NumInputOnlyParams]; }
1118
1119 // Returns whether parameter with specified index is input.
1121
1122 // Returns whether parameter with specified index is output.
1123 bool IsOutputParameter(uint32 Index) const { return Index >= NumInputOnlyParams; }
1124
1125 // Whether this function equals specified (they have the same data).
1126 bool Equals(const FFunction* Other) const;
1127};
1128
1129// Describes an HLSL preprocessor define, .e.g "#define MyDefine 123"
1131{
1132 // The define name.
1134
1135 // The define value.
1137};
1138
1139// A user-function defined with user-provided HLSL code.
1140struct FFunctionHLSL : FFunction
1141{
1142 // The HLSL code of the body of this function.
1143 FStringView Code;
1144
1145 // Array of #defines to declare in the material shader.
1147
1148 // Array of include directives to declare in the material shader.
1150
1151 // Whether this function equals specified (they have the same data).
1152 bool Equals(const FFunctionHLSL* Other) const;
1153};
1154
1155// A call instruction to a user-function.
1156struct FCall : TInstruction<VK_Call, 0>
1157{
1158 // The user-function to call.
1159 const FFunction* Function;
1160
1161 // The arguments to pass to the function parameters.
1162 FValue* Arguments[MaxNumFunctionParameters];
1163
1164 // The number of arguments.
1165 int NumArguments;
1166};
1167
1168// Instruction that evaluates some user-function call output parameter result.
1169struct FCallParameterOutput : TInstruction<VK_CallParameterOutput, 1>
1170{
1171 // The function call.
1172 FValue* Call;
1173
1174 // The index of the output parameter to fetch the value from.
1175 int32 Index;
1176};
1177
1179{
1180 // Uniform index for RVTs. Only used for UE::Shader::EPreshaderOpcode::RuntimeVirtualTextureUniform.
1181 int32 UniformIndex;
1182};
1183
1184struct FPreshaderParameter : TInstruction<VK_PreshaderParameter, 1>
1185{
1186 // Argument that points to the source parameter this dynamic parameter depends on.
1188
1189 // Specifies the opcode that needs to be encoded for this parameter. For now, only a small subset of opcodes are supported for material preshader parameters.
1191
1192 // Index into UMaterialInterface::GetReferencedTextures() pointing to the source parameter's texture.
1193 int32 TextureIndex;
1194
1195 // Payload data that depends on the opcode.
1197
1198 // Offset into the preshader buffer of the material resource.
1200};
1201
1202} // namespace MIR
1203#endif // WITH_EDITOR
#define check(expr)
Definition AssertionMacros.h:314
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
ESamplerSourceMode
Definition EngineTypes.h:281
ETextureMipValueMode
Definition EngineTypes.h:295
EMaterialSamplerType
Definition EngineTypes.h:936
EMaterialShadingModel
Definition EngineTypes.h:705
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
#define X(Name, Desc)
Definition FormatStringSan.h:47
const TCHAR * LexToString(EAnalyticsRecordEventMode Mode)
Definition IAnalyticsProvider.cpp:5
EDBufferTextureId
Definition MaterialExpressionDBufferTexture.h:12
ESceneTextureId
Definition MaterialSceneTextureId.h:13
@ BO_Min
Definition RHIDefinitions.h:462
@ BO_Add
Definition RHIDefinitions.h:460
@ BO_Subtract
Definition RHIDefinitions.h:461
@ BO_Max
Definition RHIDefinitions.h:463
EMaterialProperty
Definition SceneTypes.h:148
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
TStringView< TCHAR > FStringView
Definition StringFwd.h:45
TextureAddress
Definition TextureDefines.h:496
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 NameTypes.h:617
Definition ArrayView.h:139
constexpr int32 Len() const
Definition StringView.h:174
constexpr const CharType * GetData() const
Definition StringView.h:160
Definition MaterialParameterCollection.h:79
Definition Object.h:95
Definition RuntimeVirtualTexture.h:18
Definition Texture.h:1219
constexpr bool Includes(const DataTypeA *DataA, SizeTypeA NumA, const DataTypeB *DataB, SizeTypeB NumB, ProjectionType Projection, SortPredicateType SortPredicate)
Definition Includes.h:14
HitType * GetBlock(FSQHitBuffer< HitType > &Callback)
Definition ChaosInterfaceWrapperCore.h:253
void SetFlags(uint32 &Word3, uint32 Flags)
Definition CollisionFilterData.cpp:27
Mode
Definition AnimNode_TransitionPoseEvaluator.h:28
Type
Definition PawnAction_Move.h:11
@ TextureObject
Definition SlateShaderResource.h:26
ECompressionLevel Level
Definition OodleDataCompression.cpp:70
FString ToString(uint16 Value)
Definition PathFollowingComponent.cpp:82
Definition GlobalDistanceField.cpp:409
Definition MaterialExpression.h:36
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
EStage
Definition VulkanCommon.h:35
uint32 GetNext(uint32 Index, const IndexType *NextIndexData, const uint32 NextIndexCount)
Definition CompactHashTable.h:116
FORCEINLINE FStridedReferenceView ToView(FStridedReferenceArray In)
Definition FastReferenceCollector.h:493
FDocument::ValueType FValue
Definition RapidJsonUtils.h:61
bool IsA(const UStruct *)
Definition MassEntityElementTypes.h:49
EPreshaderOpcode
Definition Preshader.h:20
U16 Index
Definition radfft.cpp:71
Definition MaterialExternalCodeRegistry.h:113