libretro: Add CropTo16x9 core option

This commit is contained in:
sonninnos 2024-06-01 05:38:43 +03:00
parent c8b7ae817d
commit 957c4c7d74
3 changed files with 63 additions and 13 deletions

View File

@ -5,12 +5,16 @@
#include "Common/GraphicsContext.h"
#include "Common/GPU/thin3d_create.h"
#include "Core/Config.h"
#include "Core/System.h"
#include "GPU/GPUState.h"
#include "GPU/Software/SoftGpu.h"
#include "headless/Compare.h"
#include "Common/Data/Convert/ColorConv.h"
#define NATIVEWIDTH 480
#define NATIVEHEIGHT 272
class LibretroGraphicsContext : public GraphicsContext {
public:
LibretroGraphicsContext() {}
@ -54,7 +58,7 @@ public:
bool Init(bool cache_context);
void SetRenderTarget() override {}
void SwapBuffers() override {
video_cb(RETRO_HW_FRAME_BUFFER_VALID, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0);
video_cb(RETRO_HW_FRAME_BUFFER_VALID, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0);
}
virtual void ContextReset();
virtual void ContextDestroy();
@ -85,11 +89,10 @@ public:
bool Init() override { return true; }
void SwapBuffers() override {
GPUDebugBuffer buf;
u32 w = PSP_CoreParameter().pixelWidth;
u32 h = PSP_CoreParameter().pixelHeight;
gpuDebug->GetCurrentFramebuffer(buf, GPU_DBG_FRAMEBUF_DISPLAY);
const std::vector<u32> pixels = TranslateDebugBufferToCompare(&buf, w, h);
video_cb(pixels.data(), w, h, w << 2);
gpuDebug->GetOutputFramebuffer(buf);
const std::vector<u32> pixels = TranslateDebugBufferToCompare(&buf, NATIVEWIDTH, NATIVEHEIGHT);
u32 offset = g_Config.bDisplayCropTo16x9 ? NATIVEWIDTH : 0;
video_cb(pixels.data() + offset, NATIVEWIDTH, PSP_CoreParameter().pixelHeight, NATIVEWIDTH << 2);
}
GPUCore GetGPUCore() override { return GPUCORE_SOFTWARE; }
const char *Ident() override { return "Software"; }

View File

@ -503,6 +503,7 @@ static void check_variables(CoreParameter &coreParam)
int iTexScalingType_prev;
int iTexScalingLevel_prev;
int iMultiSampleLevel_prev;
bool bDisplayCropTo16x9_prev;
var.key = "ppsspp_language";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
@ -699,6 +700,17 @@ static void check_variables(CoreParameter &coreParam)
}
#endif
var.key = "ppsspp_cropto16x9";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
bDisplayCropTo16x9_prev = g_Config.bDisplayCropTo16x9;
if (!strcmp(var.value, "disabled"))
g_Config.bDisplayCropTo16x9 = false;
else
g_Config.bDisplayCropTo16x9 = true;
}
var.key = "ppsspp_skip_gpu_readbacks";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
@ -1066,6 +1078,8 @@ static void check_variables(CoreParameter &coreParam)
!g_Config.bRenderDuplicateFrames;
bool updateAvInfo = false;
bool updateGeometry = false;
if (!detectVsyncSwapInterval && (vsyncSwapInterval != 1))
{
vsyncSwapInterval = 1;
@ -1074,8 +1088,8 @@ static void check_variables(CoreParameter &coreParam)
if (g_Config.iInternalResolution != iInternalResolution_prev && !PSP_IsInited())
{
coreParam.pixelWidth = coreParam.renderWidth = g_Config.iInternalResolution * 480;
coreParam.pixelHeight = coreParam.renderHeight = g_Config.iInternalResolution * 272;
coreParam.pixelWidth = coreParam.renderWidth = g_Config.iInternalResolution * NATIVEWIDTH;
coreParam.pixelHeight = coreParam.renderHeight = g_Config.iInternalResolution * NATIVEHEIGHT;
if (gpu)
{
@ -1087,6 +1101,11 @@ static void check_variables(CoreParameter &coreParam)
}
}
if (g_Config.bDisplayCropTo16x9 != bDisplayCropTo16x9_prev && PSP_IsInited())
{
updateGeometry = true;
}
#if 0 // see issue #16786
if (g_Config.iMultiSampleLevel != iMultiSampleLevel_prev && PSP_IsInited())
{
@ -1103,6 +1122,12 @@ static void check_variables(CoreParameter &coreParam)
retro_get_system_av_info(&avInfo);
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &avInfo);
}
else if (updateGeometry)
{
retro_system_av_info avInfo;
retro_get_system_av_info(&avInfo);
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &avInfo);
}
set_variable_visibility();
}
@ -1224,11 +1249,23 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
info->timing.fps = (60.0 / 1.001) / (double)vsyncSwapInterval;
info->timing.sample_rate = SAMPLERATE;
info->geometry.base_width = g_Config.iInternalResolution * 480;
info->geometry.base_height = g_Config.iInternalResolution * 272;
info->geometry.max_width = g_Config.iInternalResolution * 480;
info->geometry.max_height = g_Config.iInternalResolution * 272;
info->geometry.aspect_ratio = 480.0 / 272.0; // Not 16:9! But very, very close.
info->geometry.base_width = g_Config.iInternalResolution * NATIVEWIDTH;
info->geometry.base_height = g_Config.iInternalResolution * NATIVEHEIGHT;
info->geometry.max_width = g_Config.iInternalResolution * NATIVEWIDTH;
info->geometry.max_height = g_Config.iInternalResolution * NATIVEHEIGHT;
if (g_Config.bDisplayCropTo16x9)
info->geometry.base_height -= g_Config.iInternalResolution * 2;
info->geometry.aspect_ratio = (float)info->geometry.base_width / (float)info->geometry.base_height;
PSP_CoreParameter().pixelWidth = info->geometry.base_width;
PSP_CoreParameter().pixelHeight = info->geometry.base_height;
/* Must reset context to resize render area properly while running,
* but not necessary with software, and not working with Vulkan.. (TODO) */
if (PSP_IsInited() && ctx && ctx->GetGPUCore() != GPUCORE_SOFTWARE && ctx->GetGPUCore() != GPUCORE_VULKAN)
((LibretroHWRenderContext *)Libretro::ctx)->ContextReset();
}
unsigned retro_api_version(void) { return RETRO_API_VERSION; }

View File

@ -348,6 +348,16 @@ struct retro_core_option_v2_definition option_defs_us[] = {
"Disabled"
},
#endif
{
"ppsspp_cropto16x9",
"Crop to 16x9",
NULL,
"Remove one line from top and bottom to get exact 16:9. Restart required with Vulkan!",
NULL,
"video",
BOOL_OPTIONS,
"enabled"
},
{
"ppsspp_skip_gpu_readbacks",
"Skip GPU Readbacks",