Blender  V3.3
mtl_backend.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include "BLI_vector.hh"
10 
11 #include "gpu_backend.hh"
12 #include "mtl_capabilities.hh"
13 
14 namespace blender::gpu {
15 
16 class Batch;
17 class DrawList;
18 class FrameBuffer;
19 class IndexBuf;
20 class QueryPool;
21 class Shader;
22 class UniformBuf;
23 class VertBuf;
24 class MTLContext;
25 
26 class MTLBackend : public GPUBackend {
27  friend class MTLContext;
28 
29  public:
30  /* Capabilities. */
32 
34  {
36  }
37 
39  {
40  MTLBackend::platform_exit();
41  }
42 
44  {
45  /* Delete any resources with context active. */
46  }
47 
48  static bool metal_is_supported();
49  static MTLBackend *get()
50  {
51  return static_cast<MTLBackend *>(GPUBackend::get());
52  }
53 
54  void samplers_update() override;
55  void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
56  {
57  /* Placeholder */
58  }
59 
60  void compute_dispatch_indirect(StorageBuf *indirect_buf) override
61  {
62  /* Placeholder */
63  }
64 
65  /* MTL Allocators need to be implemented in separate .mm files, due to allocation of Objective-C
66  * objects. */
67  Context *context_alloc(void *ghost_window) override;
68  Batch *batch_alloc() override;
69  DrawList *drawlist_alloc(int list_length) override;
70  FrameBuffer *framebuffer_alloc(const char *name) override;
71  IndexBuf *indexbuf_alloc() override;
72  QueryPool *querypool_alloc() override;
73  Shader *shader_alloc(const char *name) override;
74  Texture *texture_alloc(const char *name) override;
75  UniformBuf *uniformbuf_alloc(int size, const char *name) override;
76  StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) override;
77  VertBuf *vertbuf_alloc() override;
78 
79  /* Render Frame Coordination. */
80  void render_begin() override;
81  void render_end() override;
82  void render_step() override;
84 
85  private:
86  static void platform_init(MTLContext *ctx);
87  static void platform_exit();
88 
89  static void capabilities_init(MTLContext *ctx);
90 };
91 
92 } // namespace blender::gpu
GPUUsageType
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
static GPUBackend * get()
Definition: gpu_context.cc:292
UniformBuf * uniformbuf_alloc(int size, const char *name) override
Definition: mtl_backend.mm:83
void render_step() override
Definition: mtl_backend.mm:128
void render_begin() override
Definition: mtl_backend.mm:100
QueryPool * querypool_alloc() override
Definition: mtl_backend.mm:67
void compute_dispatch_indirect(StorageBuf *indirect_buf) override
Definition: mtl_backend.hh:60
Context * context_alloc(void *ghost_window) override
Definition: mtl_backend.mm:37
FrameBuffer * framebuffer_alloc(const char *name) override
Definition: mtl_backend.mm:54
StorageBuf * storagebuf_alloc(int size, GPUUsageType usage, const char *name) override
Definition: mtl_backend.mm:88
static bool metal_is_supported()
Definition: mtl_backend.mm:268
IndexBuf * indexbuf_alloc() override
Definition: mtl_backend.mm:61
void render_end() override
Definition: mtl_backend.mm:114
void samplers_update() override
Definition: mtl_backend.mm:33
static MTLCapabilities & get_capabilities()
Definition: mtl_backend.hh:33
Batch * batch_alloc() override
Definition: mtl_backend.mm:42
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
Definition: mtl_backend.hh:55
static MTLCapabilities capabilities
Definition: mtl_backend.hh:31
static MTLBackend * get()
Definition: mtl_backend.hh:49
VertBuf * vertbuf_alloc() override
Definition: mtl_backend.mm:94
Texture * texture_alloc(const char *name) override
Definition: mtl_backend.mm:78
DrawList * drawlist_alloc(int list_length) override
Definition: mtl_backend.mm:48
Shader * shader_alloc(const char *name) override
Definition: mtl_backend.mm:72