Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More aggressive RectWithSize usage for local rectangles #1087

Merged
merged 4 commits into from Apr 10, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -34,18 +34,21 @@ CacheClipInstance fetch_clip_item(int index) {
return cci;
}

struct ClipVertexInfo {
vec3 local_pos;
vec2 screen_pos;
RectWithSize clipped_local_rect;
};

// The transformed vertex function that always covers the whole clip area,
// which is the intersection of all clip instances of a given primitive
TransformVertexInfo write_clip_tile_vertex(vec4 local_clip_rect,
Layer layer,
ClipArea area,
int segment_index) {
vec2 lp0_base = local_clip_rect.xy;
vec2 lp1_base = local_clip_rect.xy + local_clip_rect.zw;
ClipVertexInfo write_clip_tile_vertex(RectWithSize local_clip_rect,
Layer layer,
ClipArea area,
int segment_index) {

vec2 lp0 = clamp_rect(lp0_base, layer.local_clip_rect);
vec2 lp1 = clamp_rect(lp1_base, layer.local_clip_rect);
vec4 clipped_local_rect = vec4(lp0, lp1 - lp0);
RectWithSize clipped_local_rect = intersect_rect(local_clip_rect,
layer.local_clip_rect);

vec2 outer_p0 = area.screen_origin_target_index.xy;
vec2 outer_p1 = outer_p0 + area.task_bounds.zw - area.task_bounds.xy;
@@ -85,7 +88,7 @@ TransformVertexInfo write_clip_tile_vertex(vec4 local_clip_rect,

gl_Position = uTransform * vec4(vertex_pos, 0.0, 1);

return TransformVertexInfo(layer_pos.xyw, actual_pos, clipped_local_rect);
return ClipVertexInfo(layer_pos.xyw, actual_pos, clipped_local_rect);
}

#endif //WR_VERTEX_SHADER
@@ -5,6 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

varying vec3 vPos;
flat varying vec4 vLocalRect;
flat varying RectWithSize vLocalRect;
flat varying vec4 vClipMaskUvRect;
flat varying vec4 vClipMaskUvInnerRect;
@@ -4,17 +4,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

struct ImageMaskData {
vec4 uv_rect;
vec4 local_rect;
RectWithSize uv_rect;
RectWithSize local_rect;
};

ImageMaskData fetch_mask_data(int index) {
ImageMaskData info;
vec4 rect;

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));
rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
info.uv_rect = RectWithSize(rect.xy, rect.zw);
rect = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));
info.local_rect = RectWithSize(rect.xy, rect.zw);

return info;
}
@@ -24,19 +27,20 @@ void main(void) {
ClipArea area = fetch_clip_area(cci.render_task_index);
Layer layer = fetch_layer(cci.layer_index);
ImageMaskData mask = fetch_mask_data(cci.data_index);
vec4 local_rect = mask.local_rect;
RectWithSize local_rect = mask.local_rect;

ClipVertexInfo vi = write_clip_tile_vertex(local_rect,
layer,
area,
cci.segment_index);

TransformVertexInfo vi = write_clip_tile_vertex(local_rect,
layer,
area,
cci.segment_index);
vLocalRect = vi.clipped_local_rect;
vPos = vi.local_pos;

vClipMaskUv = vec3((vPos.xy / vPos.z - local_rect.xy) / local_rect.zw, 0.0);
vClipMaskUv = vec3((vPos.xy / vPos.z - local_rect.p0) / local_rect.size, 0.0);
vec2 texture_size = vec2(textureSize(sMask, 0));
vClipMaskUvRect = mask.uv_rect / texture_size.xyxy;
vClipMaskUvRect = vec4(mask.uv_rect.p0, mask.uv_rect.size) / texture_size.xyxy;
// applying a half-texel offset to the UV boundaries to prevent linear samples from the outside
vec4 inner_rect = vec4(mask.uv_rect.xy, mask.uv_rect.xy + mask.uv_rect.zw);
vec4 inner_rect = vec4(mask.uv_rect.p0, mask.uv_rect.p0 + mask.uv_rect.size);
vClipMaskUvInnerRect = (inner_rect + vec4(0.5, 0.5, -0.5, -0.5)) / texture_size.xyxy;
}
@@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

varying vec3 vPos;
flat varying vec4 vLocalRect;
flat varying RectWithSize vLocalRect;
flat varying vec4 vClipRect;
flat varying vec4 vClipRadius;
flat varying float vClipMode;
@@ -4,23 +4,24 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

struct ClipRect {
vec4 rect;
RectWithSize rect;
vec4 mode;
};

ClipRect fetch_clip_rect(int index) {
ClipRect rect;
ClipRect cr;

ivec2 uv = get_fetch_uv_2(index);

rect.rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
rect.mode = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));
vec4 rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
cr.rect = RectWithSize(rect.xy, rect.zw);
cr.mode = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));

return rect;
return cr;
}

struct ClipCorner {
vec4 rect;
RectWithSize rect;
vec4 outer_inner_radius;
};

