From 5d2a68fda09f4cdf124841e86b56965580f33bd2 Mon Sep 17 00:00:00 2001 From: Jamie Nicol Date: Thu, 21 Nov 2024 15:45:51 +0000 Subject: [PATCH] Bug 1932416 - Avoid shader miscompile due to if statement on Adreno devices. r=gfx-reviewers,nical The brush_image shader handles normalized input UV coordinates by first unnormalizing them if the flag is set, allowing the same logic to be used subsequently regardless of whether the flag is set. Unfortunately this appears to cause a miscompilation in the REPETITION variant of the shader on some Adreno devices. Removing the additional branch by replacing the if statement with a mix() avoids the issue. Differential Revision: https://phabricator.services.mozilla.com/D229796 --- gfx/wr/webrender/res/brush_image.glsl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gfx/wr/webrender/res/brush_image.glsl b/gfx/wr/webrender/res/brush_image.glsl index 406ad189b83c..7d20f750a95d 100644 --- a/gfx/wr/webrender/res/brush_image.glsl +++ b/gfx/wr/webrender/res/brush_image.glsl @@ -170,10 +170,15 @@ void brush_vs( float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0; v_perspective.x = perspective_interpolate; - if ((brush_flags & BRUSH_FLAG_NORMALIZED_UVS) != 0) { - uv0 *= texture_size; - uv1 *= texture_size; - } + // We deliberately use mix() here rather than scaling the UVs in an if + // statement. The latter caused issues in the REPETITION variant of this + // shader on some Adreno devices. Perhaps due to the excessive number of + // branches in the repetition code, and this one broke the camel's back? + // See bug 1932416. + vec2 uv_scale = mix(vec2(1.0), texture_size, + bvec2((brush_flags & BRUSH_FLAG_NORMALIZED_UVS) != 0)); + uv0 *= uv_scale; + uv1 *= uv_scale; // Handle case where the UV coords are inverted (e.g. from an // external image).