Merge branch 'sync' into sneed

This commit is contained in:
Vindicus999
2026-07-25 22:36:30 -04:00
25 changed files with 829 additions and 620 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{};
+6 -3
View File
@@ -572,9 +572,12 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
ts_pool = gpu_timestamp_pool(vk, encode_queue.family_index, num_slots, std::format("vulkan encoder {} encode", stream_idx));
if (tmp_image)
ts_pool_image_copy = gpu_timestamp_pool(vk, encode_queue.family_index, num_slots, std::format("vulkan encoder {} image-copy", stream_idx));
const uint32_t host_copy_family = vk.transfer_queue ? vk.transfer_queue.family_index : encode_queue.family_index;
ts_pool_host_copy = gpu_timestamp_pool(vk, host_copy_family, num_slots, std::format("vulkan encoder {} host-copy", stream_idx));
ts_pool_host_copy_overflow = gpu_timestamp_pool(vk, host_copy_family, num_slots, std::format("vulkan encoder {} host-copy-overflow", stream_idx));
if (slot_data[0].host_buffer)
{
const uint32_t host_copy_family = vk.transfer_queue ? vk.transfer_queue.family_index : encode_queue.family_index;
ts_pool_host_copy = gpu_timestamp_pool(vk, host_copy_family, num_slots, std::format("vulkan encoder {} host-copy", stream_idx));
ts_pool_host_copy_overflow = gpu_timestamp_pool(vk, host_copy_family, num_slots, std::format("vulkan encoder {} host-copy-overflow", stream_idx));
}
// command pools
{
+3 -1
View File
@@ -53,6 +53,7 @@ namespace wivrn::trace
namespace
{
bool initialized = false;
bool enabled = false;
::vk_bundle * calibration = nullptr;
perfetto::Track g_encoder_track(1);
@@ -266,6 +267,7 @@ void init()
U_LOG_D("wivrn::trace: WIVRN_TRACING not set, perfetto tracing disabled");
return;
}
enabled = true;
const bool use_system = mode == tracing_mode::system or mode == tracing_mode::both;
const bool use_inprocess = mode == tracing_mode::inprocess or mode == tracing_mode::both;
@@ -321,7 +323,7 @@ void shutdown()
bool is_enabled()
{
return initialized;
return enabled;
}
void set_calibration_source(::vk_bundle * monado_vk)
+37 -1
View File
@@ -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