Blender V5.0
mtl_storage_buffer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "MEM_guardedalloc.h"
13
14#include "mtl_context.hh"
15
16namespace blender::gpu {
17
18class MTLUniformBuf;
19class MTLVertBuf;
20class MTLIndexBuf;
22
26class MTLStorageBuf : public StorageBuf {
27 friend MTLCircularBuffer;
28
29 private:
33 enum {
34 MTL_STORAGE_BUF_TYPE_DEFAULT = 0,
35 MTL_STORAGE_BUF_TYPE_UNIFORMBUF = 1,
36 MTL_STORAGE_BUF_TYPE_VERTBUF = 2,
37 MTL_STORAGE_BUF_TYPE_INDEXBUF = 3,
38 MTL_STORAGE_BUF_TYPE_TEXTURE = 4,
39 } storage_source_ = MTL_STORAGE_BUF_TYPE_DEFAULT;
40
41 union {
44 /* Wrapped type. */
49 };
50
51 /* Whether buffer has contents, if false, no GPU buffer will
52 * have yet been allocated. */
53 bool has_data_ = false;
55 int bind_slot_ = -1;
56 MTLContext *bound_ctx_ = nullptr;
57
59 GPUUsageType usage_;
60
61 /* Synchronization event for host reads. */
62 id<MTLSharedEvent> gpu_write_fence_ = nil;
63 uint64_t host_read_signal_value_ = 0;
64
65 public:
66 MTLStorageBuf(size_t size, GPUUsageType usage, const char *name);
67 ~MTLStorageBuf() override;
68
69 MTLStorageBuf(MTLUniformBuf *uniform_buf, size_t size);
70 MTLStorageBuf(MTLVertBuf *vert_buf, size_t size);
71 MTLStorageBuf(MTLIndexBuf *index_buf, size_t size);
73
74 /* Only used internally to create a bindable buffer for #Immediate. */
75 MTLStorageBuf(size_t size);
76
77 void update(const void *data) override;
78 void bind(int slot) override;
79 void unbind() override;
80 void clear(uint32_t clear_value) override;
81 void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override;
82 void read(void *data) override;
83 void async_flush_to_host() override;
84 void sync_as_indirect_buffer() override { /* No-Op. */ };
85
86 void init();
87
88 id<MTLBuffer> get_metal_buffer();
89 size_t get_size();
90 const char *get_name()
91 {
92 return name_;
93 }
94
95 private:
96 MEM_CXX_CLASS_ALLOC_FUNCS("MTLStorageBuf");
97};
98
99} // namespace blender::gpu
unsigned int uint
Read Guarded memory(de)allocation.
BMesh const char void * data
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void clear(uint32_t clear_value) override
void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override
void update(const void *data) override
MTLStorageBuf(size_t size, GPUUsageType usage, const char *name)
void bind(int slot) override
StorageBuf(size_t size, const char *name)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
const char * name