From 3fead131a6cb21f27d50bf9eb543b004d4a44f1f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 5 Nov 2026 01:55:26 -0600 Subject: [PATCH] Dynamically enable VK_KHR_internally_synchronized_queues for libplacebo v7.387.0 This is now disabled by default in libplacebo and must be explicitly enabled when the application knows that all other code sharing the device has been enlightened about the new queue synchronization flags. Since we know that Gamescope's WSI doesn't handle these new flags correctly, we will disable internally synchronized queues when that layer is present. See ValveSoftware/gamescope#2261 --- app/streaming/video/ffmpeg-renderers/plvk.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/streaming/video/ffmpeg-renderers/plvk.cpp b/app/streaming/video/ffmpeg-renderers/plvk.cpp index 07ccce8f..48081e6f 100644 --- a/app/streaming/video/ffmpeg-renderers/plvk.cpp +++ b/app/streaming/video/ffmpeg-renderers/plvk.cpp @@ -2,6 +2,7 @@ #include "streaming/session.h" #include "streaming/streamutils.h" +#include "utils.h" // Implementation in plvk_c.c #define PL_LIBAV_IMPLEMENTATION 0 @@ -375,6 +376,41 @@ bool PlVkRenderer::tryInitializeDevice(VkPhysicalDevice device, VkPhysicalDevice vkParams.extra_queues = VK_QUEUE_FLAG_BITS_MAX_ENUM; } +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(60, 31, 101) && defined(VK_KHR_internally_synchronized_queues) + // libplacebo needs explicit opt-in to use internally synchronized queues, since + // it requires cooperation with the app (ex: using vkGetDeviceQueue2). We know + // FFmpeg 9.0+ always wants internally synchronized queues if available, so we + // will turn it on when supported by the physical device. + if (isExtensionSupportedByPhysicalDevice(device, "VK_KHR_internally_synchronized_queues")) { + bool internallySynchronizedQueues; + if (!Utils::getEnvironmentVariableOverride("PLVK_INT_SYNC_QUEUES", &internallySynchronizedQueues)) { +#if LIBAVUTIL_VERSION_MAJOR < 62 + // The Gamescope WSI layer currently breaks apps using internally synchronized queues + // (failing to use vkGetDeviceQueue2), so we disable this feature when the Gamescope + // WSI layer is enabled. See gamescope#2261 for details. + internallySynchronizedQueues = (qEnvironmentVariableIntValue("ENABLE_GAMESCOPE_WSI") == 0 || + qEnvironmentVariableIntValue("DISABLE_GAMESCOPE_WSI") == 1); +#else + // We have no choice but to enable it since the queue locking callbacks are gone + internallySynchronizedQueues = true; +#endif + } + + static VkPhysicalDeviceInternallySynchronizedQueuesFeaturesKHR featInternalSyncQueues = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INTERNALLY_SYNCHRONIZED_QUEUES_FEATURES_KHR, + nullptr, + internallySynchronizedQueues, + }; + + static const VkPhysicalDeviceFeatures2 features = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + (void*)&featInternalSyncQueues, + }; + + vkParams.features = &features; + } +#endif + { // Don't let Qt take DRM master from us during pl_vulkan_create() DrmMasterLocker locker;