From bb60bcc42d7e9b4e0dfcb10e2058b4cace5c0508 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Thu, 23 Jul 2015 17:39:44 +1200 Subject: Heuristic to detect if a gamecube game is rendering 16:9 widescreen. Someone suggested on IRC that we should make a database of memory locations in GameCube games which contain the 'Widescreen' setting so we can automatically detect if the game is in 4:3 or 16:9 mode. But that's hardly optimal, when the game actually tells the gpu what aspect ratio to render in. 10 min and 6 lines of code later, this is the result. Not only does it detect the correct aspect ratio it does so on the fly. I'm a little suprised nobody thought about doing this before. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 509974c373..a6bab1aabf 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -9,6 +9,8 @@ #include "Common/BitSet.h" #include "Common/CommonTypes.h" #include "Common/MathUtil.h" +#include "Core/ConfigManager.h" +#include "Core/Core.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/CPMemory.h" #include "VideoCommon/RenderBase.h" @@ -417,6 +419,21 @@ void VertexShaderManager::SetConstants() g_fProjectionMatrix[14] = -1.0f; g_fProjectionMatrix[15] = 0.0f; + // Heuristic to detect if a GameCube game is in 16:9 anamorphic widescreen mode. + if (!SConfig::GetInstance().bWii) + { + // Due to the BT.601 standard which the GameCube is based on being a compromise + // between PAL and NTSC, neither standard gets square pixels. They are each off + // by ~9% in opposite directions. + // Just in case any game decides to take this into account, we do these tests + // with a large amount of slop. + float aspect = fabsf(rawProjection[2] / rawProjection[0]); + if (fabsf(aspect - 16.0f/9.0f) < 16.0f/9.0f * 0.11) // within 11% of 16:9 + g_aspect_wide = true; + else if (fabsf(aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11) // within 11% of 4:3 + g_aspect_wide = false; + } + SETSTAT_FT(stats.gproj_0, g_fProjectionMatrix[0]); SETSTAT_FT(stats.gproj_1, g_fProjectionMatrix[1]); SETSTAT_FT(stats.gproj_2, g_fProjectionMatrix[2]); -- cgit v1.2.3 From 615e5db0cbda4afad3ee940f6c160c1ece963c36 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 1 Aug 2015 13:18:47 +1200 Subject: Make the GameCube game widescreen heuristic smarter. The last heuristic wasn't quite smart enough and had a few false positives in Mario Kart: Double Dash and Metroid prime 2. Now we only activate if the game is rendering a 16:9 projection to a 4:3 viewport. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index a6bab1aabf..83e112021e 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -428,9 +428,11 @@ void VertexShaderManager::SetConstants() // Just in case any game decides to take this into account, we do these tests // with a large amount of slop. float aspect = fabsf(rawProjection[2] / rawProjection[0]); - if (fabsf(aspect - 16.0f/9.0f) < 16.0f/9.0f * 0.11) // within 11% of 16:9 + float viewport_aspect = fabsf(xfmem.viewport.wd / xfmem.viewport.ht); + bool viewport_is_4_3 = fabsf(viewport_aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11; + if (fabsf(aspect - 16.0f/9.0f) < 16.0f/9.0f * 0.11 && viewport_is_4_3) // within 11% of 16:9 g_aspect_wide = true; - else if (fabsf(aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11) // within 11% of 4:3 + else if (fabsf(aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11 && viewport_is_4_3) // within 11% of 4:3 g_aspect_wide = false; } -- cgit v1.2.3 From a1df1f5ae4e9534222539dd85f7454d17c4ba559 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 1 Aug 2015 14:39:34 +1200 Subject: Widescreen Heuristic: Cleanup code. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 83e112021e..46884a79d2 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -89,6 +89,23 @@ static float PHackValue(std::string sValue) return f; } +// Due to the BT.601 standard which the GameCube is based on being a compromise +// between PAL and NTSC, neither standard gets square pixels. They are each off +// by ~9% in opposite directions. +// Just in case any game decides to take this into account, we do both these +// tests with a large amount of slop. +static bool AspectIs4_3(float width, float height) +{ + float aspect = fabsf(width / height); + return fabsf(aspect - 4.0f / 3.0f) < 4.0f / 3.0f * 0.11; // within 11% of 4:3 +} + +static bool AspectIs16_9(float width, float height) +{ + float aspect = fabsf(width / height); + return fabsf(aspect - 16.0f / 9.0f) < 16.0f / 9.0f * 0.11; // within 11% of 16:9 +} + void UpdateProjectionHack(int iPhackvalue[], std::string sPhackvalue[]) { float fhackvalue1 = 0, fhackvalue2 = 0; @@ -422,18 +439,11 @@ void VertexShaderManager::SetConstants() // Heuristic to detect if a GameCube game is in 16:9 anamorphic widescreen mode. if (!SConfig::GetInstance().bWii) { - // Due to the BT.601 standard which the GameCube is based on being a compromise - // between PAL and NTSC, neither standard gets square pixels. They are each off - // by ~9% in opposite directions. - // Just in case any game decides to take this into account, we do these tests - // with a large amount of slop. - float aspect = fabsf(rawProjection[2] / rawProjection[0]); - float viewport_aspect = fabsf(xfmem.viewport.wd / xfmem.viewport.ht); - bool viewport_is_4_3 = fabsf(viewport_aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11; - if (fabsf(aspect - 16.0f/9.0f) < 16.0f/9.0f * 0.11 && viewport_is_4_3) // within 11% of 16:9 - g_aspect_wide = true; - else if (fabsf(aspect - 4.0f/3.0f) < 4.0f/3.0f * 0.11 && viewport_is_4_3) // within 11% of 4:3 - g_aspect_wide = false; + bool viewport_is_4_3 = AspectIs4_3(xfmem.viewport.wd, xfmem.viewport.ht); + if (AspectIs16_9(rawProjection[2], rawProjection[0]) && viewport_is_4_3) + g_aspect_wide = true; // Projection is 16:9 and viewport is 4:3, we are rendering an anamorphic widescreen picture + else if (AspectIs4_3(rawProjection[2], rawProjection[0]) && viewport_is_4_3) + g_aspect_wide = false; // Project and viewports are both 4:3, we are rendering a normal image. } SETSTAT_FT(stats.gproj_0, g_fProjectionMatrix[0]); -- cgit v1.2.3 From 0e41b973c79d887e90e220db9bdfedfd5f63a59c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Aug 2015 21:07:10 -0400 Subject: VertexShaderManager: Remove unused parameter --- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 46884a79d2..603fc2efb8 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -683,7 +683,7 @@ void VertexShaderManager::SetProjectionChanged() bProjectionChanged = true; } -void VertexShaderManager::SetMaterialColorChanged(int index, u32 color) +void VertexShaderManager::SetMaterialColorChanged(int index) { nMaterialsChanged[index] = true; } -- cgit v1.2.3 From 8ce04f9a65612b7553015428e617ba7c53913175 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Sep 2015 11:44:21 -0400 Subject: General: Replace GC_ALIGN macros with alignas Standard supported alignment -> out with compiler-specific. --- Source/Core/VideoCommon/VertexShaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 603fc2efb8..93d248938b 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -22,7 +22,7 @@ #include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h" -static float GC_ALIGNED16(g_fProjectionMatrix[16]); +alignas(16) static float g_fProjectionMatrix[16]; // track changes static bool bTexMatricesChanged[2], bPosNormalMatrixChanged, bProjectionChanged, bViewportChanged; -- cgit v1.2.3