Skip to content

Commit 482b59b

Browse files
author
bors-servo
authored
Auto merge of servo#615 - kvark:instance, r=glennw
Instanced attributes Closes servo#457 Performance-wise, I wasn't able to register a noticeable difference. Tested on https://github.com/servo/servo, full screen after the second page down, on `Mesa DRI Intel(R) HD Graphics 5500 (Broadwell GT2)` with resolution 2560x1440. With the change, I got 4.5 ms mean GPU time in the first test, and 4.3 ms time in the second. Without the change, I got 4.4 ms mean GPU time in the only test. I suppose the difference is not visible since we are far from being VS-bound. Note: this does not replace the optimization of having one large buffer in servo#456. Instanced attributes will benefit from it in the same way as UBOs. <!-- 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/615) <!-- Reviewable:end -->
2 parents b2e02df + 68f63db commit 482b59b

24 files changed

+490
-466
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webrender/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bit-set = "0.4"
2020
byteorder = "0.5"
2121
euclid = "0.10.3"
2222
fnv="1.0"
23-
gleam = "0.2.25"
23+
gleam = "0.2.28"
2424
lazy_static = "0.2"
2525
log = "0.3"
2626
num-traits = "0.1.32"

webrender/res/clip_shared.glsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#ifdef WR_VERTEX_SHADER
77

