[Mesa-dev] [PATCH] [rfc] radv: optimise bo descriptor updates for non-local bos.

Dave Airlie airlied at gmail.com
Mon Nov 6 07:39:11 UTC 2017


From: Dave Airlie <airlied at redhat.com>

This might be a bit over optimising.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/amd/vulkan/radv_cmd_buffer.c     |  9 +++---
 src/amd/vulkan/radv_descriptor_set.c | 55 +++++++++++++++++++++++-------------
 src/amd/vulkan/radv_private.h        |  1 +
 3 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 62adbaced10..cd642dbf690 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -2295,10 +2295,11 @@ radv_bind_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
 
 	assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
 
-	for (unsigned j = 0; j < set->layout->buffer_count; ++j)
-		if (set->descriptors[j])
-			radv_cs_add_buffer(ws, cmd_buffer->cs, set->descriptors[j], 7);
-
+	if (set->has_non_local_bo_descriptor) {
+		for (unsigned j = 0; j < set->layout->buffer_count; ++j)
+			if (set->descriptors[j])
+				radv_cs_add_buffer(ws, cmd_buffer->cs, set->descriptors[j], 7);
+	}
 	if(set->bo)
 		radv_cs_add_buffer(ws, cmd_buffer->cs, set->bo, 8);
 }
diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c
index a98ff37ced6..2595ff5cdc5 100644
--- a/src/amd/vulkan/radv_descriptor_set.c
+++ b/src/amd/vulkan/radv_descriptor_set.c
@@ -555,23 +555,27 @@ VkResult radv_FreeDescriptorSets(
 	return VK_SUCCESS;
 }
 
