• 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     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<MTLLibrary>> newLibraryWithSource(NSString *source,
53                                                      MTLCompileOptions *options,
54                                                      __autoreleasing NSError **error) const;
55 
56     AutoObjCPtr<id<MTLDepthStencilState>> newDepthStencilStateWithDescriptor(
57         MTLDepthStencilDescriptor *descriptor) const;
58 
59     AutoObjCPtr<id<MTLSharedEvent>> newSharedEvent() const;
60 
61     void setOwnerWithIdentity(id<MTLResource> resource) const;
62 
63   private:
64     using ParentClass = WrappedObject<id<MTLDevice>>;
65 
66 #if ANGLE_USE_METAL_OWNERSHIP_IDENTITY
67     task_id_token_t mOwnershipIdentity = TASK_ID_TOKEN_NULL;
68 #endif
69 };
70 
71 }  // namespace mtl
72 }  // namespace rx
73 
74 #endif /* LIBANGLE_RENDERER_METAL_CONTEXT_DEVICE_H_ */
75