Skip to content

Commit 6e0f4ba

Browse files
author
bors-servo
authored
Auto merge of #507 - glennw:tidy-batches, r=pcwalton
Tidy up how batch keys are used. Store the batch key directly inside the primitive batch structure instead of duplicating fields. This doesn't have any functional change, but the code is a bit tidier and it simplifies some upcoming PRs (that introduce additional blend modes into the batch keys). <!-- 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/507) <!-- Reviewable:end -->
2 parents 6552b0b + 66d29bc commit 6e0f4ba

File tree

2 files changed

+66
-92
lines changed

2 files changed

+66
-92
lines changed

webrender/src/renderer.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,13 @@ impl Renderer {
13911391
}
13921392

13931393
for batch in &target.alpha_batcher.batches {
1394-
self.device.set_blend(batch.blending_enabled);
1394+
let color_texture_id = batch.key.color_texture_id;
1395+
let mask_texture_id = batch.key.mask_texture_id;
1396+
let transform_kind = batch.key.flags.transform_kind();
1397+
let has_complex_clip = batch.key.flags.needs_clipping();
1398+
let blending_enabled = batch.key.flags.needs_blending();
1399+
1400+
self.device.set_blend(blending_enabled);
13951401

13961402
match &batch.data {
13971403
&PrimitiveBatchData::Blend(ref ubo_data) => {
@@ -1427,94 +1433,94 @@ impl Renderer {
14271433
}
14281434
}
14291435
&PrimitiveBatchData::Rectangles(ref ubo_data) => {
1430-
let (shader, max_prim_items) = if batch.has_complex_clip {
1436+
let (shader, max_prim_items) = if has_complex_clip {
14311437
self.gpu_profile.add_marker(GPU_TAG_PRIM_RECT_CLIP);
1432-
self.ps_rectangle_clip.get(&mut self.device, batch.transform_kind)
1438+
self.ps_rectangle_clip.get(&mut self.device, transform_kind)
14331439
} else {
14341440
self.gpu_profile.add_marker(GPU_TAG_PRIM_RECT);
1435-
self.ps_rectangle.get(&mut self.device, batch.transform_kind)
1441+
self.ps_rectangle.get(&mut self.device, transform_kind)
14361442
};
14371443
self.draw_ubo_batch(ubo_data,
14381444
shader,
14391445
1,
1440-
batch.color_texture_id,
1441-
batch.mask_texture_id,
1446+
color_texture_id,
1447+
mask_texture_id,
14421448
max_prim_items,
14431449
&projection);
14441450
}
14451451
&PrimitiveBatchData::Image(ref ubo_data) => {
1446-
let (shader, max_prim_items) = if batch.has_complex_clip {
1452+
let (shader, max_prim_items) = if has_complex_clip {
14471453
self.gpu_profile.add_marker(GPU_TAG_PRIM_IMAGE_CLIP);
1448-
self.ps_image_clip.get(&mut self.device, batch.transform_kind)
1454+
self.ps_image_clip.get(&mut self.device, transform_kind)
14491455
} else {
14501456
self.gpu_profile.add_marker(GPU_TAG_PRIM_IMAGE);
1451-
self.ps_image.get(&mut self.device, batch.transform_kind)
1457+
self.ps_image.get(&mut self.device, transform_kind)
14521458
};
14531459
self.draw_ubo_batch(ubo_data,
14541460
shader,
14551461
1,
1456-
batch.color_texture_id,
1457-
batch.mask_texture_id,
1462+
color_texture_id,
1463+
mask_texture_id,
14581464
max_prim_items,
14591465
&projection);
14601466
}
14611467
&PrimitiveBatchData::Borders(ref ubo_data) => {
14621468
self.gpu_profile.add_marker(GPU_TAG_PRIM_BORDER);
1463-
let (shader, max_prim_items) = self.ps_border.get(&mut self.device, batch.transform_kind);
1469+
let (shader, max_prim_items) = self.ps_border.get(&mut self.device, transform_kind);
14641470
self.draw_ubo_batch(ubo_data,
14651471
shader,
14661472
1,
1467-
batch.color_texture_id,
1468-
batch.mask_texture_id,
1473+
color_texture_id,
1474+
mask_texture_id,
14691475
max_prim_items,
14701476
&projection);
14711477
}
14721478
&PrimitiveBatchData::BoxShadow(ref ubo_data) => {
14731479
self.gpu_profile.add_marker(GPU_TAG_PRIM_BOX_SHADOW);
1474-
let (shader, max_prim_items) = self.ps_box_shadow.get(&mut self.device, batch.transform_kind);
1480+
let (shader, max_prim_items) = self.ps_box_shadow.get(&mut self.device, transform_kind);
14751481
self.draw_ubo_batch(ubo_data,
14761482
shader,
14771483
1,
1478-
batch.color_texture_id,
1479-
batch.mask_texture_id,
1484+
color_texture_id,
1485+
mask_texture_id,
14801486
max_prim_items,
14811487
&projection);
14821488
}
14831489
&PrimitiveBatchData::TextRun(ref ubo_data) => {
14841490
self.gpu_profile.add_marker(GPU_TAG_PRIM_TEXT_RUN);
1485-
let (shader, max_prim_items) = self.ps_text_run.get(&mut self.device, batch.transform_kind);
1491+
let (shader, max_prim_items) = self.ps_text_run.get(&mut self.device, transform_kind);
14861492
self.draw_ubo_batch(ubo_data,
14871493
shader,
14881494
1,
1489-
batch.color_texture_id,
1490-
batch.mask_texture_id,
1495+
color_texture_id,
1496+
mask_texture_id,
14911497
max_prim_items,
14921498
&projection);
14931499
}
14941500
&PrimitiveBatchData::AlignedGradient(ref ubo_data) => {
1495-
let (shader, max_prim_items) = if batch.has_complex_clip {
1501+
let (shader, max_prim_items) = if has_complex_clip {
14961502
self.gpu_profile.add_marker(GPU_TAG_PRIM_GRADIENT_CLIP);
1497-
self.ps_gradient_clip.get(&mut self.device, batch.transform_kind)
1503+
self.ps_gradient_clip.get(&mut self.device, transform_kind)
14981504
} else {
14991505
self.gpu_profile.add_marker(GPU_TAG_PRIM_GRADIENT);
1500-
self.ps_gradient.get(&mut self.device, batch.transform_kind)
1506+
self.ps_gradient.get(&mut self.device, transform_kind)
15011507
};
15021508
self.draw_ubo_batch(ubo_data,
15031509
shader,
15041510
1,
1505-
batch.color_texture_id,
1506-
batch.mask_texture_id,
1511+
color_texture_id,
1512+
mask_texture_id,
15071513
max_prim_items,
15081514
&projection);
15091515
}
15101516
&PrimitiveBatchData::AngleGradient(ref ubo_data) => {
15111517
self.gpu_profile.add_marker(GPU_TAG_PRIM_ANGLE_GRADIENT);
1512-
let (shader, max_prim_items) = self.ps_angle_gradient.get(&mut self.device, batch.transform_kind);
1518+
let (shader, max_prim_items) = self.ps_angle_gradient.get(&mut self.device, transform_kind);
15131519
self.draw_ubo_batch(ubo_data,
15141520
shader,
15151521
1,
1516-
batch.color_texture_id,
1517-
batch.mask_texture_id,
1522+
color_texture_id,
1523+
mask_texture_id,
15181524
max_prim_items,
15191525
&projection);
15201526
}

webrender/src/tiling.rs

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use webrender_traits::{BoxShadowClipMode, PipelineId, ScrollLayerId, WebGLContex
3939
const FLOATS_PER_RENDER_TASK_INFO: usize = 8;
4040

4141
trait AlphaBatchHelpers {
42-
fn get_batch_info(&self, metadata: &PrimitiveMetadata) -> (AlphaBatchKind, TextureId, TextureId);
42+
fn get_batch_kind(&self, metadata: &PrimitiveMetadata) -> AlphaBatchKind;
4343
fn prim_affects_tile(&self,
4444
prim_index: PrimitiveIndex,
4545
tile_rect: &DeviceRect,
@@ -50,14 +50,12 @@ trait AlphaBatchHelpers {
5050
batch: &mut PrimitiveBatch,
5151
layer_index: StackingContextIndex,
5252
task_id: i32,
53-
transform_kind: TransformedRectKind,
54-
needs_blending: bool,
5553
render_tasks: &RenderTaskCollection,
5654
pass_index: RenderPassIndex);
5755
}
5856

5957
impl AlphaBatchHelpers for PrimitiveStore {
60-
fn get_batch_info(&self, metadata: &PrimitiveMetadata) -> (AlphaBatchKind, TextureId, TextureId) {
58+
fn get_batch_kind(&self, metadata: &PrimitiveMetadata) -> AlphaBatchKind {
6159
let batch_kind = match metadata.prim_kind {
6260
PrimitiveKind::Border => AlphaBatchKind::Border,
6361
PrimitiveKind::BoxShadow => AlphaBatchKind::BoxShadow,
@@ -77,7 +75,7 @@ impl AlphaBatchHelpers for PrimitiveStore {
7775
}
7876
};
7977

80-
(batch_kind, metadata.color_texture_id, metadata.mask_texture_id)
78+
batch_kind
8179
}
8280

8381
// Optional narrow phase intersection test, depending on primitive type.
@@ -111,13 +109,8 @@ impl AlphaBatchHelpers for PrimitiveStore {
111109
batch: &mut PrimitiveBatch,
112110
layer_index: StackingContextIndex,
113111
task_id: i32,
114-
transform_kind: TransformedRectKind,
115-
needs_blending: bool,
116112
render_tasks: &RenderTaskCollection,
117113
child_pass_index: RenderPassIndex) {
118-
debug_assert!(transform_kind == batch.transform_kind);
119-
debug_assert!(needs_blending == batch.blending_enabled);
120-
121114
let metadata = self.get_metadata(prim_index);
122115
let layer_index = layer_index.0 as i32;
123116
let global_prim_id = prim_index.0 as i32;
@@ -370,7 +363,7 @@ impl AlphaBatcher {
370363
ctx: &RenderTargetContext,
371364
render_tasks: &RenderTaskCollection,
372365
child_pass_index: RenderPassIndex) {
373-
let mut batches: Vec<(AlphaBatchKey, PrimitiveBatch)> = vec![];
366+
let mut batches: Vec<PrimitiveBatch> = vec![];
374367
for task in &mut self.tasks {
375368
let task_index = render_tasks.get_static_task_index(&task.task_id);
376369
let task_index = task_index.0 as i32;
@@ -397,17 +390,16 @@ impl AlphaBatcher {
397390
let flags = AlphaBatchKeyFlags::new(transform_kind,
398391
needs_blending,
399392
needs_clipping);
400-
let (batch_kind, color_texture_id, mask_texture_id) = ctx.prim_store
401-
.get_batch_info(prim_metadata);
393+
let batch_kind = ctx.prim_store.get_batch_kind(prim_metadata);
402394
batch_key = AlphaBatchKey::primitive(batch_kind,
403395
flags,
404-
color_texture_id,
405-
mask_texture_id);
396+
prim_metadata.color_texture_id,
397+
prim_metadata.mask_texture_id);
406398
}
407399
}
408400

409401
while existing_batch_index < batches.len() &&
410-
!batches[existing_batch_index].0.is_compatible_with(&batch_key) {
402+
!batches[existing_batch_index].key.is_compatible_with(&batch_key) {
411403
existing_batch_index += 1
412404
}
413405

@@ -422,20 +414,14 @@ impl AlphaBatcher {
422414
AlphaRenderItem::Primitive(_, prim_index) => {
423415
// See if this task fits into the tile UBO
424416
let prim_metadata = ctx.prim_store.get_metadata(prim_index);
425-
let (batch_kind, color_texture_id, mask_texture_id) = ctx.prim_store
426-
.get_batch_info(prim_metadata);
427-
PrimitiveBatch::new(batch_kind,
428-
batch_key.flags.transform_kind(),
429-
batch_key.flags.needs_blending(),
430-
batch_key.flags.needs_clipping(),
431-
color_texture_id,
432-
mask_texture_id)
417+
let batch_kind = ctx.prim_store.get_batch_kind(prim_metadata);
418+
PrimitiveBatch::new(batch_kind, batch_key)
433419
}
434420
};
435-
batches.push((batch_key, new_batch))
421+
batches.push(new_batch)
436422
}
437423

438-
let batch = &mut batches[existing_batch_index].1;
424+
let batch = &mut batches[existing_batch_index];
439425
match item {
440426
AlphaRenderItem::Composite(src0_id, src1_id, info) => {
441427
let ok = batch.pack_composite(render_tasks.get_static_task_index(&src0_id),
@@ -455,16 +441,14 @@ impl AlphaBatcher {
455441
batch,
456442
sc_index,
457443
task_index,
458-
batch_key.flags.transform_kind(),
459-
batch_key.flags.needs_blending(),
460444
render_tasks,
461445
child_pass_index);
462446
}
463447
}
464448
}
465449
}
466450

467-
self.batches.extend(batches.into_iter().map(|(_, batch)| batch))
451+
self.batches.extend(batches.into_iter())
468452
}
469453
}
470454

@@ -818,18 +802,20 @@ enum AlphaBatchKind {
818802
}
819803

820804
#[derive(Copy, Clone, Debug)]
821-
struct AlphaBatchKey {
805+
pub struct AlphaBatchKey {
822806
kind: AlphaBatchKind,
823-
flags: AlphaBatchKeyFlags,
824-
color_texture_id: TextureId,
825-
mask_texture_id: TextureId,
807+
pub flags: AlphaBatchKeyFlags,
808+
pub color_texture_id: TextureId,
809+
pub mask_texture_id: TextureId,
826810
}
827811

828812
impl AlphaBatchKey {
829813
fn blend() -> AlphaBatchKey {
830814
AlphaBatchKey {
831815
kind: AlphaBatchKind::Blend,
832-
flags: AlphaBatchKeyFlags(0),
816+
flags: AlphaBatchKeyFlags::new(TransformedRectKind::AxisAligned,
817+
true,
818+
false),
833819
color_texture_id: TextureId::invalid(),
834820
mask_texture_id: TextureId::invalid(),
835821
}
@@ -838,7 +824,9 @@ impl AlphaBatchKey {
838824
fn composite() -> AlphaBatchKey {
839825
AlphaBatchKey {
840826
kind: AlphaBatchKind::Composite,
841-
flags: AlphaBatchKeyFlags(0),
827+
flags: AlphaBatchKeyFlags::new(TransformedRectKind::AxisAligned,
828+
true,
829+
false),
842830
color_texture_id: TextureId::invalid(),
843831
mask_texture_id: TextureId::invalid(),
844832
}
@@ -870,7 +858,7 @@ impl AlphaBatchKey {
870858
// FIXME(gw): Change these to use the bitflags!()
871859

872860
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
873-
struct AlphaBatchKeyFlags(u8);
861+
pub struct AlphaBatchKeyFlags(u8);
874862

875863
impl AlphaBatchKeyFlags {
876864
fn new(transform_kind: TransformedRectKind,
@@ -881,19 +869,19 @@ impl AlphaBatchKeyFlags {
881869
((needs_blending as u8) << 0) )
882870
}
883871

884-
fn transform_kind(&self) -> TransformedRectKind {
872+
pub fn transform_kind(&self) -> TransformedRectKind {
885873
if ((self.0 >> 1) & 1) == 0 {
886874
TransformedRectKind::AxisAligned
887875
} else {
888876
TransformedRectKind::Complex
889877
}
890878
}
891879

892-
fn needs_blending(&self) -> bool {
880+
pub fn needs_blending(&self) -> bool {
893881
(self.0 & 1) != 0
894882
}
895883

896-
fn needs_clipping(&self) -> bool {
884+
pub fn needs_clipping(&self) -> bool {
897885
(self.0 & 4) != 0
898886
}
899887
}
@@ -948,33 +936,21 @@ pub enum PrimitiveBatchData {
948936

949937
#[derive(Debug)]
950938
pub struct PrimitiveBatch {
951-
pub transform_kind: TransformedRectKind,
952-
pub has_complex_clip: bool,
953-
pub color_texture_id: TextureId, // TODO(gw): Expand to sampler array to handle all glyphs!
954-
pub mask_texture_id: TextureId,
955-
pub blending_enabled: bool,
939+
pub key: AlphaBatchKey,
956940
pub data: PrimitiveBatchData,
957941
}
958942

959943
impl PrimitiveBatch {
960944
fn blend() -> PrimitiveBatch {
961945
PrimitiveBatch {
962-
color_texture_id: TextureId::invalid(),
963-
mask_texture_id: TextureId::invalid(),
964-
transform_kind: TransformedRectKind::AxisAligned,
965-
has_complex_clip: false,
966-
blending_enabled: true,
946+
key: AlphaBatchKey::blend(),
967947
data: PrimitiveBatchData::Blend(Vec::new()),
968948
}
969949
}
970950

971951
fn composite() -> PrimitiveBatch {
972952
PrimitiveBatch {
973-
color_texture_id: TextureId::invalid(),
974-
mask_texture_id: TextureId::invalid(),
975-
transform_kind: TransformedRectKind::AxisAligned,
976-
has_complex_clip: false,
977-
blending_enabled: true,
953+
key: AlphaBatchKey::composite(),
978954
data: PrimitiveBatchData::Composite(Vec::new()),
979955
}
980956
}
@@ -1031,11 +1007,7 @@ impl PrimitiveBatch {
10311007
}
10321008

10331009
fn new(batch_kind: AlphaBatchKind,
1034-
transform_kind: TransformedRectKind,
1035-
blending_enabled: bool,
1036-
has_complex_clip: bool,
1037-
color_texture_id: TextureId,
1038-
mask_texture_id: TextureId) -> PrimitiveBatch {
1010+
key: AlphaBatchKey) -> PrimitiveBatch {
10391011
let data = match batch_kind {
10401012
AlphaBatchKind::Rectangle => PrimitiveBatchData::Rectangles(Vec::new()),
10411013
AlphaBatchKind::TextRun => PrimitiveBatchData::TextRun(Vec::new()),
@@ -1048,11 +1020,7 @@ impl PrimitiveBatch {
10481020
};
10491021

10501022
PrimitiveBatch {
1051-
color_texture_id: color_texture_id,
1052-
mask_texture_id: mask_texture_id,
1053-
transform_kind: transform_kind,
1054-
blending_enabled: blending_enabled,
1055-
has_complex_clip: has_complex_clip,
1023+
key: key,
10561024
data: data,
10571025
}
10581026
}

0 commit comments

Comments
 (0)