From ef9f0919091ac707c245704e1a3a2bed32f1e7d0 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Thu, 1 Feb 2024 20:55:50 +0800 Subject: [PATCH 1/5] Add Half Skip Mode May help #18607 --- Core/Config.h | 2 +- Core/ConfigValues.h | 1 + GPU/Common/FramebufferManagerCommon.cpp | 28 ++++++++++++++++++------- UI/GameSettingsScreen.cpp | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Core/Config.h b/Core/Config.h index a7a8c039f815..4b1e85578375 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -241,7 +241,7 @@ struct Config { float fCwCheatScrollPosition; float fGameListScrollPosition; int iBloomHack; //0 = off, 1 = safe, 2 = balanced, 3 = aggressive - int iSkipGPUReadbackMode; // 0 = off, 1 = skip, 2 = to texture + int iSkipGPUReadbackMode; // 0 = off, 1 = skip, 2 = to texture, 3 = half skip int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High bool bHardwareTessellation; bool bShaderCache; // Hidden ini-only setting, useful for debugging shader compile times. diff --git a/Core/ConfigValues.h b/Core/ConfigValues.h index 3e762d632ca9..e4be9dde4148 100644 --- a/Core/ConfigValues.h +++ b/Core/ConfigValues.h @@ -182,6 +182,7 @@ enum class SkipGPUReadbackMode : int { NO_SKIP, SKIP, COPY_TO_TEXTURE, + HALF_SKIP, }; enum class RemoteISOShareType : int { diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index f705277f5833..cc99a6fe1225 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -50,6 +50,16 @@ #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" +bool GenerateBoolean() { + int randomNumber = rand() % 100; // Generate a random number between 0 and 99 + if (randomNumber < 50) { + return true; // 50% chance of returning true + } + else { + return false; // 50% chance of returning false + } +} + static size_t FormatFramebufferName(const VirtualFramebuffer *vfb, char *tag, size_t len) { return snprintf(tag, len, "FB_%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, vfb->bufferWidth, vfb->bufferHeight, GeBufferFormatToString(vfb->fb_format)); } @@ -1032,12 +1042,14 @@ void FramebufferManagerCommon::DownloadFramebufferOnSwitch(VirtualFramebuffer *v // To support this, we save the first frame to memory when we have a safe w/h. // Saving each frame would be slow. - // TODO: This type of download could be made async, for less stutter on framebuffer creation. - if (g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP && !PSP_CoreParameter().compat.flags().DisableFirstFrameReadback) { - ReadFramebufferToMemory(vfb, 0, 0, vfb->safeWidth, vfb->safeHeight, RASTER_COLOR, Draw::ReadbackMode::BLOCK); - vfb->usageFlags = (vfb->usageFlags | FB_USAGE_DOWNLOAD | FB_USAGE_FIRST_FRAME_SAVED) & ~FB_USAGE_DOWNLOAD_CLEAR; - vfb->safeWidth = 0; - vfb->safeHeight = 0; + // TODO: This type of download could be made async, for less stutter on framebuffer creation. + if (!PSP_CoreParameter().compat.flags().DisableFirstFrameReadback) { + if (g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { + ReadFramebufferToMemory(vfb, 0, 0, vfb->safeWidth, vfb->safeHeight, RASTER_COLOR, Draw::ReadbackMode::BLOCK); + vfb->usageFlags = (vfb->usageFlags | FB_USAGE_DOWNLOAD | FB_USAGE_FIRST_FRAME_SAVED) & ~FB_USAGE_DOWNLOAD_CLEAR; + vfb->safeWidth = 0; + vfb->safeHeight = 0; + } } } } @@ -1047,9 +1059,9 @@ bool FramebufferManagerCommon::ShouldDownloadFramebufferColor(const VirtualFrame return PSP_CoreParameter().compat.flags().Force04154000Download && vfb->fb_address == 0x04154000; } -bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer *vfb) const { +bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer* vfb) const { // Download depth buffer for Syphon Filter lens flares - if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode != (int)SkipGPUReadbackMode::NO_SKIP) { + if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { return false; } return (vfb->usageFlags & FB_USAGE_RENDER_DEPTH) != 0 && vfb->width >= 480 && vfb->height >= 272; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 6b0c4dec2a2a..638cd5f94570 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -436,7 +436,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings) CheckBox *disableCulling = graphicsSettings->Add(new CheckBox(&g_Config.bDisableRangeCulling, gr->T("Disable culling"))); disableCulling->SetDisabledPtr(&g_Config.bSoftwareRendering); - static const char *skipGpuReadbackModes[] = { "No (default)", "Skip", "Copy to texture" }; + static const char *skipGpuReadbackModes[] = { "No (default)", "Skip", "Copy to texture" , "Half skip"}; PopupMultiChoice *skipGPUReadbacks = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iSkipGPUReadbackMode, gr->T("Skip GPU Readbacks"), skipGpuReadbackModes, 0, ARRAY_SIZE(skipGpuReadbackModes), I18NCat::GRAPHICS, screenManager())); skipGPUReadbacks->SetDisabledPtr(&g_Config.bSoftwareRendering); From 1c794d5223161dda25be8a3ff0084259947164f9 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Thu, 1 Feb 2024 20:59:01 +0800 Subject: [PATCH 2/5] oop --- GPU/Common/FramebufferManagerCommon.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index cc99a6fe1225..8b6d506876ee 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -1042,7 +1042,7 @@ void FramebufferManagerCommon::DownloadFramebufferOnSwitch(VirtualFramebuffer *v // To support this, we save the first frame to memory when we have a safe w/h. // Saving each frame would be slow. - // TODO: This type of download could be made async, for less stutter on framebuffer creation. + // TODO: This type of download could be made async, for less stutter on framebuffer creation. if (!PSP_CoreParameter().compat.flags().DisableFirstFrameReadback) { if (g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { ReadFramebufferToMemory(vfb, 0, 0, vfb->safeWidth, vfb->safeHeight, RASTER_COLOR, Draw::ReadbackMode::BLOCK); @@ -1059,7 +1059,7 @@ bool FramebufferManagerCommon::ShouldDownloadFramebufferColor(const VirtualFrame return PSP_CoreParameter().compat.flags().Force04154000Download && vfb->fb_address == 0x04154000; } -bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer* vfb) const { +bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer * vfb) const { // Download depth buffer for Syphon Filter lens flares if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { return false; From dd230b2d13442c8dc355e54c1b74608501514f5f Mon Sep 17 00:00:00 2001 From: sum2012 Date: Thu, 1 Feb 2024 21:02:26 +0800 Subject: [PATCH 3/5] oop 2 --- GPU/Common/FramebufferManagerCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 8b6d506876ee..e75625012029 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -1061,7 +1061,7 @@ bool FramebufferManagerCommon::ShouldDownloadFramebufferColor(const VirtualFrame bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer * vfb) const { // Download depth buffer for Syphon Filter lens flares - if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { + if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { return false; } return (vfb->usageFlags & FB_USAGE_RENDER_DEPTH) != 0 && vfb->width >= 480 && vfb->height >= 272; From f0f8c0477b2df0a15c549670ed215b67ec165d5e Mon Sep 17 00:00:00 2001 From: sum2012 Date: Thu, 1 Feb 2024 21:35:15 +0800 Subject: [PATCH 4/5] oop --- GPU/Common/FramebufferManagerCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index e75625012029..85ee5b2a2a6d 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -1059,7 +1059,7 @@ bool FramebufferManagerCommon::ShouldDownloadFramebufferColor(const VirtualFrame return PSP_CoreParameter().compat.flags().Force04154000Download && vfb->fb_address == 0x04154000; } -bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer * vfb) const { +bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer *vfb) const { // Download depth buffer for Syphon Filter lens flares if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { return false; From b06ff87e569db82fcfd43c3ebf60bf683094f372 Mon Sep 17 00:00:00 2001 From: sum2012 Date: Fri, 2 Feb 2024 06:05:44 +0800 Subject: [PATCH 5/5] Force half instead random --- GPU/Common/FramebufferManagerCommon.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 85ee5b2a2a6d..8fdf0a47e2ac 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -50,15 +50,8 @@ #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" -bool GenerateBoolean() { - int randomNumber = rand() % 100; // Generate a random number between 0 and 99 - if (randomNumber < 50) { - return true; // 50% chance of returning true - } - else { - return false; // 50% chance of returning false - } -} +bool HalfSkipDownloadFramebufferOnSwitch = false; +bool HalfSkipShouldDownloadFramebufferDepth = false; static size_t FormatFramebufferName(const VirtualFramebuffer *vfb, char *tag, size_t len) { return snprintf(tag, len, "FB_%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, vfb->bufferWidth, vfb->bufferHeight, GeBufferFormatToString(vfb->fb_format)); @@ -1043,8 +1036,9 @@ void FramebufferManagerCommon::DownloadFramebufferOnSwitch(VirtualFramebuffer *v // Saving each frame would be slow. // TODO: This type of download could be made async, for less stutter on framebuffer creation. + HalfSkipDownloadFramebufferOnSwitch = !HalfSkipDownloadFramebufferOnSwitch; if (!PSP_CoreParameter().compat.flags().DisableFirstFrameReadback) { - if (g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { + if (g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::NO_SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && HalfSkipDownloadFramebufferOnSwitch) { ReadFramebufferToMemory(vfb, 0, 0, vfb->safeWidth, vfb->safeHeight, RASTER_COLOR, Draw::ReadbackMode::BLOCK); vfb->usageFlags = (vfb->usageFlags | FB_USAGE_DOWNLOAD | FB_USAGE_FIRST_FRAME_SAVED) & ~FB_USAGE_DOWNLOAD_CLEAR; vfb->safeWidth = 0; @@ -1061,7 +1055,8 @@ bool FramebufferManagerCommon::ShouldDownloadFramebufferColor(const VirtualFrame bool FramebufferManagerCommon::ShouldDownloadFramebufferDepth(const VirtualFramebuffer *vfb) const { // Download depth buffer for Syphon Filter lens flares - if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && GenerateBoolean) { + HalfSkipShouldDownloadFramebufferDepth = !HalfSkipShouldDownloadFramebufferDepth; + if (!PSP_CoreParameter().compat.flags().ReadbackDepth || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::SKIP || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::COPY_TO_TEXTURE || g_Config.iSkipGPUReadbackMode == (int)SkipGPUReadbackMode::HALF_SKIP && HalfSkipShouldDownloadFramebufferDepth) { return false; } return (vfb->usageFlags & FB_USAGE_RENDER_DEPTH) != 0 && vfb->width >= 480 && vfb->height >= 272;