Mesa (staging/20.1): radv: When importing an image, redo the layout based on the metadata.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 14 12:10:11 UTC 2020


Module: Mesa
Branch: staging/20.1
Commit: df9c4ea203ebe8d84645d378e63e349bdd1a31cb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=df9c4ea203ebe8d84645d378e63e349bdd1a31cb

Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date:   Mon May  4 17:04:00 2020 +0200

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 at emersion.fr>

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2801
CC: mesa-stable
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6274>
(cherry picked from commit d19bc94e4eb94a2c8cbdb328c9eaa2faf1ba424c)

---

 .pick_status.json            |  2 +-
 src/amd/vulkan/radv_device.c | 20 ++++++++++++++++++++
 src/amd/vulkan/radv_image.c  | 36 +++++++++++++++++++++++++++++++-----
 3 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index f15c7533f08..b270a624539 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -13,7 +13,7 @@
         "description": "radv: When importing an image, redo the layout based on the metadata.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": null
     },
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 803f48e6664..2c9fab9bec0 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -5206,6 +5206,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,
diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index a71bf8a8d0a..2ccb72f562c 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -1353,14 +1353,40 @@ static void radv_image_disable_htile(struct radv_image *image)
 		image->planes[i].surface.htile_size = 0;
 }
 
+
+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;
@@ -1370,8 +1396,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;
 



More information about the mesa-commit mailing list