Vulkan: Add initial VkPixelBuffer. #105741

Merged
Jeroen Bakker merged 2 commits from Jeroen-Bakker/blender:vulkan-pixel-buffer into main 2023-03-13 19:25:30 +01:00
4 changed files with 27 additions and 2 deletions

View File

@ -90,6 +90,12 @@ void VKBuffer::read(void *data) const
memcpy(data, mapped_memory_, size_in_bytes_);
}
void *VKBuffer::mapped_memory_get() const
{
BLI_assert_msg(is_mapped(), "Cannot access a non-mapped buffer.");
return mapped_memory_;
}
bool VKBuffer::is_mapped() const
{
return mapped_memory_ != nullptr;

View File

@ -49,6 +49,13 @@ class VKBuffer {
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;
private:
/** Check if this buffer is mapped. */
bool is_mapped() const;

View File

@ -11,20 +11,28 @@ namespace blender::gpu {
VKPixelBuffer::VKPixelBuffer(int64_t size) : PixelBuffer(size)
{
VKContext &context = *VKContext::get();
buffer_.create(context,
size,
GPU_USAGE_STATIC,
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT));
}
void *VKPixelBuffer::map()
{
return nullptr;
/* Vulkan buffers are always mapped between allocation and freeing. */
return buffer_.mapped_memory_get();
}
void VKPixelBuffer::unmap()
{
/* Vulkan buffers are always mapped between allocation and freeing. */
}
int64_t VKPixelBuffer::get_native_handle()
{
return -1;
return int64_t(buffer_.vk_handle());
}
uint VKPixelBuffer::get_size()

View File

@ -9,9 +9,13 @@
#include "gpu_texture_private.hh"
#include "vk_buffer.hh"
namespace blender::gpu {
class VKPixelBuffer : public PixelBuffer {
VKBuffer buffer_;
public:
VKPixelBuffer(int64_t size);
void *map() override;