Mesa (master): radv: Add WSI buffers to BO list only if they can be used.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 27 18:12:24 UTC 2020


Module: Mesa
Branch: master
Commit: cbeda7f78e36caa7e4ca775bd848e1c8d38ee5d7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cbeda7f78e36caa7e4ca775bd848e1c8d38ee5d7

Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date:   Tue Mar 24 17:59:26 2020 +0100

radv: Add WSI buffers to BO list only if they can be used.

Also reverse the BO list removal loop. This way typical WSI usage
should find the entry in O(active swapchains) iterations, which
should not be a performance issues. Tested with Doom(2106) which
found the entry in 1 iteration every time.

Acked-by: Jason Ekstrand <jason at jlekstrand.net>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4306>

---

 src/amd/vulkan/radv_device.c  | 20 ++++++++++++--------
 src/amd/vulkan/radv_private.h |  5 +++++
 src/amd/vulkan/radv_wsi.c     | 31 +++++++++++++++++++++++++------
 3 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index b51d7325df8..c34674d0904 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -2231,8 +2231,8 @@ radv_bo_list_finish(struct radv_bo_list *bo_list)
 	pthread_mutex_destroy(&bo_list->mutex);
 }
 
-static VkResult radv_bo_list_add(struct radv_device *device,
-				 struct radeon_winsys_bo *bo)
+VkResult radv_bo_list_add(struct radv_device *device,
+			  struct radeon_winsys_bo *bo)
 {
 	struct radv_bo_list *bo_list = &device->bo_list;
 
@@ -2261,8 +2261,8 @@ static VkResult radv_bo_list_add(struct radv_device *device,
 	return VK_SUCCESS;
 }
 
-static void radv_bo_list_remove(struct radv_device *device,
-				struct radeon_winsys_bo *bo)
+void radv_bo_list_remove(struct radv_device *device,
+			 struct radeon_winsys_bo *bo)
 {
 	struct radv_bo_list *bo_list = &device->bo_list;
 
@@ -2273,7 +2273,9 @@ static void radv_bo_list_remove(struct radv_device *device,
 		return;
 
 	pthread_mutex_lock(&bo_list->mutex);
-	for(unsigned i = 0; i < bo_list->list.count; ++i) {
+	/* Loop the list backwards so we find the most recently added
+	 * memory first. */
+	for(unsigned i = bo_list->list.count; i-- > 0;) {
 		if (bo_list->list.bos[i] == bo) {
 			bo_list->list.bos[i] = bo_list->list.bos[bo_list->list.count - 1];
 			--bo_list->list.count;
@@ -5241,9 +5243,11 @@ static VkResult radv_alloc_memory(struct radv_device *device,
 		mem->type_index = mem_type_index;
 	}
 
-	result = radv_bo_list_add(device, mem->bo);
-	if (result != VK_SUCCESS)
-		goto fail;
+	if (!wsi_info) {
+		result = radv_bo_list_add(device, mem->bo);
+		if (result != VK_SUCCESS)
+			goto fail;
+	}
 
 	*pMem = radv_device_memory_to_handle(mem);
 
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index f3abc431e87..7a51afcbccc 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -758,6 +758,11 @@ struct radv_bo_list {
 	pthread_mutex_t mutex;
 };
 
+VkResult radv_bo_list_add(struct radv_device *device,
+			  struct radeon_winsys_bo *bo);
+void radv_bo_list_remove(struct radv_device *device,
+			 struct radeon_winsys_bo *bo);
+
 struct radv_secure_compile_process {
 	/* Secure process file descriptors. Used to communicate between the
 	 * user facing device and the idle forked device used to fork a clean
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index 960b09700bb..d93b263e859 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -35,15 +35,34 @@ radv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
 	return radv_lookup_entrypoint(pName);
 }
 
+static void
+radv_wsi_set_memory_ownership(VkDevice _device,
+                              VkDeviceMemory _mem,
+                              VkBool32 ownership)
+{
+	RADV_FROM_HANDLE(radv_device, device, _device);
+	RADV_FROM_HANDLE(radv_device_memory, mem, _mem);
+
+	if (ownership)
+		radv_bo_list_add(device, mem->bo);
+	else
+		radv_bo_list_remove(device, mem->bo);
+}
+
 VkResult
 radv_init_wsi(struct radv_physical_device *physical_device)
 {
-	return wsi_device_init(&physical_device->wsi_device,
-			       radv_physical_device_to_handle(physical_device),
-			       radv_wsi_proc_addr,
-			       &physical_device->instance->alloc,
-			       physical_device->master_fd,
-			       &physical_device->instance->dri_options);
+	VkResult result =  wsi_device_init(&physical_device->wsi_device,
+					   radv_physical_device_to_handle(physical_device),
+					   radv_wsi_proc_addr,
+					   &physical_device->instance->alloc,
+					   physical_device->master_fd,
+					   &physical_device->instance->dri_options);
+	if (result != VK_SUCCESS)
+		return result;
+
+	physical_device->wsi_device.set_memory_ownership = radv_wsi_set_memory_ownership;
+	return VK_SUCCESS;
 }
 
 void



More information about the mesa-commit mailing list