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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 18 17:43:32 UTC 2020


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

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 7963f23b4b6..4d911d08f20 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1552,7 +1552,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 51529225202..18726aabb28 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -5060,6 +5060,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 3ec9817cc3a..1673a903ae1 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -1273,14 +1273,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;
@@ -1290,8 +1316,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