A developer can switch `vk_common.hh#use_render_graph` to enable render graph. When enabled the buffers and images are tracked by the device resource state tracker. The storage buffer commands are recorded to the context render graph. The next unit tests will pass: - GPUVulkanTest.storage_buffer_create_update_read - GPUVulkanTest.storage_buffer_clear_zero - GPUVulkanTest.storage_buffer_clear - GPUVulkanTest.storage_buffer_copy_from_vertex_buffer The pattern to migrate to render graph is: - always construct CreateInfo for class. - based on `use_render_graph` call `context.command_buffers.something` or `context.render_graph.add_node`. - Hide calls to `context.flush` when `use_render_graph` is true. Pull Request: https://projects.blender.org/blender/blender/pulls/120812
86 lines
1.8 KiB
C++
86 lines
1.8 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "gpu_context_private.hh"
|
|
|
|
#include "vk_common.hh"
|
|
|
|
namespace blender::gpu {
|
|
class VKContext;
|
|
|
|
/**
|
|
* Class for handing vulkan buffers (allocation/updating/binding).
|
|
*/
|
|
class VKBuffer {
|
|
int64_t size_in_bytes_ = 0;
|
|
VkBuffer vk_buffer_ = VK_NULL_HANDLE;
|
|
VmaAllocation allocation_ = VK_NULL_HANDLE;
|
|
/* Pointer to the virtually mapped memory. */
|
|
void *mapped_memory_ = nullptr;
|
|
|
|
public:
|
|
VKBuffer() = default;
|
|
virtual ~VKBuffer();
|
|
|
|
/** Has this buffer been allocated? */
|
|
bool is_allocated() const;
|
|
bool create(int64_t size,
|
|
GPUUsageType usage,
|
|
VkBufferUsageFlags buffer_usage,
|
|
bool is_host_visible = true);
|
|
void clear(VKContext &context, uint32_t clear_value);
|
|
void update(const void *data) const;
|
|
void flush() const;
|
|
void read(VKContext &context, void *data) const;
|
|
bool free();
|
|
|
|
int64_t size_in_bytes() const
|
|
{
|
|
return size_in_bytes_;
|
|
}
|
|
|
|
VkBuffer vk_handle() const
|
|
{
|
|
return vk_buffer_;
|
|
}
|
|
|
|
/**
|
|
* Get the reference to the mapped memory.
|
|
*
|
|
* Can only be called when the buffer is (still) mapped.
|
|
*/
|
|
void *mapped_memory_get() const;
|
|
|
|
/**
|
|
* Is this buffer mapped (visible on host)
|
|
*/
|
|
bool is_mapped() const;
|
|
|
|
private:
|
|
/** Check if this buffer is mapped. */
|
|
bool map();
|
|
void unmap();
|
|
};
|
|
|
|
/**
|
|
* Helper struct to enable buffers to be bound with an offset.
|
|
*
|
|
* VKImmediate mode uses a single VKBuffer with multiple vertex layouts. Those layouts are send to
|
|
* the command buffer containing an offset.
|
|
*
|
|
* VKIndexBuffer uses this when it is a subrange of another buffer.
|
|
*/
|
|
struct VKBufferWithOffset {
|
|
const VKBuffer &buffer;
|
|
VkDeviceSize offset;
|
|
};
|
|
|
|
} // namespace blender::gpu
|