Bug 1594128 - Add brush_mix_blend to the multi-brush infrastructure. r=gw
authorNicolas Silva <nsilva@mozilla.com>
Mon, 25 Nov 2019 20:01:49 +0000
changeset 503874 5768997fb3919368e763df2c7cb9198b6d3995ff
parent 503873 0d89ea8665dfc2c9efc40054ecd29f5227172f06
child 503875 54efcc9976cf17987c5b3bbfaf120ea76f9b395e
push id101594
push usernsilva@mozilla.com
push dateTue, 26 Nov 2019 15:35:43 +0000
treeherderautoland@39f51911efa8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw
bugs1594128
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594128 - Add brush_mix_blend to the multi-brush infrastructure. r=gw Differential Revision: https://phabricator.services.mozilla.com/D53994
gfx/wr/webrender/res/brush.glsl
gfx/wr/webrender/res/brush_mix_blend.glsl
gfx/wr/webrender/res/brush_multi.glsl
--- a/gfx/wr/webrender/res/brush.glsl
+++ b/gfx/wr/webrender/res/brush.glsl
@@ -220,16 +220,22 @@ void main(void) {
             break;
         #endif
 
         #ifdef WR_FEATURE_BLEND_BRUSH
         case BRUSH_KIND_BLEND:
             blend_brush_vs(BRUSH_VS_PARAMS);
             break;
         #endif
+
+        #ifdef WR_FEATURE_MIX_BLEND_BRUSH
+        case BRUSH_KIND_MIX_BLEND:
+            mix_blend_brush_vs(BRUSH_VS_PARAMS);
+            break;
+        #endif
     }
 
 #else
     WR_BRUSH_VS_FUNCTION(BRUSH_VS_PARAMS);
 #endif
 
 }
 
@@ -275,16 +281,22 @@ void main(void) {
         }
 #endif
 #ifdef WR_FEATURE_BLEND_BRUSH
         case BRUSH_KIND_BLEND: {
             frag = blend_brush_fs();
             break;
         }
 #endif
+#ifdef WR_FEATURE_MIX_BLEND_BRUSH
+        case BRUSH_KIND_MIX_BLEND: {
+            frag = mix_blend_brush_fs();
+            break;
+        }
+#endif
     }
 #else
     frag = WR_BRUSH_FS_FUNCTION();
 #endif
 
 
 #ifdef WR_FEATURE_ALPHA_PASS
     // Apply the clip mask
--- a/gfx/wr/webrender/res/brush_mix_blend.glsl
+++ b/gfx/wr/webrender/res/brush_mix_blend.glsl
@@ -5,19 +5,23 @@
 #define VECS_PER_MIX_BLEND_BRUSH 3
 #define VECS_PER_SPECIFIC_BRUSH VECS_PER_MIX_BLEND_BRUSH
 
 #define WR_BRUSH_VS_FUNCTION mix_blend_brush_vs
 #define WR_BRUSH_FS_FUNCTION mix_blend_brush_fs
 
 #include shared,prim_shared,brush
 
-varying vec3 vSrcUv;
-varying vec3 vBackdropUv;
-flat varying int vOp;
+#define V_SRC_UV            varying_vec4_0.xy
+#define V_SRC_LAYER         varying_vec4_0.w
+
+#define V_BACKDROP_UV       varying_vec4_1.xy
+#define V_BACKDROP_LAYER    varying_vec4_1.w
+
+#define V_OP                flat_varying_ivec4_0.x
 
 #ifdef WR_VERTEX_SHADER
 
 //Note: this function is unsafe for `vi.world_pos.w <= 0.0`
 vec2 snap_device_pos(VertexInfo vi, float device_pixel_scale) {
     return vi.world_pos.xy * device_pixel_scale / max(0.0, vi.world_pos.w) + vi.snap_offset;
 }
 
@@ -30,29 +34,31 @@ void mix_blend_brush_vs(
     int specific_resource_address,
     mat4 transform,
     PictureTask pic_task,
     int brush_flags,
     vec4 unused
 ) {
     vec2 snapped_device_pos = snap_device_pos(vi, pic_task.device_pixel_scale);
     vec2 texture_size = vec2(textureSize(sPrevPassColor, 0));
-    vOp = prim_user_data.x;
+    V_OP = prim_user_data.x;
 
     PictureTask src_task = fetch_picture_task(prim_user_data.z);
     vec2 src_uv = snapped_device_pos +
                   src_task.common_data.task_rect.p0 -
                   src_task.content_origin;
-    vSrcUv = vec3(src_uv / texture_size, src_task.common_data.texture_layer_index);
+    V_SRC_UV = src_uv / texture_size;
+    V_SRC_LAYER = src_task.common_data.texture_layer_index;
 
     RenderTaskCommonData backdrop_task = fetch_render_task_common_data(prim_user_data.y);
     vec2 backdrop_uv = snapped_device_pos +
                        backdrop_task.task_rect.p0 -
                        src_task.content_origin;
-    vBackdropUv = vec3(backdrop_uv / texture_size, backdrop_task.texture_layer_index);
+    V_BACKDROP_UV = backdrop_uv / texture_size;
+    V_BACKDROP_LAYER = backdrop_task.texture_layer_index;
 }
 #endif
 
 #ifdef WR_FRAGMENT_SHADER
 vec3 Multiply(vec3 Cb, vec3 Cs) {
     return Cb * Cs;
 }
 
