Blender V4.5
vk_vertex_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
8
9#pragma once
10
11#include "GPU_vertex_buffer.hh"
12
13#include "vk_buffer.hh"
14#include "vk_common.hh"
15#include "vk_data_conversion.hh"
16
17namespace blender::gpu {
18
19class VKVertexBuffer : public VertBuf {
20 VKBuffer buffer_;
22 VkBufferView vk_buffer_view_ = VK_NULL_HANDLE;
23
24 bool data_uploaded_ = false;
25
26 public:
28
29 void bind_as_ssbo(uint binding) override;
30 void bind_as_texture(uint binding) override;
31 void wrap_handle(uint64_t handle) override;
32
33 void update_sub(uint start, uint len, const void *data) override;
34 void read(void *data) const override;
35
36 VkBuffer vk_handle() const
37 {
38 BLI_assert(buffer_.is_allocated());
39 return buffer_.vk_handle();
40 }
41
42 inline VkDeviceAddress device_address_get() const
43 {
44 return buffer_.device_address_get();
45 }
46
47 VkBufferView vk_buffer_view_get() const
48 {
49 BLI_assert(vk_buffer_view_ != VK_NULL_HANDLE);
50 return vk_buffer_view_;
51 }
52
53 void ensure_updated();
54 void ensure_buffer_view();
55
56 inline VkFormat to_vk_format()
57 {
59 }
60
61 protected:
62 void acquire_data() override;
63 void resize_data() override;
64 void release_data() override;
65 void upload_data() override;
66
67 private:
68 void allocate();
69
70 void upload_data_direct(const VKBuffer &host_buffer);
71 void upload_data_via_staging_buffer(VKContext &context);
72
73 /* VKTexture requires access to `buffer_` to convert a vertex buffer to a texture. */
74 friend class VKTexture;
75};
76
78{
79 return static_cast<VKVertexBuffer *>(vertex_buffer);
80}
81
82} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_INLINE
unsigned int uint
unsigned long long int uint64_t
VkDeviceAddress device_address_get() const
void update_sub(uint start, uint len, const void *data) override
VkBufferView vk_buffer_view_get() const
void wrap_handle(uint64_t handle) override
void bind_as_ssbo(uint binding) override
void bind_as_texture(uint binding) override
MutableSpan< T > data()
static Context * unwrap(GPUContext *ctx)
VkFormat to_vk_format(const eGPUTextureFormat format)
Definition vk_common.cc:131
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
read
uint len