From e2b3dce09dc821f5b1febe67d3ec6f766d07fd43 Mon Sep 17 00:00:00 2001 From: Shokunin <30949000+tetrisgm@users.noreply.github.com> Date: Tue, 6 Oct 2026 03:50:20 -0700 Subject: [PATCH] Dynamic resolution: shrink the copy/stencil scratch after a step A step grows the scratch to hold the old level's displayed rect and draw area, and it stayed that size: every tiled stencil rebuild renders into it, so on GL-on-Metal its size cost bandwidth on each one. Return it to the size a surface allocated at the new level starts with. Co-Authored-By: Claude Opus 5.5 --- runtime/src/gpu_gl_renderer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/runtime/src/gpu_gl_renderer.c b/runtime/src/gpu_gl_renderer.c index 97e3cb83..506f76ed 100644 --- a/runtime/src/gpu_gl_renderer.c +++ b/runtime/src/gpu_gl_renderer.c @@ -9159,6 +9159,21 @@ static int dyn_apply(int snew) { wst_all(i); /* colour only */ } } + /* 5b. The copy/stencil scratch back to its size for a surface allocated + * at snew (alloc_hr_targets): the step grew it to the old level's + * rects, and every tiled stencil rebuild renders into it. */ + { + int hw = VRAM_W * snew, hh = VRAM_H * snew; + int sw = snew <= 2 ? hw : (hw < GL_SCRATCH_TILE ? hw : GL_SCRATCH_TILE); + int sh = snew <= 2 ? hh : (hh < GL_SCRATCH_TILE ? hh : GL_SCRATCH_TILE); + if (s_scratch_w > sw || s_scratch_h > sh) { + p_glActiveTexture(PSXGL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, s_scratch_tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, sw, sh, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + s_scratch_w = sw; s_scratch_h = sh; + } + } const uint64_t t5 = dyn_mark(); /* 6. The new scale. */ s_hr_scale = s_out_scale = snew;