Blender V5.0
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
8
9#pragma once
10
11#include "BLI_vector.hh"
12
13#include "gpu_backend.hh"
14#include "gpu_shader_private.hh"
15#include "mtl_capabilities.hh"
16
17namespace blender::gpu {
18
19class Batch;
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
39 ~MTLBackend() override
40 {
41 MTLBackend::platform_exit();
42 }
43
44 void init_resources() override;
45
46 void delete_resources() override;
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 void compute_dispatch_indirect(StorageBuf *indirect_buf) override;
57
58 /* MTL Allocators need to be implemented in separate `.mm` files,
59 * due to allocation of Objective-C objects. */
60 Context *context_alloc(void *ghost_window, void *ghost_context) override;
61 Batch *batch_alloc() override;
62 Fence *fence_alloc() override;
63 FrameBuffer *framebuffer_alloc(const char *name) override;
64 IndexBuf *indexbuf_alloc() override;
65 PixelBuffer *pixelbuf_alloc(size_t size) override;
66 QueryPool *querypool_alloc() override;
67 Shader *shader_alloc(const char *name) override;
68 Texture *texture_alloc(const char *name) override;
69 UniformBuf *uniformbuf_alloc(size_t size, const char *name) override;
70 StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override;
71 VertBuf *vertbuf_alloc() override;
72 void shader_cache_dir_clear_old() override {}
73
74 /* Render Frame Coordination. */
75 void render_begin() override;
76 void render_end() override;
77 void render_step(bool force_resource_release = false) override;
79
80 private:
81 static void platform_init(MTLContext *ctx);
82 static void platform_exit();
83
84 static void capabilities_init(MTLContext *ctx);
85};
86
87} // namespace blender::gpu
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static GPUBackend * get()
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 init_resources() override
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
Shader * shader_alloc(const char *name) override
void render_step(bool force_resource_release=false) override
const char * name