Bug 1728064 - Remove all remaining flat scalar varyings from shaders on android. r=gfx-reviewers,kvark

There is a driver bug on Adreno 3xx devices causing incorrect
rendering when flat scalar varyings are used in fragment shaders. The
original report was in bug 1630356, but it has been reported since on
several occasions for various shaders, which have been fixed one at a
time. This patch removes the remaining flat scalar varyings from all
of our shaders so that we do not encounter this issue again.

Additionally, it removes the usage of #ifdefs surrounding these
workarounds so that it applies to all platforms rather than just
android. This has been done to keep the code more readable - now that
we have a test to ensure this is not regressed it no longer needs to
be loud and ugly.

Differential Revision: https://phabricator.services.mozilla.com/D124204
This commit is contained in:
Jamie Nicol 2021-09-06 13:56:58 +00:00
parent 39e95288ea
commit 4a11f7cb49
19 changed files with 150 additions and 177 deletions

View File

@ -16,11 +16,17 @@ flat varying vec4 v_uv_sample_bounds;
// x: Flag to allow perspective interpolation of UV.
// y: Filter-dependent "amount" parameter.
// Please ensure that perspective remains packed in a vector. If refactoring,
// see the v_perspective declaration in brush_image, and bug 1630356.
// Packed in to a vector to work around bug 1630356.
flat varying vec2 v_perspective_amount;
flat varying int v_op;
flat varying int v_table_address;
#define v_perspective v_perspective_amount.x
#define v_amount v_perspective_amount.y
// x: Blend op, y: Lookup table GPU cache address.
// Packed in to a vector to work around bug 1630356.
flat varying ivec2 v_op_table_address_vec;
#define v_op v_op_table_address_vec.x
#define v_table_address v_op_table_address_vec.y
flat varying mat4 v_color_mat;
flat varying ivec4 v_funcs;
flat varying vec4 v_color_offset;
@ -49,14 +55,14 @@ void brush_vs(
float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0;
v_uv = uv * inv_texture_size * mix(vi.world_pos.w, 1.0, perspective_interpolate);
v_perspective_amount.x = perspective_interpolate;
v_perspective = perspective_interpolate;
v_uv_sample_bounds = vec4(uv0 + vec2(0.5), uv1 - vec2(0.5)) * inv_texture_size.xyxy;
float amount = float(prim_user_data.z) / 65536.0;
v_op = prim_user_data.y & 0xffff;
v_perspective_amount.y = amount;
v_amount = amount;
// This assignment is only used for component transfer filters but this
// assignment has to be done here and not in the component transfer case
@ -83,7 +89,7 @@ void brush_vs(
#ifdef WR_FRAGMENT_SHADER
Fragment brush_fs() {
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective_amount.x);
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective);
vec2 uv = v_uv * perspective_divisor;
// Clamp the uvs to avoid sampling artifacts.
uv = clamp(uv, v_uv_sample_bounds.xy, v_uv_sample_bounds.zw);
@ -95,7 +101,7 @@ Fragment brush_fs() {
CalculateFilter(
Cs,
v_op,
v_perspective_amount.y,
v_amount,
v_table_address,
v_color_offset,
v_color_mat,

View File

@ -21,19 +21,9 @@ flat varying vec4 v_uv_bounds;
// sampling artifacts.
flat varying vec4 v_uv_sample_bounds;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// On Adreno 3xx devices we have observed that a flat scalar varying used to calculate
// fragment shader output can result in the entire output being "flat". Here, for example,
// v_perspective being flat results in the UV coordinate calculated for every fragment
// being equal to the UV coordinate for the provoking vertex, which results in the entire
// triangle being rendered a solid color.
// Packing the varying in a vec2 works around this. See bug 1630356.
flat varying vec2 v_perspective_vec;
#define v_perspective v_perspective_vec.x
#else
// Flag to allow perspective interpolation of UV.
flat varying float v_perspective;
#endif
// Packed in to vector to work around bug 1630356.
flat varying vec2 v_perspective;
#ifdef WR_VERTEX_SHADER
@ -174,7 +164,7 @@ void brush_vs(
}
float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0;
v_perspective = perspective_interpolate;
v_perspective.x = perspective_interpolate;
// Handle case where the UV coords are inverted (e.g. from an
// external image).
@ -323,7 +313,7 @@ vec2 compute_repeated_uvs(float perspective_divisor) {
}
Fragment brush_fs() {
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective);
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective.x);
vec2 repeated_uv = compute_repeated_uvs(perspective_divisor);
// Clamp the uvs to avoid sampling artifacts.
@ -368,7 +358,7 @@ void swgl_drawSpanRGBA8() {
}
#endif
float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, v_perspective);
float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, v_perspective.x);
#ifdef WR_FEATURE_REPETITION
// Get the UVs before any repetition, scaling, or offsetting has occurred...