@@ -205,32 +211,32 @@ const int MixBlendMode_SoftLight   = 9;
 const int MixBlendMode_Difference  = 10;
 const int MixBlendMode_Exclusion   = 11;
 const int MixBlendMode_Hue         = 12;
 const int MixBlendMode_Saturation  = 13;
 const int MixBlendMode_Color       = 14;
 const int MixBlendMode_Luminosity  = 15;
 
 Fragment mix_blend_brush_fs() {
-    vec4 Cb = textureLod(sPrevPassColor, vBackdropUv, 0.0);
-    vec4 Cs = textureLod(sPrevPassColor, vSrcUv, 0.0);
+    vec4 Cb = textureLod(sPrevPassColor, vec3(V_BACKDROP_UV, V_BACKDROP_LAYER), 0.0);
+    vec4 Cs = textureLod(sPrevPassColor, vec3(V_SRC_UV, V_SRC_LAYER), 0.0);
 
     // The mix-blend-mode functions assume no premultiplied alpha
     if (Cb.a != 0.0) {
         Cb.rgb /= Cb.a;
     }
 
     if (Cs.a != 0.0) {
         Cs.rgb /= Cs.a;
     }
 
     // Return yellow if none of the branches match (shouldn't happen).
     vec4 result = vec4(1.0, 1.0, 0.0, 1.0);
 
-    switch (vOp) {
+    switch (V_OP) {
         case MixBlendMode_Multiply:
             result.rgb = Multiply(Cb.rgb, Cs.rgb);
             break;
         case MixBlendMode_Screen:
             result.rgb = Screen(Cb.rgb, Cs.rgb);
             break;
         case MixBlendMode_Overlay:
             // Overlay is inverse of Hardlight
@@ -284,8 +290,15 @@ Fragment mix_blend_brush_fs() {
     result.rgb = (1.0 - Cb.a) * Cs.rgb + Cb.a * result.rgb;
     result.a = Cs.a;
 
     result.rgb *= result.a;
 
     return Fragment(result);
 }
 #endif
+
+// Undef macro names that could be re-defined by other shaders.
+#undef V_SRC_UV
+#undef V_SRC_LAYER
+#undef V_BACKDROP_UV
+#undef V_BACKDROP_LAYER
+#undef V_OP
--- a/gfx/wr/webrender/res/brush_multi.glsl
+++ b/gfx/wr/webrender/res/brush_multi.glsl
@@ -23,16 +23,24 @@ int vecs_per_brush(int brush_kind);
 #undef VECS_PER_SPECIFIC_BRUSH
 #undef WR_BRUSH_VS_FUNCTION
 #undef WR_BRUSH_FS_FUNCTION
 
 #ifdef WR_FEATURE_BLEND_BRUSH
 #include brush_blend
 #endif
 
+#undef VECS_PER_SPECIFIC_BRUSH
+#undef WR_BRUSH_VS_FUNCTION
+#undef WR_BRUSH_FS_FUNCTION
+
+#ifdef WR_FEATURE_MIX_BLEND_BRUSH
+#include brush_mix_blend
+#endif
+
 int vecs_per_brush(int brush_kind) {
     int result;
     switch (brush_kind) {
         #ifdef WR_FEATURE_IMAGE_BRUSH
         case BRUSH_KIND_IMAGE:
             result = VECS_PER_IMAGE_BRUSH;
             break;
         #endif
@@ -43,12 +51,18 @@ int vecs_per_brush(int brush_kind) {
             break;
         #endif
 
         #ifdef WR_FEATURE_BLEND_BRUSH
         case BRUSH_KIND_BLEND:
             result = VECS_PER_BLEND_BRUSH;
             break;
         #endif
+
+        #ifdef WR_FEATURE_MIX_BLEND_BRUSH
+        case BRUSH_KIND_MIX_BLEND:
+            result = VECS_PER_MIX_BLEND_BRUSH;
+            break;
+        #endif
     }
 
     return result;
 }