blob: 6918298d643d8127b621017e987d23c68d622b18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include <Cocoa/Cocoa.h>
#include <Metal/Metal.h>
#include <QuartzCore/QuartzCore.h>
#include "MEM_guardedalloc.h"
#include "GPU_vertex_buffer.h"
#include "gpu_vertex_buffer_private.hh"
#include "mtl_context.hh"
namespace blender::gpu {
class MTLVertBuf : public VertBuf {
friend class gpu::MTLTexture; /* For buffer texture. */
friend class MTLShader; /* For transform feedback. */
friend class MTLBatch;
friend class MTLContext; /* For transform feedback. */
private:
/** Metal buffer allocation. **/
gpu::MTLBuffer *vbo_ = nullptr;
/** Texture used if the buffer is bound as buffer texture. Init on first use. */
struct ::GPUTexture *buffer_texture_ = nullptr;
/** Defines whether the buffer handle is wrapped by this MTLVertBuf, i.e. we do not own it and
* should not free it. */
bool is_wrapper_ = false;
/** Requested allocation size for Metal buffer.
* Differs from raw buffer size as alignment is not included. */
uint64_t alloc_size_ = 0;
/** Whether existing allocation has been submitted for use by the GPU. */
bool contents_in_flight_ = false;
/* Fetch Metal buffer and offset into allocation if ncessary.
* Access limited to friend classes. */
id<MTLBuffer> get_metal_buffer()
{
vbo_->debug_ensure_used();
return vbo_->get_metal_buffer();
}
public:
MTLVertBuf();
~MTLVertBuf();
void bind();
void flag_used();
void update_sub(uint start, uint len, const void *data) override;
const void *read() const override;
void *unmap(const void *mapped_data) const override;
void wrap_handle(uint64_t handle) override;
protected:
void acquire_data() override;
void resize_data() override;
void release_data() override;
void upload_data() override;
void duplicate_data(VertBuf *dst) override;
void bind_as_ssbo(uint binding) override;
void bind_as_texture(uint binding) override;
MEM_CXX_CLASS_ALLOC_FUNCS("MTLVertBuf");
};
} // namespace blender::gpu
|