Fix main queue synchronization with monado

copy_mutex duplicated the pthread_mutex_t of vk.queue.mutex into
main_queue->mutex by value, which creates an independent mutex: monado
submissions on IPC client threads (comp_swapchain image transitions,
vkDeviceWaitIdle in image_cleanup) did not exclude wivrn's layer_commit
and encoder submissions on the same VkQueue. This intermittently
corrupts driver state when a client creates or destroys swapchains
while streaming, observed as SIGSEGV inside vkQueueSubmit2 and as
uncaught vk::SystemError from layer_commit on NVIDIA.

Initialize monado's queue mutexes and redirect vk.queue.mutex to the
main queue os_mutex so every submitter takes the same lock.
This commit is contained in:
umceko
2026-07-14 09:25:35 +02:00
committed by xytovl
parent bcf4645b88
commit e57577d675
2 changed files with 41 additions and 13 deletions
+4 -12
View File
@@ -82,17 +82,6 @@ struct method_trait<Method, Result (wivrn::compositor::*)(Args...)>
namespace
{
os_mutex copy_mutex(std::mutex & m)
{
return {
.mutex = *m.native_handle(),
#ifndef NDEBUG
.initialized = true,
.recursive = false,
#endif
};
}
const comp_swapchain_image & get_layer_image(const comp_layer & layer, uint32_t swapchain_index, uint32_t image_index)
{
return reinterpret_cast<struct comp_swapchain *>(comp_layer_get_swapchain(&layer, swapchain_index))->images[image_index];
@@ -735,8 +724,11 @@ compositor::compositor(wivrn_session & session) :
// vk_init_from_given assumes a graphics queue was provided
c_base->vk.graphics_queue = nullptr;
// Monado submits to the main queue from IPC client threads under
// main_queue->mutex: our own submissions must take the same lock.
vk::detail::resultCheck(vk::Result(vk_init_mutex(&c_base->vk)), "vk_init_mutex");
if (c_base->vk.main_queue)
c_base->vk.main_queue->mutex = copy_mutex(vk.queue.mutex);
vk.queue.mutex.share(c_base->vk.main_queue->mutex.mutex);
{
comp_vulkan_formats formats{};