Blender V4.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
9#pragma once
10
11#include "MEM_guardedalloc.h"
13
14#include "mtl_context.hh"
15
16namespace blender {
17namespace gpu {
18
19class MTLUniformBuf;
20class MTLVertBuf;
21class MTLIndexBuf;
22
26class MTLStorageBuf : public StorageBuf {
27 private:
31 enum {
32 MTL_STORAGE_BUF_TYPE_DEFAULT = 0,
33 MTL_STORAGE_BUF_TYPE_UNIFORMBUF = 1,
34 MTL_STORAGE_BUF_TYPE_VERTBUF = 2,
35 MTL_STORAGE_BUF_TYPE_INDEXBUF = 3,
36 MTL_STORAGE_BUF_TYPE_TEXTURE = 4,
37 } storage_source_ = MTL_STORAGE_BUF_TYPE_DEFAULT;
38
39 union {
42 /* Wrapped type. */
47 };
48
49 /* Whether buffer has contents, if false, no GPU buffer will
50 * have yet been allocated. */
51 bool has_data_ = false;
53 int bind_slot_ = -1;
54 MTLContext *bound_ctx_ = nullptr;
55
57 GPUUsageType usage_;
58
59 /* Synchronization event for host reads. */
60 id<MTLSharedEvent> gpu_write_fence_ = nil;
61 uint64_t host_read_signal_value_ = 0;
62
63 public:
64 MTLStorageBuf(size_t size, GPUUsageType usage, const char *name);
66
70 MTLStorageBuf(MTLTexture *texture, size_t size);
71
72 void update(const void *data) override;
73 void bind(int slot) override;
74 void unbind() override;
75 void clear(uint32_t clear_value) override;
76 void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override;
77 void read(void *data) override;
78 void async_flush_to_host() override;
79 void sync_as_indirect_buffer() override{/* No-Op. */};
80
81 void init();
82
83 id<MTLBuffer> get_metal_buffer();
84 size_t get_size();
85 const char *get_name()
86 {
87 return name_;
88 }
89
90 private:
91 MEM_CXX_CLASS_ALLOC_FUNCS("MTLStorageBuf");
92};
93
94} // namespace gpu
95} // namespace blender
unsigned int uint
Read Guarded memory(de)allocation.
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
flat(Type::VEC4, "color_and_coc1") .flat(Type no_perspective(Type::VEC2, "rect_uv1") .no_perspective(Type draw_view bokeh_lut_tx uniform_buf(6, "DepthOfFieldData", "dof_buf") .storage_buf(0
unsigned int uint32_t
Definition stdint.h:80
unsigned __int64 uint64_t
Definition stdint.h:90