From 96cceac511adccc77b9334e3fbc6e83098e0fbb0 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 12 Jul 2024 10:27:57 -0700 Subject: [PATCH] gfxstream: guest: make sure signalSemaphoreValueCount is correct 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" Internally, Mesa WSI creates placeholder semaphores/fences (see transformVkSemaphore functions in in gfxstream_vk_private.cpp). We don't want to forward that to the host, since there is no host side Vulkan object associated with the placeholder sync objects. The way to test this behavior is Zink + glxgears, on Linux hosts. It should fail without this check. Reviewed-by: Aaron Ruby Acked-by: Yonggang Luo Acked-by: Adam Jackson Part-of: --- .../guest/vulkan_enc/ResourceTracker.cpp | 29 +++++++++++++++++++ src/gfxstream/guest/vulkan_enc/vk_struct_id.h | 3 ++ 2 files changed, 32 insertions(+) diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp index 25679202793..142a3b756d9 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp @@ -5982,6 +5982,35 @@ VkResult ResourceTracker::on_vkQueueSubmit(void* context, VkResult input_result, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) { AEMU_SCOPED_TRACE("on_vkQueueSubmit"); + + /* 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" + * + * Internally, Mesa WSI creates placeholder semaphores/fences (see transformVkSemaphore functions + * in in gfxstream_vk_private.cpp). We don't want to forward that to the host, since there is + * no host side Vulkan object associated with the placeholder sync objects. + * + * The way to test this behavior is Zink + glxgears, on Linux hosts. It should fail without + * this check. + */ + for (uint32_t i = 0; i < submitCount; i++) { + VkTimelineSemaphoreSubmitInfo* tssi = const_cast( + vk_find_struct(&pSubmits[i])); + + if (tssi) { + uint32_t count = getSignalSemaphoreCount(pSubmits[i]); + if (count != tssi->signalSemaphoreValueCount) { + tssi->signalSemaphoreValueCount = count; + } + } + } + return on_vkQueueSubmitTemplate(context, input_result, queue, submitCount, pSubmits, fence); } diff --git a/src/gfxstream/guest/vulkan_enc/vk_struct_id.h b/src/gfxstream/guest/vulkan_enc/vk_struct_id.h index 5d43282ab0d..e7a6e608bfc 100644 --- a/src/gfxstream/guest/vulkan_enc/vk_struct_id.h +++ b/src/gfxstream/guest/vulkan_enc/vk_struct_id.h @@ -129,6 +129,9 @@ REGISTER_VK_STRUCT_ID(VkDeviceCreateInfo, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); REGISTER_VK_STRUCT_ID(VkPhysicalDeviceGroupProperties, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES); REGISTER_VK_STRUCT_ID(VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT); +REGISTER_VK_STRUCT_ID(VkSubmitInfo, VK_STRUCTURE_TYPE_SUBMIT_INFO); +REGISTER_VK_STRUCT_ID(VkTimelineSemaphoreSubmitInfo, + VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO); #if defined(LINUX_GUEST_BUILD) REGISTER_VK_STRUCT_ID(wsi_image_create_info, VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA); #endif