UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMRef.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
9#include "VerseVM/VVMType.h"
10
11namespace Verse
12{
13enum class EValueStringFormat;
14struct VTask;
15struct FRefAwaiter;
16
18{
19 FRefAwaiterHeader() = default;
20
23
24 template <typename FunctionType>
25 bool AnyOf(const TSet<FRefAwaiter>&, FunctionType) const;
26};
27
29{
31 : Task{Context, Task}
33 {
34 }
35
37 const FOp* AwaitPC;
38
39 friend bool operator==(const FRefAwaiter&, const FRefAwaiter&);
40
41 friend uint32 GetTypeHash(const FRefAwaiter&);
42
44 {
45 Prev = Header.Prev;
46 Get(Set, Header, Prev).Next = ThisElementId;
47 Next = {};
49 }
50
52 {
53 Get(Set, Header, Prev).Next = Next;
54 Get(Set, Header, Next).Prev = Prev;
55 }
56
57private:
59 {
60 if (ElementId.IsValidId())
61 {
62 return Set[ElementId];
63 }
64 return Header;
65 }
66};
67
68struct VRefRareData : VCell
69{
72
73 static VRefRareData& New(FAllocationContext Context)
74 {
75 return *new (Context.Allocate(FHeap::DestructorSpace, sizeof(VRefRareData))) VRefRareData{Context};
76 }
77
78 VTask* GetLiveTask() const;
79
80 void SetLiveTask(FAllocationContext, VTask*);
81
82 void AddAwaitTask(FAccessContext, VTask&, const FOp&);
83
84 template <typename UnaryFunction>
85 bool AnyAwaitTask(UnaryFunction) const;
86
87 size_t GetAllocatedSize() const
88 {
89 return AwaiterBuffer.GetAllocatedSize();
90 }
91
92private:
93 explicit VRefRareData(FAllocationContext Context)
95 {
96 FHeap::ReportAllocatedNativeBytes(GetAllocatedSize());
97 }
98
99 VRefRareData(const VRefRareData&) = delete;
100
101 VRefRareData(VRefRareData&&) = delete;
102
103 VRefRareData& operator=(const VRefRareData&) = delete;
104
105 VRefRareData& operator=(VRefRareData&&) = delete;
106
108 {
109 FHeap::ReportDeallocatedNativeBytes(GetAllocatedSize());
110 }
111
112 static bool ContainsAwaitTask(const VTask&, const FOp&);
113
117};
118
119struct VRef : VHeapValue
120{
123
124 static VRef& New(FAllocationContext Context)
125 {
126 return *new (Context.AllocateFastCell(sizeof(VRef))) VRef(Context);
127 }
128
129 VValue Get(FAllocationContext Context)
130 {
131 return Value.Get(Context);
132 }
133
134 void Set(FAllocationContext Context, VValue NewValue);
135
136 void SetNonTransactionally(FAccessContext Context, VValue NewValue)
137 {
138 return Value.Set(Context, NewValue);
139 }
140
141 void AppendToStringImpl(FAllocationContext Context, FUtf8StringBuilderBase& Builder, EValueStringFormat Format, TSet<const void*>& VisitedObjects, uint32 RecursionDepth);
143 static void SerializeLayout(FAllocationContext Context, VRef*& This, FStructuredArchiveVisitor& Visitor);
144 void SerializeImpl(FAllocationContext Context, FStructuredArchiveVisitor& Visitor);
145
146 VTask* GetLiveTask() const;
147
148 void SetLiveTask(FAllocationContext, VTask*);
149
150 void AddAwaitTask(FAllocationContext, VTask&, const FOp&);
151
152 template <typename UnaryFunction>
153 bool AnyAwaitTask(UnaryFunction F) const
154 {
155 return RareData && RareData->AnyAwaitTask(F);
156 }
157
158 void VisitMembersImpl(FAllocationContext, FDebuggerVisitor&);
159
160private:
163
164 explicit VRef(FAllocationContext Context)
166 // TODO: Figure out what split depth meets here.
167 , Value{0}
168 {
169 }
170};
171
172template <typename SetType>
174 FAllocationContext Context,
175 VValue Value,
176 VTask* Task,
177 FOp* AwaitPC,
178 SetType Set)
179{
180 AutoRTFM::UnreachableIfClosed("#jira SOL-8415");
181
182 if (VRef* TransparentRef = Value.ExtractTransparentRef())
183 {
184 if (AwaitPC)
185 {
186 TransparentRef->AddAwaitTask(Context, *Task, *AwaitPC);
187 }
188 return TransparentRef->Get(Context);
189 }
190 if (AwaitPC)
191 {
192 VRef& NewRef = VRef::New(Context);
193 NewRef.SetNonTransactionally(Context, Value);
194 NewRef.AddAwaitTask(Context, *Task, *AwaitPC);
195 Set(VValue::TransparentRef(NewRef));
196 }
197 return Value;
198}
199} // namespace Verse
200#endif // WITH_VERSE_VM
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition JsonObject.h:23
Definition SetUtilities.h:95
UE_FORCEINLINE_HINT bool IsValidId() const
Definition SetUtilities.h:101
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition StringBuilder.h:79
UE_REWRITE bool AnyOf(const RangeType &Range)
Definition AnyOf.h:20
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool SerializeImpl(const UScriptStruct *InSourceEventType, const void *InSourceEventData, FLiveLinkSerializedFrameData &OutSerializedData)
Definition LiveLinkCompression.cpp:126
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
Definition Archive.h:36
EValueStringFormat
Definition VVMValuePrinting.h:17