Blender V4.3
vk_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
12
13#include "BLI_utility_mixins.hh"
14#include "vk_common.hh"
15
16namespace blender::gpu {
17class VKContext;
18class VKDevice;
19
23class VKBuffer : public NonCopyable {
24 size_t size_in_bytes_ = 0;
25 VkBuffer vk_buffer_ = VK_NULL_HANDLE;
26 VmaAllocation allocation_ = VK_NULL_HANDLE;
27 /* Pointer to the virtually mapped memory. */
28 void *mapped_memory_ = nullptr;
29
30 public:
31 VKBuffer() = default;
32 virtual ~VKBuffer();
33
35 bool is_allocated() const;
36 bool create(size_t size,
37 GPUUsageType usage,
38 VkBufferUsageFlags buffer_usage,
39 bool is_host_visible = true);
40 void clear(VKContext &context, uint32_t clear_value);
41 void update_immediately(const void *data) const;
42
47 void update_render_graph(VKContext &context, void *data) const;
48 void flush() const;
49 void read(VKContext &context, void *data) const;
50
57 bool free();
58
62 void free_immediately(VKDevice &device);
63
65 {
66 return size_in_bytes_;
67 }
68
69 VkBuffer vk_handle() const
70 {
71 return vk_buffer_;
72 }
73
79 void *mapped_memory_get() const;
80
84 bool is_mapped() const;
85
86 private:
88 bool map();
89 void unmap();
90};
91
98 const VkBuffer buffer;
99 VkDeviceSize offset;
100};
101
102} // namespace blender::gpu
void update_immediately(const void *data) const
Definition vk_buffer.cc:109
bool is_allocated() const
Definition vk_buffer.cc:22
bool create(size_t size, GPUUsageType usage, VkBufferUsageFlags buffer_usage, bool is_host_visible=true)
Definition vk_buffer.cc:53
bool is_mapped() const
Definition vk_buffer.cc:157
void read(VKContext &context, void *data) const
Definition vk_buffer.cc:142
VkBuffer vk_handle() const
Definition vk_buffer.hh:69
void free_immediately(VKDevice &device)
Definition vk_buffer.cc:195
void clear(VKContext &context, uint32_t clear_value)
Definition vk_buffer.cc:133
void update_render_graph(VKContext &context, void *data) const
Definition vk_buffer.cc:116
void * mapped_memory_get() const
Definition vk_buffer.cc:151
int64_t size_in_bytes() const
Definition vk_buffer.hh:64
unsigned int uint32_t
Definition stdint.h:80
__int64 int64_t
Definition stdint.h:89