Mesa (main): vk/sync: add asserts for timeline semaphore count matching

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 8 04:41:22 UTC 2022


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Jan 26 15:14:43 2022 -0500

vk/sync: add asserts for timeline semaphore count matching

spec requires that the number of timeline waits/signals matches the
base number of waits/signals if there are any timeline semaphores
being processed by the submit, so asserting here is in line with what
validation will yield

failure to match these will also hang every driver I've tested, so asserting
here potentially saves some people their desktop session

Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14741>

---

 src/vulkan/runtime/vk_queue.c            | 34 ++++++++++++++++++++++++++----
 src/vulkan/runtime/vk_synchronization2.c | 36 ++++++++++++++++++++++++++------
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/src/vulkan/runtime/vk_queue.c b/src/vulkan/runtime/vk_queue.c
index a1ff0ba0283..61488320bd9 100644
--- a/src/vulkan/runtime/vk_queue.c
+++ b/src/vulkan/runtime/vk_queue.c
@@ -1158,10 +1158,36 @@ vk_common_QueueBindSparse(VkQueue _queue,
    for (uint32_t i = 0; i < bindInfoCount; i++) {
       const VkTimelineSemaphoreSubmitInfo *timeline_info =
          vk_find_struct_const(pBindInfo[i].pNext, TIMELINE_SEMAPHORE_SUBMIT_INFO);
-      const uint64_t *wait_values = timeline_info &&
-         timeline_info->waitSemaphoreValueCount ? timeline_info->pWaitSemaphoreValues : NULL;
-      const uint64_t *signal_values = timeline_info &&
-         timeline_info->signalSemaphoreValueCount ? timeline_info->pSignalSemaphoreValues : NULL;
+      const uint64_t *wait_values = NULL;
+      const uint64_t *signal_values = NULL;
+
+      if (timeline_info && timeline_info->waitSemaphoreValueCount) {
+         /* From the Vulkan 1.3.204 spec:
+          *
+          *    VUID-VkBindSparseInfo-pNext-03248
+          *
+          *    "If the pNext chain of this structure includes a VkTimelineSemaphoreSubmitInfo structure
+          *    and any element of pSignalSemaphores was created with a VkSemaphoreType of
+          *    VK_SEMAPHORE_TYPE_TIMELINE, then its signalSemaphoreValueCount member must equal
+          *    signalSemaphoreCount"
+          */
+         assert(timeline_info->waitSemaphoreValueCount == pBindInfo[i].waitSemaphoreCount);
+         wait_values = timeline_info->pWaitSemaphoreValues;
+      }
+
+      if (timeline_info && timeline_info->signalSemaphoreValueCount) {
+         /* From the Vulkan 1.3.204 spec:
+          *
+          * VUID-VkBindSparseInfo-pNext-03247
+          *
+          *    "If the pNext chain of this structure includes a VkTimelineSemaphoreSubmitInfo structure
+          *    and any element of pWaitSemaphores was created with a VkSemaphoreType of
+          *    VK_SEMAPHORE_TYPE_TIMELINE, then its waitSemaphoreValueCount member must equal
+          *    waitSemaphoreCount"
+          */
+         assert(timeline_info->signalSemaphoreValueCount == pBindInfo[i].signalSemaphoreCount);
+         signal_values = timeline_info->pSignalSemaphoreValues;
+      }
 
       STACK_ARRAY(VkSemaphoreSubmitInfoKHR, wait_semaphore_infos,
                   pBindInfo[i].waitSemaphoreCount);
diff --git a/src/vulkan/runtime/vk_synchronization2.c b/src/vulkan/runtime/vk_synchronization2.c
index 0ad796c7b5b..aead366ce17 100644
--- a/src/vulkan/runtime/vk_synchronization2.c
+++ b/src/vulkan/runtime/vk_synchronization2.c
@@ -315,12 +315,36 @@ vk_common_QueueSubmit(
       const VkTimelineSemaphoreSubmitInfoKHR *timeline_info =
          vk_find_struct_const(pSubmits[s].pNext,
                               TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR);
-      const uint64_t *wait_values =
-         timeline_info && timeline_info->waitSemaphoreValueCount ?
-         timeline_info->pWaitSemaphoreValues : NULL;
-      const uint64_t *signal_values =
-         timeline_info && timeline_info->signalSemaphoreValueCount ?
-         timeline_info->pSignalSemaphoreValues : NULL;
+      const uint64_t *wait_values = NULL;
+      const uint64_t *signal_values = NULL;
+
+      if (timeline_info && timeline_info->waitSemaphoreValueCount) {
+         /* From the Vulkan 1.3.204 spec:
+          *
+          *    VUID-VkSubmitInfo-pNext-03240
+          *
+          *    "If the pNext chain of this structure includes a VkTimelineSemaphoreSubmitInfo structure
+          *    and any element of pSignalSemaphores was created with a VkSemaphoreType of
+          *    VK_SEMAPHORE_TYPE_TIMELINE, then its signalSemaphoreValueCount member must equal
+          *    signalSemaphoreCount"
+          */
+         assert(timeline_info->waitSemaphoreValueCount == pSubmits[s].waitSemaphoreCount);
+         wait_values = timeline_info->pWaitSemaphoreValues;
+      }
+
+      if (timeline_info && timeline_info->signalSemaphoreValueCount) {
+         /* From the Vulkan 1.3.204 spec:
+          *
+          *    VUID-VkSubmitInfo-pNext-03241
+          *
+          *    "If the pNext chain of this structure includes a VkTimelineSemaphoreSubmitInfo structure
+          *    and any element of pWaitSemaphores was created with a VkSemaphoreType of
+          *    VK_SEMAPHORE_TYPE_TIMELINE, then its waitSemaphoreValueCount member must equal
+          *    waitSemaphoreCount"
+          */
+         assert(timeline_info->signalSemaphoreValueCount == pSubmits[s].signalSemaphoreCount);
+         signal_values = timeline_info->pSignalSemaphoreValues;
+      }
 
       const VkDeviceGroupSubmitInfo *group_info =
          vk_find_struct_const(pSubmits[s].pNext, DEVICE_GROUP_SUBMIT_INFO);



More information about the mesa-commit mailing list