From 7ef1767010b60d41a3b5734ea32d6fd1715f9e10 Mon Sep 17 00:00:00 2001 From: crashGG <80488411+crashGG@users.noreply.github.com> Date: Tue, 30 Jun 2026 12:07:00 +0300 Subject: [PATCH] perf(MMPX adv): optimize target out-of-bounds check perf(MMPX adv): optimize transparent out-of-bounds sampling and bug fix --- assets/shaders/tex_mmpx_adv.csh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/assets/shaders/tex_mmpx_adv.csh b/assets/shaders/tex_mmpx_adv.csh index 50664d6714..ec4ed158cb 100644 --- a/assets/shaders/tex_mmpx_adv.csh +++ b/assets/shaders/tex_mmpx_adv.csh @@ -33,10 +33,18 @@ precision mediump float; uint srcu(int x, int y) { - //* out-of-bounds check, return transparent color if coordinates are out of range - return (x >= 0 && x < params.width && y >= 0 && y < params.height) - ? readColoru(uvec2(x, y)) - : 0u; + ivec2 target = ivec2(x, y); + + //* clamp target to safe bounds + ivec2 safe = clamp(target, ivec2(0), ivec2(params.width - 1, params.height - 1)); + + uint color = readColoru(uvec2(safe)); + + //* in-bounds check + bool is_in = all(equal(target, safe)); + + //* return transparent color if out of range + return is_in ? color : 0u; } #define src(c,d) unpackUnorm4x8(srcu(c,d))