UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ScenePrivateBase.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 ScenePrivate.h: Private scene manager definitions.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "RendererInterface.h"
11
15
16// Forward declarations.
17class FScene;
18
20{
21public:
22
23 enum
24 {
26 };
27
28 // get the system-wide number of frames of buffered occlusion queries.
30
31 // get the index of the oldest query based on the current frame and number of buffered frames.
32 static uint32 GetQueryLookupIndex(int32 CurrentFrame, int32 NumBufferedFrames)
33 {
34 // queries are currently always requested earlier in the frame than they are issued.
35 // thus we can always overwrite the oldest query with the current one as we never need them
36 // to coexist. This saves us a buffer entry.
37 const uint32 QueryIndex = CurrentFrame % NumBufferedFrames;
38 return QueryIndex;
39 }
40
41 // get the index of the query to overwrite for new queries.
42 static uint32 GetQueryIssueIndex(int32 CurrentFrame, int32 NumBufferedFrames)
43 {
44 // queries are currently always requested earlier in the frame than they are issued.
45 // thus we can always overwrite the oldest query with the current one as we never need them
46 // to coexist. This saves us a buffer entry.
47 const uint32 QueryIndex = CurrentFrame % NumBufferedFrames;
48 return QueryIndex;
49 }
50};
51
53template <typename T>
55{
56 static const int32 NumElementsPerChunk = 1024;
57public:
59
60 T& Add(const T& Element)
61 {
62 return *(new (&AddUninitialized()) T(Element));
63 }
64
66 {
67 if (NumElements % NumElementsPerChunk == 0)
68 {
69 ChunkType* Chunk = new ChunkType;
70 Chunk->Reserve(NumElementsPerChunk);
71 Chunks.Emplace(Chunk);
72 }
73
74 NumElements++;
75 ChunkType& Chunk = *Chunks.Last();
76 Chunk.AddUninitialized();
77 return Chunk.Last();
78 }
79
81 {
82 check(Count <= NumElements);
83 const uint32 NumElementsNew = NumElements - Count;
84 while (NumElements != NumElementsNew)
85 {
86 --NumElements;
87
88 ChunkType& Chunk = *Chunks.Last();
89 Chunk.Pop(EAllowShrinking::No);
90
91 if (Chunk.IsEmpty())
92 {
93 Chunks.Pop(EAllowShrinking::No);
94 }
95 }
96 }
98 FORCEINLINE void Remove(uint32 Count, bool bAllowShrinking)
99 {
101 }
102
104 {
105 Chunks.Reserve(NumChunks(Count));
106 }
107
108 T& Get(int32 ElementIndex)
109 {
110 const uint32 ChunkIndex = ElementIndex / NumElementsPerChunk;
111 const uint32 ChunkElementIndex = ElementIndex % NumElementsPerChunk;
112 return (*Chunks[ChunkIndex])[ChunkElementIndex];
113 }
114
115 const T& Get(int32 ElementIndex) const
116 {
117 const uint32 ChunkIndex = ElementIndex / NumElementsPerChunk;
118 const uint32 ChunkElementIndex = ElementIndex % NumElementsPerChunk;
119 return (*Chunks[ChunkIndex])[ChunkElementIndex];
120 }
121
123 FORCEINLINE const T& operator[] (int32 Index) const { return Get(Index); }
124
125 bool IsValidIndex(int32 Index) const { return static_cast<uint32>(Index) < NumElements; }
126
127 int32 Num() const { return NumElements; }
128
129private:
130 static constexpr uint32 NumChunks(uint32 NumElements)
131 {
132 return (NumElements + NumElementsPerChunk - 1u) / NumElementsPerChunk;
133 }
134
135 using ChunkType = TArray<T>;
137 uint32 NumElements = 0;
138};
EAllowShrinking
Definition AllowShrinking.h:10
#define UE_ALLOWSHRINKING_BOOL_DEPRECATED(FunctionName)
Definition AllowShrinking.h:31
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
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
TConstSetBitIterator< SceneRenderingBitArrayAllocator > FSceneSetBitIterator
Definition ScenePrivateBase.h:13
TBitArray< SceneRenderingBitArrayAllocator > FSceneBitArray
Definition ScenePrivateBase.h:12
TConstDualSetBitIterator< SceneRenderingBitArrayAllocator, SceneRenderingBitArrayAllocator > FSceneDualSetBitIterator
Definition ScenePrivateBase.h:14
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ScenePrivateBase.h:20
static int32 GetNumBufferedFrames(ERHIFeatureLevel::Type FeatureLevel)
Definition SceneOcclusion.cpp:107
@ MaxBufferedOcclusionFrames
Definition ScenePrivateBase.h:25
static uint32 GetQueryLookupIndex(int32 CurrentFrame, int32 NumBufferedFrames)
Definition ScenePrivateBase.h:32
static uint32 GetQueryIssueIndex(int32 CurrentFrame, int32 NumBufferedFrames)
Definition ScenePrivateBase.h:42
Definition ScenePrivate.h:2875
Definition BitArray.h:350
Definition BitArray.h:2072
Definition BitArray.h:1944
Definition ScenePrivateBase.h:55
T & Add(const T &Element)
Definition ScenePrivateBase.h:60
const T & Get(int32 ElementIndex) const
Definition ScenePrivateBase.h:115
T & AddUninitialized()
Definition ScenePrivateBase.h:65
bool IsValidIndex(int32 Index) const
Definition ScenePrivateBase.h:125
void Reserve(int32 Count)
Definition ScenePrivateBase.h:103
int32 Num() const
Definition ScenePrivateBase.h:127
FORCEINLINE T & operator[](int32 Index)
Definition ScenePrivateBase.h:122
TScenePrimitiveArray()=default
T & Get(int32 ElementIndex)
Definition ScenePrivateBase.h:108
void Remove(uint32 Count, EAllowShrinking AllowShrinking)
Definition ScenePrivateBase.h:80
Type
Definition RHIFeatureLevel.h:20
U16 Index
Definition radfft.cpp:71