Skip to content

Commit b444aa0

Browse files
author
bors-servo
authored
Auto merge of #3573 - moz-gfx:__wrlastsync, r=moz-gfx
Sync changes from mozilla-central <!-- 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/3573) <!-- Reviewable:end -->
2 parents b4b0f52 + 34db10a commit b444aa0

30 files changed

+1052
-117
lines changed

examples/animation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl App {
6767
&LayoutPrimitiveInfo::new(LayoutRect::zero()),
6868
spatial_id,
6969
&filters,
70+
&[],
7071
);
7172

7273
let space_and_clip = SpaceAndClipInfo {

examples/scrolling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Example for App {
5656
vec![],
5757
None,
5858
ScrollSensitivity::ScriptAndInputEvents,
59-
LayoutPoint::zero(),
59+
LayoutVector2D::zero(),
6060
);
6161

6262
// now put some content into it.
@@ -88,7 +88,7 @@ impl Example for App {
8888
vec![],
8989
None,
9090
ScrollSensitivity::ScriptAndInputEvents,
91-
LayoutPoint::zero(),
91+
LayoutVector2D::zero(),
9292
);
9393

9494
// give it a giant gray background just to distinguish it and to easily

webrender/res/brush_blend.glsl

+78-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#define VECS_PER_SPECIFIC_BRUSH 3
66

7+
#define COMPONENT_TRANSFER_IDENTITY 0
8+
#define COMPONENT_TRANSFER_TABLE 1
9+
#define COMPONENT_TRANSFER_DISCRETE 2
10+
#define COMPONENT_TRANSFER_LINEAR 3
11+
#define COMPONENT_TRANSFER_GAMMA 4
12+
713
#include shared,prim_shared,brush
814

915
// Interpolated UV coordinates to sample.
@@ -16,6 +22,8 @@ flat varying int vOp;
1622
flat varying mat3 vColorMat;
1723
flat varying vec3 vColorOffset;
1824
flat varying vec4 vUvClipBounds;
25+
flat varying int vTableAddress;
26+
flat varying int vFuncs[4];
1927

2028
#ifdef WR_VERTEX_SHADER
2129

@@ -55,9 +63,21 @@ void brush_vs(
5563
float amount = float(user_data.z) / 65536.0;
5664
float invAmount = 1.0 - amount;
5765

58-
vOp = user_data.y;
66+
vOp = user_data.y & 0xffff;
5967
vAmount = amount;
6068

69+
// This assignment is only used for component transfer filters but this
70+
// assignment has to be done here and not in the component transfer case
71+
// below because it doesn't get executed on Windows because of a suspected
72+
// miscompile of this shader on Windows. See
73+
// https://github.com/servo/webrender/wiki/Driver-issues#bug-1505871---assignment-to-varying-flat-arrays-inside-switch-statement-of-vertex-shader-suspected-miscompile-on-windows
74+
// default: just to satisfy angle_shader_validation.rs which needs one
75+
// default: for every switch, even in comments.
76+
vFuncs[0] = (user_data.y >> 28) & 0xf; // R
77+
vFuncs[1] = (user_data.y >> 24) & 0xf; // G
78+
vFuncs[2] = (user_data.y >> 20) & 0xf; // B
79+
vFuncs[3] = (user_data.y >> 16) & 0xf; // A
80+
6181
switch (vOp) {
6282
case 2: {
6383
// Grayscale
@@ -109,6 +129,11 @@ void brush_vs(
109129
vColorOffset = offset_data.rgb;
110130
break;
111131
}
132+
case 13: {
133+
// Component Transfer
134+
vTableAddress = user_data.z;
135+
break;
136+
}
112137
default: break;
113138
}
114139
}
@@ -177,6 +202,58 @@ Fragment brush_fs() {
177202
case 12:
178203
color = LinearToSrgb(color);
179204
break;
205+
case 13: // Component Transfer
206+
int offset = 0;
207+
vec4 texel;
208+
int k;
209+
210+
// We push a different amount of data to the gpu cache depending
211+
// on the function type.
212+
// Identity => 0 blocks
213+
// Table/Discrete => 64 blocks (256 values)
214+
// Linear => 1 block (2 values)
215+
// Gamma => 1 block (3 values)
216+
// We loop through the color components and increment the offset
217+
// (for the next color component) into the gpu cache based on how
218+
// many blocks that function type put into the gpu cache.
219+
// Table/Discrete use a 256 entry look up table.
220+
// Linear/Gamma are a simple calculation.
221+
vec4 colora = alpha != 0.0 ? Cs / alpha : Cs;
222+
for (int i = 0; i < 4; i++) {
223+
switch (vFuncs[i]) {
224+
case COMPONENT_TRANSFER_IDENTITY:
225+
break;
226+
case COMPONENT_TRANSFER_TABLE:
227+
case COMPONENT_TRANSFER_DISCRETE:
228+
// fetch value from lookup table
229+
k = int(floor(colora[i]*255.0));
230+
texel = fetch_from_gpu_cache_1(vTableAddress + offset + k/4);
231+
colora[i] = clamp(texel[k % 4], 0.0, 1.0);
232+
// offset plus 256/4 blocks
233+
offset = offset + 64;
234+
break;
235+
case COMPONENT_TRANSFER_LINEAR:
236+
// fetch the two values for use in the linear equation
237+
texel = fetch_from_gpu_cache_1(vTableAddress + offset);
238+
colora[i] = clamp(texel[0] * colora[i] + texel[1], 0.0, 1.0);
239+
// offset plus 1 block
240+
offset = offset + 1;
241+
break;
242+
case COMPONENT_TRANSFER_GAMMA:
243+
// fetch the three values for use in the gamma equation
244+
texel = fetch_from_gpu_cache_1(vTableAddress + offset);
245+
colora[i] = clamp(texel[0] * pow(colora[i], texel[1]) + texel[2], 0.0, 1.0);
246+
// offset plus 1 block
247+
offset = offset + 1;
248+
break;
249+
default:
250+
// shouldn't happen
251+
break;
252+
}
253+
}
254+
color = colora.rgb;
255+
alpha = colora.a;
256+
break;
180257
default:
181258
color = vColorMat * color + vColorOffset;
182259
}

webrender/res/gpu_cache.glsl

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ vec4[2] fetch_from_gpu_cache_2(int address) {
3333
);
3434
}
3535

36+
vec4 fetch_from_gpu_cache_1_direct(ivec2 address) {
37+
return texelFetch(sGpuCache, address, 0);
38+
}
39+
40+
vec4 fetch_from_gpu_cache_1(int address) {
41+
ivec2 uv = get_gpu_cache_uv(address);
42+
return texelFetch(sGpuCache, uv, 0);
43+
}
44+
3645
#ifdef WR_VERTEX_SHADER
3746

3847
vec4[8] fetch_from_gpu_cache_8(int address) {
@@ -85,15 +94,6 @@ vec4[4] fetch_from_gpu_cache_4(int address) {
8594
);
8695
}
8796

88-
vec4 fetch_from_gpu_cache_1_direct(ivec2 address) {
89-
return texelFetch(sGpuCache, address, 0);
90-
}
91-
92-
vec4 fetch_from_gpu_cache_1(int address) {
93-
ivec2 uv = get_gpu_cache_uv(address);
94-
return texelFetch(sGpuCache, uv, 0);
95-
}
96-
9797
//TODO: image resource is too specific for this module
9898

9999
struct ImageResource {

webrender/src/batch.rs

+56
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ impl AlphaBatchBuilder {
13881388
FilterOp::ColorMatrix(..) => 10,
13891389
FilterOp::SrgbToLinear => 11,
13901390
FilterOp::LinearToSrgb => 12,
1391+
FilterOp::ComponentTransfer => unreachable!(),
13911392
};
13921393

13931394
let user_data = match filter {
@@ -1413,6 +1414,7 @@ impl AlphaBatchBuilder {
14131414
FilterOp::ColorMatrix(_) => {
14141415
picture.extra_gpu_data_handle.as_int(gpu_cache)
14151416
}
1417+
FilterOp::ComponentTransfer => unreachable!(),
14161418
};
14171419

14181420
let (uv_rect_address, textures) = surface
@@ -1452,6 +1454,60 @@ impl AlphaBatchBuilder {
14521454
}
14531455
}
14541456
}
1457+
PictureCompositeMode::ComponentTransferFilter(handle) => {
1458+
// This is basically the same as the general filter case above
1459+
// except we store a little more data in the filter mode and
1460+
// a gpu cache handle in the user data.
1461+
let surface = ctx.surfaces[raster_config.surface_index.0]
1462+
.surface
1463+
.as_ref()
1464+
.expect("bug: surface must be allocated by now");
1465+
1466+
1467+
let filter_data = &ctx.data_stores.filterdata[handle];
1468+
let filter_mode : i32 = 13 |
1469+
((filter_data.data.r_func.to_int() << 28 |
1470+
filter_data.data.g_func.to_int() << 24 |
1471+
filter_data.data.b_func.to_int() << 20 |
1472+
filter_data.data.a_func.to_int() << 16) as i32);
1473+
1474+
let user_data = filter_data.gpu_cache_handle.as_int(gpu_cache);
1475+
1476+
let (uv_rect_address, textures) = surface
1477+
.resolve(
1478+
render_tasks,
1479+
ctx.resource_cache,
1480+
gpu_cache,
1481+
);
1482+
1483+
let key = BatchKey::new(
1484+
BatchKind::Brush(BrushBatchKind::Blend),
1485+
BlendMode::PremultipliedAlpha,
1486+
textures,
1487+
);
1488+
1489+
let prim_header_index = prim_headers.push(&prim_header, z_id, [
1490+
uv_rect_address.as_int(),
1491+
filter_mode,
1492+
user_data,
1493+
]);
1494+
1495+
let instance = BrushInstance {
1496+
prim_header_index,
1497+
clip_task_address,
1498+
segment_index: INVALID_SEGMENT_INDEX,
1499+
edge_flags: EdgeAaSegmentMask::empty(),
1500+
brush_flags,
1501+
user_data: 0,
1502+
};
1503+
1504+
self.current_batch_list().push_single_instance(
1505+
key,
1506+
bounding_rect,
1507+
z_id,
1508+
PrimitiveInstanceData::from(instance),
1509+
);
1510+
}
14551511
PictureCompositeMode::Puppet { master: Some(source) } if ctx.is_picture_surface_visible(source) => return,
14561512
PictureCompositeMode::MixBlend { mode, backdrop } if ctx.is_picture_surface_visible(backdrop) => {
14571513
let backdrop_picture = &ctx.prim_store.pictures[backdrop.0];

webrender/src/clip_scroll_tree.rs

+2
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ impl ClipScrollTree {
433433
content_size: &LayoutSize,
434434
scroll_sensitivity: ScrollSensitivity,
435435
frame_kind: ScrollFrameKind,
436+
external_scroll_offset: LayoutVector2D,
436437
) -> SpatialNodeIndex {
437438
let node = SpatialNode::new_scroll_frame(
438439
pipeline_id,
@@ -442,6 +443,7 @@ impl ClipScrollTree {
442443
content_size,
443444
scroll_sensitivity,
444445
frame_kind,
446+
external_scroll_offset,
445447
);
446448
self.add_spatial_node(node)
447449
}

webrender/src/device/gl.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2345,18 +2345,14 @@ impl Device {
23452345
ibo_id: IBOId,
23462346
owns_vertices_and_indices: bool,
23472347
) -> VAO {
2348-
debug_assert!(self.inside_frame);
2349-
23502348
let instance_stride = descriptor.instance_stride() as usize;
23512349
let vao_id = self.gl.gen_vertex_arrays(1)[0];
23522350

2353-
self.gl.bind_vertex_array(vao_id);
2351+
self.bind_vao_impl(vao_id);
23542352

23552353
descriptor.bind(self.gl(), main_vbo_id, instance_vbo_id);
23562354
ibo_id.bind(self.gl()); // force it to be a part of VAO
23572355

2358-
self.gl.bind_vertex_array(0);
2359-
23602356
VAO {
23612357
id: vao_id,
23622358
ibo_id,
@@ -2374,7 +2370,7 @@ impl Device {
23742370
debug_assert!(self.inside_frame);
23752371

23762372
let vao_id = self.gl.gen_vertex_arrays(1)[0];
2377-
self.gl.bind_vertex_array(vao_id);
2373+
self.bind_vao_impl(vao_id);
23782374

23792375
let mut attrib_index = 0;
23802376
for stream in streams {
@@ -2388,8 +2384,6 @@ impl Device {
23882384
attrib_index += stream.attributes.len();
23892385
}
23902386

2391-
self.gl.bind_vertex_array(0);
2392-
23932387
CustomVAO {
23942388
id: vao_id,
23952389
}

0 commit comments

Comments
 (0)