From 5132173d39a97e0d461bdaed0e4f8e4482ebdbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 15:12:54 +0200 Subject: [PATCH 01/18] frametests.py --adb: Name the device's SoC, and its GPU only where SurfaceFlinger reports one Co-Authored-By: Claude Opus 5.5 --- frametests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frametests.py b/frametests.py index 6c43e8a359..e4f10a6955 100644 --- a/frametests.py +++ b/frametests.py @@ -181,8 +181,11 @@ class AdbDevice: self.adb("push", "--sync", str(test_root) + "/.", self.dir + "/dumps") self.shell("rm -rf %s/shots && mkdir -p %s/shots" % (shlex.quote(self.dir), shlex.quote(self.dir))) model = self.shell("getprop ro.product.model").stdout.strip() - gpu = self.shell("dumpsys SurfaceFlinger | grep GLES", check=False).stdout.strip() - return "%s (%s)" % (model, gpu) if gpu else model + soc = self.shell("getprop ro.soc.model", check=False).stdout.strip() + # SurfaceFlinger names the GPU, except where it reports its own render engine instead (Samsung's Skia). + gles = self.shell("dumpsys SurfaceFlinger | grep GLES", check=False).stdout.strip() + gpu = next((l.strip() for l in gles.splitlines() if re.search(r"Adreno|Mali|Immortalis|PowerVR|Xclipse", l)), "") + return ", ".join(s for s in (model, soc, gpu) if s) def run_side_by_side(headless, host_args, device, dump_path, rel, variant_args, host_path, actual_path, diff_path, From fbe1224fed06ae886114e7fd74fdff9e442269dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 17:03:02 +0200 Subject: [PATCH 02/18] Headless: --disable-gpu-features=framebuffer-fetch Co-Authored-By: Claude Opus 5.5 --- Core/CmdLine.cpp | 2 +- Core/CmdLine.h | 2 +- headless/Headless.cpp | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index ca29199c87..936d27327b 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -207,7 +207,7 @@ static const CommandLineParam g_autoParams[] = { {POFF(replayEnd), CmdParamType::Int, "replay-end", '\0', "When replaying a GE frame dump, only draw primitives up to this one (1-based)", CmdLineMode::Headless}, {POFF(dumpCompat), CmdParamType::Bool, "dump-compat", '\0', "Apply the game's compat.ini settings when replaying a GE frame dump (off by default)", CmdLineMode::Headless}, {POFF(hardwareTransform), CmdParamType::Bool, "hardware-transform", '\0', "Transform vertices on the GPU (default true); false transforms them on the CPU", CmdLineMode::Headless}, - {POFF(disableGPUFeatures), CmdParamType::String, "disable-gpu-features", '\0', "Act as if the GPU lacked these, to test the fallbacks: comma-separated clip-distance, cull-distance, depth-clamp", CmdLineMode::Headless}, + {POFF(disableGPUFeatures), CmdParamType::String, "disable-gpu-features", '\0', "Act as if the GPU lacked these, to test the fallbacks: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch", CmdLineMode::Headless}, {POFF(depthFilenameSave), CmdParamType::String, "depth-save", '\0', "Save the depth buffer to FILE along with the screenshot (u32 width, u32 height, u16 depths; float depths if FILE ends in .f32)", CmdLineMode::Headless}, {POFF(screenshotRenderTarget), CmdParamType::Bool, "screenshot-render-target", '\0', "Take screenshots of the current render target instead of the displayed framebuffer", CmdLineMode::Headless}, {POFF(screenshotFilenameDiff), CmdParamType::String, "screenshot-diff", '\0', "Save a visual comparison image to FILE when comparing screenshots", CmdLineMode::Headless}, diff --git a/Core/CmdLine.h b/Core/CmdLine.h index 3bc1dea616..88d4483e69 100644 --- a/Core/CmdLine.h +++ b/Core/CmdLine.h @@ -189,7 +189,7 @@ struct CommandLineOptions { // Headless: apply the game's compatibility settings when replaying a GE frame dump. std::optional dumpCompat; std::optional hardwareTransform; - // Headless: comma-separated clip-distance, cull-distance, depth-clamp. + // Headless: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch. std::optional disableGPUFeatures; std::optional screenshotRenderTarget; std::optional screenshotFilenameDiff; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 7e563cbfc4..7fde71bb8a 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -1128,8 +1128,10 @@ int main(int argc, const char* argv[]) { coreParameter.disabledGPUFeatures |= GPU_USE_CULL_DISTANCE; } else if (name == "depth-clamp") { coreParameter.disabledGPUFeatures |= GPU_USE_DEPTH_CLAMP; + } else if (name == "framebuffer-fetch") { + coreParameter.disabledGPUFeatures |= GPU_USE_FRAMEBUFFER_FETCH; } else { - fprintf(stderr, "Unknown feature for --disable-gpu-features: %s (expected clip-distance, cull-distance or depth-clamp)\n", name.c_str()); + fprintf(stderr, "Unknown feature for --disable-gpu-features: %s (expected clip-distance, cull-distance, depth-clamp or framebuffer-fetch)\n", name.c_str()); return 1; } } From 48f709574fd1861a9a594a8739055bd3bcb5a4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 23:09:33 +0200 Subject: [PATCH 03/18] Headless: --disable-gpu-features=dual-source-blend Mali-G71 and PowerVR GE8320 Vulkan lack it, and without it WipEout Pure, Juiced 2 and 16131 UCES00001 render like they do there. Co-Authored-By: Claude Opus 5.5 --- Core/CmdLine.cpp | 2 +- Core/CmdLine.h | 2 +- headless/Headless.cpp | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index 936d27327b..3745081c7e 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -207,7 +207,7 @@ static const CommandLineParam g_autoParams[] = { {POFF(replayEnd), CmdParamType::Int, "replay-end", '\0', "When replaying a GE frame dump, only draw primitives up to this one (1-based)", CmdLineMode::Headless}, {POFF(dumpCompat), CmdParamType::Bool, "dump-compat", '\0', "Apply the game's compat.ini settings when replaying a GE frame dump (off by default)", CmdLineMode::Headless}, {POFF(hardwareTransform), CmdParamType::Bool, "hardware-transform", '\0', "Transform vertices on the GPU (default true); false transforms them on the CPU", CmdLineMode::Headless}, - {POFF(disableGPUFeatures), CmdParamType::String, "disable-gpu-features", '\0', "Act as if the GPU lacked these, to test the fallbacks: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch", CmdLineMode::Headless}, + {POFF(disableGPUFeatures), CmdParamType::String, "disable-gpu-features", '\0', "Act as if the GPU lacked these, to test the fallbacks: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch, dual-source-blend", CmdLineMode::Headless}, {POFF(depthFilenameSave), CmdParamType::String, "depth-save", '\0', "Save the depth buffer to FILE along with the screenshot (u32 width, u32 height, u16 depths; float depths if FILE ends in .f32)", CmdLineMode::Headless}, {POFF(screenshotRenderTarget), CmdParamType::Bool, "screenshot-render-target", '\0', "Take screenshots of the current render target instead of the displayed framebuffer", CmdLineMode::Headless}, {POFF(screenshotFilenameDiff), CmdParamType::String, "screenshot-diff", '\0', "Save a visual comparison image to FILE when comparing screenshots", CmdLineMode::Headless}, diff --git a/Core/CmdLine.h b/Core/CmdLine.h index 88d4483e69..5c2fcf4258 100644 --- a/Core/CmdLine.h +++ b/Core/CmdLine.h @@ -189,7 +189,7 @@ struct CommandLineOptions { // Headless: apply the game's compatibility settings when replaying a GE frame dump. std::optional dumpCompat; std::optional hardwareTransform; - // Headless: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch. + // Headless: comma-separated clip-distance, cull-distance, depth-clamp, framebuffer-fetch, dual-source-blend. std::optional disableGPUFeatures; std::optional screenshotRenderTarget; std::optional screenshotFilenameDiff; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 7fde71bb8a..e05c3edb2d 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -1130,8 +1130,10 @@ int main(int argc, const char* argv[]) { coreParameter.disabledGPUFeatures |= GPU_USE_DEPTH_CLAMP; } else if (name == "framebuffer-fetch") { coreParameter.disabledGPUFeatures |= GPU_USE_FRAMEBUFFER_FETCH; + } else if (name == "dual-source-blend") { + coreParameter.disabledGPUFeatures |= GPU_USE_DUALSOURCE_BLEND; } else { - fprintf(stderr, "Unknown feature for --disable-gpu-features: %s (expected clip-distance, cull-distance, depth-clamp or framebuffer-fetch)\n", name.c_str()); + fprintf(stderr, "Unknown feature for --disable-gpu-features: %s (expected clip-distance, cull-distance, depth-clamp, framebuffer-fetch or dual-source-blend)\n", name.c_str()); return 1; } } From e3577fad74cef896c56180d35678500f41918df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 15:20:54 +0200 Subject: [PATCH 04/18] GL: Actually enable depth clamp on GLES GLES drivers with GL_EXT_depth_clamp reported depth clamp as supported, but glEnable(GL_DEPTH_CLAMP) was compiled out with USING_GLES2. The shaders then relied on clamping that never happened, and geometry outside the depth range was clipped: on the Adreno 840, Hokuto no Ken's title screen came out black and Hot Pixel's background was missing. Co-Authored-By: Claude Opus 5.5 --- Common/GPU/OpenGL/GLCommon.h | 5 +++++ Common/GPU/OpenGL/GLQueueRunner.cpp | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Common/GPU/OpenGL/GLCommon.h b/Common/GPU/OpenGL/GLCommon.h index 26f9220d7f..2ea3a0885b 100644 --- a/Common/GPU/OpenGL/GLCommon.h +++ b/Common/GPU/OpenGL/GLCommon.h @@ -35,6 +35,11 @@ #define GL_MAX_EXT 0x8008 #endif +#ifndef GL_DEPTH_CLAMP +// GL_DEPTH_CLAMP_EXT, from GL_EXT_depth_clamp. Not in every platform header. +#define GL_DEPTH_CLAMP 0x864F +#endif + #if defined(__ANDROID__) #include // Additional extensions not included in GLES2/gl2ext.h from the NDK diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index ac8c23b5b2..86c56925b2 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -1422,7 +1422,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last glDisable(GL_DITHER); ditherEnabled = false; } -#ifndef USING_GLES2 + // GLES has it too, with GL_EXT_depth_clamp (depthClampSupported). if (c.raster.depthClampEnable) { if (!depthClampEnabled) { glEnable(GL_DEPTH_CLAMP); @@ -1432,7 +1432,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last glDisable(GL_DEPTH_CLAMP); depthClampEnabled = false; } -#endif CHECK_GL_ERROR_IF_DEBUG(); break; default: @@ -1473,9 +1472,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last glDisable(GL_BLEND); if (cullEnabled) glDisable(GL_CULL_FACE); -#ifndef USING_GLES2 if (depthClampEnabled) glDisable(GL_DEPTH_CLAMP); +#ifndef USING_GLES2 if (!gl_extensions.IsGLES && logicEnabled) { glDisable(GL_COLOR_LOGIC_OP); } From e801f5a420c1f8bddd1eda1f1760b38940ae6cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 16:35:28 +0200 Subject: [PATCH 05/18] GL: Set GL_UNPACK_ALIGNMENT to 1, texture uploads are tightly packed With the default of 4, the driver reads past the end of any upload whose rows aren't a multiple of 4 bytes, like a 16-bit texture of odd width. The Adreno 840 crashed in glTexImage2D on one in SOCOM Fireteam Bravo 3. Co-Authored-By: Claude Opus 5.5 --- Common/GPU/OpenGL/GLQueueRunner.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 86c56925b2..fc03129d33 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -50,6 +50,11 @@ void GLQueueRunner::CreateDeviceObjects() { glGenVertexArrays(1, &globalVAO_); } + // Texture uploads pass tightly packed rows. With the default of 4, the driver reads past the end of + // any whose rows aren't a multiple of 4 bytes (a 16-bit texture of odd width): the Adreno 840 crashed + // on one in SOCOM Fireteam Bravo 3. + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // An eternal optimist. sawOutOfMemory_ = false; From 168149e3f2cea26855804f8e414ab88231b4d86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 18:21:49 +0200 Subject: [PATCH 06/18] GL: Use 0..1 clip space depth where clip control is available With the default -1..1, window depth 0 comes from z = -w, where the rasterizer's rounding is an ulp of 1.0. Puyo Puyo Fever 2's ground at z = 0 got depths just above 0 with depth clamp on, and the sprites on it that test GEQUAL lost pixels (910 px off the PSP on an Adreno 840, now 0). Use glClipControl (GL 4.5, ARB/EXT_clip_control) as in Vulkan. Not in libretro, where the frontend shares the context. Co-Authored-By: Claude Opus 5.5 --- Common/GPU/OpenGL/GLCommon.h | 8 ++++++++ Common/GPU/OpenGL/GLFeatures.cpp | 19 +++++++++++++++++++ Common/GPU/OpenGL/GLFeatures.h | 2 ++ Common/GPU/OpenGL/GLQueueRunner.cpp | 13 +++++++++++++ Common/GPU/OpenGL/thin3d_gl.cpp | 4 ++++ 5 files changed, 46 insertions(+) diff --git a/Common/GPU/OpenGL/GLCommon.h b/Common/GPU/OpenGL/GLCommon.h index 2ea3a0885b..09dd8dee7b 100644 --- a/Common/GPU/OpenGL/GLCommon.h +++ b/Common/GPU/OpenGL/GLCommon.h @@ -63,6 +63,14 @@ typedef void (EGLAPIENTRYP PFNGLBLITFRAMEBUFFERNVPROC) ( #endif extern PFNGLBLITFRAMEBUFFERNVPROC glBlitFramebufferNV; +#ifndef GL_ZERO_TO_ONE_EXT +#define GL_LOWER_LEFT_EXT 0x8CA1 +#define GL_ZERO_TO_ONE_EXT 0x935F +#endif +// Our own name for the type and the pointer, since not every NDK header declares GL_EXT_clip_control. +typedef void (GL_APIENTRYP PPSSPP_PFNGLCLIPCONTROLEXTPROC) (GLenum origin, GLenum depth); +extern PPSSPP_PFNGLCLIPCONTROLEXTPROC glClipControlEXTFunc; + #if PPSSPP_PLATFORM(IOS) extern PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT; extern PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES; diff --git a/Common/GPU/OpenGL/GLFeatures.cpp b/Common/GPU/OpenGL/GLFeatures.cpp index 6877dbd76c..3fcbe41ddd 100644 --- a/Common/GPU/OpenGL/GLFeatures.cpp +++ b/Common/GPU/OpenGL/GLFeatures.cpp @@ -30,6 +30,7 @@ PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOES; PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOES; PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOES; PFNGLISVERTEXARRAYOESPROC glIsVertexArrayOES; +PPSSPP_PFNGLCLIPCONTROLEXTPROC glClipControlEXTFunc; #endif #if !PPSSPP_PLATFORM(IOS) #include "EGL/egl.h" @@ -381,6 +382,7 @@ bool CheckGLExtensions() { gl_extensions.ARB_draw_instanced = g_set_gl_extensions.count("GL_ARB_draw_instanced") != 0; gl_extensions.ARB_cull_distance = g_set_gl_extensions.count("GL_ARB_cull_distance") != 0; gl_extensions.ARB_depth_clamp = g_set_gl_extensions.count("GL_ARB_depth_clamp") != 0; + gl_extensions.ARB_clip_control = g_set_gl_extensions.count("GL_ARB_clip_control") != 0; gl_extensions.ARB_uniform_buffer_object = g_set_gl_extensions.count("GL_ARB_uniform_buffer_object") != 0; gl_extensions.ARB_explicit_attrib_location = g_set_gl_extensions.count("GL_ARB_explicit_attrib_location") != 0; gl_extensions.ARB_texture_non_power_of_two = g_set_gl_extensions.count("GL_ARB_texture_non_power_of_two") != 0; @@ -407,6 +409,7 @@ bool CheckGLExtensions() { gl_extensions.EXT_buffer_storage = g_set_gl_extensions.count("GL_EXT_buffer_storage") != 0; gl_extensions.EXT_clip_cull_distance = g_set_gl_extensions.count("GL_EXT_clip_cull_distance") != 0; gl_extensions.EXT_depth_clamp = g_set_gl_extensions.count("GL_EXT_depth_clamp") != 0; + gl_extensions.EXT_clip_control = g_set_gl_extensions.count("GL_EXT_clip_control") != 0; gl_extensions.EXT_disjoint_timer_query = g_set_gl_extensions.count("GL_EXT_disjoint_timer_query") != 0; gl_extensions.APPLE_clip_distance = g_set_gl_extensions.count("GL_APPLE_clip_distance") != 0; @@ -432,6 +435,11 @@ bool CheckGLExtensions() { glBlitFramebufferNV = (PFNGLBLITFRAMEBUFFERNVPROC)eglGetProcAddress("glBlitFramebufferNV"); } + if (gl_extensions.EXT_clip_control) { + glClipControlEXTFunc = (PPSSPP_PFNGLCLIPCONTROLEXTPROC)eglGetProcAddress("glClipControlEXT"); + gl_extensions.EXT_clip_control = glClipControlEXTFunc != nullptr; + } + gl_extensions.OES_vertex_array_object = g_set_gl_extensions.count("GL_OES_vertex_array_object") != 0; if (gl_extensions.OES_vertex_array_object) { glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES"); @@ -448,6 +456,7 @@ bool CheckGLExtensions() { #else gl_extensions.OES_vertex_array_object = false; gl_extensions.EXT_discard_framebuffer = false; + gl_extensions.EXT_clip_control = false; #endif } else { gl_extensions.ARB_blend_func_extended = g_set_gl_extensions.count("GL_ARB_blend_func_extended") != 0; @@ -574,6 +583,7 @@ bool CheckGLExtensions() { gl_extensions.ARB_buffer_storage = true; } if (gl_extensions.VersionGEThan(4, 5)) { + gl_extensions.ARB_clip_control = true; gl_extensions.ARB_cull_distance = true; } if (gl_extensions.VersionGEThan(4, 6)) { @@ -589,6 +599,15 @@ bool CheckGLExtensions() { gl_extensions.EXT_clip_cull_distance = false; } + if (gl_extensions.IsGLES) { + gl_extensions.ARB_clip_control = false; + } +#if defined(__LIBRETRO__) + // The frontend shares the context, and doesn't expect its clip control changed. + gl_extensions.ARB_clip_control = false; + gl_extensions.EXT_clip_control = false; +#endif + bool clipDistanceSupported = false; bool cullDistanceSupported = false; diff --git a/Common/GPU/OpenGL/GLFeatures.h b/Common/GPU/OpenGL/GLFeatures.h index 26172e2b12..1223542b17 100644 --- a/Common/GPU/OpenGL/GLFeatures.h +++ b/Common/GPU/OpenGL/GLFeatures.h @@ -76,6 +76,7 @@ struct GLExtensions { bool ARB_clip_distance; bool ARB_cull_distance; bool ARB_depth_clamp; + bool ARB_clip_control; bool ARB_uniform_buffer_object; bool ARB_texture_non_power_of_two; bool ARB_stencil_texturing; @@ -104,6 +105,7 @@ struct GLExtensions { bool EXT_buffer_storage; bool EXT_clip_cull_distance; bool EXT_depth_clamp; + bool EXT_clip_control; // NV bool NV_copy_image; diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index fc03129d33..1e73369e0a 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -55,6 +55,19 @@ void GLQueueRunner::CreateDeviceObjects() { // on one in SOCOM Fireteam Bravo 3. glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // Depth from 0 to w in clip space, as in Vulkan (see depthMinusOneToOne in thin3d_gl.cpp). +#if defined(USING_GLES2) +#if defined(__ANDROID__) + if (gl_extensions.EXT_clip_control) { + glClipControlEXTFunc(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT); + } +#endif +#else + if (gl_extensions.ARB_clip_control) { + glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); + } +#endif + // An eternal optimist. sawOutOfMemory_ = false; diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 7ce2faf158..8b549704fd 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -673,6 +673,10 @@ OpenGLContext::OpenGLContext(bool canChangeSwapInterval) : renderManager_(frameT #endif shaderLanguageDesc_.Init(GLSL_1xx); + // With clip control set up by GLQueueRunner, depth is 0 to w like in Vulkan. Without it, window depth 0 + // comes from z = -w, where the rasterizer rounds to an ulp of 1.0 rather than of 0: a flat ground at + // z = 0 got depths just above 0, and sprites on it that test GEQUAL failed (Puyo Puyo Fever 2). + shaderLanguageDesc_.depthMinusOneToOne = !(gl_extensions.ARB_clip_control || gl_extensions.EXT_clip_control); shaderLanguageDesc_.glslVersionNumber = gl_extensions.GLSLVersion(); From 70800855715a053d48a769c5127908b7aa1c140e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 17:34:07 +0200 Subject: [PATCH 07/18] GLES: Apply the texture LOD bias in the shader GL_TEXTURE_LOD_BIAS is desktop GL only, and the queue runner skipped it on GLES, but GLES still reported sampler LOD bias as supported, so the bias was dropped and textures used the wrong mip levels: Super Monkey Ball Adventure's intro came out blurred on the Adreno 840. Report it unsupported, so the shader applies it (GPU_USE_SHADER_LOD_BIAS), and give the GL backend the uniform that Vulkan has in its uniform block. Co-Authored-By: Claude Opus 5.5 --- Common/GPU/OpenGL/thin3d_gl.cpp | 2 ++ GPU/Common/FragmentShaderGenerator.cpp | 3 +++ GPU/GLES/ShaderManagerGLES.cpp | 6 ++++++ GPU/GLES/ShaderManagerGLES.h | 1 + 4 files changed, 12 insertions(+) diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 8b549704fd..7df9715822 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -548,6 +548,8 @@ OpenGLContext::OpenGLContext(bool canChangeSwapInterval) : renderManager_(frameT // 30 is an ok value for the max since it's 2^31-1, which is the max value for a signed int. NVIDIA also reports this. caps_.samplerLodControl = true; } + // GL_TEXTURE_LOD_BIAS is desktop GL only, so the shader has to apply the bias. + caps_.samplerLodBias = false; caps_.texture3DSupported = gl_extensions.GLES3 || gl_extensions.OES_texture_3D; caps_.textureDepthSupported = gl_extensions.GLES3 || gl_extensions.OES_depth_texture; } else { diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 49b1943f99..53a1c510c3 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -394,6 +394,9 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (texture3D) { *uniformMask |= DIRTY_MIPBIAS; WRITE(p, "uniform float u_mipBias;\n"); + } else if (doTexture && gstate_c.Use(GPU_USE_SHADER_LOD_BIAS)) { + *uniformMask |= DIRTY_MIPBIAS; + WRITE(p, "uniform float u_texLodBias;\n"); } if (fsMinmaxDiscard) { diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index c27a75a2af..0d5d62c8af 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -173,6 +173,7 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs, queries.push_back({ &u_depal_mask_shift_off_fmt, "u_depal_mask_shift_off_fmt" }); queries.push_back({ &u_mipBias, "u_mipBias" }); + queries.push_back({ &u_texLodBias, "u_texLodBias" }); attrMask = vs->GetAttrMask(); availableUniforms = vs->GetUniformMask() | fs->GetUniformMask(); @@ -463,6 +464,11 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, const ShaderLanguageDesc render_->SetUniformF(&u_mipBias, 1, &mipBias); } + if ((dirty & DIRTY_MIPBIAS) && u_texLodBias != -1) { + // For GPU_USE_SHADER_LOD_BIAS, like ShaderUniforms.cpp: the sampler applies the bias only in auto mode. + float lodBias = gstate.getTexLevelMode() == GE_TEXLEVEL_MODE_AUTO ? (float)gstate.getTexLevelOffset16() * (1.0f / 16.0f) : 0.0f; + render_->SetUniformF(&u_texLodBias, 1, &lodBias); + } // Transform if (dirty & DIRTY_WORLDMATRIX) { diff --git a/GPU/GLES/ShaderManagerGLES.h b/GPU/GLES/ShaderManagerGLES.h index db14a7135e..ce5b2d551e 100644 --- a/GPU/GLES/ShaderManagerGLES.h +++ b/GPU/GLES/ShaderManagerGLES.h @@ -70,6 +70,7 @@ public: int u_texmtx; int u_world; int u_mipBias; + int u_texLodBias; int u_scaleX; int u_scaleY; int u_NaN; From 9bef51177b30b4a1da50e7fe035f289c49c0b1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 14 Oct 2026 00:25:25 +0200 Subject: [PATCH 08/18] GLES: Don't skip uniform updates while a program's locations aren't known UpdateUniforms checked some locations against -1 before queueing the update, but the GL thread fills them in when it links the program, which can be later. On drivers that link slowly the check saw -1, the update was dropped along with its dirty flag, and the uniform stayed unset. On a PowerVR GE8320 and a Mali-G71 the texture clamp values never arrived, so Harvest Moon's and 11655's composites sampled one point of the framebuffer (122k and 76k px off the Mac's Vulkan render, now 0). The GL thread already skips -1. Co-Authored-By: Claude Opus 5.5 --- GPU/GLES/ShaderManagerGLES.cpp | 43 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 0d5d62c8af..669a308fd1 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -448,23 +448,24 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, const ShaderLanguageDesc render_->SetUniformF(&u_uvscaleoffset, 4, uvscaleoff); } - if ((dirty & DIRTY_TEXCLAMP) && u_texclamp != -1) { + // No checks for a location of -1 here: the GL thread fills the locations in when it links the program, which + // may be after this runs, and skips the uniforms a program doesn't have itself. Skipping them here dropped the + // values for good on drivers that link slowly (PowerVR and Mali sampled Harvest Moon's framebuffer at one + // point, with no texture clamp values). + if (dirty & DIRTY_TEXCLAMP) { float texclamp[4]; float texclampoff[2]; CalcTexClamp(texclamp, texclampoff); render_->SetUniformF(&u_texclamp, 4, texclamp); - if (u_texclampoff != -1) { - render_->SetUniformF(&u_texclampoff, 2, texclampoff); - } + render_->SetUniformF(&u_texclampoff, 2, texclampoff); } - if ((dirty & DIRTY_MIPBIAS) && u_mipBias != -1) { + if (dirty & DIRTY_MIPBIAS) { float mipBias = (float)gstate.getTexLevelOffset16() * (1.0 / 16.0f); mipBias = (mipBias + 0.5f) / (float)(gstate.getTextureMaxLevel() + 1); render_->SetUniformF(&u_mipBias, 1, &mipBias); - } - if ((dirty & DIRTY_MIPBIAS) && u_texLodBias != -1) { + // For GPU_USE_SHADER_LOD_BIAS, like ShaderUniforms.cpp: the sampler applies the bias only in auto mode. float lodBias = gstate.getTexLevelMode() == GE_TEXLEVEL_MODE_AUTO ? (float)gstate.getTexLevelOffset16() * (1.0f / 16.0f) : 0.0f; render_->SetUniformF(&u_texLodBias, 1, &lodBias); @@ -526,20 +527,14 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, const ShaderLanguageDesc } if (dirty & DIRTY_SHADERBLEND) { - if (u_blendFixA != -1) { - SetColorUniform3(render_, &u_blendFixA, gstate.getFixA()); - } - if (u_blendFixB != -1) { - SetColorUniform3(render_, &u_blendFixB, gstate.getFixB()); - } + SetColorUniform3(render_, &u_blendFixA, gstate.getFixA()); + SetColorUniform3(render_, &u_blendFixB, gstate.getFixB()); const float fbotexSize[2] = { 1.0f / (float)gstate_c.curRTRenderWidth, 1.0f / (float)gstate_c.curRTRenderHeight, }; - if (u_fbotexSize != -1) { - render_->SetUniformF(&u_fbotexSize, 2, fbotexSize); - } + render_->SetUniformF(&u_fbotexSize, 2, fbotexSize); } // Lighting @@ -570,15 +565,13 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, const ShaderLanguageDesc } else { SetFloat24Uniform3(render_, &u_lightpos[i], &gstate.lpos[i * 3]); } - if (u_lightdir[i] != -1) SetFloat24Uniform3Normalized(render_, &u_lightdir[i], &gstate.ldir[i * 3]); - if (u_lightatt[i] != -1) SetFloat24Uniform3(render_, &u_lightatt[i], &gstate.latt[i * 3]); - if (u_lightangle_spotCoef[i] != -1) { - float lightangle_spotCoef[2] = { getFloat24(gstate.lcutoff[i]), PSPLightExponent(getFloat24(gstate.lconv[i])) }; - SetFloatUniform2(render_, &u_lightangle_spotCoef[i], lightangle_spotCoef); - } - if (u_lightambient[i] != -1) SetColorUniform3(render_, &u_lightambient[i], gstate.lcolor[i * 3]); - if (u_lightdiffuse[i] != -1) SetColorUniform3(render_, &u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]); - if (u_lightspecular[i] != -1) SetColorUniform3(render_, &u_lightspecular[i], gstate.lcolor[i * 3 + 2]); + SetFloat24Uniform3Normalized(render_, &u_lightdir[i], &gstate.ldir[i * 3]); + SetFloat24Uniform3(render_, &u_lightatt[i], &gstate.latt[i * 3]); + float lightangle_spotCoef[2] = { getFloat24(gstate.lcutoff[i]), PSPLightExponent(getFloat24(gstate.lconv[i])) }; + SetFloatUniform2(render_, &u_lightangle_spotCoef[i], lightangle_spotCoef); + SetColorUniform3(render_, &u_lightambient[i], gstate.lcolor[i * 3]); + SetColorUniform3(render_, &u_lightdiffuse[i], gstate.lcolor[i * 3 + 1]); + SetColorUniform3(render_, &u_lightspecular[i], gstate.lcolor[i * 3 + 2]); } } } From 5fb61b4e4054518c8bd69386b817df5e9cb74834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 16:46:28 +0200 Subject: [PATCH 09/18] GLES: Use highp for the texcoord and the math in CLUT8 depal Picking a byte out of a 16-bit framebuffer needs more than the defaults. The texcoord reached the shader as a mediump varying, which Adreno keeps in fp16: its byte coordinate (u times up to 2048) then picks the wrong byte for every other one past 512, and SOCOM Tactical Strike's night vision came out striped in the right half. On a PowerVR GE8320 the default lowp in the rest of the shader made SOCOM's night vision and full screen effect far too bright (53k and 17k px off the Mac's Vulkan render, now 0). Vulkan already uses highp. Where the fragment shader has full precision, the vertex shader now writes the texcoord in highp, and CLUT8 depal reads it that way and computes in highp. Co-Authored-By: Claude Opus 5.5 --- GPU/Common/FragmentShaderGenerator.cpp | 10 ++++++++++ GPU/Common/VertexShaderGenerator.cpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 53a1c510c3..bbcff932a0 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -135,6 +135,16 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } ShaderDepalMode shaderDepalMode = (ShaderDepalMode)id.Bits(FS_BIT_SHADER_DEPAL_MODE, 2); + if (shaderDepalMode == ShaderDepalMode::CLUT8 && gstate_c.Use(GPU_USE_FULL_PRECISION_IN_FRAGMENT)) { + // The byte coordinate is u * up to 2048: a mediump texcoord (fp16 on Adreno) picks the wrong byte for half + // of them past 512, striping SOCOM's night vision. Vulkan always uses highp here. + highpTexcoord = true; + if (compat.gles) { + // Picking the byte also needs more than the default lowp in the rest of the shader: on PowerVR, + // SOCOM's night vision came out far too bright. + WRITE(p, "precision highp float;\n"); + } + } GEBufferFormat shaderDepalFmt = (GEBufferFormat)(id.Bits(FS_BIT_SHADER_DEPAL_FORMAT, 3)); if (texture3D) { shaderDepalMode = ShaderDepalMode::OFF; diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 40f7874013..734f4cc4bf 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -69,7 +69,8 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag *vertexShaderFlags = (VertexShaderFlags)0; bool highpFog = false; - bool highpTexcoord = false; + // Highp costs nothing here, and the fragment shader can then pick it up where it needs it (CLUT8 depal). + bool highpTexcoord = gstate_c.Use(GPU_USE_FULL_PRECISION_IN_FRAGMENT); const bool isModeThrough = id.Bit(VS_BIT_IS_THROUGH); const bool useHWTransform = id.Bit(VS_BIT_USE_HW_TRANSFORM); From 026bbf56d687c43fb988da4a8f1fc2faf3a069a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 14 Oct 2026 01:14:00 +0200 Subject: [PATCH 10/18] GLES: Declare u_minZmaxZ highp in both shaders The fragment shader's min/max Z discard declared it with the default precision, the vertex shader with highp, and PowerVR refuses to link such a program, so every draw that needed the discard was dropped. On a PowerVR GE8320 that was Street Riders, Valkyria Chronicles, Flatout and Frontier Gate, and with the discard taking one-sided depth ranges too (next commit), most of Pursuit Force. Co-Authored-By: Claude Opus 5.5 --- GPU/Common/FragmentShaderGenerator.cpp | 3 ++- GPU/Common/VertexShaderGenerator.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index bbcff932a0..208b4cb65e 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -411,7 +411,8 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (fsMinmaxDiscard) { *uniformMask |= DIRTY_RASTER_OFFSET; // they're updated together - WRITE(p, "uniform vec2 u_minZmaxZ;\n"); + // The same precision as in the vertex shader, or PowerVR fails to link the program. + WRITE(p, "uniform highp vec2 u_minZmaxZ;\n"); } // Varyings diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 734f4cc4bf..a1434e6864 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -328,7 +328,8 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag WRITE(p, "uniform float u_NaN;\n"); *uniformMask |= DIRTY_FRAMEBUFFER_DIM; - WRITE(p, "uniform vec2 u_minZmaxZ;\n"); + // highp to match the fragment shader's (see there). + WRITE(p, "uniform highp vec2 u_minZmaxZ;\n"); *uniformMask |= DIRTY_RASTER_OFFSET; // this flag is shared with raster offset. if (!isModeThrough) { From b25344ab7b2cbe5165061ad0f274c958a9a954f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 20:34:01 +0200 Subject: [PATCH 11/18] Discard against one-sided depth ranges in the fragment fallback Without clip distances, the fragment shader's min/max Z discard only came on when both minz and maxz were set, while the clip planes take each side on its own. Pursuit Force's sky has minz 0 and maxz 300 and lies past 300, so the PSP drops it (its replays of 11399 UCES00019 and 11216 UCUS98703 show that), but GPUs without clip distances drew it over the scene: 13.9k px off the PSP on a Mali-G71, now 8 as with clip distances. The discard can now come with the fragment depth clamp, for the side that's at the limit. Co-Authored-By: Claude Opus 5.5 --- GPU/Common/DrawEngineCommon.cpp | 4 +++- GPU/Common/ShaderId.h | 4 +++- GPU/Common/VertexShaderGenerator.cpp | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index e9d0da0701..047c75f2cd 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -461,7 +461,9 @@ static bool TestBoundingBoxFast(const float *cullMatrix, const void *vdata, cons // // Alternatively, we just do a compat flag for the affected games until we can solve this. - if (needFragmentMinMaxClipping() && (minProjZ < gstate.getDepthRangeMin() || maxProjZ > gstate.getDepthRangeMax())) { + const int depthRangeMin = gstate.getDepthRangeMin(); + const int depthRangeMax = gstate.getDepthRangeMax(); + if ((depthRangeMin != 0 && minProjZ < depthRangeMin) || (depthRangeMax != 0xFFFF && maxProjZ > depthRangeMax)) { if (gstate_c.Use(GPU_USE_CLIP_DISTANCE)) { flags |= ClipInfoFlags::MinMaxZClip; } else { diff --git a/GPU/Common/ShaderId.h b/GPU/Common/ShaderId.h index 436ec86350..10ac650ea6 100644 --- a/GPU/Common/ShaderId.h +++ b/GPU/Common/ShaderId.h @@ -12,8 +12,10 @@ enum class ClipInfoFlags; // Shared ID checks for when the vertex and fragment shaders (and host code) need to coordinate. // NOTE: Both of these assume non-through-mode. Don't check these if in through mode. +// Each side on its own, like the clip planes: Pursuit Force's sky has min 0 and max 300, and the PSP drops it past 300. +// Can be needed together with needFragmentDepthClamp, for the side at the limit. inline bool needFragmentMinMaxClipping() { - return gstate.getDepthRangeMin() != 0 && gstate.getDepthRangeMax() != 0xFFFF; + return gstate.getDepthRangeMin() != 0 || gstate.getDepthRangeMax() != 0xFFFF; } inline bool needFragmentDepthClamp() { diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index a1434e6864..f5f0517874 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -961,8 +961,9 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag } if (fsDepthClamp) { - // After the rounding, so the fragment shader clamps the Z that hardware depth clamp would. - // (Never needed together with fsMinmaxDiscard, which wants it unrounded.) + // After the rounding, so the fragment shader clamps the Z that hardware depth clamp would. With fsMinmaxDiscard + // too, this replaces its unrounded Z: the same for the max side, which rounds down anyway, and up to 2 off for + // the min one, which only meets the clamp when max is 65535. WRITE(p, " %sv_zw = vec2(outPos.z * outPos.w, outPos.w);\n", compat.vsOutPrefix); } From 3e4458c7b7e350348e0423e1e6ece9817045f9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 17:30:15 +0200 Subject: [PATCH 12/18] Rebind the render target after writing stencil to another framebuffer PerformWriteStencilFromMemory bound the framebuffer it wrote the stencil to and, unless it blitted, left it bound. When that wasn't the current render target, the following draws landed in it. Draws that copy the target for shader blending rebind it themselves, which hid this; with framebuffer fetch they don't, and OutRun 2006's masked water draws went into the old 5551 buffer at the address instead of the new 565 one. Over the framedumps set on Vulkan, 9 dumps get closer to the PSP (OutRun ULUS10064_0002 12295 -> 483 px, F1 2009, God of War) and one a little further (16131 ULUS10193, a slight brightness shift). Co-Authored-By: Claude Opus 5.5 --- GPU/Common/StencilCommon.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GPU/Common/StencilCommon.cpp b/GPU/Common/StencilCommon.cpp index 4ea201d693..52f47f81a7 100644 --- a/GPU/Common/StencilCommon.cpp +++ b/GPU/Common/StencilCommon.cpp @@ -407,6 +407,10 @@ bool FramebufferManagerCommon::PerformWriteStencilFromMemory(u32 addr, int size, draw_->SetScissorRect(0, 0, dstBuffer->renderWidth, dstBuffer->renderHeight); draw_->BlitFramebuffer(blitFBO, 0, 0, w, h, dstBuffer->fbo, 0, 0, dstBuffer->renderWidth, dstBuffer->renderHeight, Draw::Aspect::STENCIL_BIT, Draw::FB_BLIT_NEAREST, "WriteStencilFromMemory_Blit"); RebindFramebuffer("RebindFramebuffer - Stencil"); + } else if (dstBuffer != currentRenderVfb_) { + // dstBuffer is bound as the target now, and the draws after this don't all rebind the current one: with + // framebuffer fetch, OutRun 2006's masked draws make no copy of the target that would, and landed in dstBuffer. + RebindFramebuffer("RebindFramebuffer - Stencil"); } draw_->Invalidate(InvalidationFlags::CACHED_RENDER_STATE); From b9780bc1322fb696edce5ccf8a8055052ef4f597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 18:54:02 +0200 Subject: [PATCH 13/18] Keep the stencil when resizing a framebuffer ResizeFramebufFBO copied color and depth into the new FBO but left its stencil cleared. Need for Speed Shift grows its framebuffer from 480 to 512 wide just before stencil testing, and the frame came out far too dark on Android (112k px off the PSP on an Adreno 840, now 4k). MoltenVK happened to keep it. Co-Authored-By: Claude Opus 5.5 --- GPU/Common/FramebufferManagerCommon.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index e42233a40f..43680970d2 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -2034,6 +2034,17 @@ void FramebufferManagerCommon::ResizeFramebufFBO(VirtualFramebuffer *vfb, int w, if (vfb->usageFlags & FB_USAGE_RENDER_DEPTH) { BlitFramebuffer(vfb, 0, 0, &old, 0, 0, std::min((u16)oldWidth, std::min(vfb->bufferWidth, vfb->width)), std::min((u16)oldHeight, std::min(vfb->height, vfb->bufferHeight)), 0, RASTER_DEPTH, "BlitDepth_ResizeFramebufFBO"); } + if (!skipCopy && vfb->fb_format != GE_FORMAT_565) { + // Keep the stencil too (Need for Speed Shift stencil tests right after its framebuffer grows from 480 to + // 512 wide). D3D11 has no separate stencil copy, but copies it along with the depth above. + const int stencilW = std::min(old.renderWidth, vfb->renderWidth); + const int stencilH = std::min(old.renderHeight, vfb->renderHeight); + if (draw_->GetDeviceCaps().framebufferSeparateDepthCopySupported) { + draw_->CopyFramebufferImage(old.fbo, 0, 0, 0, 0, vfb->fbo, 0, 0, 0, 0, stencilW, stencilH, 1, Draw::Aspect::STENCIL_BIT, "CopyStencil_ResizeFramebufFBO"); + } else if (draw_->GetDeviceCaps().framebufferStencilBlitSupported) { + draw_->BlitFramebuffer(old.fbo, 0, 0, stencilW, stencilH, vfb->fbo, 0, 0, stencilW, stencilH, Draw::Aspect::STENCIL_BIT, Draw::FB_BLIT_NEAREST, "BlitStencil_ResizeFramebufFBO"); + } + } } fbosToDelete_.push_back(old.fbo); draw_->BindFramebufferAsRenderTarget(vfb->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, Draw::RPAction::KEEP }, "ResizeFramebufFBO"); From 6b989f9d12b150ea3388d2daca1d6981dc210644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 17:30:15 +0200 Subject: [PATCH 14/18] Don't use BlueToAlpha with framebuffer fetch With fetch, the shader applies the colour masks and logic ops to the real bits, and OutRun 2006's water mask comes out like the software renderer's. BlueToAlpha put the first step in alpha while the masked logic-op steps after it worked on blue, so on the Adreno 840's OpenGL the water was off by twice as much as on Vulkan. Now it matches or beats Vulkan there. Co-Authored-By: Claude Opus 5.5 --- GPU/GPUCommonHW.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index b62c718501..269435a77a 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -895,8 +895,10 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { } // See the documentation for gstate_c.blueToAlpha. + // With framebuffer fetch, the shader applies the masks and logic ops to the real bits, which gets the whole + // sequence right (OutRun 2006's water mask comes out like the software renderer's), so it isn't needed there. bool blueToAlpha = false; - if (PSP_CoreParameter().compat.flags().BlueToAlpha) { + if (PSP_CoreParameter().compat.flags().BlueToAlpha && !gstate_c.Use(GPU_USE_FRAMEBUFFER_FETCH)) { if (gstate_c.framebufFormat == GEBufferFormat::GE_FORMAT_565 && gstate.getColorMask() == 0x0FFFFF && !gstate.isLogicOpEnabled()) { blueToAlpha = true; gstate_c.framebufFormat = GEBufferFormat::GE_FORMAT_4444; From e48086484c7afb09e3b1437bb9ae1ad6a6832c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 14 Oct 2026 00:57:11 +0200 Subject: [PATCH 15/18] Blend in the shader where stencil to alpha needs dual source blending we lack A draw that blends with the source alpha while setting the stencil (the alpha on the PSP) needs dual source blending to write both. Without it the alpha came out wrong, and later draws that blend with the destination alpha differed: WipEout Pure, Juiced 2 and 16131 UCES00001 on a Mali-G71 and a PowerVR GE8320. With framebuffer fetch, blend those in the shader instead, which matches the Mac's Vulkan render now. Without fetch it would take a framebuffer copy per draw, too slow for something this common. A draw that writes no color can't need the source alpha, so it writes the stencil as alpha directly. Co-Authored-By: Claude Opus 5.5 --- GPU/Common/GPUStateUtils.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index 5995f7ec65..87e56e3d6c 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -181,20 +181,34 @@ const bool nonAlphaDestFactors[16] = { true, }; +// Whether the color blend uses the source alpha, so the stencil can only be written as alpha with a second output. +static bool StencilToAlphaNeedsDualSource(ReplaceBlendType replaceBlend) { + if (IsStencilTestOutputDisabled() || gstate.isModeClear()) { + return false; + } + if (replaceBlend == REPLACE_BLEND_NO || replaceBlend == REPLACE_BLEND_READ_FRAMEBUFFER) { + return false; + } + if (nonAlphaSrcFactors[gstate.getBlendFuncA()] && nonAlphaDestFactors[gstate.getBlendFuncB()]) { + return false; + } + // With no color written, the color blend can't need the source alpha (WipEout Pure writes only the stencil + // this way, then blends with it as the destination alpha). + return (gstate.getColorMask() & 0x00FFFFFF) != 0x00FFFFFF; +} + ReplaceAlphaType ReplaceAlphaWithStencil(ReplaceBlendType replaceBlend) { if (IsStencilTestOutputDisabled() || gstate.isModeClear()) { return REPLACE_ALPHA_NO; } if (replaceBlend != REPLACE_BLEND_NO && replaceBlend != REPLACE_BLEND_READ_FRAMEBUFFER) { - if (nonAlphaSrcFactors[gstate.getBlendFuncA()] && nonAlphaDestFactors[gstate.getBlendFuncB()]) { + if (!StencilToAlphaNeedsDualSource(replaceBlend)) { return REPLACE_ALPHA_YES; + } else if (gstate_c.Use(GPU_USE_DUALSOURCE_BLEND)) { + return REPLACE_ALPHA_DUALSOURCE; } else { - if (gstate_c.Use(GPU_USE_DUALSOURCE_BLEND)) { - return REPLACE_ALPHA_DUALSOURCE; - } else { - return REPLACE_ALPHA_NO; - } + return REPLACE_ALPHA_NO; } } @@ -967,6 +981,11 @@ static void ConvertBlendState(GenericBlendState &blendState, FBReadSetting useFB if (useFBRead == FBReadSetting::Forced) { // Enforce blend replacement if enabled. If not, shouldn't do anything of course. replaceBlend = gstate.isAlphaBlendEnabled() ? REPLACE_BLEND_READ_FRAMEBUFFER : REPLACE_BLEND_NO; + } else if (useFBRead == FBReadSetting::Allowed && replaceBlend != REPLACE_BLEND_BLUE_TO_ALPHA && !gstate_c.Use(GPU_USE_DUALSOURCE_BLEND) && + gstate_c.Use(GPU_USE_FRAMEBUFFER_FETCH) && StencilToAlphaNeedsDualSource(replaceBlend)) { + // Blend in the shader, which can then write the stencil as alpha. Only with fetch: elsewhere a framebuffer + // copy per draw costs too much for something this common, so the alpha stays wrong (WipEout Pure). + replaceBlend = REPLACE_BLEND_READ_FRAMEBUFFER; } blendState.replaceBlend = replaceBlend; From c46bf4aca50d885afe6401b7c1c860d0e1b509b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 15:32:21 +0200 Subject: [PATCH 16/18] Compat: Turn on CorrectCullAfterClip for GachiTora A strip through the near plane leaves a sliver at the screen edge on GPUs with cull distances, where it isn't software clipped. The PSP range-culls it after clipping. Co-Authored-By: Claude Opus 5.5 --- assets/compat.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/compat.ini b/assets/compat.ini index 02eec157ef..d45d2881b8 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -2072,7 +2072,7 @@ ULUS10064 = true ULKS46087 = true [CorrectCullAfterClip] -# Only two known games need culling to happen accurately *after* clipping: Sengoku Cannon and Flatout. +# Only a few known games need culling to happen accurately *after* clipping: Sengoku Cannon, Flatout and GachiTora. # Sengoku Cannon UCAS40019 = true @@ -2083,6 +2083,10 @@ ULUS10328 = true ULES00968 = true ULES00969 = true +# GachiTora! Abarenbou Kyoushi in High School: a sliver at the screen edge from a strip through the near plane +ULJS00355 = true +NPJH50409 = true + [SpriteBorderFix] # TODO: We really need some kind of aggregation method... saying that Ridge racer is this list of IDs. From 49e0711d1096e81512646952b43c3bf06b673b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 15:36:07 +0200 Subject: [PATCH 17/18] Compat: Turn on CorrectCullAfterClip for Nova The same as GachiTora: without it, GPUs with cull distances draw parts the PSP range-culls after clipping. Co-Authored-By: Claude Opus 5.5 --- assets/compat.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/compat.ini b/assets/compat.ini index d45d2881b8..acd0fc2ee8 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -2072,7 +2072,7 @@ ULUS10064 = true ULKS46087 = true [CorrectCullAfterClip] -# Only a few known games need culling to happen accurately *after* clipping: Sengoku Cannon, Flatout and GachiTora. +# Only a few known games need culling to happen accurately *after* clipping: Sengoku Cannon, Flatout, GachiTora and Nova. # Sengoku Cannon UCAS40019 = true @@ -2087,6 +2087,9 @@ ULES00969 = true ULJS00355 = true NPJH50409 = true +# Nova (minis): like GachiTora +NPUZ00179 = true + [SpriteBorderFix] # TODO: We really need some kind of aggregation method... saying that Ridge racer is this list of IDs. From b555ba044ef4b4e224a10f4ad8d82917dddbe2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 13 Oct 2026 16:58:57 +0200 Subject: [PATCH 18/18] frametests: Add 13 dumps from ppsspp-framedumps Co-Authored-By: Claude Opus 5.5 --- frametests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frametests b/frametests index 4bccabd3d3..2c7812d28e 160000 --- a/frametests +++ b/frametests @@ -1 +1 @@ -Subproject commit 4bccabd3d3951fd7cebb01a23794807e5faa47d8 +Subproject commit 2c7812d28e2cc755c617c20f4b07983def7569bf