From fb237bddadb937ded6fd7bfb0f5bb9e061fdaaa2 Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 16:02:49 +0200 Subject: [PATCH 1/7] libraries: libc: fix for `FSin` implementation --- src/core/libraries/libc/libc_math.cpp | 10 ++++++++-- src/core/libraries/libc/libc_math.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/libraries/libc/libc_math.cpp b/src/core/libraries/libc/libc_math.cpp index 281585c6..3b51c80e 100644 --- a/src/core/libraries/libc/libc_math.cpp +++ b/src/core/libraries/libc/libc_math.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include "common/assert.h" #include "core/libraries/libc/libc_math.h" namespace Libraries::LibC { @@ -38,8 +39,13 @@ double PS4_SYSV_ABI ps4__Sin(double x) { return sin(x); } -float PS4_SYSV_ABI ps4__Fsin(float arg) { - return sinf(arg); +float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int m, int n) { + ASSERT(n == 0); + if (m != 0) { + return cosf(arg); + } else { + return sinf(arg); + } } double PS4_SYSV_ABI ps4_exp2(double arg) { diff --git a/src/core/libraries/libc/libc_math.h b/src/core/libraries/libc/libc_math.h index 83af029e..70e2f99b 100644 --- a/src/core/libraries/libc/libc_math.h +++ b/src/core/libraries/libc/libc_math.h @@ -13,7 +13,7 @@ float PS4_SYSV_ABI ps4_tanf(float num); float PS4_SYSV_ABI ps4_asinf(float num); double PS4_SYSV_ABI ps4_pow(double base, double exponent); double PS4_SYSV_ABI ps4__Sin(double x); -float PS4_SYSV_ABI ps4__Fsin(float arg); +float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int,int); double PS4_SYSV_ABI ps4_exp2(double arg); float PS4_SYSV_ABI ps4_powf(float x, float y); float PS4_SYSV_ABI ps4_roundf(float arg); From e5486cc57f9dfa6cf46803c776561361ec511186 Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 12:47:40 +0200 Subject: [PATCH 2/7] video_core: amdgpu: proper destruction of processing thread --- src/video_core/amdgpu/liverpool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 50e5398f..ae5bd4bc 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -19,6 +19,7 @@ Liverpool::Liverpool() { Liverpool::~Liverpool() { process_thread.request_stop(); cv_submit.notify_one(); + process_thread.join(); } void Liverpool::Process(std::stop_token stoken) { From db113bbc7b3a05d836943d42d44b2d81f9cc7661 Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 12:48:21 +0200 Subject: [PATCH 3/7] videoout, platform: fix for ooo irqs --- src/core/libraries/videoout/driver.h | 2 +- src/core/libraries/videoout/video_out.cpp | 1 + src/core/platform.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/videoout/driver.h b/src/core/libraries/videoout/driver.h index e3a2667b..d98e62ee 100644 --- a/src/core/libraries/videoout/driver.h +++ b/src/core/libraries/videoout/driver.h @@ -18,7 +18,7 @@ struct VideoOutPort { bool is_open = false; SceVideoOutResolutionStatus resolution; std::array buffer_slots; - std::array buffer_labels; // should be contiguous in memory + std::array buffer_labels; // should be contiguous in memory static_assert(sizeof(buffer_labels[0]) == 8u); std::array groups; FlipStatus flip_status; diff --git a/src/core/libraries/videoout/video_out.cpp b/src/core/libraries/videoout/video_out.cpp index a1f971b5..bb19c586 100644 --- a/src/core/libraries/videoout/video_out.cpp +++ b/src/core/libraries/videoout/video_out.cpp @@ -251,6 +251,7 @@ s32 sceVideoOutSubmitEopFlip(s32 handle, u32 buf_id, u32 mode, u32 arg, void** u Platform::IrqC::Instance()->RegisterOnce( Platform::InterruptId::GfxFlip, [=](Platform::InterruptId irq) { ASSERT_MSG(irq == Platform::InterruptId::GfxFlip, "An unexpected IRQ occured"); + ASSERT_MSG(port->buffer_labels[buf_id] == 1, "Out of order flip IRQ"); const auto result = driver->SubmitFlip(port, buf_id, arg, true); ASSERT_MSG(result, "EOP flip submission failed"); }); diff --git a/src/core/platform.h b/src/core/platform.h index c8cc2a4f..d8064c52 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -66,7 +66,7 @@ struct IrqController { h(irq); } - while (!ctx.one_time_subscribers.empty()) { + if (!ctx.one_time_subscribers.empty()) { const auto& h = ctx.one_time_subscribers.front(); h(irq); From 5f37a6be83c7dd38cc2dc1513c05cdf1c2f951af Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 16:03:37 +0200 Subject: [PATCH 4/7] video_core: amdgpu: fix for a deadlock in wait on idle --- src/video_core/amdgpu/liverpool.cpp | 29 +++++++++++------------------ src/video_core/amdgpu/liverpool.h | 3 --- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index ae5bd4bc..163c1e31 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -18,7 +18,8 @@ Liverpool::Liverpool() { Liverpool::~Liverpool() { process_thread.request_stop(); - cv_submit.notify_one(); + num_submits = -1; + num_submits.notify_one(); process_thread.join(); } @@ -26,10 +27,7 @@ void Liverpool::Process(std::stop_token stoken) { Common::SetCurrentThreadName("GPU_CommandProcessor"); while (!stoken.stop_requested()) { - { - std::unique_lock lock{m_submit}; - cv_submit.wait(lock, stoken, [this]() { return num_submits != 0; }); - } + num_submits.wait(0); if (stoken.stop_requested()) { break; @@ -63,13 +61,14 @@ void Liverpool::Process(std::stop_token stoken) { --num_submits; } } - cv_complete.notify_all(); // Notify GPU idle + num_submits.notify_all(); } } void Liverpool::WaitGpuIdle() { - std::unique_lock lock{m_submit}; - cv_complete.wait(lock, [this]() { return num_submits == 0; }); + while (const auto old = num_submits.load()) { + num_submits.wait(old); + } } Liverpool::Task Liverpool::ProcessCeUpdate(std::span ccb) { @@ -309,11 +308,8 @@ void Liverpool::SubmitGfx(std::span dcb, std::span ccb) { queue.submits.emplace(task.handle); } - { - std::unique_lock lock{m_submit}; - ++num_submits; - } - cv_submit.notify_one(); + ++num_submits; + num_submits.notify_one(); } void Liverpool::SubmitAsc(u32 vqid, std::span acb) { @@ -326,11 +322,8 @@ void Liverpool::SubmitAsc(u32 vqid, std::span acb) { queue.submits.emplace(task.handle); } - { - std::unique_lock lock{m_submit}; - ++num_submits; - } - cv_submit.notify_one(); + ++num_submits; + num_submits.notify_one(); } } // namespace AmdGpu diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index 1ddf4fc9..ed9899f8 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -771,9 +771,6 @@ private: Vulkan::Rasterizer* rasterizer{}; std::jthread process_thread{}; - std::condition_variable_any cv_submit{}; - std::condition_variable cv_complete{}; - std::mutex m_submit{}; std::atomic num_submits{}; }; From a67b8f7a0b9204f78c7e4071e92a18c4b5fbe59e Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 17:06:46 +0200 Subject: [PATCH 5/7] video_core: renderer_vulkan: proper inclusion of maintenance4 --- src/video_core/renderer_vulkan/vk_instance.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_instance.cpp b/src/video_core/renderer_vulkan/vk_instance.cpp index da88ba4c..658d7a36 100644 --- a/src/video_core/renderer_vulkan/vk_instance.cpp +++ b/src/video_core/renderer_vulkan/vk_instance.cpp @@ -206,6 +206,7 @@ bool Instance::CreateDevice() { }, vk::PhysicalDeviceVulkan13Features{ .dynamicRendering = true, + .maintenance4 = true, }, vk::PhysicalDeviceCustomBorderColorFeaturesEXT{ .customBorderColors = true, @@ -214,9 +215,6 @@ bool Instance::CreateDevice() { vk::PhysicalDeviceIndexTypeUint8FeaturesEXT{ .indexTypeUint8 = true, }, - vk::PhysicalDeviceMaintenance4Features{ - .maintenance4 = true, - }, }; if (!index_type_uint8) { From 055dec11499f7f8e7d607642225a8daa5dbbd04e Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 17:17:24 +0200 Subject: [PATCH 6/7] video_core: texture_cache: proper `UniqueImage` class movers --- src/video_core/texture_cache/image.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/video_core/texture_cache/image.h b/src/video_core/texture_cache/image.h index 1f29d0d4..74c9cf5d 100644 --- a/src/video_core/texture_cache/image.h +++ b/src/video_core/texture_cache/image.h @@ -53,9 +53,14 @@ struct UniqueImage { UniqueImage(const UniqueImage&) = delete; UniqueImage& operator=(const UniqueImage&) = delete; - UniqueImage(UniqueImage&& other) : image{std::exchange(other.image, VK_NULL_HANDLE)} {} + UniqueImage(UniqueImage&& other) + : image{std::exchange(other.image, VK_NULL_HANDLE)}, + allocator{std::exchange(other.allocator, VK_NULL_HANDLE)}, + allocation{std::exchange(other.allocation, VK_NULL_HANDLE)} {} UniqueImage& operator=(UniqueImage&& other) { image = std::exchange(other.image, VK_NULL_HANDLE); + allocator = std::exchange(other.allocator, VK_NULL_HANDLE); + allocation = std::exchange(other.allocation, VK_NULL_HANDLE); return *this; } From 7fc273c6bc6817696364421cc1f88965e36e99a4 Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 29 May 2024 20:31:34 +0200 Subject: [PATCH 7/7] clang fmt --- src/core/libraries/libc/libc_math.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/libraries/libc/libc_math.h b/src/core/libraries/libc/libc_math.h index 70e2f99b..f73a33f1 100644 --- a/src/core/libraries/libc/libc_math.h +++ b/src/core/libraries/libc/libc_math.h @@ -13,7 +13,7 @@ float PS4_SYSV_ABI ps4_tanf(float num); float PS4_SYSV_ABI ps4_asinf(float num); double PS4_SYSV_ABI ps4_pow(double base, double exponent); double PS4_SYSV_ABI ps4__Sin(double x); -float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int,int); +float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int, int); double PS4_SYSV_ABI ps4_exp2(double arg); float PS4_SYSV_ABI ps4_powf(float x, float y); float PS4_SYSV_ABI ps4_roundf(float arg);