-static void write_texel_buffer_descriptor(struct radv_device *device,
+static bool write_texel_buffer_descriptor(struct radv_device *device,
 					  struct radv_cmd_buffer *cmd_buffer,
 					  unsigned *dst,
 					  struct radeon_winsys_bo **buffer_list,
 					  const VkBufferView _buffer_view)
 {
 	RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
-
+	bool ret = false;
 	memcpy(dst, buffer_view->state, 4 * 4);
 
 	if (cmd_buffer)
 		radv_cs_add_buffer(device->ws, cmd_buffer->cs, buffer_view->bo, 7);
-	else
+	else {
 		*buffer_list = buffer_view->bo;
+		if (buffer_view->bo->is_local)
+			ret = true;
+	}
+	return ret;
 }
 
-static void write_buffer_descriptor(struct radv_device *device,
+static bool write_buffer_descriptor(struct radv_device *device,
                                     struct radv_cmd_buffer *cmd_buffer,
                                     unsigned *dst,
                                     struct radeon_winsys_bo **buffer_list,
@@ -580,7 +584,7 @@ static void write_buffer_descriptor(struct radv_device *device,
 	RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
 	uint64_t va = radv_buffer_get_va(buffer->bo);
 	uint32_t range = buffer_info->range;
-
+	bool is_local = true;
 	if (buffer_info->range == VK_WHOLE_SIZE)
 		range = buffer->size - buffer_info->offset;
 
@@ -597,11 +601,14 @@ static void write_buffer_descriptor(struct radv_device *device,
 
 	if (cmd_buffer)
 		radv_cs_add_buffer(device->ws, cmd_buffer->cs, buffer->bo, 7);
-	else
+	else {
 		*buffer_list = buffer->bo;
+		is_local = buffer->bo->is_local;
+	}
+	return is_local;
 }
 
-static void write_dynamic_buffer_descriptor(struct radv_device *device,
+static bool write_dynamic_buffer_descriptor(struct radv_device *device,
                                             struct radv_descriptor_range *range,
                                             struct radeon_winsys_bo **buffer_list,
                                             const VkDescriptorBufferInfo *buffer_info)
@@ -618,9 +625,10 @@ static void write_dynamic_buffer_descriptor(struct radv_device *device,
 	range->size = size;
 
 	*buffer_list = buffer->bo;
+	return buffer->bo->is_local;
 }
 
-static void
+static bool
 write_image_descriptor(struct radv_device *device,
 		       struct radv_cmd_buffer *cmd_buffer,
 		       unsigned *dst,
@@ -629,7 +637,7 @@ write_image_descriptor(struct radv_device *device,
 		       const VkDescriptorImageInfo *image_info)
 {
 	RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
-
+	bool ret = true;
 	if (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
 		memcpy(dst, iview->storage_descriptor, 8 * 4);
 		memcpy(dst + 8, iview->storage_fmask_descriptor, 8 * 4);
@@ -640,11 +648,14 @@ write_image_descriptor(struct radv_device *device,
 
 	if (cmd_buffer)
 		radv_cs_add_buffer(device->ws, cmd_buffer->cs, iview->bo, 7);
-	else
+	else {
 		*buffer_list = iview->bo;
+		ret = iview->bo->is_local;
+	}
+	return ret;
 }
 
-static void
+static bool
 write_combined_image_sampler_descriptor(struct radv_device *device,
 					struct radv_cmd_buffer *cmd_buffer,
 					unsigned *dst,
@@ -654,11 +665,12 @@ write_combined_image_sampler_descriptor(struct radv_device *device,
 					bool has_sampler)
 {
 	RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
-
-	write_image_descriptor(device, cmd_buffer, dst, buffer_list, descriptor_type, image_info);
+	bool is_local;
+	is_local = write_image_descriptor(device, cmd_buffer, dst, buffer_list, descriptor_type, image_info);
 	/* copy over sampler state */
 	if (has_sampler)
 		memcpy(dst + 16, sampler->state, 16);
+	return is_local;
 }
 
 static void
@@ -689,6 +701,7 @@ void radv_update_descriptor_sets(
 			set->layout->binding + writeset->dstBinding;
 		uint32_t *ptr = set->mapped_ptr;
 		struct radeon_winsys_bo **buffer_list =  set->descriptors;
+		bool is_local = true;
 		/* Immutable samplers are not copied into push descriptors when they are
 		 * allocated, so if we are writing push descriptors we have to copy the
 		 * immutable samplers into them now.
@@ -708,29 +721,29 @@ void radv_update_descriptor_sets(
 				unsigned idx = writeset->dstArrayElement + j;
 				idx += binding_layout->dynamic_offset_offset;
 				assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
-				write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
+				is_local = write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
 								buffer_list, writeset->pBufferInfo + j);
 				break;
 			}
 			case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
 			case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
-				write_buffer_descriptor(device, cmd_buffer, ptr, buffer_list,
-							writeset->pBufferInfo + j);
+				is_local = write_buffer_descriptor(device, cmd_buffer, ptr, buffer_list,
+								   writeset->pBufferInfo + j);
 				break;
 			case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
 			case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-				write_texel_buffer_descriptor(device, cmd_buffer, ptr, buffer_list,
-							      writeset->pTexelBufferView[j]);
+				is_local = write_texel_buffer_descriptor(device, cmd_buffer, ptr, buffer_list,
+									 writeset->pTexelBufferView[j]);
 				break;
 			case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
 			case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
 			case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
-				write_image_descriptor(device, cmd_buffer, ptr, buffer_list,
+				is_local = write_image_descriptor(device, cmd_buffer, ptr, buffer_list,
 						       writeset->descriptorType,
 						       writeset->pImageInfo + j);
 				break;
 			case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-				write_combined_image_sampler_descriptor(device, cmd_buffer, ptr, buffer_list,
+				is_local = write_combined_image_sampler_descriptor(device, cmd_buffer, ptr, buffer_list,
 									writeset->descriptorType,
 									writeset->pImageInfo + j,
 									!binding_layout->immutable_samplers_offset);
@@ -754,6 +767,8 @@ void radv_update_descriptor_sets(
 			}
 			ptr += binding_layout->size / 4;
 			++buffer_list;
+			if (is_local == false)
+				set->has_non_local_bo_descriptor = true;
 		}
 
 	}
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index c2c1f6056da..5ba13f4836e 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -606,6 +606,7 @@ struct radv_descriptor_range {
 struct radv_descriptor_set {
 	const struct radv_descriptor_set_layout *layout;
 	uint32_t size;
+	bool has_non_local_bo_descriptor;
 
 	struct radeon_winsys_bo *bo;
 	uint64_t va;
-- 
2.14.2



More information about the mesa-dev mailing list