Skip to content

Commit

Permalink
Update WR - texture layers, image mask, profiler, optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Oct 26, 2016
1 parent 4b28750 commit 86eaef2
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 57 deletions.
1 change: 1 addition & 0 deletions components/layout/webrender_helpers.rs
Expand Up @@ -160,6 +160,7 @@ impl ToClipRegion for ClippingRegion {
complex_clipping_region.radii.to_border_radius(),
)
}).collect(),
None,
&mut frame_builder.auxiliary_lists_builder)
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions resources/shaders/clip_shared.glsl
Expand Up @@ -5,14 +5,19 @@

flat varying vec4 vClipRect;
flat varying vec4 vClipRadius;
flat varying vec4 vClipMaskUvRect;
flat varying vec4 vClipMaskLocalRect;

#ifdef WR_VERTEX_SHADER
void write_clip(Clip clip) {
void write_clip(ClipInfo clip) {
vClipRect = vec4(clip.rect.rect.xy, clip.rect.rect.xy + clip.rect.rect.zw);
vClipRadius = vec4(clip.top_left.outer_inner_radius.x,
clip.top_right.outer_inner_radius.x,
clip.bottom_right.outer_inner_radius.x,
clip.bottom_left.outer_inner_radius.x);
//TODO: interpolate the final mask UV
vClipMaskUvRect = clip.mask_info.uv_rect;
vClipMaskLocalRect = clip.mask_info.local_rect; //TODO: transform
}
#endif

Expand All @@ -29,23 +34,31 @@ float do_clip(vec2 pos) {
float d_bl = distance(pos, ref_bl);

float pixels_per_fragment = length(fwidth(pos.xy));
// TODO: compute the `nudge` separately for X and Y
float nudge = 0.5 * pixels_per_fragment;
vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;

bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > vClipRadius.x - nudge;
bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > vClipRadius.y - nudge;
bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > vClipRadius.z - nudge;
bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > vClipRadius.w - nudge;
bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
pos.x > ref_tr.x && pos.y < ref_tr.y,
pos.x > ref_br.x && pos.y > ref_br.y,
pos.x < ref_bl.x && pos.y > ref_bl.y);

vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;
float distance_from_border = dot(vec4(out0, out1, out2, out3), distances);
float distance_from_border = dot(vec4(is_out),
max(vec4(0.0, 0.0, 0.0, 0.0), distances));

// Move the distance back into pixels.
distance_from_border /= pixels_per_fragment;

// Apply a more gradual fade out to transparent.
//distance_from_border -= 0.5;

return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
float border_alpha = 1.0 - smoothstep(0.0, 1.0, distance_from_border);

bool repeat_mask = false; //TODO
vec2 vMaskUv = (pos - vClipMaskLocalRect.xy) / vClipMaskLocalRect.zw;
vec2 clamped_mask_uv = repeat_mask ? fract(vMaskUv) :
clamp(vMaskUv, vec2(0.0, 0.0), vec2(1.0, 1.0));
vec2 source_uv = clamped_mask_uv * vClipMaskUvRect.zw + vClipMaskUvRect.xy;
float mask_alpha = texture(sMask, source_uv).r; //careful: texture has type A8

return border_alpha * mask_alpha;
}
#endif
48 changes: 34 additions & 14 deletions resources/shaders/prim_shared.glsl
Expand Up @@ -34,6 +34,8 @@

#define MAX_STOPS_PER_ANGLE_GRADIENT 8

uniform sampler2DArray sCache;

#ifdef WR_VERTEX_SHADER

#define VECS_PER_LAYER 13
Expand Down Expand Up @@ -121,7 +123,7 @@ Layer fetch_layer(int index) {

struct Tile {
vec4 screen_origin_task_origin;
vec4 size;
vec4 size_target_index;
};

Tile fetch_tile(int index) {
Expand All @@ -130,7 +132,7 @@ Tile fetch_tile(int index) {
ivec2 uv = get_fetch_uv(index, VECS_PER_TILE);

tile.screen_origin_task_origin = texelFetchOffset(sRenderTasks, uv, 0, ivec2(0, 0));
tile.size = texelFetchOffset(sRenderTasks, uv, 0, ivec2(1, 0));
tile.size_target_index = texelFetchOffset(sRenderTasks, uv, 0, ivec2(1, 0));

return tile;
}
Expand Down Expand Up @@ -257,7 +259,6 @@ PrimitiveInstance fetch_instance(int index) {

return pi;
}

struct Primitive {
Layer layer;
Tile tile;
Expand Down Expand Up @@ -298,11 +299,28 @@ ClipRect fetch_clip_rect(int index) {
ivec2 uv = get_fetch_uv_2(index);

rect.rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
rect.dummy = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));
//rect.dummy = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));
rect.dummy = vec4(0.0, 0.0, 0.0, 0.0);

return rect;
}

struct ImageMaskInfo {
vec4 uv_rect;
vec4 local_rect;
};

ImageMaskInfo fetch_mask_info(int index) {
ImageMaskInfo info;

ivec2 uv = get_fetch_uv_2(index);

info.uv_rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
info.local_rect = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));

