From ac1f8c54964e7919a6ccd8ea0755f8548cc827bb Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 11 Mar 2020 12:05:16 +0000 Subject: [PATCH] Bug 1612941 - WR shader changes to support SWGL instance attribs. r=jrmuizel,gw Add annotations to vertex shaders so that SWGL can detect when a vertex attribute is generated by per-instance data rather than per-vertex data. Differential Revision: https://phabricator.services.mozilla.com/D65614 --HG-- extra : moz-landing-system : lando --- gfx/wr/webrender/res/base.glsl | 8 ++++++++ gfx/wr/webrender/res/clip_shared.glsl | 14 +++++++------- gfx/wr/webrender/res/composite.glsl | 16 ++++++++-------- gfx/wr/webrender/res/cs_blur.glsl | 6 +++--- gfx/wr/webrender/res/cs_border_segment.glsl | 18 +++++++++--------- gfx/wr/webrender/res/cs_border_solid.glsl | 18 +++++++++--------- gfx/wr/webrender/res/cs_gradient.glsl | 16 ++++++++-------- gfx/wr/webrender/res/cs_line_decoration.glsl | 10 +++++----- gfx/wr/webrender/res/cs_scale.glsl | 6 +++--- gfx/wr/webrender/res/cs_svg_filter.glsl | 14 +++++++------- gfx/wr/webrender/res/debug_color.glsl | 2 +- gfx/wr/webrender/res/debug_font.glsl | 2 +- gfx/wr/webrender/res/pf_vector_cover.glsl | 8 ++++---- gfx/wr/webrender/res/pf_vector_stencil.glsl | 16 ++++++++-------- gfx/wr/webrender/res/pls_init.glsl | 2 +- gfx/wr/webrender/res/pls_resolve.glsl | 2 +- gfx/wr/webrender/res/prim_shared.glsl | 2 +- gfx/wr/webrender/res/shared.glsl | 2 +- 18 files changed, 85 insertions(+), 77 deletions(-) diff --git a/gfx/wr/webrender/res/base.glsl b/gfx/wr/webrender/res/base.glsl index 9d66a064a939..eb343c019b57 100644 --- a/gfx/wr/webrender/res/base.glsl +++ b/gfx/wr/webrender/res/base.glsl @@ -36,6 +36,14 @@ #endif #ifdef WR_VERTEX_SHADER + #ifdef SWGL + // Annotate a vertex attribute as being flat per each drawn primitive instance. + // SWGL can use this information to avoid redundantly loading the attribute in all SIMD lanes. + #define PER_INSTANCE flat + #else + #define PER_INSTANCE + #endif + #define varying out #endif diff --git a/gfx/wr/webrender/res/clip_shared.glsl b/gfx/wr/webrender/res/clip_shared.glsl index a6a7d2dd50a1..e5b803896872 100644 --- a/gfx/wr/webrender/res/clip_shared.glsl +++ b/gfx/wr/webrender/res/clip_shared.glsl @@ -6,13 +6,13 @@ #ifdef WR_VERTEX_SHADER -in ivec2 aTransformIds; -in ivec4 aClipDataResourceAddress; -in vec2 aClipLocalPos; -in vec4 aClipTileRect; -in vec4 aClipDeviceArea; -in vec4 aClipOrigins; -in float aDevicePixelScale; +PER_INSTANCE in ivec2 aTransformIds; +PER_INSTANCE in ivec4 aClipDataResourceAddress; +PER_INSTANCE in vec2 aClipLocalPos; +PER_INSTANCE in vec4 aClipTileRect; +PER_INSTANCE in vec4 aClipDeviceArea; +PER_INSTANCE in vec4 aClipOrigins; +PER_INSTANCE in float aDevicePixelScale; struct ClipMaskInstance { int clip_transform_id; diff --git a/gfx/wr/webrender/res/composite.glsl b/gfx/wr/webrender/res/composite.glsl index a63df80e023d..81b4454fabfc 100644 --- a/gfx/wr/webrender/res/composite.glsl +++ b/gfx/wr/webrender/res/composite.glsl @@ -23,16 +23,16 @@ varying vec2 vUv; #endif #ifdef WR_VERTEX_SHADER -in vec4 aDeviceRect; -in vec4 aDeviceClipRect; -in vec4 aColor; -in vec4 aParams; -in vec3 aTextureLayers; +PER_INSTANCE in vec4 aDeviceRect; +PER_INSTANCE in vec4 aDeviceClipRect; +PER_INSTANCE in vec4 aColor; +PER_INSTANCE in vec4 aParams; +PER_INSTANCE in vec3 aTextureLayers; #ifdef WR_FEATURE_YUV -in vec4 aUvRect0; -in vec4 aUvRect1; -in vec4 aUvRect2; +PER_INSTANCE in vec4 aUvRect0; +PER_INSTANCE in vec4 aUvRect1; +PER_INSTANCE in vec4 aUvRect2; #endif void main(void) { diff --git a/gfx/wr/webrender/res/cs_blur.glsl b/gfx/wr/webrender/res/cs_blur.glsl index db3583210b3f..a10fe00d7909 100644 --- a/gfx/wr/webrender/res/cs_blur.glsl +++ b/gfx/wr/webrender/res/cs_blur.glsl @@ -18,9 +18,9 @@ flat varying int vSupport; #define DIR_HORIZONTAL 0 #define DIR_VERTICAL 1 -in int aBlurRenderTaskAddress; -in int aBlurSourceTaskAddress; -in int aBlurDirection; +PER_INSTANCE in int aBlurRenderTaskAddress; +PER_INSTANCE in int aBlurSourceTaskAddress; +PER_INSTANCE in int aBlurDirection; struct BlurTask { RenderTaskCommonData common_data; diff --git a/gfx/wr/webrender/res/cs_border_segment.glsl b/gfx/wr/webrender/res/cs_border_segment.glsl index 0b833d278ab2..9eb5155f1f6c 100644 --- a/gfx/wr/webrender/res/cs_border_segment.glsl +++ b/gfx/wr/webrender/res/cs_border_segment.glsl @@ -72,15 +72,15 @@ varying vec2 vPos; #ifdef WR_VERTEX_SHADER -in vec2 aTaskOrigin; -in vec4 aRect; -in vec4 aColor0; -in vec4 aColor1; -in int aFlags; -in vec2 aWidths; -in vec2 aRadii; -in vec4 aClipParams1; -in vec4 aClipParams2; +PER_INSTANCE in vec2 aTaskOrigin; +PER_INSTANCE in vec4 aRect; +PER_INSTANCE in vec4 aColor0; +PER_INSTANCE in vec4 aColor1; +PER_INSTANCE in int aFlags; +PER_INSTANCE in vec2 aWidths; +PER_INSTANCE in vec2 aRadii; +PER_INSTANCE in vec4 aClipParams1; +PER_INSTANCE in vec4 aClipParams2; vec2 get_outer_corner_scale(int segment) { vec2 p; diff --git a/gfx/wr/webrender/res/cs_border_solid.glsl b/gfx/wr/webrender/res/cs_border_solid.glsl index dde00b83ec7a..d5748143533f 100644 --- a/gfx/wr/webrender/res/cs_border_solid.glsl +++ b/gfx/wr/webrender/res/cs_border_solid.glsl @@ -45,15 +45,15 @@ varying vec2 vPos; #ifdef WR_VERTEX_SHADER -in vec2 aTaskOrigin; -in vec4 aRect; -in vec4 aColor0; -in vec4 aColor1; -in int aFlags; -in vec2 aWidths; -in vec2 aRadii; -in vec4 aClipParams1; -in vec4 aClipParams2; +PER_INSTANCE in vec2 aTaskOrigin; +PER_INSTANCE in vec4 aRect; +PER_INSTANCE in vec4 aColor0; +PER_INSTANCE in vec4 aColor1; +PER_INSTANCE in int aFlags; +PER_INSTANCE in vec2 aWidths; +PER_INSTANCE in vec2 aRadii; +PER_INSTANCE in vec4 aClipParams1; +PER_INSTANCE in vec4 aClipParams2; vec2 get_outer_corner_scale(int segment) { vec2 p; diff --git a/gfx/wr/webrender/res/cs_gradient.glsl b/gfx/wr/webrender/res/cs_gradient.glsl index 6e848a34dc9e..6e6b5c4ad06d 100644 --- a/gfx/wr/webrender/res/cs_gradient.glsl +++ b/gfx/wr/webrender/res/cs_gradient.glsl @@ -13,14 +13,14 @@ flat varying vec4 vColor3; #ifdef WR_VERTEX_SHADER -in vec4 aTaskRect; -in float aAxisSelect; -in vec4 aStops; -in vec4 aColor0; -in vec4 aColor1; -in vec4 aColor2; -in vec4 aColor3; -in vec2 aStartStop; +PER_INSTANCE in vec4 aTaskRect; +PER_INSTANCE in float aAxisSelect; +PER_INSTANCE in vec4 aStops; +PER_INSTANCE in vec4 aColor0; +PER_INSTANCE in vec4 aColor1; +PER_INSTANCE in vec4 aColor2; +PER_INSTANCE in vec4 aColor3; +PER_INSTANCE in vec2 aStartStop; void main(void) { vPos = mix(aStartStop.x, aStartStop.y, mix(aPosition.x, aPosition.y, aAxisSelect)); diff --git a/gfx/wr/webrender/res/cs_line_decoration.glsl b/gfx/wr/webrender/res/cs_line_decoration.glsl index 42336fcc1164..7063bcffb12c 100644 --- a/gfx/wr/webrender/res/cs_line_decoration.glsl +++ b/gfx/wr/webrender/res/cs_line_decoration.glsl @@ -21,22 +21,22 @@ flat varying vec4 vParams; #ifdef WR_VERTEX_SHADER // The size of the mask tile we're rendering, in pixels. -in vec4 aTaskRect; +PER_INSTANCE in vec4 aTaskRect; // The size of the mask tile. aLocalSize.x is always horizontal and .y vertical, // regardless of the line's orientation. The size is chosen by // prim_store::get_line_decoration_sizes. -in vec2 aLocalSize; +PER_INSTANCE in vec2 aLocalSize; // A LINE_STYLE_* value, indicating what sort of line to draw. -in int aStyle; +PER_INSTANCE in int aStyle; // 0.0 for a horizontal line, 1.0 for a vertical line. -in float aAxisSelect; +PER_INSTANCE in float aAxisSelect; // The thickness of the wavy line itself, not the amplitude of the waves (i.e., // the thickness of the final decorated line). -in float aWavyLineThickness; +PER_INSTANCE in float aWavyLineThickness; void main(void) { vec2 size = mix(aLocalSize, aLocalSize.yx, aAxisSelect); diff --git a/gfx/wr/webrender/res/cs_scale.glsl b/gfx/wr/webrender/res/cs_scale.glsl index 183e6774cc47..6d0c0e59982b 100644 --- a/gfx/wr/webrender/res/cs_scale.glsl +++ b/gfx/wr/webrender/res/cs_scale.glsl @@ -9,9 +9,9 @@ flat varying vec4 vUvRect; #ifdef WR_VERTEX_SHADER -in vec4 aScaleTargetRect; -in ivec4 aScaleSourceRect; -in int aScaleSourceLayer; +PER_INSTANCE in vec4 aScaleTargetRect; +PER_INSTANCE in ivec4 aScaleSourceRect; +PER_INSTANCE in int aScaleSourceLayer; void main(void) { RectWithSize src_rect = RectWithSize(vec2(aScaleSourceRect.xy), vec2(aScaleSourceRect.zw)); diff --git a/gfx/wr/webrender/res/cs_svg_filter.glsl b/gfx/wr/webrender/res/cs_svg_filter.glsl index b43ca2ecf90d..62d808a1e3d5 100644 --- a/gfx/wr/webrender/res/cs_svg_filter.glsl +++ b/gfx/wr/webrender/res/cs_svg_filter.glsl @@ -39,13 +39,13 @@ flat varying int vFuncs[4]; #ifdef WR_VERTEX_SHADER -in int aFilterRenderTaskAddress; -in int aFilterInput1TaskAddress; -in int aFilterInput2TaskAddress; -in int aFilterKind; -in int aFilterInputCount; -in int aFilterGenericInt; -in ivec2 aFilterExtraDataAddress; +PER_INSTANCE in int aFilterRenderTaskAddress; +PER_INSTANCE in int aFilterInput1TaskAddress; +PER_INSTANCE in int aFilterInput2TaskAddress; +PER_INSTANCE in int aFilterKind; +PER_INSTANCE in int aFilterInputCount; +PER_INSTANCE in int aFilterGenericInt; +PER_INSTANCE in ivec2 aFilterExtraDataAddress; struct FilterTask { RenderTaskCommonData common_data; diff --git a/gfx/wr/webrender/res/debug_color.glsl b/gfx/wr/webrender/res/debug_color.glsl index 15285bdbbe5d..b5a636e535ef 100644 --- a/gfx/wr/webrender/res/debug_color.glsl +++ b/gfx/wr/webrender/res/debug_color.glsl @@ -11,7 +11,7 @@ in vec4 aColor; void main(void) { vColor = vec4(aColor.rgb * aColor.a, aColor.a); - vec4 pos = vec4(aPosition, 1.0); + vec4 pos = vec4(aPosition, 0.0, 1.0); pos.xy = floor(pos.xy + 0.5); gl_Position = uTransform * pos; } diff --git a/gfx/wr/webrender/res/debug_font.glsl b/gfx/wr/webrender/res/debug_font.glsl index b93c4bcaa57e..5b9fb2109fbd 100644 --- a/gfx/wr/webrender/res/debug_font.glsl +++ b/gfx/wr/webrender/res/debug_font.glsl @@ -14,7 +14,7 @@ in vec2 aColorTexCoord; void main(void) { vColor = aColor; vColorTexCoord = aColorTexCoord; - vec4 pos = vec4(aPosition, 1.0); + vec4 pos = vec4(aPosition, 0.0, 1.0); pos.xy = floor(pos.xy + 0.5); gl_Position = uTransform * pos; } diff --git a/gfx/wr/webrender/res/pf_vector_cover.glsl b/gfx/wr/webrender/res/pf_vector_cover.glsl index a4eece1a1fc7..1b2eeabb7dc7 100644 --- a/gfx/wr/webrender/res/pf_vector_cover.glsl +++ b/gfx/wr/webrender/res/pf_vector_cover.glsl @@ -6,10 +6,10 @@ #ifdef WR_VERTEX_SHADER -in ivec4 aTargetRect; -in ivec2 aStencilOrigin; -in int aSubpixel; -in int aPad; +PER_INSTANCE in ivec4 aTargetRect; +PER_INSTANCE in ivec2 aStencilOrigin; +PER_INSTANCE in int aSubpixel; +PER_INSTANCE in int aPad; out vec2 vStencilUV; flat out int vSubpixel; diff --git a/gfx/wr/webrender/res/pf_vector_stencil.glsl b/gfx/wr/webrender/res/pf_vector_stencil.glsl index e951eeba1663..2029768fcb9a 100644 --- a/gfx/wr/webrender/res/pf_vector_stencil.glsl +++ b/gfx/wr/webrender/res/pf_vector_stencil.glsl @@ -6,14 +6,14 @@ #ifdef WR_VERTEX_SHADER -in vec2 aFromPosition; -in vec2 aCtrlPosition; -in vec2 aToPosition; -in vec2 aFromNormal; -in vec2 aCtrlNormal; -in vec2 aToNormal; -in int aPathID; -in int aPad; +PER_INSTANCE in vec2 aFromPosition; +PER_INSTANCE in vec2 aCtrlPosition; +PER_INSTANCE in vec2 aToPosition; +PER_INSTANCE in vec2 aFromNormal; +PER_INSTANCE in vec2 aCtrlNormal; +PER_INSTANCE in vec2 aToNormal; +PER_INSTANCE in int aPathID; +PER_INSTANCE in int aPad; out vec2 vFrom; out vec2 vCtrl; diff --git a/gfx/wr/webrender/res/pls_init.glsl b/gfx/wr/webrender/res/pls_init.glsl index 4d3e391a7e4f..a9fe0a6c4a63 100644 --- a/gfx/wr/webrender/res/pls_init.glsl +++ b/gfx/wr/webrender/res/pls_init.glsl @@ -11,7 +11,7 @@ #include shared #ifdef WR_VERTEX_SHADER -in vec4 aRect; +PER_INSTANCE in vec4 aRect; void main(void) { vec2 pos = aRect.xy + aPosition.xy * aRect.zw; diff --git a/gfx/wr/webrender/res/pls_resolve.glsl b/gfx/wr/webrender/res/pls_resolve.glsl index 70ba5f1cca2b..363ce2ccfefa 100644 --- a/gfx/wr/webrender/res/pls_resolve.glsl +++ b/gfx/wr/webrender/res/pls_resolve.glsl @@ -11,7 +11,7 @@ #include shared #ifdef WR_VERTEX_SHADER -in vec4 aRect; +PER_INSTANCE in vec4 aRect; void main(void) { vec2 pos = aRect.xy + aPosition.xy * aRect.zw; diff --git a/gfx/wr/webrender/res/prim_shared.glsl b/gfx/wr/webrender/res/prim_shared.glsl index d4a06b2a2d63..f89340ff49cc 100644 --- a/gfx/wr/webrender/res/prim_shared.glsl +++ b/gfx/wr/webrender/res/prim_shared.glsl @@ -45,7 +45,7 @@ uniform HIGHP_SAMPLER_FLOAT sampler2D sPrimitiveHeadersF; uniform HIGHP_SAMPLER_FLOAT isampler2D sPrimitiveHeadersI; // Instanced attributes -in ivec4 aData; +PER_INSTANCE in ivec4 aData; #define VECS_PER_PRIM_HEADER_F 2U #define VECS_PER_PRIM_HEADER_I 2U diff --git a/gfx/wr/webrender/res/shared.glsl b/gfx/wr/webrender/res/shared.glsl index 0b375d66f4b0..7723b70f19cb 100644 --- a/gfx/wr/webrender/res/shared.glsl +++ b/gfx/wr/webrender/res/shared.glsl @@ -50,7 +50,7 @@ uniform mat4 uTransform; // Orthographic projection // Attribute inputs - in vec3 aPosition; + in vec2 aPosition; // get_fetch_uv is a macro to work around a macOS Intel driver parsing bug. // TODO: convert back to a function once the driver issues are resolved, if ever.