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