View File

@ -6,7 +6,9 @@
#include shared,prim_shared,brush,gradient_shared
flat varying float v_start_offset;
// Start offset. Packed in to vector to work around bug 1630356.
flat varying vec2 v_start_offset;
flat varying vec2 v_scale_dir;
#ifdef WR_VERTEX_SHADER
@ -57,7 +59,7 @@ void brush_vs(
// Normalize UV and offsets to 0..1 scale.
v_scale_dir = dir / dot(dir, dir);
v_start_offset = dot(start_point, v_scale_dir);
v_start_offset.x = dot(start_point, v_scale_dir);
v_scale_dir *= v_repeated_size;
}
#endif
@ -65,7 +67,7 @@ void brush_vs(
#ifdef WR_FRAGMENT_SHADER
float get_gradient_offset(vec2 pos) {
// Project position onto a direction vector to compute offset.
return dot(pos, v_scale_dir) - v_start_offset;
return dot(pos, v_scale_dir) - v_start_offset.x;
}
Fragment brush_fs() {
@ -80,17 +82,17 @@ Fragment brush_fs() {
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address), int(GRADIENT_ENTRIES + 2.0));
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}
#ifndef WR_FEATURE_ALPHA_PASS
swgl_commitLinearGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat != 0.0,
swgl_commitLinearGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
get_gradient_offset(v_pos));
#else
while (swgl_SpanLength > 0) {
float offset = get_gradient_offset(compute_repeated_pos());
if (v_gradient_repeat != 0.0) offset = fract(offset);
if (v_gradient_repeat.x != 0.0) offset = fract(offset);
float entry = clamp_gradient_entry(offset);
swgl_commitGradientRGBA8(sGpuCache, address, entry);
v_pos += swgl_interpStep(v_pos);

View File

@ -15,19 +15,11 @@ flat varying vec4 v_src_uv_sample_bounds;
varying vec2 v_backdrop_uv;
flat varying vec4 v_backdrop_uv_sample_bounds;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying vec2 v_perspective_vec;
#define v_perspective v_perspective_vec.x
flat varying ivec2 v_op_vec;
#define v_op v_op_vec.x
#else
// Flag to allow perspective interpolation of UV.
flat varying float v_perspective;
// mix-blend op
flat varying int v_op;
#endif
// Packed in to vector to work around bug 1630356.
flat varying vec2 v_perspective;
// mix-blend op. Packed in to vector to work around bug 1630356.
flat varying ivec2 v_op;
#ifdef WR_VERTEX_SHADER
@ -66,8 +58,8 @@ void brush_vs(
vec2 f = (vi.local_pos - local_rect.p0) / rect_size(local_rect);
float perspective_interpolate = (brush_flags & BRUSH_FLAG_PERSPECTIVE_INTERPOLATION) != 0 ? 1.0 : 0.0;
float perspective_f = mix(vi.world_pos.w, 1.0, perspective_interpolate);
v_perspective = perspective_interpolate;
v_op = prim_user_data.x;
v_perspective.x = perspective_interpolate;
v_op.x = prim_user_data.x;
get_uv(
prim_user_data.y,
@ -248,7 +240,7 @@ const int MixBlendMode_Color = 14;
const int MixBlendMode_Luminosity = 15;
Fragment brush_fs() {
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective);
float perspective_divisor = mix(gl_FragCoord.w, 1.0, v_perspective.x);
vec2 src_uv = v_src_uv * perspective_divisor;
src_uv = clamp(src_uv, v_src_uv_sample_bounds.xy, v_src_uv_sample_bounds.zw);
@ -277,7 +269,7 @@ Fragment brush_fs() {
// gets optimized away by glslopt. Adding a bitwise AND prevents that.
// See bug 1726755.
// default: default: to appease angle_shader_validation
switch (v_op & 0xFF) {
switch (v_op.x & 0xFF) {
case MixBlendMode_Multiply:
result.rgb = Multiply(Cb.rgb, Cs.rgb);
break;

View File

@ -14,17 +14,10 @@ varying vec2 v_uv;
// sampling artifacts.
flat varying vec4 v_uv_sample_bounds;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying vec2 v_perspective_vec;
#define v_perspective v_perspective_vec.x
#else
flat varying vec2 v_opacity_perspective_vec;
#define v_opacity v_opacity_perspective_vec.x
// Flag to allow perspective interpolation of UV.
flat varying float v_perspective;
#endif
flat varying float v_opacity;
#define v_perspective v_opacity_perspective_vec.y
#ifdef WR_VERTEX_SHADER
void brush_vs(

View File

@ -17,7 +17,9 @@ flat varying vec4 vUvBounds_V;
YUV_PRECISION flat varying vec3 vYcbcrBias;
YUV_PRECISION flat varying mat3 vRgbFromDebiasedYcbcr;
flat varying int vFormat;
// YUV format. Packed in to vector to work around bug 1630356.
flat varying ivec2 vFormat;
#ifdef SWGL_DRAW_SPAN
flat varying int vRescaleFactor;
@ -67,22 +69,22 @@ void brush_vs(
vYcbcrBias = mat_info.ycbcr_bias;
vRgbFromDebiasedYcbcr = mat_info.rgb_from_debiased_ycbrc;
vFormat = prim.yuv_format;
vFormat.x = prim.yuv_format;
// The additional test for 99 works around a gen6 shader compiler bug: 1708937
if (vFormat == YUV_FORMAT_PLANAR || vFormat == 99) {
if (vFormat.x == YUV_FORMAT_PLANAR || vFormat.x == 99) {
ImageSource res_y = fetch_image_source(prim_user_data.x);
ImageSource res_u = fetch_image_source(prim_user_data.y);
ImageSource res_v = fetch_image_source(prim_user_data.z);
write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
write_uv_rect(res_u.uv_rect.p0, res_u.uv_rect.p1, f, TEX_SIZE_YUV(sColor1), vUv_U, vUvBounds_U);
write_uv_rect(res_v.uv_rect.p0, res_v.uv_rect.p1, f, TEX_SIZE_YUV(sColor2), vUv_V, vUvBounds_V);
} else if (vFormat == YUV_FORMAT_NV12) {
} else if (vFormat.x == YUV_FORMAT_NV12) {
ImageSource res_y = fetch_image_source(prim_user_data.x);
ImageSource res_u = fetch_image_source(prim_user_data.y);
write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
write_uv_rect(res_u.uv_rect.p0, res_u.uv_rect.p1, f, TEX_SIZE_YUV(sColor1), vUv_U, vUvBounds_U);
} else if (vFormat == YUV_FORMAT_INTERLEAVED) {
} else if (vFormat.x == YUV_FORMAT_INTERLEAVED) {
ImageSource res_y = fetch_image_source(prim_user_data.x);
write_uv_rect(res_y.uv_rect.p0, res_y.uv_rect.p1, f, TEX_SIZE_YUV(sColor0), vUv_Y, vUvBounds_Y);
}
@ -93,7 +95,7 @@ void brush_vs(
Fragment brush_fs() {
vec4 color = sample_yuv(
vFormat,
vFormat.x,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vUv_Y,
@ -116,20 +118,20 @@ Fragment brush_fs() {
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
if (vFormat == YUV_FORMAT_PLANAR) {
if (vFormat.x == YUV_FORMAT_PLANAR) {
swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
sColor1, vUv_U, vUvBounds_U,
sColor2, vUv_V, vUvBounds_V,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vRescaleFactor);
} else if (vFormat == YUV_FORMAT_NV12) {
} else if (vFormat.x == YUV_FORMAT_NV12) {
swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
sColor1, vUv_U, vUvBounds_U,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vRescaleFactor);
} else if (vFormat == YUV_FORMAT_INTERLEAVED) {
} else if (vFormat.x == YUV_FORMAT_INTERLEAVED) {
swgl_commitTextureLinearYUV(sColor0, vUv_Y, vUvBounds_Y,
vYcbcrBias,
vRgbFromDebiasedYcbcr,

View File

@ -18,7 +18,8 @@
#ifdef WR_FEATURE_YUV
YUV_PRECISION flat varying vec3 vYcbcrBias;
YUV_PRECISION flat varying mat3 vRgbFromDebiasedYcbcr;
flat varying int vYuvFormat;
// YUV format. Packed in to vector to avoid bug 1630356.
flat varying ivec2 vYuvFormat;
#ifdef SWGL_DRAW_SPAN
flat varying int vRescaleFactor;
@ -105,7 +106,7 @@ void main(void) {
vYcbcrBias = mat_info.ycbcr_bias;
vRgbFromDebiasedYcbcr = mat_info.rgb_from_debiased_ycbrc;
vYuvFormat = prim.yuv_format;
vYuvFormat.x = prim.yuv_format;
write_uv_rect(
aUvRect0.xy,
@ -169,7 +170,7 @@ void main(void) {
void main(void) {
#ifdef WR_FEATURE_YUV
vec4 color = sample_yuv(
vYuvFormat,
vYuvFormat.x,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vUV_y,
@ -200,20 +201,20 @@ void main(void) {
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
#ifdef WR_FEATURE_YUV
if (vYuvFormat == YUV_FORMAT_PLANAR) {
if (vYuvFormat.x == YUV_FORMAT_PLANAR) {
swgl_commitTextureLinearYUV(sColor0, vUV_y, vUVBounds_y,
sColor1, vUV_u, vUVBounds_u,
sColor2, vUV_v, vUVBounds_v,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vRescaleFactor);
} else if (vYuvFormat == YUV_FORMAT_NV12) {
} else if (vYuvFormat.x == YUV_FORMAT_NV12) {
swgl_commitTextureLinearYUV(sColor0, vUV_y, vUVBounds_y,
sColor1, vUV_u, vUVBounds_u,
vYcbcrBias,
vRgbFromDebiasedYcbcr,
vRescaleFactor);
} else if (vYuvFormat == YUV_FORMAT_INTERLEAVED) {
} else if (vYuvFormat.x == YUV_FORMAT_INTERLEAVED) {
swgl_commitTextureLinearYUV(sColor0, vUV_y, vUVBounds_y,
vYcbcrBias,
vRgbFromDebiasedYcbcr,

View File

@ -10,7 +10,8 @@ varying vec2 vUv;
flat varying vec4 vUvRect;
flat varying vec2 vOffsetScale;
// The number of pixels on each end that we apply the blur filter over.
flat varying int vSupport;
// Packed in to vector to work around bug 1630356.
flat varying ivec2 vSupport;
flat varying vec2 vGaussCoefficients;
#ifdef WR_VERTEX_SHADER
@ -53,7 +54,7 @@ void calculate_gauss_coefficients(float sigma) {
vec3 gauss_coefficient = vec3(vGaussCoefficients,
vGaussCoefficients.y * vGaussCoefficients.y);
float gauss_coefficient_total = gauss_coefficient.x;
for (int i = 1; i <= vSupport; i += 2) {
for (int i = 1; i <= vSupport.x; i += 2) {
gauss_coefficient.xy *= gauss_coefficient.yz;
float gauss_coefficient_subtotal = gauss_coefficient.x;
gauss_coefficient.xy *= gauss_coefficient.yz;
@ -79,9 +80,9 @@ void main(void) {
//
// TODO(pcwalton): Actually make use of this fact and use the texture
// hardware for linear filtering.
vSupport = int(ceil(1.5 * blur_task.blur_radius)) * 2;
vSupport.x = int(ceil(1.5 * blur_task.blur_radius)) * 2;
if (vSupport > 0) {
if (vSupport.x > 0) {
calculate_gauss_coefficients(blur_task.blur_radius);
} else {
// The gauss function gets NaNs when blur radius is zero.
@ -158,7 +159,7 @@ void main(void) {
// Clamp loop condition variable to a statically known value to workaround
// driver bug on Adreno 3xx. vSupport should not exceed 300 anyway, due to
// the max blur radius being 100. See bug 1720841 for details.
int support = min(vSupport, 300);
int support = min(vSupport.x, 300);
for (int i = 1; i <= support; i += 2) {
gauss_coefficient.xy *= gauss_coefficient.yz;
@ -182,12 +183,12 @@ void main(void) {
#ifdef WR_FEATURE_COLOR_TARGET
void swgl_drawSpanRGBA8() {
swgl_commitGaussianBlurRGBA8(sColor0, vUv, vUvRect, vOffsetScale.x != 0.0,
vSupport, vGaussCoefficients);
vSupport.x, vGaussCoefficients);
}
#else
void swgl_drawSpanR8() {
swgl_commitGaussianBlurR8(sColor0, vUv, vUvRect, vOffsetScale.x != 0.0,
vSupport, vGaussCoefficients);
vSupport.x, vGaussCoefficients);
}
#endif
#endif

View File

@ -17,15 +17,9 @@ flat varying vec4 vColor1;
// transition occurs. Used for corners only.
flat varying vec4 vColorLine;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying ivec2 vMixColorsVec;
#define vMixColors vMixColorsVec.x
#else
// A boolean indicating that we should be mixing between edge colors.
flat varying int vMixColors;
#endif
// Packed in to a vector to work around bug 1630356.
flat varying ivec2 vMixColors;
// xy = Local space position of the clip center.
// zw = Scale the rect origin by this to get the outer
@ -110,7 +104,7 @@ void main(void) {
break;
}
vMixColors = mix_colors;
vMixColors.x = mix_colors;
vPos = size * aPosition.xy;
vColor0 = aColor0;
@ -138,10 +132,10 @@ void main(void) {
#ifdef WR_FRAGMENT_SHADER
void main(void) {
float aa_range = compute_aa_range(vPos);
bool do_aa = vMixColors != MIX_NO_AA;
bool do_aa = vMixColors.x != MIX_NO_AA;
float mix_factor = 0.0;
if (vMixColors != DONT_MIX) {
if (vMixColors.x != DONT_MIX) {
float d_line = distance_to_line(vColorLine.xy, vColorLine.zw, vPos);
if (do_aa) {
mix_factor = distance_aa(aa_range, -d_line);

View File

@ -9,14 +9,8 @@ varying vec2 vUv;
flat varying vec4 vUvBounds;
flat varying vec4 vEdge;
flat varying vec4 vUvBounds_NoClamp;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying vec2 vClipModeVec;
#define vClipMode vClipModeVec.x
#else
flat varying float vClipMode;
#endif
// Clip mode. Packed in to a vector to avoid bug 1630356.
flat varying vec2 vClipMode;
#define MODE_STRETCH 0
#define MODE_SIMPLE 1
@ -80,7 +74,7 @@ void main(void) {
cmi.base.screen_origin,
cmi.base.device_pixel_scale
);
vClipMode = float(bs_data.clip_mode);
vClipMode.x = float(bs_data.clip_mode);
vec2 texture_size = vec2(TEX_SIZE(sColor0));
vec2 local_pos = vi.local_pos.xy / vi.local_pos.w;
@ -137,8 +131,8 @@ void main(void) {
float texel = TEX_SAMPLE(sColor0, uv).r;
float alpha = mix(texel, 1.0 - texel, vClipMode);
float result = vLocalPos.w > 0.0 ? mix(vClipMode, alpha, in_shadow_rect) : 0.0;
float alpha = mix(texel, 1.0 - texel, vClipMode.x);
float result = vLocalPos.w > 0.0 ? mix(vClipMode.x, alpha, in_shadow_rect) : 0.0;
oFragColor = vec4(result);
}
@ -224,7 +218,7 @@ void swgl_drawSpanR8() {
// Fill any initial sections of the span that are clipped out based on clip mode.
if (swgl_SpanLength > shadow_start_len) {
int num_before = swgl_SpanLength - shadow_start_len;
swgl_commitPartialSolidR8(num_before, vClipMode);
swgl_commitPartialSolidR8(num_before, vClipMode.x);
float steps_before = float(num_before / swgl_StepSize);
uv_linear += steps_before * uv_linear_step;
local_pos += steps_before * local_step;
@ -249,8 +243,8 @@ void swgl_drawSpanR8() {
float texel = TEX_SAMPLE(sColor0, uv).r;
float alpha = mix(texel, 1.0 - texel, vClipMode);
float result = mix(vClipMode, alpha, in_shadow_rect);
float alpha = mix(texel, 1.0 - texel, vClipMode.x);
float result = mix(vClipMode.x, alpha, in_shadow_rect);
swgl_commitColorR8(result);
uv_linear += uv_linear_step;
@ -302,9 +296,9 @@ void swgl_drawSpanR8() {
if (uv_bounds.xy == uv_bounds.zw) {
uv = clamp(uv, uv_bounds.xy, uv_bounds.zw);
float texel = TEX_SAMPLE(sColor0, uv).r;
float alpha = mix(texel, 1.0 - texel, vClipMode);
float alpha = mix(texel, 1.0 - texel, vClipMode.x);
swgl_commitPartialSolidR8(num_inside, alpha);
} else if (vClipMode != 0.0) {
} else if (vClipMode.x != 0.0) {
swgl_commitPartialTextureLinearInvertR8(num_inside, sColor0, uv, uv_bounds);
} else {
swgl_commitPartialTextureLinearR8(num_inside, sColor0, uv, uv_bounds);
@ -320,7 +314,7 @@ void swgl_drawSpanR8() {
// Fill any remaining sections of the span that are clipped out.
if (swgl_SpanLength > 0) {
swgl_commitPartialSolidR8(swgl_SpanLength, vClipMode);
swgl_commitPartialSolidR8(swgl_SpanLength, vClipMode.x);
}
}
#endif

View File

@ -19,7 +19,8 @@ flat varying vec4 vClipCenter_Radius_BR;
flat varying vec4 vClipCorner_BR;
#endif
#endif
flat varying float vClipMode;
// Clip mode. Packed in to a vector to work around bug 1630356.
flat varying vec2 vClipMode;
#ifdef WR_VERTEX_SHADER
@ -100,7 +101,7 @@ void main(void) {
cmi.base.device_pixel_scale
);
vClipMode = clip.rect.mode;
vClipMode.x = clip.rect.mode;
vLocalPos = vi.local_pos;
#ifdef WR_FEATURE_FAST_PATH
@ -191,7 +192,7 @@ void main(void) {
float alpha = distance_aa(aa_range, dist);
// Select alpha or inverse alpha depending on clip in/out.
float final_alpha = mix(alpha, 1.0 - alpha, vClipMode);
float final_alpha = mix(alpha, 1.0 - alpha, vClipMode.x);
float final_final_alpha = vLocalPos.w > 0.0 ? final_alpha : 0.0;
oFragColor = vec4(final_final_alpha, 0.0, 0.0, 1.0);
@ -420,7 +421,7 @@ void swgl_drawSpanR8() {
// Output fully clear while we're outside the AA region.
if (swgl_SpanLength > aa_start_len) {
int num_aa = swgl_SpanLength - aa_start_len;
swgl_commitPartialSolidR8(num_aa, vClipMode);
swgl_commitPartialSolidR8(num_aa, vClipMode.x);
local_pos += float(num_aa / swgl_StepSize) * local_step;
}
#ifdef AA_CORNER
@ -435,7 +436,7 @@ void swgl_drawSpanR8() {
dot(local_pos - start_plane.xy, start_plane.zw) > 0.0
? AA_CORNER(local_pos, start_corner)
: AA_RECT(local_pos));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode.x));
local_pos += local_step;
}
}
@ -443,14 +444,14 @@ void swgl_drawSpanR8() {
// If there's no start corner, just do rect AA until opaque.
while (swgl_SpanLength > opaque_start_len) {
float alpha = distance_aa(aa_range, AA_RECT(local_pos));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode.x));
local_pos += local_step;
}
// Now we're finally in the opaque inner octagon part of the span. Just
// output a solid run.
if (swgl_SpanLength > opaque_end_len) {
int num_opaque = swgl_SpanLength - opaque_end_len;
swgl_commitPartialSolidR8(num_opaque, 1.0 - vClipMode);
swgl_commitPartialSolidR8(num_opaque, 1.0 - vClipMode.x);
local_pos += float(num_opaque / swgl_StepSize) * local_step;
}
#ifdef AA_CORNER
@ -466,7 +467,7 @@ void swgl_drawSpanR8() {
dot(local_pos - end_plane.xy, end_plane.zw) > 0.0
? AA_CORNER(local_pos, end_corner)
: AA_RECT(local_pos));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode.x));
local_pos += local_step;
}
}
@ -474,13 +475,13 @@ void swgl_drawSpanR8() {
// If there's no end corner, just do rect AA until clear.
while (swgl_SpanLength > aa_end_len) {
float alpha = distance_aa(aa_range, AA_RECT(local_pos));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode));
swgl_commitColorR8(mix(alpha, 1.0 - alpha, vClipMode.x));
local_pos += local_step;
}
// We're now outside the outer AA octagon on the other side. Just output
// fully clear.
if (swgl_SpanLength > 0) {
swgl_commitPartialSolidR8(swgl_SpanLength, vClipMode);
swgl_commitPartialSolidR8(swgl_SpanLength, vClipMode.x);
}
}
#endif

View File

@ -9,9 +9,13 @@
varying vec2 v_pos;
flat varying vec2 v_center;
flat varying float v_start_offset;
flat varying float v_offset_scale;
flat varying float v_angle;
// x: start offset, y: offset scale, z: angle
// Packed in to a vector to work around bug 1630356.
flat varying vec3 v_start_offset_offset_scale_angle_vec;
#define v_start_offset v_start_offset_offset_scale_angle_vec.x
#define v_offset_scale v_start_offset_offset_scale_angle_vec.y
#define v_angle v_start_offset_offset_scale_angle_vec.z
#ifdef WR_VERTEX_SHADER
@ -43,8 +47,8 @@ void main(void) {
v_center = aCenter * v_offset_scale;
v_pos = (aTaskRect.zw - aTaskRect.xy) * aPosition.xy * v_offset_scale * aScale;
v_gradient_repeat = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address = aGradientStopsAddress;
v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address.x = aGradientStopsAddress;
}
#endif

View File

@ -15,7 +15,9 @@
// being decorated.
varying vec2 vLocalPos;
flat varying int vStyle;
// Line style. Packed in to a vector to work around bug 1630356.
flat varying ivec2 vStyle;
flat varying vec4 vParams;
#ifdef WR_VERTEX_SHADER
@ -40,9 +42,9 @@ PER_INSTANCE in float aWavyLineThickness;
void main(void) {
vec2 size = mix(aLocalSize, aLocalSize.yx, aAxisSelect);
vStyle = aStyle;
vStyle.x = aStyle;
switch (vStyle) {
switch (vStyle.x) {
case LINE_STYLE_SOLID: {
break;
}
@ -98,7 +100,7 @@ void main(void) {
float aa_range = compute_aa_range(pos);
float alpha = 1.0;
switch (vStyle) {
switch (vStyle.x) {
case LINE_STYLE_SOLID: {
break;
}

View File

@ -7,7 +7,9 @@
varying vec2 v_pos;
flat varying vec2 v_scale_dir;
flat varying float v_start_offset;
// Start offset. Packed in to a vector to work around bug 1630356.
flat varying vec2 v_start_offset;
#ifdef WR_VERTEX_SHADER
@ -30,12 +32,12 @@ void main(void) {
// Normalize UV and offsets to 0..1 scale.
v_scale_dir = dir / dot(dir, dir);
v_start_offset = dot(aStartPoint, v_scale_dir);
v_start_offset.x = dot(aStartPoint, v_scale_dir);
v_scale_dir *= (aTaskRect.zw - aTaskRect.xy);
v_gradient_repeat = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address = aGradientStopsAddress;
v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address.x = aGradientStopsAddress;
}
#endif
@ -44,7 +46,7 @@ void main(void) {
void main(void) {
// Project position onto a direction vector to compute offset.
float offset = dot(v_pos, v_scale_dir) - v_start_offset;
float offset = dot(v_pos, v_scale_dir) - v_start_offset.x;
oFragColor = sample_gradient(offset);
}
@ -52,13 +54,13 @@ void main(void) {
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address), int(GRADIENT_ENTRIES + 2.0));
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}
float offset = dot(v_pos, v_scale_dir) - v_start_offset;
swgl_commitLinearGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat != 0.0,
float offset = dot(v_pos, v_scale_dir) - v_start_offset.x;
swgl_commitLinearGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
offset);
}
#endif

View File

@ -6,7 +6,8 @@
varying vec2 v_pos;
flat varying float v_start_radius;
// Start radius. Packed in to a vector to work around bug 1630356.
flat varying vec2 v_start_radius;
#ifdef WR_VERTEX_SHADER
@ -30,7 +31,7 @@ void main(void) {
vec2 pos = mix(aTaskRect.xy, aTaskRect.zw, aPosition.xy);
gl_Position = uTransform * vec4(pos, 0.0, 1.0);
v_start_radius = aStartRadius * radius_scale;
v_start_radius.x = aStartRadius * radius_scale;
// Transform all coordinates by the y scale so the
// fragment shader can work with circles
@ -40,8 +41,8 @@ void main(void) {
v_pos = ((aTaskRect.zw - aTaskRect.xy) * aPosition.xy * aScale - aCenter) * radius_scale;
v_pos.y *= aXYRatio;
v_gradient_repeat = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address = aGradientStopsAddress;
v_gradient_repeat.x = float(aExtendMode == EXTEND_MODE_REPEAT);
v_gradient_address.x = aGradientStopsAddress;
}
#endif
@ -50,20 +51,20 @@ void main(void) {
void main(void) {
// Solve for t in length(pd) = v_start_radius + t * rd
float offset = length(v_pos) - v_start_radius;
float offset = length(v_pos) - v_start_radius.x;
oFragColor = sample_gradient(offset);
}
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address),
int address = swgl_validateGradient(sGpuCache, get_gpu_cache_uv(v_gradient_address.x),
int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}
swgl_commitRadialGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat != 0.0,
v_pos, v_start_radius);
swgl_commitRadialGradientRGBA8(sGpuCache, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
v_pos, v_start_radius.x);
}
#endif

View File

@ -10,19 +10,18 @@ varying vec2 vInput1Uv;
varying vec2 vInput2Uv;
flat varying vec4 vInput1UvRect;
flat varying vec4 vInput2UvRect;
flat varying int vFilterInputCount;
flat varying int vFilterKind;
flat varying ivec4 vData;
flat varying vec4 vFilterData0;
flat varying vec4 vFilterData1;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying vec2 vFloat0Vec;
#define vFloat0 vFloat0Vec.x
#else
flat varying float vFloat0;
#endif
// x: Filter input count, y: Filter kind.
// Packed in to a vector to work around bug 1630356.
flat varying ivec2 vFilterInputCountFilterKindVec;
#define vFilterInputCount vFilterInputCountFilterKindVec.x
#define vFilterKind vFilterInputCountFilterKindVec.y
// Packed in to a vector to work around bug 1630356.
flat varying vec2 vFloat0;
flat varying mat4 vColorMat;
flat varying ivec4 vFuncs;
@ -130,7 +129,7 @@ void main(void) {
vFilterData0 = fetch_from_gpu_cache_1_direct(aFilterExtraDataAddress);
break;
case FILTER_OPACITY:
vFloat0 = filter_task.user_data.x;
vFloat0.x = filter_task.user_data.x;
break;
case FILTER_COLOR_MATRIX:
vec4 mat_data[4] = fetch_from_gpu_cache_4_direct(aFilterExtraDataAddress);
@ -555,7 +554,7 @@ void main(void) {
break;
case FILTER_OPACITY:
result.rgb = Ca.rgb;
result.a = Ca.a * vFloat0;
result.a = Ca.a * vFloat0.x;
break;
case FILTER_COLOR_MATRIX:
result = vColorMat * Ca + vFilterData0;

View File

@ -2,17 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
flat varying HIGHP_FS_ADDRESS int v_gradient_address;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bugs 1630356 and for details.
flat varying vec2 v_gradient_repeat_vec;
#define v_gradient_repeat v_gradient_repeat_vec.x
#else
// Gradient GPU cache address.
// Packed in to a vector to work around bug 1630356.
flat varying HIGHP_FS_ADDRESS ivec2 v_gradient_address;
// Repetition along the gradient stops.
flat varying float v_gradient_repeat;
#endif
// Packed in to a vector to work around bug 1630356.
flat varying vec2 v_gradient_repeat;
#ifdef WR_FRAGMENT_SHADER
@ -49,7 +44,7 @@ float clamp_gradient_entry(float offset) {
vec4 sample_gradient(float offset) {
// Modulo the offset if the gradient repeats.
offset -= floor(offset) * v_gradient_repeat;
offset -= floor(offset) * v_gradient_repeat.x;
// Calculate the texel to index into the gradient color entries:
// floor(x) is the gradient color entry index
@ -59,7 +54,7 @@ vec4 sample_gradient(float offset) {
float entry_fract = x - entry_index;
// Fetch the start and end color. There is a [start, end] color per entry.
vec4 texels[2] = fetch_from_gpu_cache_2(v_gradient_address + 2 * int(entry_index));
vec4 texels[2] = fetch_from_gpu_cache_2(v_gradient_address.x + 2 * int(entry_index));
// Finally interpolate and apply dithering
return dither(texels[0] + texels[1] * entry_fract);

View File

@ -40,10 +40,10 @@ void write_gradient_vertex(
// Normalize UV to 0..1 scale.
v_pos /= v_repeated_size;
v_gradient_address = prim_user_data.x;
v_gradient_address.x = prim_user_data.x;
// Whether to repeat the gradient along the line instead of clamping.
v_gradient_repeat = float(extend_mode == EXTEND_MODE_REPEAT);
v_gradient_repeat.x = float(extend_mode == EXTEND_MODE_REPEAT);
#ifdef WR_FEATURE_ALPHA_PASS
v_tile_repeat = tile_repeat;

View File

@ -9,15 +9,9 @@
// interpolated UV coordinates to sample.
varying vec2 vUv;
#if defined(PLATFORM_ANDROID) && !defined(SWGL)
// Work around Adreno 3xx driver bug. See the v_perspective comment in
// brush_image or bug 1630356 for details.
flat varying vec2 vPerspectiveVec;
#define vPerspective vPerspectiveVec.x
#else
// Flag to allow perspective interpolation of UV.
flat varying float vPerspective;
#endif
// Packed in to a vector to work around bug 1630356.
flat varying vec2 vPerspective;
flat varying vec4 vUvSampleBounds;
@ -116,21 +110,21 @@ void main(void) {
float perspective_interpolate = float(ph.user_data.y);
vUv = uv / texture_size * mix(gl_Position.w, 1.0, perspective_interpolate);
vPerspective = perspective_interpolate;
vPerspective.x = perspective_interpolate;
}
#endif
#ifdef WR_FRAGMENT_SHADER
void main(void) {
float alpha = do_clip();
float perspective_divisor = mix(gl_FragCoord.w, 1.0, vPerspective);
float perspective_divisor = mix(gl_FragCoord.w, 1.0, vPerspective.x);
vec2 uv = clamp(vUv * perspective_divisor, vUvSampleBounds.xy, vUvSampleBounds.zw);
write_output(alpha * texture(sColor0, uv));
}
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, vPerspective);
float perspective_divisor = mix(swgl_forceScalar(gl_FragCoord.w), 1.0, vPerspective.x);
vec2 uv = vUv * perspective_divisor;
swgl_commitTextureRGBA8(sColor0, uv, vUvSampleBounds);