UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RenderGraphBlackboard.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
7#include "HAL/PlatformMath.h"
13
15#define RDG_REGISTER_BLACKBOARD_STRUCT(StructType) \
16 template <> \
17 inline FString FRDGBlackboard::GetTypeName<StructType>() \
18 { \
19 return GetTypeName(TEXT(#StructType), TEXT(__FILE__), __LINE__); \
20 }
21
57{
58public:
60 template <typename StructType, typename... ArgsType>
61 StructType& Create(ArgsType&&... Args)
62 {
64
66 if (StructIndex >= Blackboard.Num())
67 {
68 Blackboard.SetNumZeroed(StructIndex + 1);
69 }
70
71 checkf(!Blackboard[StructIndex], TEXT("RDGBlackboard duplicate Create called on struct '%s'. Only one Create call per struct is allowed."), GetGeneratedTypeName<StructType>());
72 FStruct* Result = Allocator.Alloc<HelperStructType>(Forward<ArgsType&&>(Args)...);
73 check(Result);
74 Blackboard[StructIndex] = Result;
75 return static_cast<HelperStructType*>(Result)->Struct;
76 }
77
79 template <typename StructType>
80 StructType* GetMutable() const
81 {
83
85 if (StructIndex < Blackboard.Num())
86 {
87 if (HelperStructType* Element = static_cast<HelperStructType*>(Blackboard[StructIndex]))
88 {
89 return &Element->Struct;
90 }
91 }
92 return nullptr;
93 }
94
96 template <typename StructType>
97 const StructType* Get() const
98 {
100 }
101
102 template <typename StructType, typename... ArgsType>
103 StructType& GetOrCreate(ArgsType&&... Args)
104 {
105 if (StructType* Struct = GetMutable<StructType>())
106 {
107 return *Struct;
108 }
110 }
111
113 template <typename StructType>
114 StructType& GetMutableChecked() const
115 {
116 StructType* Struct = GetMutable<StructType>();
117 checkf(Struct, TEXT("RDGBlackboard Get failed to find instance of struct '%s' in the blackboard."), GetGeneratedTypeName<StructType>());
118 return *Struct;
119 }
120
122 template <typename StructType>
123 const StructType& GetChecked() const
124 {
126 }
127
128private:
130 : Allocator(InAllocator)
131 {}
132
133 void Clear()
134 {
135 Blackboard.Empty();
136 }
137
138 struct FStruct
139 {
140 virtual ~FStruct() = default;
141 };
142
143 template <typename StructType>
144 struct TStruct final : public FStruct
145 {
146 template <typename... TArgs>
147 inline TStruct(TArgs&&... Args)
148 : Struct(Forward<TArgs&&>(Args)...)
149 {}
150
151 StructType Struct;
152 };
153
154 template <typename StructType>
155 static FString GetTypeName()
156 {
157 // Forces the compiler to only evaluate the assert on a concrete type.
158 static_assert(sizeof(StructType) == 0, "Struct has not been registered with the RDG blackboard. Use RDG_REGISTER_BLACKBOARD_STRUCT to do this.");
159 return FString();
160 }
161
162 static RENDERCORE_API FString GetTypeName(const TCHAR* ClassName, const TCHAR* FileName, uint32 LineNumber);
163 static RENDERCORE_API uint32 AllocateIndex(FString&& TypeName);
164
165 template <typename StructType>
166 static uint32 GetStructIndex()
167 {
168 static uint32 Index = UINT_MAX;
169 if (Index == UINT_MAX)
170 {
171 Index = AllocateIndex(GetTypeName<StructType>());
172 }
173 return Index;
174 }
175
176 FRDGAllocator& Allocator;
178
179 friend class FRDGBuilder;
180};
#define check(expr)
Definition AssertionMacros.h:314
#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
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
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RenderGraphAllocator.h:24
void * Alloc(uint64 SizeInBytes, uint32 AlignInBytes)
Definition RenderGraphAllocator.h:53
Definition RenderGraphBlackboard.h:57
const StructType * Get() const
Definition RenderGraphBlackboard.h:97
StructType & GetMutableChecked() const
Definition RenderGraphBlackboard.h:114
const StructType & GetChecked() const
Definition RenderGraphBlackboard.h:123
StructType * GetMutable() const
Definition RenderGraphBlackboard.h:80
StructType & GetOrCreate(ArgsType &&... Args)
Definition RenderGraphBlackboard.h:103
StructType & Create(ArgsType &&... Args)
Definition RenderGraphBlackboard.h:61
Definition RenderGraphBuilder.h:49
Definition Array.h:670
U16 Index
Definition radfft.cpp:71