UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderPlatformCachedIniValue.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "RHIShaderPlatform.h"
8#include "RHIStrings.h"
9
11
12template<typename Type>
14{
16 : CVarName(InCVarName)
17 , CVar(nullptr)
18 {
19 }
20
25
26 Type Get(EShaderPlatform ShaderPlatform)
27 {
28 Type Value{};
29
31
33 // find the cvar if needed
34 if (CVar == nullptr)
35 {
36 CVar = IConsoleManager::Get().FindConsoleVariable(*CVarName);
37 }
38
39 // if we are looking up our own platform, just use the current value, however
40 // ShaderPlatformToPlatformName can return the wrong platform than expected - for instance, Linux Vulkan will return Windows
41 // so instead of hitting an asser below, we detect that the request SP is the current SP, and use the CVar value that is set currently
42 if (IniPlatformName == FPlatformProperties::IniPlatformName() || ActualShaderPlatform == GMaxRHIShaderPlatform)
43 {
44 checkf(CVar != nullptr, TEXT("Failed to find CVar %s when getting current value for FShaderPlatformCachedIniValue"), *CVarName);
45
46 CVar->GetValue(Value);
47 return Value;
48 }
49
50#if ALLOW_OTHER_PLATFORM_CONFIG
51 // create a dummy cvar if needed
52 if (CVar == nullptr)
53 {
54 // this could be a cvar that only exists on the target platform so create a dummy one
55 CVar = IConsoleManager::Get().RegisterConsoleVariable(*CVarName, Type(), TEXT(""), ECVF_ReadOnly);
56 }
57
58 // now get the value from the platform that makes sense for this shader platform
59 TSharedPtr<IConsoleVariable> OtherPlatformVar = CVar->GetPlatformValueVariable(IniPlatformName);
60 ensureMsgf(OtherPlatformVar.IsValid(), TEXT("Failed to get another platform's version of a cvar (possible name: '%s'). It is probably an esoteric subclass that needs to implement GetPlatformValueVariable."), *CVarName);
61 if (OtherPlatformVar.IsValid())
62 {
63 OtherPlatformVar->GetValue(Value);
64 }
65 else
66 {
67 // get this platform's value, even tho it could be wrong
68 CVar->GetValue(Value);
69 }
70#else
71 checkf(IniPlatformName == FName(FPlatformProperties::IniPlatformName()), TEXT("FShaderPlatformCachedIniValue can only look up the current platform when ALLOW_OTHER_PLATFORM_CONFIG is false"));
72#endif
73 return Value;
74 }
75
76private:
77 FString CVarName;
78 IConsoleVariable* CVar;
79};
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#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
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ ECVF_ReadOnly
Definition IConsoleManager.h:71
EShaderPlatform
Definition RHIShaderPlatform.h:11
FName ShaderPlatformToPlatformName(EShaderPlatform Platform)
Definition RHIStrings.cpp:197
EShaderPlatform GMaxRHIShaderPlatform
Definition RHI.cpp:1335
RENDERCORE_API EShaderPlatform GetEditorShaderPlatform(EShaderPlatform ShaderPlatform)
Definition RenderUtils.cpp:689
Definition NameTypes.h:617
Definition IConsoleManager.h:558
void GetValue(int32 &OutIntValue) const
Definition IConsoleManager.h:640
Definition SharedPointer.h:692
Definition ShaderPlatformCachedIniValue.h:14
Type Get(EShaderPlatform ShaderPlatform)
Definition ShaderPlatformCachedIniValue.h:26
FShaderPlatformCachedIniValue(const TCHAR *InCVarName)
Definition ShaderPlatformCachedIniValue.h:15
FShaderPlatformCachedIniValue(IConsoleVariable *InCVar)
Definition ShaderPlatformCachedIniValue.h:21
virtual IConsoleVariable * RegisterConsoleVariable(const TCHAR *Name, bool DefaultValue, const TCHAR *Help, uint32 Flags=ECVF_Default)=0
virtual IConsoleVariable * FindConsoleVariable(const TCHAR *Name, bool bTrackFrequentCalls=true) const =0
static IConsoleManager & Get()
Definition IConsoleManager.h:1270