radv: When importing an image, redo the layout based on the metadata.

When importing a DMA-BUF, the image layout created in vkImageCreate may
not match the imported BO's. To make this work we redo the layout based
on the metadata of the imported image.

The original patch did a delayed allocation just as for AHB, but that
does not work for images that are not imported (but e.g. exported only).

Original patch by Simon Ser <contact@emersion.fr>

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2801
CC: mesa-stable
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6274>
This commit is contained in:
Bas Nieuwenhuizen 2020-05-04 17:04:00 +02:00 committed by Marge Bot
parent a0d67b7a1c
commit d19bc94e4e
2 changed files with 51 additions and 5 deletions

View File

@ -5079,6 +5079,26 @@ static VkResult radv_alloc_memory(struct radv_device *device,
} else {
close(import_info->fd);
}
if (mem->image && mem->image->plane_count == 1 &&
!vk_format_is_depth_or_stencil(mem->image->vk_format)) {
struct radeon_bo_metadata metadata;
device->ws->buffer_get_metadata(mem->bo, &metadata);
struct radv_image_create_info create_info = {
.no_metadata_planes = true,
.bo_metadata = &metadata
};
/* This gives a basic ability to import radeonsi images
* that don't have DCC. This is not guaranteed by any
* spec and can be removed after we support modifiers. */
result = radv_image_create_layout(device, create_info, mem->image);
if (result != VK_SUCCESS) {
device->ws->buffer_destroy(mem->bo);
goto fail;
}
}
} else if (host_ptr_info) {
assert(host_ptr_info->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT);
mem->bo = device->ws->buffer_from_ptr(device->ws, host_ptr_info->pHostPointer,

View File

@ -1283,14 +1283,40 @@ radv_image_alloc_values(const struct radv_device *device, struct radv_image *ima
}
}
static void
radv_image_reset_layout(struct radv_image *image)
{
image->size = 0;
image->alignment = 1;
image->tc_compatible_cmask = image->tc_compatible_htile = 0;
image->fce_pred_offset = image->dcc_pred_offset = 0;
image->clear_value_offset = image->tc_compat_zrange_offset = 0;
for (unsigned i = 0; i < image->plane_count; ++i) {
VkFormat format = vk_format_get_plane_format(image->vk_format, i);
uint32_t flags = image->planes[i].surface.flags;
memset(image->planes + i, 0, sizeof(image->planes[i]));
image->planes[i].surface.flags = flags;
image->planes[i].surface.blk_w = vk_format_get_blockwidth(format);
image->planes[i].surface.blk_h = vk_format_get_blockheight(format);
image->planes[i].surface.bpe = vk_format_get_blocksize(vk_format_depth_only(format));
/* align byte per element on dword */
if (image->planes[i].surface.bpe == 3) {
image->planes[i].surface.bpe = 4;
}
}
}
VkResult
radv_image_create_layout(struct radv_device *device,
struct radv_image_create_info create_info,
struct radv_image *image)
{
/* Check that we did not initialize things earlier */
assert(!image->planes[0].surface.surf_size);
/* Clear the pCreateInfo pointer so we catch issues in the delayed case when we test in the
* common internal case. */
create_info.vk_info = NULL;
@ -1300,8 +1326,8 @@ radv_image_create_layout(struct radv_device *device,
if (result != VK_SUCCESS)
return result;
image->size = 0;
image->alignment = 1;
radv_image_reset_layout(image);
for (unsigned plane = 0; plane < image->plane_count; ++plane) {
struct ac_surf_info info = image_info;