Blender V4.5
vk_staging_buffer.cc
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
10#include "vk_context.hh"
11
12namespace blender::gpu {
13
15 Direction direction,
16 VkDeviceSize device_buffer_offset,
17 VkDeviceSize region_size)
18 : device_buffer_(device_buffer),
19 device_buffer_offset_(device_buffer_offset),
20 region_size_(region_size == UINT64_MAX ? device_buffer.size_in_bytes() : region_size)
21{
22 VkBufferUsageFlags usage;
23 switch (direction) {
25 usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
26 break;
28 usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
29 }
30
31 host_buffer_.create(region_size_,
32 usage,
33 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
34 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
35 VMA_ALLOCATION_CREATE_MAPPED_BIT |
36 VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
37 0.4f);
38 debug::object_label(host_buffer_.vk_handle(), "StagingBuffer");
39}
40
42{
43 BLI_assert(host_buffer_.is_allocated() && host_buffer_.is_mapped());
45 copy_buffer.src_buffer = host_buffer_.vk_handle();
46 copy_buffer.dst_buffer = device_buffer_.vk_handle();
47 copy_buffer.region.dstOffset = device_buffer_offset_;
48 copy_buffer.region.size = region_size_;
49
50 context.render_graph().add_node(copy_buffer);
51}
52
54{
55 BLI_assert(host_buffer_.is_allocated() && host_buffer_.is_mapped());
57 copy_buffer.src_buffer = device_buffer_.vk_handle();
58 copy_buffer.dst_buffer = host_buffer_.vk_handle();
59 copy_buffer.region.srcOffset = device_buffer_offset_;
60 copy_buffer.region.size = region_size_;
61
62 context.render_graph().add_node(copy_buffer);
63}
64
66{
67 host_buffer_.free();
68}
69
70} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:46
VKStagingBuffer(const VKBuffer &device_buffer, Direction direction, VkDeviceSize device_buffer_offset=0, VkDeviceSize region_size=UINT64_MAX)
void copy_from_device(VKContext &context)
void copy_to_device(VKContext &context)
#define UINT64_MAX
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:329