GTE: Pack local config in struct

This commit is contained in:
Stenzek 2024-07-06 19:33:38 +10:00
parent b6a264b8b4
commit 23962fd07e
No known key found for this signature in database
1 changed files with 28 additions and 20 deletions

View File

@ -30,10 +30,17 @@ static constexpr s32 IR0_MAX_VALUE = 0x1000;
static constexpr s32 IR123_MIN_VALUE = -(INT64_C(1) << 15);
static constexpr s32 IR123_MAX_VALUE = (INT64_C(1) << 15) - 1;
static DisplayAspectRatio s_aspect_ratio = DisplayAspectRatio::R4_3;
static u32 s_custom_aspect_ratio_numerator;
static u32 s_custom_aspect_ratio_denominator;
static float s_custom_aspect_ratio_f;
namespace {
struct Config
{
DisplayAspectRatio aspect_ratio = DisplayAspectRatio::R4_3;
u32 custom_aspect_ratio_numerator;
u32 custom_aspect_ratio_denominator;
float custom_aspect_ratio_f;
};
} // namespace
ALIGN_TO_CACHE_LINE static Config s_config;
#define REGS CPU::g_state.gte_regs
@ -207,7 +214,7 @@ static void Execute_GPF(Instruction inst);
void GTE::Initialize()
{
s_aspect_ratio = DisplayAspectRatio::R4_3;
s_config.aspect_ratio = DisplayAspectRatio::R4_3;
Reset();
}
@ -226,20 +233,20 @@ void GTE::UpdateAspectRatio()
{
if (!g_settings.gpu_widescreen_hack)
{
s_aspect_ratio = DisplayAspectRatio::R4_3;
s_config.aspect_ratio = DisplayAspectRatio::R4_3;
return;
}
s_aspect_ratio = g_settings.display_aspect_ratio;
s_config.aspect_ratio = g_settings.display_aspect_ratio;
u32 num, denom;
switch (s_aspect_ratio)
switch (s_config.aspect_ratio)
{
case DisplayAspectRatio::MatchWindow:
{
if (!g_gpu_device)
{
s_aspect_ratio = DisplayAspectRatio::R4_3;
s_config.aspect_ratio = DisplayAspectRatio::R4_3;
return;
}
@ -264,10 +271,11 @@ void GTE::UpdateAspectRatio()
const u32 y = 3u * num;
const u32 gcd = std::gcd(x, y);
s_custom_aspect_ratio_numerator = x / gcd;
s_custom_aspect_ratio_denominator = y / gcd;
s_config.custom_aspect_ratio_numerator = x / gcd;
s_config.custom_aspect_ratio_denominator = y / gcd;
s_custom_aspect_ratio_f = static_cast<float>((4.0 / 3.0) / (static_cast<double>(num) / static_cast<double>(denom)));
s_config.custom_aspect_ratio_f =
static_cast<float>((4.0 / 3.0) / (static_cast<double>(num) / static_cast<double>(denom)));
}
u32 GTE::ReadRegister(u32 index)
@ -694,7 +702,7 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
const s64 result = static_cast<s64>(ZeroExtend64(UNRDivide(REGS.H, REGS.SZ3)));
s64 Sx;
switch (s_aspect_ratio)
switch (s_config.aspect_ratio)
{
case DisplayAspectRatio::R16_9:
Sx = ((((s64(result) * s64(REGS.IR1)) * s64(3)) / s64(4)) + s64(REGS.OFX));
@ -710,8 +718,8 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
case DisplayAspectRatio::Custom:
case DisplayAspectRatio::MatchWindow:
Sx = ((((s64(result) * s64(REGS.IR1)) * s64(s_custom_aspect_ratio_numerator)) /
s64(s_custom_aspect_ratio_denominator)) +
Sx = ((((s64(result) * s64(REGS.IR1)) * s64(s_config.custom_aspect_ratio_numerator)) /
s64(s_config.custom_aspect_ratio_denominator)) +
s64(REGS.OFX));
break;
@ -762,11 +770,11 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
const float fofy = float(REGS.OFY) / float(1 << 16);
float precise_x = precise_ir1 * precise_h_div_sz;
switch (s_aspect_ratio)
switch (s_config.aspect_ratio)
{
case DisplayAspectRatio::MatchWindow:
case DisplayAspectRatio::Custom:
precise_x = precise_x * s_custom_aspect_ratio_f;
precise_x = precise_x * s_config.custom_aspect_ratio_f;
break;
case DisplayAspectRatio::R16_9: