1 // 2 // Copyright 2021 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // mtl_device.h: 7 // Defines the wrapper class for Metal's MTLDevice per context. 8 // 9 10 #ifndef LIBANGLE_RENDERER_METAL_CONTEXT_DEVICE_H_ 11 #define LIBANGLE_RENDERER_METAL_CONTEXT_DEVICE_H_ 12 13 #import <Metal/Metal.h> 14 #import <mach/mach_types.h> 15 16 #include "common/apple/apple_platform.h" 17 #include "libANGLE/renderer/metal/mtl_common.h" 18 19 namespace rx 20 { 21 namespace mtl 22 { 23 24 class ContextDevice final : public WrappedObject<id<MTLDevice>>, angle::NonCopyable 25 { 26 public: 27 ContextDevice(GLint ownershipIdentity); 28 ~ContextDevice(); set(id<MTLDevice> metalDevice)29 inline void set(id<MTLDevice> metalDevice) { ParentClass::set(metalDevice); } 30 31 AutoObjCPtr<id<MTLSamplerState>> newSamplerStateWithDescriptor( 32 MTLSamplerDescriptor *descriptor) const; 33 34 AutoObjCPtr<id<MTLTexture>> newTextureWithDescriptor(MTLTextureDescriptor *descriptor) const; 35 AutoObjCPtr<id<MTLTexture>> newTextureWithDescriptor(MTLTextureDescriptor *descriptor, 36 IOSurfaceRef iosurface, 37 NSUInteger plane) const; 38 39 AutoObjCPtr<id<MTLBuffer>> newBufferWithLength(NSUInteger length, 40 MTLResourceOptions options) const; 41 AutoObjCPtr<id<MTLBuffer>> newBufferWithBytes(const void *pointer, 42 NSUInteger length, 43 MTLResourceOptions options) const; 44 45 AutoObjCPtr<id<MTLComputePipelineState>> newComputePipelineStateWithFunction( 46 id<MTLFunction> computeFunction, 47 __autoreleasing NSError **error) const; 48 AutoObjCPtr<id<MTLRenderPipelineState>> newRenderPipelineStateWithDescriptor( 49 MTLRenderPipelineDescriptor *descriptor, 50 __autoreleasing NSError **error) const; 51 52 AutoObjCPtr<id<MTLDepthStencilState>> newDepthStencilStateWithDescriptor( 53 MTLDepthStencilDescriptor *descriptor) const; 54 55 AutoObjCPtr<id<MTLSharedEvent>> newSharedEvent() const; 56 AutoObjCPtr<id<MTLEvent>> newEvent() const; 57 58 void setOwnerWithIdentity(id<MTLResource> resource) const; 59 bool hasUnifiedMemory() const; 60 61 private: 62 using ParentClass = WrappedObject<id<MTLDevice>>; 63 64 #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY 65 task_id_token_t mOwnershipIdentity = TASK_ID_TOKEN_NULL; 66 #endif 67 }; 68 69 } // namespace mtl 70 } // namespace rx 71 72 #endif /* LIBANGLE_RENDERER_METAL_CONTEXT_DEVICE_H_ */ 73