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:
@@ -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