From 5691cf7e917052f11f3439d32f6d147e80e0fb69 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 3 Mar 2024 01:43:28 +0200 Subject: [PATCH 1/2] y2r: Delay completion event --- src/core/hle/service/cam/y2r_u.cpp | 19 +++++++++++++++++-- src/core/hle/service/cam/y2r_u.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/cam/y2r_u.cpp b/src/core/hle/service/cam/y2r_u.cpp index 266cf2e929..65c4376dc4 100644 --- a/src/core/hle/service/cam/y2r_u.cpp +++ b/src/core/hle/service/cam/y2r_u.cpp @@ -522,7 +522,13 @@ void Y2R_U::StartConversion(Kernel::HLERequestContext& ctx) { HW::Y2R::PerformConversion(system.Memory(), conversion); - completion_event->Signal(); + if (is_busy_conversion) { + system.CoreTiming().RemoveEvent(completion_signal_event); + } + + static constexpr s64 MinY2RDelay = 20000; + system.CoreTiming().ScheduleEvent(MinY2RDelay, completion_signal_event); + is_busy_conversion = true; IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultSuccess); @@ -533,6 +539,10 @@ void Y2R_U::StartConversion(Kernel::HLERequestContext& ctx) { void Y2R_U::StopConversion(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); + if (is_busy_conversion) { + system.CoreTiming().RemoveEvent(completion_signal_event); + } + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultSuccess); @@ -544,7 +554,7 @@ void Y2R_U::IsBusyConversion(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(ResultSuccess); - rb.Push(0); // StartConversion always finishes immediately + rb.Push(is_busy_conversion); LOG_DEBUG(Service_Y2R, "called"); } @@ -697,6 +707,11 @@ Y2R_U::Y2R_U(Core::System& system) : ServiceFramework("y2r:u", 1), system(system RegisterHandlers(functions); completion_event = system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "Y2R:Completed"); + completion_signal_event = + system.CoreTiming().RegisterEvent("Y2R Completion Signal Event", [this](uintptr_t, s64) { + completion_event->Signal(); + is_busy_conversion = false; + }); } Y2R_U::~Y2R_U() = default; diff --git a/src/core/hle/service/cam/y2r_u.h b/src/core/hle/service/cam/y2r_u.h index b8757cd776..f15af8c409 100644 --- a/src/core/hle/service/cam/y2r_u.h +++ b/src/core/hle/service/cam/y2r_u.h @@ -349,11 +349,13 @@ private: Core::System& system; std::shared_ptr completion_event; + Core::TimingEventType* completion_signal_event; ConversionConfiguration conversion{}; DitheringWeightParams dithering_weight_params{}; bool temporal_dithering_enabled = false; bool transfer_end_interrupt_enabled = false; bool spacial_dithering_enabled = false; + bool is_busy_conversion = false; template void serialize(Archive& ar, const unsigned int); From db3da09d8592bc4a81caa9c0ab44b7374823fa3f Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 3 Mar 2024 02:32:37 +0200 Subject: [PATCH 2/2] y2r: Remove goto --- src/core/hle/service/cam/y2r_u.cpp | 54 +++++++++++++++++------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/core/hle/service/cam/y2r_u.cpp b/src/core/hle/service/cam/y2r_u.cpp index 65c4376dc4..10194f8538 100644 --- a/src/core/hle/service/cam/y2r_u.cpp +++ b/src/core/hle/service/cam/y2r_u.cpp @@ -7,6 +7,7 @@ #include "common/archives.h" #include "common/common_funcs.h" #include "common/logging/log.h" +#include "common/scope_exit.h" #include "core/core.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/event.h" @@ -526,7 +527,10 @@ void Y2R_U::StartConversion(Kernel::HLERequestContext& ctx) { system.CoreTiming().RemoveEvent(completion_signal_event); } - static constexpr s64 MinY2RDelay = 20000; + // This value has been estimated as the minimum amount of cycles to resolve a race condition + // in the intro cutscene of the FIFA series of games. + // TODO: Measure the cycle count more accurately based on hardware. + static constexpr s64 MinY2RDelay = 50000; system.CoreTiming().ScheduleEvent(MinY2RDelay, completion_signal_event); is_busy_conversion = true; @@ -568,34 +572,38 @@ void Y2R_U::SetPackageParameter(Kernel::HLERequestContext& ctx) { conversion.rotation = params.rotation; conversion.block_alignment = params.block_alignment; - Result result = conversion.SetInputLineWidth(params.input_line_width); - - if (result.IsError()) - goto cleanup; - - result = conversion.SetInputLines(params.input_lines); - - if (result.IsError()) - goto cleanup; - - result = conversion.SetStandardCoefficient(params.standard_coefficient); - - if (result.IsError()) - goto cleanup; - - conversion.padding = params.padding; - conversion.alpha = params.alpha; - -cleanup: - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(result); - LOG_DEBUG(Service_Y2R, "called input_format={} output_format={} rotation={} block_alignment={} " "input_line_width={} input_lines={} standard_coefficient={} reserved={} alpha={:X}", params.input_format, params.output_format, params.rotation, params.block_alignment, params.input_line_width, params.input_lines, params.standard_coefficient, params.padding, params.alpha); + + auto result = conversion.SetInputLineWidth(params.input_line_width); + + SCOPE_EXIT({ + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(result); + }); + + if (result.IsError()) { + return; + } + + result = conversion.SetInputLines(params.input_lines); + + if (result.IsError()) { + return; + } + + result = conversion.SetStandardCoefficient(params.standard_coefficient); + + if (result.IsError()) { + return; + } + + conversion.padding = params.padding; + conversion.alpha = params.alpha; } void Y2R_U::PingProcess(Kernel::HLERequestContext& ctx) {