UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RayTracingGeometryManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5
7#include "Containers/Map.h"
8#include "IO/IoBuffer.h"
10
11#if RHI_RAYTRACING
12
14class UStaticMesh;
16
18{
19public:
20
23
25
26 ENGINE_API virtual void RemoveBuildRequest(FBuildRequestIndex InRequestIndex) override;
27 ENGINE_API virtual void BoostPriority(FBuildRequestIndex InRequestIndex, float InBoostValue) override;
30
33
34 ENGINE_API virtual RayTracing::FGeometryGroupHandle RegisterRayTracingGeometryGroup(uint32 NumLODs, uint32 CurrentFirstLODIdx = 0) override;
36
38
41
42 ENGINE_API virtual void PreRender() override;
43 ENGINE_API virtual void Tick(FRHICommandList& RHICmdList) override;
44
47
48 ENGINE_API virtual void RequestUpdateCachedRenderState(RayTracing::FGeometryGroupHandle InRayTracingGeometryGroupHandle) override;
49
53
54#if DO_CHECK
57#endif
58
61 ENGINE_API void ResetVisibleGeometries(); // TODO: Temp - is it needed?
62
63private:
64
65 struct FBuildRequest
66 {
67 FRayTracingGeometry* Owner = nullptr;
68
69 FBuildRequestIndex RequestIndex = INDEX_NONE;
70
71 float BuildPriority = 0.0f;
73 bool bReleaseBuffersAfterBuild = false;
74
75 // TODO: Implement use-after-free checks in FBuildRequestIndex using some bits to identify generation
76 };
77
79
81
84
86
88
90
91 // Working array with all active build build params in the RHI
94
95 // Operations such as registering geometry/groups can be done from different render command pipes (eg: SkeletalMesh)
96 // so need to use critical section in relevant functions
98
100 {
102
104
105 uint8 CurrentFirstLODIdx = INDEX_NONE;
106
107 // Due to the way we batch release FRenderResource and SceneProxies,
108 // ReleaseRayTracingGeometryGroup(...) can end up being called before all FRayTracingGeometry and SceneProxies are actually released.
109 // To deal with this, we keep track of whether the group is still referenced and only release the group handle once all references are released.
110 uint32 NumReferences = 0;
111
112 // TODO: Implement use-after-free checks in RayTracing::FGeometryGroupHandle using some bits to identify generation
113 };
114
116 {
117 FRayTracingGeometry* Geometry = nullptr;
119 uint32 Size = 0;
120
121 FRayTracingStreamableAsset* StreamableAsset = nullptr;
124
126
127 enum class FStatus : uint8
128 {
130 Streaming,
132 };
133
134 FStatus Status = FStatus::StreamedOut;
135 bool bEvicted : 1 = false;
136 bool bAlwaysResident : 1 = false;
137 };
138
139 struct FStreamingRequest
140 {
141 FIoBuffer RequestBuffer;
143
146
147 bool bBuffersOnly = false;
148
149 bool bCancelled = false;
150
151 bool IsValid() const { return (GeometryHandle != INDEX_NONE) || bCancelled; }
152
153 void Cancel()
154 {
156 bCancelled = true;
157
158 if (Request.IsPending())
159 {
160 Request.Cancel();
161 }
162 }
163
164 void Reset()
165 {
167 bCancelled = false;
168
169 checkf(!Request.IsPending(), TEXT("Can't cancel ray tracing geometry streaming request that is still in-flight."));
170 Request.Reset();
171 RequestBuffer = {};
172 }
173 };
174
175 void CancelStreamingRequest(FRegisteredGeometry& RegisteredGeometry);
176
177 // Helper function to stream out geometry
178 // Must call this instead of FRayTracingGeometry::ReleaseRHIForStreaming() directly
180
181 // Helper function to make geometry resident + necessary management
182 // Must call this instead of FRayTracingGeometry::MakeResident() directly
184
185 // Helper function to evict geometry + necessary streaming management
186 // Must call this instead of FRayTracingGeometry::Evict() directly
188
190 void EvictAllGeometries(FRHICommandList& RHICmdList);
191
193
194#if DO_CHECK
195 void CheckIntegrity();
196#endif
197
199
201
202 // Used for keeping track of geometries when ray tracing is dynamic
204
207
210
212
213 TSet<FGeometryHandle> ReferencedGeometries;
215
217
219
220 TArray<FStreamingRequest> StreamingRequests;
223
224 // Total size of the BLASes currently being streamed.
225 // Used to keep track of how much TotalResidentSize will increase when the requests complete.
227
228 // Feedback
230
231 bool bRenderedFrame = false;
232};
233
234#endif // RHI_RAYTRACING
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
EAccelerationStructureBuildMode
Definition RHIContext.h:579
ERTAccelerationStructureBuildPriority
Definition RayTracingGeometry.h:21
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BulkData.h:1295
Definition IoBuffer.h:15
Definition PrimitiveSceneProxy.h:296
Definition RHICommandList.h:455
Definition RHICommandList.h:3819
Definition RHICommandList.h:2735
Definition RHIResourceReplace.h:55
Definition RayTracingGeometry.h:31
Definition RayTracingStreamableAsset.h:13
Definition ArrayView.h:139
Definition Array.h:670
Definition SparseArray.h:524
Definition StaticMesh.h:593
int32 FGeometryGroupHandle
Definition SceneManagement.h:74