Skip to content

Commit 56131c9

Browse files
author
bors-servo
authored
Auto merge of #648 - glennw:zb, r=kvark
Use z-buffer for rejecting opaque fragments. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/648) <!-- Reviewable:end -->
2 parents fcf7673 + 7eb458c commit 56131c9

20 files changed

+404
-249
lines changed

replay/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ fn main() {
119119
debug: false,
120120
enable_subpixel_aa: false,
121121
clear_framebuffer: true,
122-
clear_empty_tiles: false,
123122
clear_color: ColorF::new(1.0, 1.0, 1.0, 1.0),
124123
};
125124

sample/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ fn main() {
8585
renderer_kind: RendererKind::Native,
8686
enable_subpixel_aa: false,
8787
clear_framebuffer: true,
88-
clear_empty_tiles: false,
8988
clear_color: ColorF::new(1.0, 1.0, 1.0, 1.0),
9089
};
9190

webrender/res/prim_shared.glsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ in int aClipTaskIndex;
6161
in int aLayerIndex;
6262
in int aElementIndex;
6363
in ivec2 aUserData;
64+
in int aZIndex;
6465

6566
// get_fetch_uv is a macro to work around a macOS Intel driver parsing bug.
6667
// TODO: convert back to a function once the driver issues are resolved, if ever.
@@ -250,6 +251,7 @@ struct PrimitiveInstance {
250251
int clip_task_index;
251252
int layer_index;
252253
int sub_index;
254+
int z;
253255
ivec2 user_data;
254256
};
255257

@@ -263,6 +265,7 @@ PrimitiveInstance fetch_prim_instance() {
263265
pi.layer_index = aLayerIndex;
264266
pi.sub_index = aElementIndex;
265267
pi.user_data = aUserData;
268+
pi.z = aZIndex;
266269

267270
return pi;
268271
}
@@ -300,6 +303,7 @@ struct Primitive {
300303
// this index allows the vertex shader to recognize the difference
301304
int sub_index;
302305
ivec2 user_data;
306+
float z;
303307
};
304308

