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

Author: Tatsuyuki Ishi <ishitatsuy...@gmail.com>
Date:   Sat Dec  2 14:17:27 2023 +0900

radv: Add workaround to allow sparse binding on gfx queues.

For working around improper usage of sparse in DOOM Eternal.

When fully explicit sync sparse binding is implemented, this path will
remain implicit sync to also deal with the improper semaphore usage.
radv_queue_submit_bind_sparse_memory will likely get a bool parameter to
control explicit / implicit sync in that case.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26464>

---

 src/amd/vulkan/layers/radv_sqtt_layer.c |  3 +++
 src/amd/vulkan/radv_instance.c          |  3 +++
 src/amd/vulkan/radv_physical_device.c   | 10 ++++++++--
 src/amd/vulkan/radv_private.h           |  1 +
 src/amd/vulkan/radv_queue.c             |  9 +++++++++
 src/util/driconf.h                      |  4 ++++
 6 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/amd/vulkan/layers/radv_sqtt_layer.c 
b/src/amd/vulkan/layers/radv_sqtt_layer.c
index 2707b32d785..35626c4f184 100644
--- a/src/amd/vulkan/layers/radv_sqtt_layer.c
+++ b/src/amd/vulkan/layers/radv_sqtt_layer.c
@@ -338,6 +338,9 @@ radv_describe_begin_cmd_buffer(struct radv_cmd_buffer 
*cmd_buffer)
    if (cmd_buffer->qf == RADV_QUEUE_GENERAL)
       marker.queue_flags |= VK_QUEUE_GRAPHICS_BIT;
 
+   if (cmd_buffer->device->instance->legacy_sparse_binding)
+      marker.queue_flags |= VK_QUEUE_SPARSE_BINDING_BIT;
+
    radv_emit_sqtt_userdata(cmd_buffer, &marker, sizeof(marker) / 4);
 }
 
diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c
index 370e16a6083..9f005f923a4 100644
--- a/src/amd/vulkan/radv_instance.c
+++ b/src/amd/vulkan/radv_instance.c
@@ -152,6 +152,7 @@ static const driOptionDescription radv_dri_options[] = {
       DRI_CONF_RADV_TEX_NON_UNIFORM(false)
       DRI_CONF_RADV_FLUSH_BEFORE_TIMESTAMP_WRITE(false)
       DRI_CONF_RADV_RT_WAVE64(false)
+      DRI_CONF_RADV_LEGACY_SPARSE_BINDING(false)
       DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION(false)
       DRI_CONF_RADV_OVERRIDE_GRAPHICS_SHADER_VERSION(0)
       DRI_CONF_RADV_OVERRIDE_COMPUTE_SHADER_VERSION(0)
@@ -215,6 +216,8 @@ radv_init_dri_options(struct radv_instance *instance)
 
    instance->dual_color_blend_by_location = 
driQueryOptionb(&instance->dri_options, "dual_color_blend_by_location");
 
+   instance->legacy_sparse_binding = driQueryOptionb(&instance->dri_options, 
"radv_legacy_sparse_binding");
+
    instance->override_graphics_shader_version =
       driQueryOptioni(&instance->dri_options, 
"radv_override_graphics_shader_version");
    instance->override_compute_shader_version =
diff --git a/src/amd/vulkan/radv_physical_device.c 
b/src/amd/vulkan/radv_physical_device.c
index 26161212289..6b31daab971 100644
--- a/src/amd/vulkan/radv_physical_device.c
+++ b/src/amd/vulkan/radv_physical_device.c
@@ -2092,8 +2092,11 @@ radv_get_physical_device_queue_family_properties(struct 
radv_physical_device *pd
 
    idx = 0;
    if (*pCount >= 1) {
+      VkQueueFlags gfx_flags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | 
VK_QUEUE_TRANSFER_BIT;
+      if (pdevice->instance->legacy_sparse_binding)
+         gfx_flags |= VK_QUEUE_SPARSE_BINDING_BIT;
       *pQueueFamilyProperties[idx] = (VkQueueFamilyProperties){
-         .queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | 
VK_QUEUE_TRANSFER_BIT,
+         .queueFlags = gfx_flags,
          .queueCount = 1,
          .timestampValidBits = 64,
          .minImageTransferGranularity = (VkExtent3D){1, 1, 1},
@@ -2103,9 +2106,12 @@ radv_get_physical_device_queue_family_properties(struct 
radv_physical_device *pd
 
    if (pdevice->rad_info.ip[AMD_IP_COMPUTE].num_queues > 0 &&
        !(pdevice->instance->debug_flags & RADV_DEBUG_NO_COMPUTE_QUEUE)) {
+      VkQueueFlags compute_flags = VK_QUEUE_COMPUTE_BIT | 
VK_QUEUE_TRANSFER_BIT;
+      if (pdevice->instance->legacy_sparse_binding)
+         compute_flags |= VK_QUEUE_SPARSE_BINDING_BIT;
       if (*pCount > idx) {
          *pQueueFamilyProperties[idx] = (VkQueueFamilyProperties){
-            .queueFlags = VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT,
+            .queueFlags = compute_flags,
             .queueCount = pdevice->rad_info.ip[AMD_IP_COMPUTE].num_queues,
             .timestampValidBits = 64,
             .minImageTransferGranularity = (VkExtent3D){1, 1, 1},
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index ea1232a382d..36959847e84 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -423,6 +423,7 @@ struct radv_instance {
    bool flush_before_timestamp_write;
    bool force_rt_wave64;
    bool dual_color_blend_by_location;
+   bool legacy_sparse_binding;
    char *app_layer;
    uint8_t override_graphics_shader_version;
    uint8_t override_compute_shader_version;
diff --git a/src/amd/vulkan/radv_queue.c b/src/amd/vulkan/radv_queue.c
index 85aa03c2125..294e49b1013 100644
--- a/src/amd/vulkan/radv_queue.c
+++ b/src/amd/vulkan/radv_queue.c
@@ -1728,6 +1728,14 @@ radv_queue_submit(struct vk_queue *vqueue, struct 
vk_queue_submit *submission)
    struct radv_queue *queue = (struct radv_queue *)vqueue;
    VkResult result;
 
+   if (queue->device->instance->legacy_sparse_binding) {
+      result = radv_queue_submit_bind_sparse_memory(queue->device, submission);
+      if (result != VK_SUCCESS)
+         goto fail;
+   } else {
+      assert(!submission->buffer_bind_count && !submission->image_bind_count 
&& !submission->image_opaque_bind_count);
+   }
+
    if (!submission->command_buffer_count && !submission->wait_count && 
!submission->signal_count)
       return VK_SUCCESS;
 
@@ -1737,6 +1745,7 @@ radv_queue_submit(struct vk_queue *vqueue, struct 
vk_queue_submit *submission)
       result = radv_queue_submit_normal(queue, submission);
    }
 
+fail:
    if (result != VK_SUCCESS && result != VK_ERROR_DEVICE_LOST) {
       /* When something bad happened during the submission, such as
        * an out of memory issue, it might be hard to recover from
diff --git a/src/util/driconf.h b/src/util/driconf.h
index 702ed78df03..c67acf8cc4d 100644
--- a/src/util/driconf.h
+++ b/src/util/driconf.h
@@ -686,6 +686,10 @@
    DRI_CONF_OPT_B(radv_rt_wave64, def, \
                   "Force wave64 in RT shaders")
 
+#define DRI_CONF_RADV_LEGACY_SPARSE_BINDING(def) \
+   DRI_CONF_OPT_B(radv_legacy_sparse_binding, def, \
+                  "Enable legacy sparse binding (with implicit 
synchronization) on the graphics and compute queue")
+
 /**
  * Overrides for forcing re-compilation of pipelines when 
RADV_BUILD_ID_OVERRIDE is enabled.
  * These need to be bumped every time a compiler bugfix is backported (up to 8 
shader

Reply via email to