• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     angle::ObjCPtr<id<MTLSamplerState>> newSamplerStateWithDescriptor(
32         MTLSamplerDescriptor *descriptor) const;
33 
34     angle::ObjCPtr<id<MTLTexture>> newTextureWithDescriptor(MTLTextureDescriptor *descriptor) const;
35     angle::ObjCPtr<id<MTLTexture>> newTextureWithDescriptor(MTLTextureDescriptor *descriptor,
36                                                             IOSurfaceRef iosurface,
37                                                             NSUInteger plane) const;
38 
39     angle::ObjCPtr<id<MTLBuffer>> newBufferWithLength(NSUInteger length,
40                                                       MTLResourceOptions options) const;
41     angle::ObjCPtr<id<MTLBuffer>> newBufferWithBytes(const void *pointer,
42                                                      NSUInteger length,
43                                                      MTLResourceOptions options) const;
44 
45     angle::ObjCPtr<id<MTLComputePipelineState>> newComputePipelineStateWithFunction(
46         id<MTLFunction> computeFunction,
47         __autoreleasing NSError **error) const;
48     angle::ObjCPtr<id<MTLRenderPipelineState>> newRenderPipelineStateWithDescriptor(
49         MTLRenderPipelineDescriptor *descriptor,
50         __autoreleasing NSError **error) const;
51 
52     angle::ObjCPtr<id<MTLDepthStencilState>> newDepthStencilStateWithDescriptor(
53         MTLDepthStencilDescriptor *descriptor) const;
54 
55     angle::ObjCPtr<id<MTLSharedEvent>> newSharedEvent() const;
56     angle::ObjCPtr<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