diff --git a/source/blender/gpu/vulkan/vk_buffer.cc b/source/blender/gpu/vulkan/vk_buffer.cc index 134190c11d0..a5afcde7162 100644 --- a/source/blender/gpu/vulkan/vk_buffer.cc +++ b/source/blender/gpu/vulkan/vk_buffer.cc @@ -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; diff --git a/source/blender/gpu/vulkan/vk_buffer.hh b/source/blender/gpu/vulkan/vk_buffer.hh index 2cbd7f1205b..917103114a5 100644 --- a/source/blender/gpu/vulkan/vk_buffer.hh +++ b/source/blender/gpu/vulkan/vk_buffer.hh @@ -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; diff --git a/source/blender/gpu/vulkan/vk_pixel_buffer.cc b/source/blender/gpu/vulkan/vk_pixel_buffer.cc index 609c6ec68a8..f673d444f27 100644 --- a/source/blender/gpu/vulkan/vk_pixel_buffer.cc +++ b/source/blender/gpu/vulkan/vk_pixel_buffer.cc @@ -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(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() diff --git a/source/blender/gpu/vulkan/vk_pixel_buffer.hh b/source/blender/gpu/vulkan/vk_pixel_buffer.hh index 7ea1529fd46..c5430444052 100644 --- a/source/blender/gpu/vulkan/vk_pixel_buffer.hh +++ b/source/blender/gpu/vulkan/vk_pixel_buffer.hh @@ -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;