UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaterialIRValueAnalyzer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_EDITOR
6
13#include "MaterialShared.h"
14#include "Engine/Texture.h"
15
16// It analyzes a value or instruction, performing semantic validation and side-effects execution.
17//
18// These analyze functions allow a value or instruction to perform non-trivial custom operations
19// and validation. These operations may have side effects, such as setting state in
20// CompilationOutput, allocating resources, etc. The reason these are done here (rather than at
21// FValue emission time) is that only values which are *actually* used (not pruned as unused or
22// optimized out) are analyzed. In other words, while implementing a value's analyze function, you
23// are guaranteed that the value is needed in the final material.
24//
25// Only values that require this kind of post-emission validation or that generate sidecar
26// resources should define Analyze functions. Otherwise, they can omit them.
27
28// There are two types of analyze functions: Analyze() and AnalyzeInStage().
29// - Analyze() is invoked once, regardless of which stage (vertex, pixel, or both) the value is
30// scheduled for. It runs before any per-stage logic.
31// - Some values require all or part of their analysis logic to run per stage. These should
32// implement AnalyzeInStage() with that stage-specific logic.
33//
34// IMPORTANT: Only give a value AnalyzeInStage() if it needs per-stage analysis. If the logic is
35// stage-agnostic, it belongs in Analyze(). A value can implement both Analyze() and
36// AnalyzeInStage() if it needs general logic once and other logic per stage.
37//
38// # GraphProperties
39// Analyze functions can set and read GraphProperty flags. These are per-value bitflags that are
40// automatically propagated as the IR graph is analyzed. When a value receives its Analyze() call,
41// all its dependencies have already been analyzed, so it can freely inspect their GraphProperties.
42// For example, it can verify that no other value sets a specific graph property upstream.
44{
45 // Translator specific structure during generation of VT stacks. This is later converted to FMaterialVirtualTextureStack entries in FUniformExpressionSet.
46 // The equivalent in the old translator is FHLSLMaterialTranslator::FMaterialVTStackEntry.
47 struct FVTStackEntry
48 {
49 MIR::FValue* TexCoord{};
50 bool bGenerateFeedback{};
51 TextureAddress AddressU{ TA_MAX };
52 TextureAddress AddressV{ TA_MAX };
53 MIR::FValue* MipValue{};
54 ETextureMipValueMode MipValueMode{ TMVM_None };
55 };
56
57 // Resets the analyzer to process a new translation run.
59
60 // Performs stage-agnostic analysis on the given value.
61 void Analyze(MIR::FValue* Value);
62
63 // Performs stage-specific analysis on the given value, if the value kind requires some.
64 void AnalyzeInStage(MIR::FValue* Value, MIR::EStage Stage);
65
66 // The material being built.
68
69 // The destination module that will contain the result of material translation.
70 FMaterialIRModule* Module{};
71
72 // Optional. Specifies the target MaterialInsights to populate, if provided.
74
75 // The destination compilation output whose state to populate, based on the values being analyzed.
77
78 // Maps default values to their default-value offset, as used in UniformExpressionSet (e.g. UniformExpressionSet.AddDefaultParameterValue() and UniformExpressionSet.FindOrAddNumericParameter()).
80
81 // Stores free uniform buffer offsets for 1, 2, and 3 leftover components to optimize float4 packing
83
84 // List of enabled shader environment defines.
85 TSet<FName> EnvironmentDefines;
86
87 // VT stack entries during analysis. This is later converted to FMaterialVirtualTextureStack entries in FUniformExpressionSet.
89};
90
91#endif // #if WITH_EDITOR
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ETextureMipValueMode
Definition EngineTypes.h:295
TextureAddress
Definition TextureDefines.h:496
Definition MaterialShared.h:806
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition Material.h:432
#define TA_MAX(a, b)
Definition radaudio_encoder.c:1994
A structure that holds reflection information about a material. This structure is typically populated...
Definition MaterialInsights.h:21