Blender V4.3
mtl_vertex_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 <Cocoa/Cocoa.h>
12#include <Metal/Metal.h>
13#include <QuartzCore/QuartzCore.h>
14
15#include "MEM_guardedalloc.h"
16
17#include "GPU_vertex_buffer.hh"
18#include "mtl_context.hh"
19
20namespace blender::gpu {
21
22class MTLVertBuf : public VertBuf {
23 friend class gpu::MTLTexture; /* For buffer texture. */
24 friend class MTLShader; /* For transform feedback. */
25 friend class MTLBatch;
26 friend class MTLContext; /* For transform feedback. */
27 friend class MTLStorageBuf; /* For bind as SSBO resource access and copy sub. */
28
29 private:
31 gpu::MTLBuffer *vbo_ = nullptr;
33 ::GPUTexture *buffer_texture_ = nullptr;
36 bool is_wrapper_ = false;
39 uint64_t alloc_size_ = 0;
41 bool contents_in_flight_ = false;
42 /* SSBO wrapper for bind_as_ssbo support. */
43 MTLStorageBuf *ssbo_wrapper_ = nullptr;
44
45 /* Fetch Metal buffer and offset into allocation if necessary.
46 * Access limited to friend classes. */
47 id<MTLBuffer> get_metal_buffer()
48 {
49 BLI_assert(vbo_ != nullptr);
50 vbo_->debug_ensure_used();
51 return vbo_->get_metal_buffer();
52 }
53
54 public:
55 MTLVertBuf();
57
58 void bind();
59 void flag_used();
60
61 void update_sub(uint start, uint len, const void *data) override;
62
63 void read(void *data) const override;
64
65 void wrap_handle(uint64_t handle) override;
66
67 protected:
68 void acquire_data() override;
69 void resize_data() override;
70 void release_data() override;
71 void upload_data() override;
72 void duplicate_data(VertBuf *dst) override;
73 void bind_as_ssbo(uint binding) override;
74 void bind_as_texture(uint binding) override;
75
77};
78
79} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:50
unsigned int uint
Read Guarded memory(de)allocation.
id< MTLBuffer > get_metal_buffer() const
void duplicate_data(VertBuf *dst) override
MEM_CXX_CLASS_ALLOC_FUNCS("MTLVertBuf")
void wrap_handle(uint64_t handle) override
void bind_as_ssbo(uint binding) override
void update_sub(uint start, uint len, const void *data) override
void read(void *data) const override
void bind_as_texture(uint binding) override
int len
unsigned __int64 uint64_t
Definition stdint.h:90