diff --git a/OptiScaler/nvapi/fakenvapi/low_latency.cpp b/OptiScaler/nvapi/fakenvapi/low_latency.cpp index 652a477e..9e30ff54 100644 --- a/OptiScaler/nvapi/fakenvapi/low_latency.cpp +++ b/OptiScaler/nvapi/fakenvapi/low_latency.cpp @@ -17,6 +17,8 @@ void LowLatency::update_effective_fg_state() void LowLatency::update_enabled_override() { + std::scoped_lock lock(active_tech_mutex); + if (!currently_active_tech) return; diff --git a/OptiScaler/nvapi/fakenvapi/low_latency_d3d.cpp b/OptiScaler/nvapi/fakenvapi/low_latency_d3d.cpp index ad6212cf..afe72212 100644 --- a/OptiScaler/nvapi/fakenvapi/low_latency_d3d.cpp +++ b/OptiScaler/nvapi/fakenvapi/low_latency_d3d.cpp @@ -208,6 +208,8 @@ NvAPI_Status LowLatency::Sleep(IUnknown* pDevice) if (!update_low_latency_tech(pDevice)) return ERROR(); + // Make deinit wait for sleep to finish + std::scoped_lock lock(active_tech_mutex); currently_active_tech->sleep(); return OK(); @@ -262,6 +264,10 @@ NvAPI_Status LowLatency::SetLatencyMarker(IUnknown* pDev, NV_LATENCY_MARKER_PARA marker_params.frame_id = pSetLatencyMarkerParams->frameID; marker_params.marker_type = (MarkerType) pSetLatencyMarkerParams->markerType; // requires enums to match + // We can't mutex using the same one here as for sleep + // This would make for example Present markers unable to mark during sleep + // std::scoped_lock lock(active_tech_mutex); + currently_active_tech->set_marker(pDev, &marker_params); LOG_TRACE_FAKENVAPI("{}: {}", magic_enum::enum_name(marker_params.marker_type), marker_params.frame_id); diff --git a/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.cpp b/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.cpp index 830a991f..9278d913 100644 --- a/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.cpp +++ b/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.cpp @@ -4,8 +4,6 @@ inline HRESULT AntiLag2::al2_sleep() { - std::scoped_lock lock(sleep_mutex); - int max_fps = 0; // TODO: test more, config for this? @@ -125,9 +123,6 @@ bool AntiLag2::init_using_ctx(void* context) void AntiLag2::deinit() { - // Wait for sleep to finish - std::scoped_lock lock(sleep_mutex); - if (inited_using_context) { LOG_INFO("AntiLag 2 DX12 deinit called while inited using context, skipping deinitialization"); diff --git a/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.h b/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.h index c924db39..2290c130 100644 --- a/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.h +++ b/OptiScaler/nvapi/fakenvapi/low_latency_tech/ll_antilag2.h @@ -12,7 +12,6 @@ class AntiLag2 : public virtual LowLatencyTech AMD::AntiLag2DX11::Context dx11_ctx = {}; std::mutex amdxc64_load_mutex; - std::mutex sleep_mutex; uint64_t amdxc64_load_times = 0; uint32_t minimum_interval_us = 0; diff --git a/OptiScaler/nvapi/fakenvapi/low_latency_vk.cpp b/OptiScaler/nvapi/fakenvapi/low_latency_vk.cpp index fa19df92..647106f8 100644 --- a/OptiScaler/nvapi/fakenvapi/low_latency_vk.cpp +++ b/OptiScaler/nvapi/fakenvapi/low_latency_vk.cpp @@ -163,6 +163,8 @@ NvAPI_Status LowLatency::Sleep(HANDLE vkDevice) if (!update_low_latency_tech(vkDevice)) return ERROR(); + // Make deinit wait for sleep to finish + std::scoped_lock lock(active_tech_mutex); currently_active_tech->sleep(); return OK(); @@ -215,6 +217,10 @@ NvAPI_Status LowLatency::SetLatencyMarker(HANDLE vkDevice, NV_VULKAN_LATENCY_MAR marker_params.frame_id = pSetLatencyMarkerParams->frameID; marker_params.marker_type = (MarkerType) pSetLatencyMarkerParams->markerType; // requires enums to match + // We can't mutex using the same one here as for sleep + // This would make for example Present markers unable to mark during sleep + // std::scoped_lock lock(active_tech_mutex); + // This cast is not ideal as it needs to be cast to VkDevice while knowing it's vulkan currently_active_tech->set_marker((IUnknown*) vkDevice, &marker_params);