Blender V5.3
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:
35 enum {
36 MTL_STORAGE_BUF_TYPE_DEFAULT = 0,
37 MTL_STORAGE_BUF_TYPE_UNIFORMBUF = 1,
38 MTL_STORAGE_BUF_TYPE_VERTBUF = 2,
39 MTL_STORAGE_BUF_TYPE_INDEXBUF = 3,
40 MTL_STORAGE_BUF_TYPE_TEXTURE = 4,
41 } storage_source_ = MTL_STORAGE_BUF_TYPE_DEFAULT;
42
43 union {
45 gpu::MTLBuffer *metal_buffer_;
46 /* Wrapped type. */
47 MTLUniformBuf *uniform_buffer_;
48 MTLVertBuf *vertex_buffer_;
49 MTLIndexBuf *index_buffer_;
50 gpu::MTLTexture *texture_;
51 };
52
53 /* Whether buffer has contents, if false, no GPU buffer will
54 * have yet been allocated. */
55 bool has_data_ = false;
57 int bind_slot_ = -1;
58 MTLContext *bound_ctx_ = nullptr;
59
61 GPUUsageType usage_;
62
63 /* Synchronization event for host reads. */
64 id<MTLSharedEvent> gpu_write_fence_ = nil;
65 uint64_t host_read_signal_value_ = 0;
66
67 public:
68 MTLStorageBuf(size_t size, GPUUsageType usage, const char *name);
69 ~MTLStorageBuf() override;
70
71 MTLStorageBuf(MTLUniformBuf *uniform_buf, size_t size);
72 MTLStorageBuf(MTLVertBuf *vert_buf, size_t size);
73 MTLStorageBuf(MTLIndexBuf *index_buf, size_t size);
74 MTLStorageBuf(MTLTexture *texture, size_t size);
75
76 /* Only used internally to create a bindable buffer for #Immediate. */
77 MTLStorageBuf(size_t size);
78
79 void update(const void *data) override;
80 void bind(int slot) override;
81 void unbind() override;
82 void clear(uint32_t clear_value) override;
83 void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override;
84 void read(void *data) override;
85 void async_flush_to_host() override;
86 void sync_as_indirect_buffer() override { /* No-Op. */ };
87
88 void init();
89
91 size_t get_size();
92 const char *get_name()
93 {
94 return name_;
95 }
96
97 private:
98 MEM_CXX_CLASS_ALLOC_FUNCS("MTLStorageBuf");
99};
100
101} // namespace blender::gpu
Read Blender memory allocation and freeing.
void read(void *data) override
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
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55
unsigned int uint32_t
Definition BKE_text.h:81
BMesh const char void * data