Blender V5.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
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 compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override;
55 void compute_dispatch_indirect(StorageBuf *indirect_buf) override;
56
57 /* MTL Allocators need to be implemented in separate `.mm` files,
58 * due to allocation of Objective-C objects. */
59 Context *context_alloc(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context) override;
60 Batch *batch_alloc() override;
61 Fence *fence_alloc() override;
62 WorkInFlight *work_in_flight_alloc(unsigned int max_in_flight) 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;
70 UniformBuf *uniformbuf_alloc(size_t size, const char *name) override;
71 StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override;
72 VertBuf *vertbuf_alloc() override;
73 TopLevelAS *tlas_alloc(const char *name) override;
74 BottomLevelAS *blas_alloc(const char *name) override;
75 void shader_cache_dir_clear_old() override {}
76
77 /* Render Frame Coordination. */
78 void render_begin() override;
79 void render_end() override;
80 void render_step(bool force_resource_release = false) override;
82
83 private:
84 static void platform_init(MTLContext *ctx);
85 static void platform_exit();
86
87 static void capabilities_init(MTLContext *ctx);
88};
89
90} // namespace blender::gpu
static GPUBackend * get()
TopLevelAS * tlas_alloc(const char *name) override
void render_begin() override
TexturePool * texturepool_alloc() override
QueryPool * querypool_alloc() override
static MTLCapabilities & get_capabilities()
void compute_dispatch_indirect(StorageBuf *indirect_buf) 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
WorkInFlight * work_in_flight_alloc(unsigned int max_in_flight) override
Context * context_alloc(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context) override
Batch * batch_alloc() override
Fence * fence_alloc() override
static MTLBackend * get()
void init_resources() override
BottomLevelAS * blas_alloc(const char *name) 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