Files
test2/source/blender/gpu/vulkan/vk_vertex_buffer.hh
Jeroen Bakker 7de4e6d2ee Vulkan: Add support for ReBAR
This adds initial support for ReBAR capable platforms.

It ensures that when allocating buffers that should not be host visible, still
tries to allocate in host visible memory. When there is space in this memory
heap the buffer will be automatically mapped to host memory.

When mapped staging buffers can be skipped when the buffer was newly
created. In order to make better usage of ReBAR the `VKBuffer::create`
function will need to be revisit. It currently hides to much options to allocate
in the correct memory heap. This change isn't part of this PR.

Using shader_balls.blend rendering the first 50 frames in main takes 1516ms.
When using ReBAR it takes 1416ms.
```
Operating system: Linux-6.8.0-49-generic-x86_64-with-glibc2.39 64 Bits, X11 UI
Graphics card: AMD Radeon Pro W7700 (RADV NAVI32) Advanced Micro Devices radv Mesa 24.3.1 - kisak-mesa PPA Vulkan Backend
```

Pull Request: https://projects.blender.org/blender/blender/pulls/131856
2024-12-16 10:09:33 +01:00

76 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "GPU_vertex_buffer.hh"
#include "vk_buffer.hh"
#include "vk_data_conversion.hh"
namespace blender::gpu {
class VKVertexBuffer : public VertBuf {
VKBuffer buffer_;
/** When a vertex buffer is used as a UNIFORM_TEXEL_BUFFER the buffer requires a buffer view. */
VkBufferView vk_buffer_view_ = VK_NULL_HANDLE;
VertexFormatConverter vertex_format_converter;
bool data_uploaded_ = false;
public:
~VKVertexBuffer();
void bind_as_ssbo(uint binding) override;
void bind_as_texture(uint binding) override;
void wrap_handle(uint64_t handle) override;
void update_sub(uint start, uint len, const void *data) override;
void read(void *data) const override;
VkBuffer vk_handle() const
{
BLI_assert(buffer_.is_allocated());
return buffer_.vk_handle();
}
VkBufferView vk_buffer_view_get() const
{
BLI_assert(vk_buffer_view_ != VK_NULL_HANDLE);
return vk_buffer_view_;
}
void device_format_ensure();
const GPUVertFormat &device_format_get() const;
void ensure_updated();
void ensure_buffer_view();
protected:
void acquire_data() override;
void resize_data() override;
void release_data() override;
void upload_data() override;
void duplicate_data(VertBuf *dst) override;
private:
void allocate();
void upload_data_direct(const VKBuffer &host_buffer);
void upload_data_via_staging_buffer(VKContext &context);
/* VKTexture requires access to `buffer_` to convert a vertex buffer to a texture. */
friend class VKTexture;
};
BLI_INLINE VKVertexBuffer *unwrap(VertBuf *vertex_buffer)
{
return static_cast<VKVertexBuffer *>(vertex_buffer);
}
} // namespace blender::gpu