Blender V5.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
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
22MTLVertexFormat gpu_vertex_format_to_metal(VertAttrType vert_format);
24
25class MTLVertBuf : public VertBuf {
26 friend class gpu::MTLTexture; /* For buffer texture. */
27 friend class MTLBatch;
28 friend class MTLStorageBuf; /* For bind as SSBO resource access and copy sub. */
29 friend class MTLBottomLevelAS; /* For acceleration structure geometry. */
30
31 private:
33 gpu::MTLBuffer *vbo_ = nullptr;
35 gpu::Texture *buffer_texture_ = nullptr;
40 bool is_wrapper_ = false;
45 uint64_t alloc_size_ = 0;
47 bool contents_in_flight_ = false;
48 /* SSBO wrapper for bind_as_ssbo support. */
49 MTLStorageBuf *ssbo_wrapper_ = nullptr;
50
51 /* Fetch Metal buffer and offset into allocation if necessary.
52 * Access limited to friend classes. */
53 id<MTLBuffer> get_metal_buffer()
54 {
55 BLI_assert(vbo_ != nullptr);
56 vbo_->debug_ensure_used();
57 return vbo_->get_metal_buffer();
58 }
59
60 public:
61 MTLVertBuf();
62 ~MTLVertBuf() override;
63
64 void bind();
65 void flag_used();
66
67 void update_sub(uint start, uint len, const void *data) override;
68 void copy_sub(VertBuf &source_buf,
69 uint source_first_vertex,
70 uint dest_first_vertex,
71 uint vertex_len) override;
72
73 void read(void *data) const override;
74
75 void wrap_handle(uint64_t handle) override;
76
77 protected:
78 void acquire_data() override;
79 void resize_data() override;
80 void release_data() override;
81 void upload_data() override;
82 void bind_as_ssbo(uint binding) override;
83 void bind_as_texture(uint binding) override;
84
86};
87
88} // namespace blender::gpu
Read Blender memory allocation and freeing.
MEM_CXX_CLASS_ALLOC_FUNCS("MTLVertBuf")
void wrap_handle(uint64_t handle) override
void bind_as_ssbo(uint binding) override
void copy_sub(VertBuf &source_buf, uint source_first_vertex, uint dest_first_vertex, uint vertex_len) override
Copy from part of source vertex buffer into the vertex buffer.
void update_sub(uint start, uint len, const void *data) override
void read(void *data) const override
void bind_as_texture(uint binding) override
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
MTLVertexFormat gpu_vertex_format_to_metal(VertAttrType vert_format)
MTLVertexFormat gpu_type_to_metal_vertex_format(shader::Type type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55
BMesh const char void * data