@@ -29,7 +30,8 @@ ClipCorner fetch_clip_corner(int index) {

ivec2 uv = get_fetch_uv_2(index);

corner.rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
vec4 rect = texelFetchOffset(sData32, uv, 0, ivec2(0, 0));
corner.rect = RectWithSize(rect.xy, rect.zw);
corner.outer_inner_radius = texelFetchOffset(sData32, uv, 0, ivec2(1, 0));

return corner;
@@ -60,17 +62,17 @@ void main(void) {
ClipArea area = fetch_clip_area(cci.render_task_index);
Layer layer = fetch_layer(cci.layer_index);
ClipData clip = fetch_clip(cci.data_index);
vec4 local_rect = clip.rect.rect;
RectWithSize local_rect = clip.rect.rect;

TransformVertexInfo vi = write_clip_tile_vertex(local_rect,
layer,
area,
cci.segment_index);
ClipVertexInfo vi = write_clip_tile_vertex(local_rect,
layer,
area,
cci.segment_index);
vLocalRect = vi.clipped_local_rect;
vPos = vi.local_pos;

vClipMode = clip.rect.mode.x;
vClipRect = vec4(local_rect.xy, local_rect.xy + local_rect.zw);
vClipRect = vec4(local_rect.p0, local_rect.p0 + local_rect.size);
vClipRadius = vec4(clip.top_left.outer_inner_radius.x,
clip.top_right.outer_inner_radius.x,
clip.bottom_right.outer_inner_radius.x,
@@ -36,7 +36,61 @@
uniform sampler2DArray sCacheA8;
uniform sampler2DArray sCacheRGBA8;

flat varying vec4 vClipMaskUvBounds;
struct RectWithSize {
vec2 p0;
vec2 size;
};

struct RectWithEndpoint {
vec2 p0;
vec2 p1;
};

RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;

return result;
}

RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;

return result;
}

vec2 clamp_rect(vec2 point, RectWithSize rect) {
return clamp(point, rect.p0, rect.p0 + rect.size);
}

vec2 clamp_rect(vec2 point, RectWithEndpoint rect) {
return clamp(point, rect.p0, rect.p1);
}

// Clamp 2 points at once.
vec4 clamp_rect(vec4 points, RectWithSize rect) {
return clamp(points, rect.p0.xyxy, rect.p0.xyxy + rect.size.xyxy);
}

vec4 clamp_rect(vec4 points, RectWithEndpoint rect) {
return clamp(points, rect.p0.xyxy, rect.p1.xyxy);
}

RectWithSize intersect_rect(RectWithSize a, RectWithSize b) {
vec4 p = clamp_rect(vec4(a.p0, a.p0 + a.size), b);
return RectWithSize(p.xy, max(vec2(0.0), p.zw - p.xy));
}

RectWithEndpoint intersect_rect(RectWithEndpoint a, RectWithEndpoint b) {
vec4 p = clamp_rect(vec4(a.p0, a.p1), b);
return RectWithEndpoint(p.xy, max(p.xy, p.zw));
}


flat varying RectWithEndpoint vClipMaskUvBounds;
varying vec3 vClipMaskUv;

#ifdef WR_VERTEX_SHADER
@@ -87,49 +141,6 @@ ivec2 get_fetch_uv_8(int index) {
return get_fetch_uv(index, 8);
}

struct RectWithSize {
vec2 p0;
vec2 size;
};

struct RectWithEndpoint {
vec2 p0;
vec2 p1;
};

RectWithEndpoint to_rect_with_endpoint(RectWithSize rect) {
RectWithEndpoint result;
result.p0 = rect.p0;
result.p1 = rect.p0 + rect.size;

return result;
}

RectWithSize to_rect_with_size(RectWithEndpoint rect) {
RectWithSize result;
result.p0 = rect.p0;
result.size = rect.p1 - rect.p0;

return result;
}

vec2 clamp_rect(vec2 point, RectWithSize rect) {
return clamp(point, rect.p0, rect.p0 + rect.size);
}

vec2 clamp_rect(vec2 point, RectWithEndpoint rect) {
return clamp(point, rect.p0, rect.p1);
}

// Clamp 2 points at once.
vec4 clamp_rect(vec4 points, RectWithSize rect) {
return clamp(points, rect.p0.xyxy, rect.p0.xyxy + rect.size.xyxy);
}

vec4 clamp_rect(vec4 points, RectWithEndpoint rect) {
return clamp(points, rect.p0.xyxy, rect.p1.xyxy);
}

struct Layer {
mat4 transform;
mat4 inv_transform;
@@ -454,7 +465,6 @@ vec4 get_layer_pos(vec2 pos, Layer layer) {
}

struct VertexInfo {
RectWithEndpoint local_rect;
vec2 local_pos;
vec2 screen_pos;
};
@@ -464,13 +474,11 @@ VertexInfo write_vertex(RectWithSize instance_rect,
float z,
Layer layer,
AlphaBatchTask task) {
RectWithEndpoint local_rect = to_rect_with_endpoint(instance_rect);

// Select the corner of the local rect that we are processing.
vec2 local_pos = mix(local_rect.p0, local_rect.p1, aPosition.xy);
vec2 local_pos = instance_rect.p0 + instance_rect.size * aPosition.xy;

// xy = top left corner of the local rect, zw = position of current vertex.
vec4 local_p0_pos = vec4(local_rect.p0, local_pos);
vec4 local_p0_pos = vec4(instance_rect.p0, local_pos);

// Clamp to the two local clip rects.
local_p0_pos = clamp_rect(local_p0_pos, local_clip_rect);
@@ -496,7 +504,7 @@ VertexInfo write_vertex(RectWithSize instance_rect,

gl_Position = uTransform * vec4(final_pos, z, 1.0);

VertexInfo vi = VertexInfo(local_rect, local_p0_pos.zw, device_p0_pos.zw);
VertexInfo vi = VertexInfo(local_p0_pos.zw, device_p0_pos.zw);
return vi;
}

@@ -505,7 +513,6 @@ VertexInfo write_vertex(RectWithSize instance_rect,
struct TransformVertexInfo {
vec3 local_pos;
vec2 screen_pos;
vec4 clipped_local_rect;
};

float cross2(vec2 v0, vec2 v1) {
@@ -605,7 +612,7 @@ TransformVertexInfo write_transform_vertex(RectWithSize instance_rect,

vec4 layer_pos = get_layer_pos(device_pos / uDevicePixelRatio, layer);

return TransformVertexInfo(layer_pos.xyw, device_pos, vec4(instance_rect.p0, instance_rect.size));
return TransformVertexInfo(layer_pos.xyw, device_pos);
}

#endif //WR_FEATURE_TRANSFORM
@@ -714,7 +721,8 @@ BoxShadow fetch_boxshadow(int index) {
void write_clip(vec2 global_pos, ClipArea area) {
vec2 texture_size = vec2(textureSize(sCacheA8, 0).xy);
vec2 uv = global_pos + area.task_bounds.xy - area.screen_origin_target_index.xy;
vClipMaskUvBounds = area.task_bounds / texture_size.xyxy;
vClipMaskUvBounds = RectWithEndpoint(area.task_bounds.xy / texture_size,
area.task_bounds.zw / texture_size);
vClipMaskUv = vec3(uv / texture_size, area.screen_origin_target_index.z);
}
#endif //WR_VERTEX_SHADER
@@ -725,7 +733,7 @@ float signed_distance_rect(vec2 pos, vec2 p0, vec2 p1) {
return length(max(vec2(0.0), d)) + min(0.0, max(d.x, d.y));
}

vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha) {
vec2 init_transform_fs(vec3 local_pos, RectWithSize local_rect, out float fragment_alpha) {
fragment_alpha = 1.0;
vec2 pos = local_pos.xy / local_pos.z;

@@ -741,8 +749,8 @@ vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha
// above to get correct distance values. This ensures that we only apply
// anti-aliasing when the fragment has partial coverage.
float d = signed_distance_rect(pos,
local_rect.xy + dxdy,
local_rect.xy + local_rect.zw - dxdy);
local_rect.p0 + dxdy,
local_rect.p0 + local_rect.size - dxdy);

// Find the appropriate distance to apply the AA smoothstep over.
float afwidth = 0.5 / length(fw);
@@ -756,10 +764,10 @@ vec2 init_transform_fs(vec3 local_pos, vec4 local_rect, out float fragment_alpha
float do_clip() {
// anything outside of the mask is considered transparent
bvec4 inside = lessThanEqual(
vec4(vClipMaskUvBounds.xy, vClipMaskUv.xy),
vec4(vClipMaskUv.xy, vClipMaskUvBounds.zw));
vec4(vClipMaskUvBounds.p0, vClipMaskUv.xy),
vec4(vClipMaskUv.xy, vClipMaskUvBounds.p1));
// check for the dummy bounds, which are given to the opaque objects
return vClipMaskUvBounds.xy == vClipMaskUvBounds.zw ? 1.0:
return vClipMaskUvBounds.p0 == vClipMaskUvBounds.p1 ? 1.0:
all(inside) ? textureLod(sCacheA8, vClipMaskUv, 0.0).r : 0.0;
}

@@ -419,9 +419,9 @@ void main(void) {
float distance_from_mix_line = (local_pos.x - vPieceRect.x) * vPieceRect.w -
(local_pos.y - vPieceRect.y) * vPieceRect.z;
distance_from_mix_line /= vPieceRectHypotenuseLength;
float distance_from_middle = (local_pos.x - vLocalRect.x) +
(local_pos.y - vLocalRect.y) -
0.5 * (vLocalRect.z + vLocalRect.w);
float distance_from_middle = (local_pos.x - vBorderRect.p0.x) +
(local_pos.y - vBorderRect.p0.y) -
0.5 * (vBorderRect.size.x + vBorderRect.size.y);
#else
float distance_from_mix_line = vDistanceFromMixLine;
float distance_from_middle = vDistanceFromMiddle;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.