UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DynamicRHIResourceArray.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
8#include "Containers/Array.h"
9#include "CoreGlobals.h"
12
19
27template< typename ElementType, uint32 Alignment = DEFAULT_ALIGNMENT>
30 , public TArray<ElementType, TMemoryImageAllocator<Alignment>>
31{
34public:
36
40 [[nodiscard]] explicit TResourceArray(bool InNeedsCPUAccess=false)
41 : Super()
42 , bNeedsCPUAccess(InNeedsCPUAccess)
43 {
44 }
45
50
51 virtual ~TResourceArray() = default;
52
53
54 // FResourceArrayInterface
55
59 [[nodiscard]] virtual const void* GetResourceData() const override
60 {
61 return &(*this)[0];
62 }
63
67 [[nodiscard]] virtual uint32 GetResourceDataSize() const override
68 {
69 if (this->Num() > UINT32_MAX / sizeof(ElementType))
70 {
71 UE_LOG(LogCore, Fatal, TEXT("Resource data size too large for uint32, will overflow. Calculate with larger data type or use fewer elements. sizeof(ElementType): %" SIZE_T_FMT), sizeof(ElementType));
72 return 0;
73 }
74 return this->Num() * sizeof(ElementType);
75 }
76
82 virtual void Discard() override
83 {
84 if(!bNeedsCPUAccess && FPlatformProperties::RequiresCookedData() && !IsRunningCommandlet())
85 {
86 this->Empty();
87 }
88 }
89
93 [[nodiscard]] virtual bool IsStatic() const override
94 {
95 return false;
96 }
97
101 [[nodiscard]] virtual bool GetAllowCPUAccess() const override
102 {
103 return bNeedsCPUAccess;
104 }
105
109 virtual void SetAllowCPUAccess(bool bInNeedsCPUAccess) override
110 {
111 bNeedsCPUAccess = bInNeedsCPUAccess;
112 }
113
114 // Assignment operators.
116 {
118 return *this;
119 }
120
133
134private:
139 LAYOUT_FIELD(bool, bNeedsCPUAccess);
140};
141
147template<typename ElementType, uint32 Alignment>
#define SIZE_T_FMT
Definition AndroidPlatformString.h:30
FORCEINLINE bool IsRunningCommandlet()
Definition CoreGlobals.h:247
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FArchive & operator<<(FArchive &Ar, TResourceArray< ElementType, Alignment > &ResourceArray)
Definition DynamicRHIResourceArray.h:148
EResourceAlignment
Definition DynamicRHIResourceArray.h:15
@ INDEXBUFFER_ALIGNMENT
Definition DynamicRHIResourceArray.h:17
@ VERTEXBUFFER_ALIGNMENT
Definition DynamicRHIResourceArray.h:16
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
@ DEFAULT_ALIGNMENT
Definition MemoryBase.h:24
#define LAYOUT_FIELD(T, Name,...)
Definition MemoryLayout.h:471
#define DECLARE_INLINE_TYPE_LAYOUT_EXPLICIT_BASES(T, Interface,...)
Definition MemoryLayout.h:562
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition ResourceArray.h:77
Definition Array.h:670
void BulkSerialize(FArchive &Ar, bool bForcePerElementSerialization=false)
Definition Array.h:1593
UE_REWRITE SizeType Num() const
Definition Array.h:1144
InElementType ElementType
Definition Array.h:676
TArray & operator=(std::initializer_list< InElementType > InitList)
Definition Array.h:785
Definition DynamicRHIResourceArray.h:31
virtual bool IsStatic() const override
Definition DynamicRHIResourceArray.h:93
virtual uint32 GetResourceDataSize() const override
Definition DynamicRHIResourceArray.h:67
TResourceArray(bool InNeedsCPUAccess=false)
Definition DynamicRHIResourceArray.h:40
void BulkSerialize(FArchive &Ar, bool bForcePerElementSerialization=false)
Definition DynamicRHIResourceArray.h:129
virtual ~TResourceArray()=default
TResourceArray & operator=(TResourceArray &&)=default
virtual const void * GetResourceData() const override
Definition DynamicRHIResourceArray.h:59
virtual void Discard() override
Definition DynamicRHIResourceArray.h:82
TResourceArray & operator=(const Super &Other)
Definition DynamicRHIResourceArray.h:115
virtual bool GetAllowCPUAccess() const override
Definition DynamicRHIResourceArray.h:101
TResourceArray & operator=(const TResourceArray &)=default
TResourceArray(TResourceArray &&)=default
TResourceArray(const TResourceArray &)=default
virtual void SetAllowCPUAccess(bool bInNeedsCPUAccess) override
Definition DynamicRHIResourceArray.h:109