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