Files
test/source/blender/gpu/vulkan/vk_uniform_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

72 lines
1.4 KiB
C++

/* SPDX-FileCopyrightText: 2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "BLI_utility_mixins.hh"
#include "gpu_uniform_buffer_private.hh"
#include "vk_buffer.hh"
namespace blender::gpu {
class VKUniformBuffer : public UniformBuf, NonCopyable {
VKBuffer buffer_;
/**
* Has this uniform data already been fed with data. When so we are not allowed to directly
* overwrite the data as it could still be in use.
*/
bool data_uploaded_ = false;
public:
VKUniformBuffer(size_t size, const char *name) : UniformBuf(size, name) {}
void update(const void *data) override;
void clear_to_zero() override;
void bind(int slot) override;
void bind_as_ssbo(int slot) override;
/**
* Unbind uniform buffer from active context.
*/
void unbind() override;
VkBuffer vk_handle() const
{
return buffer_.vk_handle();
}
size_t size_in_bytes() const
{
return size_in_bytes_;
}
void ensure_updated();
/**
* Reset data uploaded flag. When the resource is sure it isn't used, the caller can call
* reset_data_uploaded so the next update can use ReBAR when available.
*/
void reset_data_uploaded()
{
data_uploaded_ = false;
}
private:
void allocate();
};
BLI_INLINE UniformBuf *wrap(VKUniformBuffer *uniform_buffer)
{
return static_cast<UniformBuf *>(uniform_buffer);
}
} // namespace blender::gpu