Blender V4.3
mtl_uniform_buffer.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 "MEM_guardedalloc.h"
13
14#include "mtl_context.hh"
15
16namespace blender::gpu {
17
18class MTLStorageBuf;
19
23class MTLUniformBuf : public UniformBuf {
24 friend class MTLStorageBuf; /* For bind as SSBO resource access. */
25
26 private:
27 /* Allocation Handle. */
28 gpu::MTLBuffer *metal_buffer_ = nullptr;
29
30 /* Whether buffer has contents, if false, no GPU buffer will
31 * have yet been allocated. */
32 bool has_data_ = false;
33
34 /* Bind-state tracking. */
35 int bind_slot_ = -1;
36 MTLContext *bound_ctx_ = nullptr;
37
38 /* SSBO wrapper for bind_as_ssbo support. */
39 MTLStorageBuf *ssbo_wrapper_ = nullptr;
40
41 public:
42 MTLUniformBuf(size_t size, const char *name);
44
45 void update(const void *data) override;
46 void bind(int slot) override;
47 void bind_as_ssbo(int slot) override;
48 void unbind() override;
49 void clear_to_zero() override;
50
51 id<MTLBuffer> get_metal_buffer();
52 size_t get_size();
53 const char *get_name()
54 {
55 return name_;
56 }
57
58 MEM_CXX_CLASS_ALLOC_FUNCS("MTLUniformBuf");
59};
60
61} // namespace blender::gpu
Read Guarded memory(de)allocation.
MEM_CXX_CLASS_ALLOC_FUNCS("MTLUniformBuf")
MTLUniformBuf(size_t size, const char *name)
void bind(int slot) override
void bind_as_ssbo(int slot) override
void update(const void *data) override