305309
Primitive load_primitive_custom(PrimitiveInstance pi) {
@@ -316,6 +320,7 @@ Primitive load_primitive_custom(PrimitiveInstance pi) {
316320
prim.prim_index = pi.specific_prim_index;
317321
prim.sub_index = pi.sub_index;
318322
prim.user_data = pi.user_data;
323+
prim.z = float(pi.z);
319324

320325
return prim;
321326
}
@@ -388,6 +393,7 @@ struct VertexInfo {
388393

389394
VertexInfo write_vertex(vec4 instance_rect,
390395
vec4 local_clip_rect,
396+
float z,
391397
Layer layer,
392398
Tile tile) {
393399
vec2 p0 = floor(0.5 + instance_rect.xy * uDevicePixelRatio) / uDevicePixelRatio;
@@ -415,7 +421,7 @@ VertexInfo write_vertex(vec4 instance_rect,
415421

416422
vec2 final_pos = clamped_pos + tile.screen_origin_task_origin.zw - tile.screen_origin_task_origin.xy;
417423

418-
gl_Position = uTransform * vec4(final_pos, 0, 1);
424+
gl_Position = uTransform * vec4(final_pos, z, 1.0);
419425

420426
VertexInfo vi = VertexInfo(Rect(p0, p1), local_clamped_pos.xy, clamped_pos.xy);
421427
return vi;
@@ -431,6 +437,7 @@ struct TransformVertexInfo {
431437

432438
TransformVertexInfo write_transform_vertex(vec4 instance_rect,
433439
vec4 local_clip_rect,
440+
float z,
434441
Layer layer,
435442
Tile tile) {
436443
vec2 lp0_base = instance_rect.xy;
@@ -482,7 +489,7 @@ TransformVertexInfo write_transform_vertex(vec4 instance_rect,
482489
// apply the task offset
483490
vec2 final_pos = clamped_pos + tile.screen_origin_task_origin.zw - tile.screen_origin_task_origin.xy;
484491

485-
gl_Position = uTransform * vec4(final_pos, 0.0, 1.0);
492+
gl_Position = uTransform * vec4(final_pos, z, 1.0);
486493

487494
return TransformVertexInfo(layer_pos.xyw, clamped_pos, clipped_local_rect);
488495
}

webrender/res/ps_angle_gradient.vs.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void main(void) {
99

1010
VertexInfo vi = write_vertex(prim.local_rect,
1111
prim.local_clip_rect,
12+
prim.z,
1213
prim.layer,
1314
prim.tile);
1415

webrender/res/ps_blend.vs.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct Blend {
77
ivec4 src_id_target_id_op_amount;
8+
int z;
89
};
910

1011
Blend fetch_blend() {
@@ -15,6 +16,7 @@ Blend fetch_blend() {
1516
pi.render_task_index,
1617
pi.sub_index,
1718
pi.user_data.y);
19+
blend.z = pi.z;
1820

1921
return blend;
2022
}
@@ -40,5 +42,5 @@ void main(void) {
4042
vOp = blend.src_id_target_id_op_amount.z;
4143
vAmount = blend.src_id_target_id_op_amount.w / 65535.0;
4244

43-
gl_Position = uTransform * vec4(local_pos, 0, 1);
45+
gl_Position = uTransform * vec4(local_pos, blend.z, 1.0);
4446
}

webrender/res/ps_border.vs.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void main(void) {
136136
#ifdef WR_FEATURE_TRANSFORM
137137
TransformVertexInfo vi = write_transform_vertex(segment_rect,
138138
prim.local_clip_rect,
139+
prim.z,
139140
prim.layer,
140141
prim.tile);
141142
vLocalPos = vi.local_pos;
@@ -145,6 +146,7 @@ void main(void) {
145146
#else
146147
VertexInfo vi = write_vertex(segment_rect,
147148
prim.local_clip_rect,
149+
prim.z,
148150
prim.layer,
149151
prim.tile);
150152
vLocalPos = vi.local_clamped_pos.xy;

webrender/res/ps_box_shadow.vs.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ void main(void) {
1010

1111
VertexInfo vi = write_vertex(segment_rect,
1212
prim.local_clip_rect,
13+
prim.z,
1314
prim.layer,
1415
prim.tile);
1516

webrender/res/ps_cache_image.vs.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void main(void) {
1111

1212
VertexInfo vi = write_vertex(prim.local_rect,
1313
prim.local_clip_rect,
14+
prim.z,
1415
prim.layer,
1516
prim.tile);
1617

webrender/res/ps_composite.vs.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct Composite {
77
ivec4 src0_src1_target_id_op;
8+
int z;
89
};
910

1011
Composite fetch_composite() {
@@ -14,6 +15,7 @@ Composite fetch_composite() {
1415
composite.src0_src1_target_id_op = ivec4(pi.user_data.xy,
1516
pi.render_task_index,
1617
pi.sub_index);
18+
composite.z = pi.z;
1719

1820
return composite;
1921
}
@@ -44,5 +46,5 @@ void main(void) {
4446

4547
vOp = composite.src0_src1_target_id_op.w;
4648

47-
gl_Position = uTransform * vec4(local_pos, 0, 1);
49+
gl_Position = uTransform * vec4(local_pos, composite.z, 1.0);
4850
}

webrender/res/ps_gradient.vs.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void main(void) {
3939
#ifdef WR_FEATURE_TRANSFORM
4040
TransformVertexInfo vi = write_transform_vertex(segment_rect,
4141
prim.local_clip_rect,
42+
prim.z,
4243
prim.layer,
4344
prim.tile);
4445
vLocalRect = vi.clipped_local_rect;
@@ -47,6 +48,7 @@ void main(void) {
4748
#else
4849
VertexInfo vi = write_vertex(segment_rect,
4950
prim.local_clip_rect,
51+
prim.z,
5052
prim.layer,
5153
prim.tile);
5254

0 commit comments

Comments
 (0)