mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-28 21:07:00 -08:00
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:
1 parent
7e6618bf7c
commit
f22a100ef0
2 files changed
+41
-13
No files matched your search
@@ -81,17 +81,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];
|
||||
@@ -723,8 +712,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{};
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <cstdint>
|
||||
#include <inplace_vector.hpp>
|
||||
#include <mutex>
|
||||
#include <pthread.h>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
@@ -62,9 +63,44 @@ uint64_t vk_handle(const T & handle)
|
||||
|
||||
struct vk_bundle
|
||||
{
|
||||
// Lockable that can be redirected to a pthread_mutex_t owned by monado,
|
||||
// so that all VkQueue submitters take the same lock.
|
||||
class queue_mutex
|
||||
{
|
||||
pthread_mutex_t storage = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t * mutex = &storage;
|
||||
|
||||
public:
|
||||
queue_mutex() = default;
|
||||
queue_mutex(const queue_mutex &) = delete;
|
||||
queue_mutex & operator=(const queue_mutex &) = delete;
|
||||
~queue_mutex()
|
||||
{
|
||||
pthread_mutex_destroy(&storage);
|
||||
}
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
bool try_lock()
|
||||
{
|
||||
return pthread_mutex_trylock(mutex) == 0;
|
||||
}
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
// external must be initialized, not currently locked, and
|
||||
// outlive the last lock()
|
||||
void share(pthread_mutex_t & external)
|
||||
{
|
||||
mutex = &external;
|
||||
}
|
||||
};
|
||||
|
||||
struct queue_data
|
||||
{
|
||||
std::mutex mutex;
|
||||
queue_mutex mutex;
|
||||
vk::raii::Queue queue = nullptr;
|
||||
uint32_t family_index = vk::QueueFamilyIgnored;
|
||||
operator bool() const
|
||||
|
||||
Reference in new issue
Block a user