Skip to content

Commit e4e17a3

Browse files
committed
[wip] Use segments when drawing clip masks, decouple from tiles.
1 parent a214bf2 commit e4e17a3

13 files changed

+265
-284
lines changed

webrender/res/clip_shared.glsl

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55

66
#ifdef WR_VERTEX_SHADER
77

8+
#define SEGMENT_ALL 0
9+
#define SEGMENT_CORNER_TL 1
10+
#define SEGMENT_CORNER_TR 2
11+
#define SEGMENT_CORNER_BL 3
12+
#define SEGMENT_CORNER_BR 4
13+
814
in int aClipRenderTaskIndex;
915
in int aClipLayerIndex;
1016
in int aClipDataIndex;
11-
in int aClipBaseTaskIndex;
17+
in int aClipSegmentIndex;
1218

1319
struct CacheClipInstance {
1420
int render_task_index;
1521
int layer_index;
1622
int data_index;
17-
int base_task_index;
23+
int segment_index;
1824
};
1925

2026
CacheClipInstance fetch_clip_item(int index) {
@@ -23,7 +29,7 @@ CacheClipInstance fetch_clip_item(int index) {
2329
cci.render_task_index = aClipRenderTaskIndex;
2430
cci.layer_index = aClipLayerIndex;
2531
cci.data_index = aClipDataIndex;
26-
cci.base_task_index = aClipBaseTaskIndex;
32+
cci.segment_index = aClipSegmentIndex;
2733

2834
return cci;
2935
}
@@ -32,23 +38,54 @@ CacheClipInstance fetch_clip_item(int index) {
3238
// which is the intersection of all clip instances of a given primitive
3339
TransformVertexInfo write_clip_tile_vertex(vec4 local_clip_rect,
3440
Layer layer,
35-
ClipArea area) {
41+
ClipArea area,
42+
int segment_index) {
3643
vec2 lp0_base = local_clip_rect.xy;
3744
vec2 lp1_base = local_clip_rect.xy + local_clip_rect.zw;
3845

3946
vec2 lp0 = clamp_rect(lp0_base, layer.local_clip_rect);
4047
vec2 lp1 = clamp_rect(lp1_base, layer.local_clip_rect);
4148
vec4 clipped_local_rect = vec4(lp0, lp1 - lp0);
4249

43-
vec2 final_pos = mix(area.task_bounds.xy, area.task_bounds.zw, aPosition.xy);
50+
vec2 outer_p0 = area.screen_origin_target_index.xy;
51+
vec2 outer_p1 = outer_p0 + area.task_bounds.zw - area.task_bounds.xy;
52+
vec2 inner_p0 = area.inner_rect.xy;
53+
vec2 inner_p1 = area.inner_rect.zw;
54+
55+
vec2 p0, p1;
56+
switch (segment_index) {
57+
case SEGMENT_ALL:
58+
p0 = outer_p0;
59+
p1 = outer_p1;
60+
break;
61+
case SEGMENT_CORNER_TL:
62+
p0 = outer_p0;
63+
p1 = inner_p0;
64+
break;
65+
case SEGMENT_CORNER_BL:
66+
p0 = vec2(outer_p0.x, outer_p1.y);
67+
p1 = vec2(inner_p0.x, inner_p1.y);
68+
break;
69+
case SEGMENT_CORNER_TR:
70+
p0 = vec2(outer_p1.x, outer_p1.y);
71+
p1 = vec2(inner_p1.x, inner_p1.y);
72+
break;
73+
case SEGMENT_CORNER_BR:
74+
p0 = vec2(outer_p1.x, outer_p0.y);
75+
p1 = vec2(inner_p1.x, inner_p0.y);
76+
break;
77+
}
78+
79+
vec2 actual_pos = mix(p0, p1, aPosition.xy);
80+
81+
vec4 layer_pos = get_layer_pos(actual_pos / uDevicePixelRatio, layer);
4482

4583
// compute the point position in side the layer, in CSS space
46-
vec2 clamped_pos = final_pos + area.screen_origin_target_index.xy - area.task_bounds.xy;
47-
vec4 layer_pos = get_layer_pos(clamped_pos / uDevicePixelRatio, layer);
84+
vec2 vertex_pos = actual_pos + area.task_bounds.xy - area.screen_origin_target_index.xy;
4885

49-
gl_Position = uTransform * vec4(final_pos, 0.0, 1);
86+
gl_Position = uTransform * vec4(vertex_pos, 0.0, 1);
5087

51-
return TransformVertexInfo(layer_pos.xyw, clamped_pos, clipped_local_rect);
88+
return TransformVertexInfo(layer_pos.xyw, actual_pos, clipped_local_rect);
5289
}
5390

5491
#endif //WR_VERTEX_SHADER

webrender/res/cs_clip_copy.fs.glsl

Lines changed: 0 additions & 8 deletions
This file was deleted.

webrender/res/cs_clip_copy.vs.glsl

Lines changed: 0 additions & 19 deletions
This file was deleted.

webrender/res/cs_clip_image.vs.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ void main(void) {
2828

2929
TransformVertexInfo vi = write_clip_tile_vertex(local_rect,
3030
layer,
31-
area);
31+
area,
32+
cci.segment_index);
3233
vLocalRect = vi.clipped_local_rect;
3334
vPos = vi.local_pos;
3435

webrender/res/cs_clip_rectangle.vs.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void main(void) {
6565

6666
TransformVertexInfo vi = write_clip_tile_vertex(local_rect,
6767
layer,
68-
area);
68+
area,
69+
cci.segment_index);
6970
vLocalRect = vi.clipped_local_rect;
7071
vPos = vi.local_pos;
7172

webrender/res/prim_shared.glsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ varying vec3 vClipMaskUv;
3838
#ifdef WR_VERTEX_SHADER
3939

4040
#define VECS_PER_LAYER 13
41-
#define VECS_PER_RENDER_TASK 2
41+
#define VECS_PER_RENDER_TASK 3
4242
#define VECS_PER_PRIM_GEOM 2
4343

4444
#define GRADIENT_HORIZONTAL 0
@@ -128,6 +128,7 @@ Layer fetch_layer(int index) {
128128
struct RenderTaskData {
129129
vec4 data0;
130130
vec4 data1;
131+
vec4 data2;
131132
};
132133

133134
RenderTaskData fetch_render_task(int index) {
@@ -137,6 +138,7 @@ RenderTaskData fetch_render_task(int index) {
137138

138139
task.data0 = texelFetchOffset(sRenderTasks, uv, 0, ivec2(0, 0));
139140
task.data1 = texelFetchOffset(sRenderTasks, uv, 0, ivec2(1, 0));
141+
task.data2 = texelFetchOffset(sRenderTasks, uv, 0, ivec2(2, 0));
140142

141143
return task;
142144
}
@@ -159,6 +161,7 @@ Tile fetch_tile(int index) {
159161
struct ClipArea {
160162
vec4 task_bounds;
161163
vec4 screen_origin_target_index;
164+
vec4 inner_rect;
162165
};
163166

164167
ClipArea fetch_clip_area(int index) {
@@ -167,10 +170,12 @@ ClipArea fetch_clip_area(int index) {
167170
if (index == 0x7FFFFFFF) { //special sentinel task index
168171
area.task_bounds = vec4(0.0, 0.0, 0.0, 0.0);
169172
area.screen_origin_target_index = vec4(0.0, 0.0, 0.0, 0.0);
173+
area.inner_rect = vec4(0.0);
170174
} else {
171175
RenderTaskData task = fetch_render_task(index);
172176
area.task_bounds = task.data0;
173177
area.screen_origin_target_index = task.data1;
178+
area.inner_rect = task.data2;
174179
}
175180

176181
return area;

webrender/src/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl VertexFormat {
268268
for (i, &attrib) in [ClipAttribute::RenderTaskIndex,
269269
ClipAttribute::LayerIndex,
270270
ClipAttribute::DataIndex,
271-
ClipAttribute::BaseTaskIndex,
271+
ClipAttribute::SegmentIndex,
272272
].into_iter().enumerate() {
273273
gl::enable_vertex_attrib_array(attrib as gl::GLuint);
274274
gl::vertex_attrib_divisor(attrib as gl::GLuint, 1);
@@ -401,7 +401,7 @@ impl Program {
401401
gl::bind_attrib_location(self.id, ClipAttribute::RenderTaskIndex as gl::GLuint, "aClipRenderTaskIndex");
402402
gl::bind_attrib_location(self.id, ClipAttribute::LayerIndex as gl::GLuint, "aClipLayerIndex");
403403
gl::bind_attrib_location(self.id, ClipAttribute::DataIndex as gl::GLuint, "aClipDataIndex");
404-
gl::bind_attrib_location(self.id, ClipAttribute::BaseTaskIndex as gl::GLuint, "aClipBaseTaskIndex");
404+
gl::bind_attrib_location(self.id, ClipAttribute::SegmentIndex as gl::GLuint, "aClipSegmentIndex");
405405

406406
gl::link_program(self.id);
407407
if gl::get_program_iv(self.id, gl::LINK_STATUS) == (0 as gl::GLint) {

webrender/src/internal_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub enum ClipAttribute {
266266
RenderTaskIndex,
267267
LayerIndex,
268268
DataIndex,
269-
BaseTaskIndex,
269+
SegmentIndex,
270270
}
271271

272272
#[derive(Debug, Clone, Copy)]

webrender/src/prim_store.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub struct PrimitiveMetadata {
112112
// that implements a 2-pass separable blur on a
113113
// text run.
114114
pub render_task: Option<RenderTask>,
115+
pub clip_task: Option<RenderTask>,
115116
}
116117

117118
#[derive(Debug, Clone)]
@@ -490,6 +491,7 @@ impl PrimitiveStore {
490491
gpu_data_address: GpuStoreAddress(0),
491492
gpu_data_count: 0,
492493
render_task: None,
494+
clip_task: None,
493495
};
494496

495497
metadata
@@ -509,6 +511,7 @@ impl PrimitiveStore {
509511
gpu_data_address: gpu_glyphs_address,
510512
gpu_data_count: text_cpu.glyph_range.length as i32,
511513
render_task: None,
514+
clip_task: None,
512515
};
513516

514517
self.cpu_text_runs.push(text_cpu);
@@ -529,6 +532,7 @@ impl PrimitiveStore {
529532
gpu_data_address: GpuStoreAddress(0),
530533
gpu_data_count: 0,
531534
render_task: None,
535+
clip_task: None,
532536
};
533537

534538
self.cpu_images.push(image_cpu);
@@ -547,6 +551,7 @@ impl PrimitiveStore {
547551
gpu_data_address: GpuStoreAddress(0),
548552
gpu_data_count: 0,
549553
render_task: None,
554+
clip_task: None,
550555
};
551556

552557
self.cpu_yuv_images.push(image_cpu);
@@ -565,6 +570,7 @@ impl PrimitiveStore {
565570
gpu_data_address: GpuStoreAddress(0),
566571
gpu_data_count: 0,
567572
render_task: None,
573+
clip_task: None,
568574
};
569575

570576
self.cpu_borders.push(border_cpu);
@@ -584,6 +590,7 @@ impl PrimitiveStore {
584590
gpu_data_address: gpu_stops_address,
585591
gpu_data_count: gradient_cpu.stops_range.length as i32,
586592
render_task: None,
593+
clip_task: None,
587594
};
588595

589596
self.cpu_gradients.push(gradient_cpu);
@@ -628,6 +635,7 @@ impl PrimitiveStore {
628635
gpu_data_address: gpu_data_address,
629636
gpu_data_count: instance_rects.len() as i32,
630637
render_task: Some(render_task),
638+
clip_task: None,
631639
};
632640

633641
for rect in instance_rects {

webrender/src/renderer.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ pub struct Renderer {
288288
/// These are "cache clip shaders". These shaders are used to
289289
/// draw clip instances into the cached clip mask. The results
290290
/// of these shaders are also used by the primitive shaders.
291-
cs_clip_copy: LazilyCompiledShader,
292291
cs_clip_rectangle: LazilyCompiledShader,
293292
cs_clip_image: LazilyCompiledShader,
294293

@@ -421,11 +420,6 @@ impl Renderer {
421420
&mut device,
422421
options.precache_shaders);
423422

424-
let cs_clip_copy = LazilyCompiledShader::new(ShaderKind::ClipCache,
425-
"cs_clip_copy",
426-
&[],
427-
&mut device,
428-
options.precache_shaders);
429423
let cs_clip_rectangle = LazilyCompiledShader::new(ShaderKind::ClipCache,
430424
"cs_clip_rectangle",
431425
&[],
@@ -619,7 +613,6 @@ impl Renderer {
619613
cs_box_shadow: cs_box_shadow,
620614
cs_text_run: cs_text_run,
621615
cs_blur: cs_blur,
622-
cs_clip_copy: cs_clip_copy,
623616
cs_clip_rectangle: cs_clip_rectangle,
624617
cs_clip_image: cs_clip_image,
625618
ps_rectangle: ps_rectangle,
@@ -1060,7 +1053,7 @@ impl Renderer {
10601053
// tasks can assume that pixels are transparent if not
10611054
// rendered. (This is relied on by the compositing support
10621055
// for mix-blend-mode etc).
1063-
[1.0, 0.0, 0.0, 0.0],
1056+
[1.0, 1.0, 1.0, 0.0],
10641057
Matrix4D::ortho(0.0,
10651058
target_size.width,
10661059
0.0,
@@ -1137,17 +1130,7 @@ impl Renderer {
11371130
{
11381131
let _gm = self.gpu_profile.add_marker(GPU_TAG_CACHE_CLIP);
11391132
let vao = self.clip_vao_id;
1140-
// Optionally, copy the contents from another task
1141-
if !target.clip_batcher.copies.is_empty() {
1142-
self.device.set_blend(false);
1143-
let shader = self.cs_clip_copy.get(&mut self.device);
1144-
self.draw_instanced_batch(&target.clip_batcher.copies,
1145-
vao,
1146-
shader,
1147-
&BatchTextures::no_texture(),
1148-
&projection);
1149-
}
1150-
// now switch to multiplicative blending
1133+
// switch to multiplicative blending
11511134
self.device.set_blend(true);
11521135
self.device.set_blend_mode_multiply();
11531136
// draw rounded cornered rectangles

0 commit comments

Comments
 (0)