v3dv: implement VK_KHR_bind_memory2

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11001>
This commit is contained in:
Iago Toral Quiroga 2021-05-25 13:21:55 +02:00 committed by Marge Bot
parent ea003df98e
commit 5283c6d47b
3 changed files with 45 additions and 28 deletions

View File

@ -422,7 +422,7 @@ Vulkan 1.0 -- all DONE: anv, lvp, radv, tu, v3dv, vn
Vulkan 1.1 -- all DONE: anv, lvp, radv, tu, vn
VK_KHR_16bit_storage DONE (anv/gen8+, lvp, radv, tu/a650, vn)
VK_KHR_bind_memory2 DONE (anv, lvp, radv, tu, vn)
VK_KHR_bind_memory2 DONE (anv, lvp, radv, tu, v3dv, vn)
VK_KHR_dedicated_allocation DONE (anv, lvp, radv, tu, vn)
VK_KHR_descriptor_update_template DONE (anv, lvp, radv, tu, vn)
VK_KHR_device_group DONE (lvp, tu, vn)

View File

@ -130,6 +130,7 @@ get_device_extensions(const struct v3dv_physical_device *device,
struct vk_device_extension_table *ext)
{
*ext = (struct vk_device_extension_table) {
.KHR_bind_memory2 = true,
.KHR_external_memory = true,
.KHR_external_memory_fd = true,
.KHR_maintenance1 = true,
@ -1977,14 +1978,11 @@ v3dv_GetImageMemoryRequirements(VkDevice _device,
pMemoryRequirements->memoryTypeBits = 0x1;
}
VkResult
v3dv_BindImageMemory(VkDevice _device,
VkImage _image,
VkDeviceMemory _memory,
VkDeviceSize memoryOffset)
static void
bind_image_memory(const VkBindImageMemoryInfo *info)
{
V3DV_FROM_HANDLE(v3dv_device_memory, mem, _memory);
V3DV_FROM_HANDLE(v3dv_image, image, _image);
V3DV_FROM_HANDLE(v3dv_image, image, info->image);
V3DV_FROM_HANDLE(v3dv_device_memory, mem, info->memory);
/* Valid usage:
*
@ -1992,11 +1990,20 @@ v3dv_BindImageMemory(VkDevice _device,
* the VkMemoryRequirements structure returned from a call to
* vkGetImageMemoryRequirements with image"
*/
assert(memoryOffset % image->alignment == 0);
assert(memoryOffset < mem->bo->size);
assert(info->memoryOffset % image->alignment == 0);
assert(info->memoryOffset < mem->bo->size);
image->mem = mem;
image->mem_offset = memoryOffset;
image->mem_offset = info->memoryOffset;
}
VkResult
v3dv_BindImageMemory2(VkDevice _device,
uint32_t bindInfoCount,
const VkBindImageMemoryInfo *pBindInfos)
{
for (uint32_t i = 0; i < bindInfoCount; i++)
bind_image_memory(&pBindInfos[i]);
return VK_SUCCESS;
}
@ -2014,14 +2021,11 @@ v3dv_GetBufferMemoryRequirements(VkDevice _device,
align64(buffer->size, pMemoryRequirements->alignment);
}
VkResult
v3dv_BindBufferMemory(VkDevice _device,
VkBuffer _buffer,
VkDeviceMemory _memory,
VkDeviceSize memoryOffset)
static void
bind_buffer_memory(const VkBindBufferMemoryInfo *info)
{
V3DV_FROM_HANDLE(v3dv_device_memory, mem, _memory);
V3DV_FROM_HANDLE(v3dv_buffer, buffer, _buffer);
V3DV_FROM_HANDLE(v3dv_buffer, buffer, info->buffer);
V3DV_FROM_HANDLE(v3dv_device_memory, mem, info->memory);
/* Valid usage:
*
@ -2029,11 +2033,21 @@ v3dv_BindBufferMemory(VkDevice _device,
* the VkMemoryRequirements structure returned from a call to
* vkGetBufferMemoryRequirements with buffer"
*/
assert(memoryOffset % buffer->alignment == 0);
assert(memoryOffset < mem->bo->size);
assert(info->memoryOffset % buffer->alignment == 0);
assert(info->memoryOffset < mem->bo->size);
buffer->mem = mem;
buffer->mem_offset = memoryOffset;
buffer->mem_offset = info->memoryOffset;
}
VkResult
v3dv_BindBufferMemory2(VkDevice device,
uint32_t bindInfoCount,
const VkBindBufferMemoryInfo *pBindInfos)
{
for (uint32_t i = 0; i < bindInfoCount; i++)
bind_buffer_memory(&pBindInfos[i]);
return VK_SUCCESS;
}

View File

@ -27,6 +27,7 @@
#include "broadcom/cle/v3dx_pack.h"
#include "vk_format_info.h"
#include "util/u_pack_color.h"
#include "vulkan/util/vk_common_entrypoints.h"
static uint32_t
meta_blit_key_hash(const void *key)
@ -1118,9 +1119,10 @@ copy_image_to_buffer_blit(struct v3dv_cmd_buffer *cmd_buffer,
cmd_buffer, (uintptr_t)uiview,
(v3dv_cmd_buffer_private_obj_destroy_cb)v3dv_DestroyImage);
result = v3dv_BindImageMemory(_device, uiview,
v3dv_device_memory_to_handle(image->mem),
image->mem_offset);
result =
vk_common_BindImageMemory(_device, uiview,
v3dv_device_memory_to_handle(image->mem),
image->mem_offset);
if (result != VK_SUCCESS)
return handled;
@ -1158,9 +1160,10 @@ copy_image_to_buffer_blit(struct v3dv_cmd_buffer *cmd_buffer,
/* Bind the buffer memory to the image */
VkDeviceSize buffer_offset = buffer->mem_offset + region->bufferOffset +
i * buf_width * buf_height * buffer_bpp;
result = v3dv_BindImageMemory(_device, buffer_image,
v3dv_device_memory_to_handle(buffer->mem),
buffer_offset);
result =
vk_common_BindImageMemory(_device, buffer_image,
v3dv_device_memory_to_handle(buffer->mem),
buffer_offset);
if (result != VK_SUCCESS)
return handled;
@ -3741,7 +3744,7 @@ copy_buffer_to_image_blit(struct v3dv_cmd_buffer *cmd_buffer,
cmd_buffer, (uintptr_t)buffer_image,
(v3dv_cmd_buffer_private_obj_destroy_cb)v3dv_DestroyImage);
result = v3dv_BindImageMemory(_device, buffer_image, mem, 0);
result = vk_common_BindImageMemory(_device, buffer_image, mem, 0);
if (result != VK_SUCCESS)
return handled;