MTLContext provides functionality for command encoding, binding management and graphics device management. MTLImmediate provides simple draw enablement with dynamically encoded data. These draws utilise temporary scratch buffer memory to provide minimal bandwidth overhead during workload submission.
This patch also contains empty placeholders for MTLBatch and MTLDrawList to enable testing of first pixels on-screen without failure.
The Metal API also requires access to the GHOST_Context to ensure the same pre-initialized Metal GPU device is used by the viewport. Given the explicit nature of Metal, explicit control is also needed over presentation, to ensure correct work scheduling and rendering pipeline state.
Authored by Apple: Michael Parkin-White
Ref T96261
(The diff is based on 043f59cb3b)
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D15953
92 lines
2.1 KiB
C++
92 lines
2.1 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_vector.hh"
|
|
|
|
#include "gpu_backend.hh"
|
|
#include "mtl_capabilities.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
class Batch;
|
|
class DrawList;
|
|
class FrameBuffer;
|
|
class QueryPool;
|
|
class Shader;
|
|
class UniformBuf;
|
|
class VertBuf;
|
|
class MTLContext;
|
|
|
|
class MTLBackend : public GPUBackend {
|
|
friend class MTLContext;
|
|
|
|
public:
|
|
/* Capabilities. */
|
|
static MTLCapabilities capabilities;
|
|
|
|
static MTLCapabilities &get_capabilities()
|
|
{
|
|
return MTLBackend::capabilities;
|
|
}
|
|
|
|
~MTLBackend()
|
|
{
|
|
MTLBackend::platform_exit();
|
|
}
|
|
|
|
void delete_resources() override
|
|
{
|
|
/* Delete any resources with context active. */
|
|
}
|
|
|
|
static bool metal_is_supported();
|
|
static MTLBackend *get()
|
|
{
|
|
return static_cast<MTLBackend *>(GPUBackend::get());
|
|
}
|
|
|
|
void samplers_update() override;
|
|
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
|
|
{
|
|
/* Placeholder */
|
|
}
|
|
|
|
void compute_dispatch_indirect(StorageBuf *indirect_buf) override
|
|
{
|
|
/* Placeholder */
|
|
}
|
|
|
|
/* MTL Allocators need to be implemented in separate .mm files, due to allocation of Objective-C
|
|
* objects. */
|
|
Context *context_alloc(void *ghost_window, void *ghost_context) override;
|
|
Batch *batch_alloc() override;
|
|
DrawList *drawlist_alloc(int list_length) override;
|
|
FrameBuffer *framebuffer_alloc(const char *name) override;
|
|
IndexBuf *indexbuf_alloc() override;
|
|
QueryPool *querypool_alloc() override;
|
|
Shader *shader_alloc(const char *name) override;
|
|
Texture *texture_alloc(const char *name) override;
|
|
UniformBuf *uniformbuf_alloc(int size, const char *name) override;
|
|
StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) override;
|
|
VertBuf *vertbuf_alloc() override;
|
|
|
|
/* Render Frame Coordination. */
|
|
void render_begin() override;
|
|
void render_end() override;
|
|
void render_step() override;
|
|
bool is_inside_render_boundary();
|
|
|
|
private:
|
|
static void platform_init(MTLContext *ctx);
|
|
static void platform_exit();
|
|
|
|
static void capabilities_init(MTLContext *ctx);
|
|
};
|
|
|
|
} // namespace blender::gpu
|