UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MetalFence.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4#pragma once
5
6#include "MetalRHIPrivate.h"
8
9#pragma clang diagnostic ignored "-Wnullability-completeness"
10
12{
13public:
15 : NumRefs(0)
16 {
17 Reset();
18 }
19
20 explicit FMetalFence(FMetalFence const& Other)
21 : NumRefs(0)
22 {
24 }
25
27 {
28 check(!NumRefs);
29 }
30
31 uint32 AddRef() const
32 {
33 return uint32(FPlatformAtomics::InterlockedIncrement(&NumRefs));
34 }
35 uint32 Release() const;
37 {
38 return uint32(FPlatformAtomics::AtomicRead(&NumRefs));
39 }
40
42 {
43 if (&Other != this)
44 {
45 Fence = Other.Fence;
46 }
47 return *this;
48 }
49
50 void Reset(void)
51 {
52 WriteNum = 0;
53 WaitNum = 0;
54 }
55
56 void Write()
57 {
58 WriteNum++;
59 }
60
61 void Wait()
62 {
63 WaitNum++;
64 }
65
66 int8 NumWrite() const
67 {
68 return WriteNum;
69 }
70
71 int8 NumWait() const
72 {
73 return WaitNum;
74 }
75
76 MTL::Fence* Get() const
77 {
78 return Fence;
79 }
80
81 void Set(MTL::Fence* InFence)
82 {
83 Fence = InFence;
84 }
85
86private:
87 MTL::Fence* Fence;
88 int8 WriteNum;
89 int8 WaitNum;
90 mutable int32 NumRefs;
91};
92
94{
95 enum
96 {
97 NumFences = 2048
98 };
99public:
101
103 {
104 static FMetalFencePool sSelf;
105 return sSelf;
106 }
107
108 void Initialise(MTL::Device* InDevice);
109
112
113 int32 Max() const { return Count; }
114 int32 Num() const { return Allocated; }
115
116private:
117 int32 Count;
118 int32 Allocated;
119 MTL::Device* Device;
120#if METAL_DEBUG_OPTIONS
121 TSet<FMetalFence*> Fences;
122 FCriticalSection Mutex;
123#endif
125};
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MetalFence.h:94
static FMetalFencePool & Get()
Definition MetalFence.h:102
void Initialise(MTL::Device *InDevice)
Definition MetalFence.cpp:19
FMetalFence * AllocateFence()
Definition MetalFence.cpp:32
FMetalFencePool()
Definition MetalFence.h:100
void ReleaseFence(FMetalFence *InFence)
Definition MetalFence.cpp:46
int32 Num() const
Definition MetalFence.h:114
int32 Max() const
Definition MetalFence.h:113
Definition MetalFence.h:12
FMetalFence()
Definition MetalFence.h:14
int8 NumWrite() const
Definition MetalFence.h:66
void Write()
Definition MetalFence.h:56
FMetalFence & operator=(FMetalFence const &Other)
Definition MetalFence.h:41
int8 NumWait() const
Definition MetalFence.h:71
void Reset(void)
Definition MetalFence.h:50
void Wait()
Definition MetalFence.h:61
MTL::Fence * Get() const
Definition MetalFence.h:76
FMetalFence(FMetalFence const &Other)
Definition MetalFence.h:20
uint32 AddRef() const
Definition MetalFence.h:31
void Set(MTL::Fence *InFence)
Definition MetalFence.h:81
uint32 Release() const
Definition MetalFence.cpp:9
uint32 GetRefCount() const
Definition MetalFence.h:36
~FMetalFence()
Definition MetalFence.h:26
Definition LockFreeList.h:910