return info;
}

struct ClipCorner {
vec4 rect;
vec4 outer_inner_radius;
Expand All @@ -319,22 +337,24 @@ ClipCorner fetch_clip_corner(int index) {
return corner;
}

struct Clip {
struct ClipInfo {
ClipRect rect;
ClipCorner top_left;
ClipCorner top_right;
ClipCorner bottom_left;
ClipCorner bottom_right;
ImageMaskInfo mask_info;
};

Clip fetch_clip(int index) {
Clip clip;
ClipInfo fetch_clip(int index) {
ClipInfo clip;

clip.rect = fetch_clip_rect(index + 0);
clip.top_left = fetch_clip_corner(index + 1);
clip.top_right = fetch_clip_corner(index + 2);
clip.bottom_left = fetch_clip_corner(index + 3);
clip.bottom_right = fetch_clip_corner(index + 4);
clip.mask_info = fetch_mask_info(index+5);

return clip;
}
Expand Down Expand Up @@ -407,7 +427,7 @@ VertexInfo write_vertex(vec4 instance_rect,

vec2 clamped_pos = clamp(device_pos,
vec2(tile.screen_origin_task_origin.xy),
vec2(tile.screen_origin_task_origin.xy + tile.size.xy));
vec2(tile.screen_origin_task_origin.xy + tile.size_target_index.xy));

vec4 local_clamped_pos = layer.inv_transform * vec4(clamped_pos / uDevicePixelRatio, world_pos.z, 1);
local_clamped_pos.xyz /= local_clamped_pos.w;
Expand Down Expand Up @@ -461,11 +481,11 @@ TransformVertexInfo write_transform_vertex(vec4 instance_rect,

vec2 min_pos_clamped = clamp(min_pos * uDevicePixelRatio,
vec2(tile.screen_origin_task_origin.xy),
vec2(tile.screen_origin_task_origin.xy + tile.size.xy));
vec2(tile.screen_origin_task_origin.xy + tile.size_target_index.xy));

vec2 max_pos_clamped = clamp(max_pos * uDevicePixelRatio,
vec2(tile.screen_origin_task_origin.xy),
vec2(tile.screen_origin_task_origin.xy + tile.size.xy));
vec2(tile.screen_origin_task_origin.xy + tile.size_target_index.xy));

vec2 clamped_pos = mix(min_pos_clamped,
max_pos_clamped,
Expand Down Expand Up @@ -578,7 +598,7 @@ Composite fetch_composite(int index) {
#endif

#ifdef WR_FRAGMENT_SHADER
float squared_distance_from_rect(vec2 p, vec2 origin, vec2 size) {
float distance_from_rect(vec2 p, vec2 origin, vec2 size) {
vec2 clamped = clamp(p, origin, origin + size);
return distance(clamped, p);
}
Expand All @@ -587,10 +607,10 @@ vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha
fragment_alpha = 1.0;
vec2 pos = local_pos.xy / local_pos.z;

float squared_distance = squared_distance_from_rect(pos, local_rect.xy, local_rect.zw);
if (squared_distance != 0.0) {
float border_distance = distance_from_rect(pos, local_rect.xy, local_rect.zw);
if (border_distance != 0.0) {
float delta = length(fwidth(local_pos.xy));
fragment_alpha = smoothstep(1.0, 0.0, squared_distance / delta * 2.0);
fragment_alpha = 1.0 - smoothstep(0.0, 1.0, border_distance / delta * 2.0);
}

return pos;
Expand Down
2 changes: 0 additions & 2 deletions resources/shaders/ps_blend.fs.glsl
Expand Up @@ -2,8 +2,6 @@
* 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/. */

uniform sampler2D sCache;

vec3 rgbToHsv(vec3 c) {
float value = max(max(c.r, c.g), c.b);

Expand Down
2 changes: 1 addition & 1 deletion resources/shaders/ps_blend.glsl
Expand Up @@ -2,6 +2,6 @@
* 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/. */

varying vec2 vUv;
varying vec3 vUv;
flat varying float vAmount;
flat varying int vOp;
9 changes: 5 additions & 4 deletions resources/shaders/ps_blend.vs.glsl
Expand Up @@ -13,12 +13,13 @@ void main(void) {
src.screen_origin_task_origin.xy;

vec2 local_pos = mix(dest_origin,
dest_origin + src.size.xy,
dest_origin + src.size_target_index.xy,
aPosition.xy);

vec2 st0 = vec2(src.screen_origin_task_origin.zw) / 2048.0;
vec2 st1 = vec2(src.screen_origin_task_origin.zw + src.size.xy) / 2048.0;
vUv = mix(st0, st1, aPosition.xy);
vec2 texture_size = vec2(textureSize(sCache, 0));
vec2 st0 = src.screen_origin_task_origin.zw / texture_size;
vec2 st1 = (src.screen_origin_task_origin.zw + src.size_target_index.xy) / texture_size;
vUv = vec3(mix(st0, st1, aPosition.xy), src.size_target_index.z);

vOp = blend.src_id_target_id_op_amount.z;
vAmount = blend.src_id_target_id_op_amount.w / 65535.0;
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/ps_border.fs.glsl
Expand Up @@ -41,7 +41,7 @@ float alpha_for_solid_border(float distance_from_ref,
// Apply a more gradual fade out to transparent.
// distance_from_border -= 0.5;

return smoothstep(1.0, 0.0, distance_from_border);
return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
}

float alpha_for_solid_border_corner(vec2 local_pos,
Expand Down Expand Up @@ -97,7 +97,7 @@ vec4 draw_dotted_edge(vec2 local_pos, vec4 piece_rect, float pixels_per_fragment
// Move the distance back into pixels.
distance_from_circle_edge /= pixels_per_fragment;

float alpha = smoothstep(1.0, 0.0, min(1.0, max(0.0, distance_from_circle_edge)));
float alpha = 1.0 - smoothstep(0.0, 1.0, min(1.0, max(0.0, distance_from_circle_edge)));
return vHorizontalColor * vec4(1.0, 1.0, 1.0, alpha);
}

Expand Down
2 changes: 0 additions & 2 deletions resources/shaders/ps_composite.fs.glsl
Expand Up @@ -4,8 +4,6 @@
* 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/. */

uniform sampler2D sCache;

float gauss(float x, float sigma) {
if (sigma == 0.0)
return 1.0;
Expand Down
4 changes: 2 additions & 2 deletions resources/shaders/ps_composite.glsl
Expand Up @@ -2,7 +2,7 @@
* 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/. */

varying vec2 vUv0;
varying vec2 vUv1;
varying vec3 vUv0;
varying vec3 vUv1;
flat varying vec4 vUv1Rect;
flat varying int vOp;
19 changes: 10 additions & 9 deletions resources/shaders/ps_composite.vs.glsl
Expand Up @@ -10,20 +10,21 @@ void main(void) {
Tile dest = fetch_tile(composite.src0_src1_target_id_op.z);

vec2 local_pos = mix(dest.screen_origin_task_origin.zw,
dest.screen_origin_task_origin.zw + dest.size.xy,
dest.screen_origin_task_origin.zw + dest.size_target_index.xy,
aPosition.xy);

vec2 st0 = vec2(src0.screen_origin_task_origin.zw) / 2048.0;
vec2 st1 = vec2(src0.screen_origin_task_origin.zw + src0.size.xy) / 2048.0;
vUv0 = mix(st0, st1, aPosition.xy);
vec2 texture_size = vec2(textureSize(sCache, 0));
vec2 st0 = src0.screen_origin_task_origin.zw / texture_size;
vec2 st1 = (src0.screen_origin_task_origin.zw + src0.size_target_index.xy) / texture_size;
vUv0 = vec3(mix(st0, st1, aPosition.xy), src0.size_target_index.z);

st0 = vec2(src1.screen_origin_task_origin.zw) / 2048.0;
st1 = vec2(src1.screen_origin_task_origin.zw + src1.size.xy) / 2048.0;
st0 = vec2(src1.screen_origin_task_origin.zw) / texture_size;
st1 = vec2(src1.screen_origin_task_origin.zw + src1.size_target_index.xy) / texture_size;
vec2 local_virtual_pos = mix(dest.screen_origin_task_origin.xy,
dest.screen_origin_task_origin.xy + dest.size.xy,
dest.screen_origin_task_origin.xy + dest.size_target_index.xy,
aPosition.xy);
vec2 f = (local_virtual_pos - src1.screen_origin_task_origin.xy) / src1.size.xy;
vUv1 = mix(st0, st1, f);
vec2 f = (local_virtual_pos - src1.screen_origin_task_origin.xy) / src1.size_target_index.xy;
vUv1 = vec3(mix(st0, st1, f), src1.size_target_index.z);
vUv1Rect = vec4(st0, st1);

vOp = composite.src0_src1_target_id_op.w;
Expand Down
15 changes: 15 additions & 0 deletions resources/shaders/ps_gradient.fs.glsl
@@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

void main(void) {
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0.0;
vec2 local_pos = init_transform_fs(vLocalPos, vLocalRect, alpha);
#else
float alpha = 1.0;
vec2 local_pos = vPos;
#endif

oFragColor = vColor * vec4(1, 1, 1, alpha);
}
12 changes: 12 additions & 0 deletions resources/shaders/ps_gradient.glsl
@@ -0,0 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

varying vec4 vColor;

#ifdef WR_FEATURE_TRANSFORM
varying vec3 vLocalPos;
flat varying vec4 vLocalRect;
#else
varying vec2 vPos;
#endif

0 comments on commit 86eaef2

Please sign in to comment.