UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MetalDevice.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4#pragma once
5
6#include "MetalViewport.h"
7#include "MetalCommandQueue.h"
8#include "MetalBuffer.h"
10#include "MetalTempAllocator.h"
11#include "MetalStateCache.h"
12#include "MetalCounterSampler.h"
13
14#if PLATFORM_IOS
15#include "IOS/IOSView.h"
16#endif
18
19// Defines a unique command queue type within a Metal Device (owner by the command list managers).
20// Currently only implements direct
22{
23 Direct = 0,
24 Count,
25};
26
72
85
96
98
100
102{
103public:
104 static FMetalDevice* CreateDevice();
105 virtual ~FMetalDevice();
106
108 inline bool SupportsFeature(EMetalFeatures InFeature) { return ((Features & InFeature) != 0); }
109
110 inline FMetalResourceHeap& GetResourceHeap(void) { return Heap; }
111
112 void EndDrawingViewport(bool bPresent);
113
114 MTLTexturePtr CreateTexture(FMetalSurface* Surface, MTL::TextureDescriptor* Descriptor);
117
118 void DrainHeap();
119 void GarbageCollect();
120
122 uint32 GetDeviceIndex(void) const;
123
125 {
126 return TransferBufferAllocator;
127 }
128
130 {
131 return UniformBufferAllocator;
132 }
133
135 {
136 return FrameNumberRHIThread;
137 }
138
140 {
141 check(QueueType < EMetalQueueType::Count);
142 return *CommandQueues[(uint32_t)QueueType];
143 }
144
145#if PLATFORM_SUPPORTS_BINDLESS_RENDERING
146 FMetalBindlessDescriptorManager* GetBindlessDescriptorManager()
147 {
148 return BindlessDescriptorManager;
149 }
150#endif
151
152#if METAL_DEBUG_OPTIONS
153 void AddActiveBuffer(MTL::Buffer* Buffer, const NS::Range& Range);
154 void RemoveActiveBuffer(MTL::Buffer* Buffer, const NS::Range& Range);
155 bool ValidateIsInactiveBuffer(MTL::Buffer* Buffer, const NS::Range& Range);
156#endif
157
158 MTL::Device* GetDevice()
159 {
160 return Device;
161 }
162
164 {
165 return RuntimeDebuggingLevel;
166 }
167
169 {
170 FrameNumberRHIThread++;
171 }
172
174 {
175 return FrameSemaphore;
176 }
177
179 {
180 return CounterSampler;
181 }
182
184 {
185 return bShaderValidationEnabled;
186 }
187
188private:
189 FMetalDevice(MTL::Device* MetalDevice, uint32 DeviceIndex);
190
191 void FlushFreeList(bool const bFlushFences = true);
192
193private:
194 MTL::Device* Device;
195
197
199 dispatch_semaphore_t FrameSemaphore;
200
202 uint32 DeviceIndex;
203
206
208 FMetalCaptureManager* CaptureManager;
209
210 FMetalTempAllocator* UniformBufferAllocator;
211 FMetalTempAllocator* TransferBufferAllocator;
212
213#if METAL_DEBUG_OPTIONS
215 TArray<FMetalFence*> FrameFences;
216
217 FCriticalSection ActiveBuffersMutex;
218
221#endif
222
224 FCriticalSection FreeListMutex;
225
227 FEvent* FrameReadyEvent;
228
230 uint32 FrameCounter = 0;
231
233 uint64 Features = 0;
234
237
239 uint32 FrameNumberRHIThread = 0;
240
241 int32 RuntimeDebuggingLevel = 0;
242
243 FMetalCounterSampler* CounterSampler = nullptr;
244
245 bool bShaderValidationEnabled = false;
246
247#if PLATFORM_SUPPORTS_BINDLESS_RENDERING
249 FMetalBindlessDescriptorManager* BindlessDescriptorManager;
250#endif
251
252#if METAL_RHI_RAYTRACING
253 FMetalRayTracingCompactionRequestHandler* RayTracingCompactionRequestHandler;
254
255 void InitializeRayTracing();
256 void CleanUpRayTracing();
257
258public:
260
261 inline FMetalRayTracingCompactionRequestHandler* GetRayTracingCompactionRequestHandler() const { return RayTracingCompactionRequestHandler; }
262
263 // Dummy Index buffer used when creating descriptors
265#endif // METAL_RHI_RAYTRACING
266};
267
#define check(expr)
Definition AssertionMacros.h:314
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
typedef NS_OPTIONS(uint32, EMetalFeatures)
Definition MetalDevice.h:31
EMetalShaderValidationType
Definition MetalDevice.h:90
EMetalDebugLevel
Definition MetalDevice.h:77
@ EMetalDebugLevelResetOnBind
Definition MetalDevice.h:80
@ EMetalDebugLevelWaitForComplete
Definition MetalDevice.h:83
@ EMetalDebugLevelOff
Definition MetalDevice.h:78
@ EMetalDebugLevelFastValidation
Definition MetalDevice.h:79
@ EMetalDebugLevelConditionalSubmit
Definition MetalDevice.h:81
@ EMetalDebugLevelValidation
Definition MetalDevice.h:82
EMetalQueueType
Definition MetalDevice.h:22
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Event.h:21
Definition MetalCaptureManager.h:10
Definition MetalCommandQueue.h:39
Definition MetalCounterSampler.h:65
Definition MetalDevice.h:102
uint32 GetDeviceIndex(void) const
Definition MetalDevice.cpp:647
int32 GetRuntimeDebuggingLevel(void) const
Definition MetalDevice.h:163
static FMetalDevice * CreateDevice()
Definition MetalDevice.cpp:326
void AddActiveBuffer(MTL::Buffer *Buffer, const NS::Range &Range)
Definition MetalDevice.cpp:653
uint32 GetFrameNumberRHIThread()
Definition MetalDevice.h:134
MTLTexturePtr CreateTexture(FMetalSurface *Surface, MTL::TextureDescriptor *Descriptor)
Definition MetalDevice.cpp:597
bool ValidateIsInactiveBuffer(MTL::Buffer *Buffer, const NS::Range &Range)
Definition MetalDevice.cpp:687
FMetalTempAllocator * GetUniformAllocator()
Definition MetalDevice.h:129
void RemoveActiveBuffer(MTL::Buffer *Buffer, const NS::Range &Range)
Definition MetalDevice.cpp:675
MTL::Device * GetDevice()
Definition MetalDevice.h:158
FMetalResourceHeap & GetResourceHeap(void)
Definition MetalDevice.h:110
FMetalCommandQueue & GetCommandQueue(EMetalQueueType QueueType)
Definition MetalDevice.h:139
virtual ~FMetalDevice()
Definition MetalDevice.cpp:438
bool IsShaderValidationEnabled()
Definition MetalDevice.h:183
FMetalBufferPtr CreatePooledBuffer(FMetalPooledBufferArgs const &Args)
Definition MetalDevice.cpp:608
void GarbageCollect()
Definition MetalDevice.cpp:589
void EnumerateFeatureSupport()
Definition MetalDevice.cpp:469
FMetalCounterSampler * GetCounterSampler()
Definition MetalDevice.h:178
dispatch_semaphore_t & GetFrameSemaphore()
Definition MetalDevice.h:173
FMetalTempAllocator * GetTransferAllocator()
Definition MetalDevice.h:124
void EndDrawingViewport(bool bPresent)
Definition MetalDevice.cpp:569
void DrainHeap()
Definition MetalDevice.cpp:584
MTLEventPtr CreateEvent()
Definition MetalDevice.cpp:641
void IncrementFrameRHIThread()
Definition MetalDevice.h:168
bool SupportsFeature(EMetalFeatures InFeature)
Definition MetalDevice.h:108
Definition MetalPipeline.h:93
Definition MetalRHIContext.h:48
Definition MetalBuffer.h:398
Definition MetalResources.h:206
Definition MetalTempAllocator.h:16
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition ContainerAllocationPolicies.h:894
Definition MetalBuffer.h:17