8+
in int aClipRenderTaskIndex;
9+
in int aClipLayerIndex;
10+
in int aClipDataIndex;
11+
in int aClipBaseTaskIndex;
12+
813
struct CacheClipInstance {
914
int render_task_index;
1015
int layer_index;
@@ -15,14 +20,10 @@ struct CacheClipInstance {
1520
CacheClipInstance fetch_clip_item(int index) {
1621
CacheClipInstance cci;
1722

18-
int offset = index * 1;
19-
20-
ivec4 data0 = int_data[offset + 0];
21-
22-
cci.render_task_index = data0.x;
23-
cci.layer_index = data0.y;
24-
cci.data_index = data0.z;
25-
cci.base_task_index = data0.w;
23+
cci.render_task_index = aClipRenderTaskIndex;
24+
cci.layer_index = aClipLayerIndex;
25+
cci.data_index = aClipDataIndex;
26+
cci.base_task_index = aClipBaseTaskIndex;
2627

2728
return cci;
2829
}

webrender/res/cs_blur.vs.glsl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,28 @@
99
#define DIR_HORIZONTAL 0
1010
#define DIR_VERTICAL 1
1111

12+
in int aBlurRenderTaskIndex;
13+
in int aBlurSourceTaskIndex;
14+
in int aBlurDirection;
15+
16+
struct BlurCommand {
17+
int task_id;
18+
int src_task_id;
19+
int dir;
20+
};
21+
22+
BlurCommand fetch_blur() {
23+
BlurCommand blur;
24+
25+
blur.task_id = aBlurRenderTaskIndex;
26+
blur.src_task_id = aBlurSourceTaskIndex;
27+
blur.dir = aBlurDirection;
28+
29+
return blur;
30+
}
31+
1232
void main(void) {
13-
BlurCommand cmd = fetch_blur(gl_InstanceID);
33+
BlurCommand cmd = fetch_blur();
1434
RenderTaskData task = fetch_render_task(cmd.task_id);
1535
RenderTaskData src_task = fetch_render_task(cmd.src_task_id);
1636

webrender/res/cs_box_shadow.vs.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

66
void main(void) {
7-
CachePrimitiveInstance cpi = fetch_cache_instance(gl_InstanceID);
7+
CachePrimitiveInstance cpi = fetch_cache_instance();
88
RenderTaskData task = fetch_render_task(cpi.render_task_index);
99
BoxShadow bs = fetch_boxshadow(cpi.specific_prim_index);
1010

webrender/res/cs_text_run.vs.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// as text-shadow.
99

1010
void main(void) {
11-
CachePrimitiveInstance cpi = fetch_cache_instance(gl_InstanceID);
11+
CachePrimitiveInstance cpi = fetch_cache_instance();
1212
RenderTaskData task = fetch_render_task(cpi.render_task_index);
1313
TextRun text = fetch_text_run(cpi.specific_prim_index);
1414
Glyph glyph = fetch_glyph(cpi.sub_index);

webrender/res/prim_shared.glsl

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ uniform sampler2D sData64;
6565
uniform sampler2D sData128;
6666
uniform sampler2D sResourceRects;
6767

68+
// Instanced attributes
69+
in int aGlobalPrimId;
70+
in int aPrimitiveAddress;
71+
in int aTaskIndex;
72+
in int aClipTaskIndex;
73+
in int aLayerIndex;
74+
in int aElementIndex;
75+
in ivec2 aUserData;
76+
6877
#define get_fetch_uv(i, vpi) ivec2(vpi * (i % (WR_MAX_VERTEX_TEXTURE_WIDTH/vpi)), i / (WR_MAX_VERTEX_TEXTURE_WIDTH/vpi))
6978

7079
ivec2 get_fetch_uv_1(int index) {
@@ -90,10 +99,6 @@ struct Layer {
9099
vec4 screen_vertices[4];
91100
};
92101

93-
layout(std140) uniform Data {
94-
ivec4 int_data[WR_MAX_UBO_VECTORS];
95-
};
96-
97102
Layer fetch_layer(int index) {
98103
Layer layer;
99104

@@ -280,66 +285,38 @@ struct PrimitiveInstance {
280285
ivec2 user_data;
281286
};
282287

283-
PrimitiveInstance fetch_instance(int index) {
288+
PrimitiveInstance fetch_prim_instance() {
284289
PrimitiveInstance pi;
285290

286-
int offset = index * 2;
287-
288-
ivec4 data0 = int_data[offset + 0];
289-
ivec4 data1 = int_data[offset + 1];
290-
291-
pi.global_prim_index = data0.x;
292-
pi.specific_prim_index = data0.y;
293-
pi.render_task_index = data0.z;
294-
pi.clip_task_index = data0.w;
295-
pi.layer_index = data1.x;
296-
pi.sub_index = data1.y;
297-
pi.user_data = data1.zw;
291+
pi.global_prim_index = aGlobalPrimId;
292+
pi.specific_prim_index = aPrimitiveAddress;
293+
pi.render_task_index = aTaskIndex;
294+
pi.clip_task_index = aClipTaskIndex;
295+
pi.layer_index = aLayerIndex;
296+
pi.sub_index = aElementIndex;
297+
pi.user_data = aUserData;
298298

299299
return pi;
300300
}
301301

302-
struct BlurCommand {
303-
int task_id;
304-
int src_task_id;
305-
int dir;
306-
};
307-
308-
BlurCommand fetch_blur(int index) {
309-
BlurCommand blur;
310-
311-
int offset = index * 1;
312-
313-
ivec4 data0 = int_data[offset + 0];
314-
315-
blur.task_id = data0.x;
316-
blur.src_task_id = data0.y;
317-
blur.dir = data0.z;
318-
319-
return blur;
320-
}
321-
322302
struct CachePrimitiveInstance {
323303
int global_prim_index;
324304
int specific_prim_index;
325305
int render_task_index;
326306
int sub_index;
327-
ivec4 user_data;
307+
ivec2 user_data;
328308
};
329309

330-
CachePrimitiveInstance fetch_cache_instance(int index) {
310+
CachePrimitiveInstance fetch_cache_instance() {
331311
CachePrimitiveInstance cpi;
332312

333-
int offset = index * 2;
334-
335-
ivec4 data0 = int_data[offset + 0];
336-
ivec4 data1 = int_data[offset + 1];
313+
PrimitiveInstance pi = fetch_prim_instance();
337314

338-
cpi.global_prim_index = data0.x;
339-
cpi.specific_prim_index = data0.y;
340-
cpi.render_task_index = data0.z;
341-
cpi.sub_index = data0.w;
342-
cpi.user_data = data1;
315+
cpi.global_prim_index = pi.global_prim_index;
316+
cpi.specific_prim_index = pi.specific_prim_index;
317+
cpi.render_task_index = pi.render_task_index;
318+
cpi.sub_index = pi.sub_index;
319+
cpi.user_data = pi.user_data;
343320

344321
return cpi;
345322
}
@@ -357,11 +334,9 @@ struct Primitive {
357334
ivec2 user_data;
358335
};
359336

360-
Primitive load_primitive(int index) {
337+
Primitive load_primitive_custom(PrimitiveInstance pi) {
361338
Primitive prim;
362339

363-
PrimitiveInstance pi = fetch_instance(index);
364-
365340
prim.layer = fetch_layer(pi.layer_index);
366341
prim.tile = fetch_tile(pi.render_task_index);
367342
prim.clip_area = fetch_clip_area(pi.clip_task_index);
@@ -377,6 +352,13 @@ Primitive load_primitive(int index) {
377352
return prim;
378353
}
379354

355+
Primitive load_primitive() {
356+
PrimitiveInstance pi = fetch_prim_instance();
357+
358+
return load_primitive_custom(pi);
359+
}
360+
361+
380362
// Return the intersection of the plane (set up by "normal" and "point")
381363
// with the ray (set up by "ray_origin" and "ray_dir"),
382364
// writing the resulting scaler into "t".

webrender/res/ps_angle_gradient.vs.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

66
void main(void) {
7-
Primitive prim = load_primitive(gl_InstanceID);
7+
Primitive prim = load_primitive();
88
Gradient gradient = fetch_gradient(prim.prim_index);
99

1010
VertexInfo vi = write_vertex(prim.local_rect,

webrender/res/ps_blend.vs.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ struct Blend {
77
ivec4 src_id_target_id_op_amount;
88
};
99

10-
Blend fetch_blend(int index) {
11-
PrimitiveInstance pi = fetch_instance(index);
10+
Blend fetch_blend() {
11+
PrimitiveInstance pi = fetch_prim_instance();
1212

1313
Blend blend;
1414
blend.src_id_target_id_op_amount = ivec4(pi.user_data.x,
@@ -20,7 +20,7 @@ Blend fetch_blend(int index) {
2020
}
2121

2222
void main(void) {
23-
Blend blend = fetch_blend(gl_InstanceID);
23+
Blend blend = fetch_blend();
2424
Tile src = fetch_tile(blend.src_id_target_id_op_amount.x);
2525
Tile dest = fetch_tile(blend.src_id_target_id_op_amount.y);
2626

webrender/res/ps_border.vs.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

66
void main(void) {
7-
Primitive prim = load_primitive(gl_InstanceID);
7+
Primitive prim = load_primitive();
88
Border border = fetch_border(prim.prim_index);
99
int sub_part = prim.sub_index;
1010

0 commit comments

Comments
 (0)