diff --git a/piet-scene/src/scene/builder.rs b/piet-scene/src/scene/builder.rs index b202cea..fd1e3f7 100644 --- a/piet-scene/src/scene/builder.rs +++ b/piet-scene/src/scene/builder.rs @@ -277,12 +277,12 @@ fn encode_blend_mode(mode: BlendMode) -> u32 { (mode.mix as u32) << 8 | mode.compose as u32 } -// Tags for draw objects. See shader/drawtag.h for the authoritative source. +// Tags for draw objects. See shader/shared/drawtag.wgsl for the authoritative source. const DRAWTAG_FILLCOLOR: u32 = 0x44; const DRAWTAG_FILLLINGRADIENT: u32 = 0x114; const DRAWTAG_FILLRADGRADIENT: u32 = 0x2dc; -const DRAWTAG_BEGINCLIP: u32 = 0x89; -const DRAWTAG_ENDCLIP: u32 = 0xa1; +const DRAWTAG_BEGINCLIP: u32 = 0x9; +const DRAWTAG_ENDCLIP: u32 = 0x21; #[repr(C)] #[derive(Clone, Copy, Debug, Default, Zeroable, Pod)] diff --git a/piet-wgsl/shader/clip_leaf.wgsl b/piet-wgsl/shader/clip_leaf.wgsl index 219ba76..601e3ac 100644 --- a/piet-wgsl/shader/clip_leaf.wgsl +++ b/piet-wgsl/shader/clip_leaf.wgsl @@ -26,9 +26,6 @@ var draw_monoids: array; @group(0) @binding(6) var clip_bboxes: array>; -@group(0) @binding(7) -var info: array; - let WG_SIZE = 256u; var sh_bic: array; var sh_stack: array; @@ -69,7 +66,7 @@ fn search_link(bic: ptr, ix: u32) -> i32 { } } -fn load_clip_inp(ix: u32) -> i32 { +fn load_clip_path(ix: u32) -> i32 { if ix < config.n_clip { return clip_inp[ix].path_ix; } else { @@ -131,7 +128,7 @@ fn main( sh_stack_bbox[local_id.x] = bbox; // Read input and compute Bic binary tree - let inp = load_clip_inp(global_id.x); + let inp = load_clip_path(global_id.x); let is_push = inp >= 0; var bic = Bic(1u - u32(is_push), u32(is_push)); sh_bic[local_id.x] = bic; @@ -193,12 +190,8 @@ fn main( let parent_ix = parent_clip.ix; let ix = ~inp; draw_monoids[ix].path_ix = u32(path_ix); - // Copy blend mode and alpha from parent - let di = draw_monoids[ix].info_offset; - let parent_di = draw_monoids[parent_ix].info_offset; - info[di] = info[parent_di]; - info[di + 1u] = info[parent_di + 1u]; - + // Make EndClip point to the same draw data as BeginClip + draw_monoids[ix].scene_offset = draw_monoids[parent_ix].scene_offset; if grandparent >= 0 { bbox = sh_bbox[grandparent]; } else if grandparent + i32(stack_size) >= 0 { diff --git a/piet-wgsl/shader/coarse.wgsl b/piet-wgsl/shader/coarse.wgsl index 2bd14d8..9a836d0 100644 --- a/piet-wgsl/shader/coarse.wgsl +++ b/piet-wgsl/shader/coarse.wgsl @@ -281,8 +281,9 @@ fn main( var is_blend = false; if is_clip { let BLEND_CLIP = (128u << 8u) | 3u; - let di = draw_monoids[drawobj_ix].info_offset; - let blend = info[di]; + let scene_offset = draw_monoids[drawobj_ix].scene_offset; + let dd = config.drawdata_base + scene_offset; + let blend = scene[dd]; is_blend = blend != BLEND_CLIP; } let include_tile = tile.segments != 0u || (tile.backdrop == 0) == is_clip || is_blend; @@ -347,7 +348,7 @@ fn main( write_grad(CMD_RAD_GRAD, index, info_offset); } // DRAWTAG_BEGIN_CLIP - case 0x89u: { + case 0x9u: { if tile.segments == 0u && tile.backdrop == 0 { clip_zero_depth = clip_depth + 1u; } else { @@ -358,11 +359,11 @@ fn main( clip_depth += 1u; } // DRAWTAG_END_CLIP - case 0xa1u: { + case 0x21u: { clip_depth -= 1u; write_path(tile, -1.0); - let blend = info[di]; - let alpha = bitcast(info[di + 1u]); + let blend = scene[dd]; + let alpha = bitcast(scene[dd + 1u]); write_end_clip(CmdEndClip(blend, alpha)); render_blend_depth -= 1u; } @@ -372,11 +373,11 @@ fn main( // In "clip zero" state, suppress all drawing switch drawtag { // DRAWTAG_BEGIN_CLIP - case 0x89u: { + case 0x9u: { clip_depth += 1u; } // DRAWTAG_END_CLIP - case 0xa1u: { + case 0x21u: { if clip_depth == clip_zero_depth { clip_zero_depth = 0u; } diff --git a/piet-wgsl/shader/draw_leaf.wgsl b/piet-wgsl/shader/draw_leaf.wgsl index 05bd80f..b7d0f95 100644 --- a/piet-wgsl/shader/draw_leaf.wgsl +++ b/piet-wgsl/shader/draw_leaf.wgsl @@ -170,15 +170,6 @@ fn main( info[di + 9u] = bitcast(ra); info[di + 10u] = bitcast(roff); } - // DRAWTAG_BEGIN_CLIP - case 0x89u: { - // Store blend mode and alpha in info for two reasons: 1) we don't need - // to bind scene in clip_leaf which keeps us at 8 buffer bindings and 2) - // the logic in coarse to check clip state for tile inclusion is the - // same for BeginClip/EndClip. - info[di] = scene[dd]; - info[di + 1u] = scene[dd + 1u]; - } default: {} } } diff --git a/piet-wgsl/shader/shared/clip.wgsl b/piet-wgsl/shader/shared/clip.wgsl index a845ce9..a0a7a0e 100644 --- a/piet-wgsl/shader/shared/clip.wgsl +++ b/piet-wgsl/shader/shared/clip.wgsl @@ -11,7 +11,11 @@ fn bic_combine(x: Bic, y: Bic) -> Bic { } struct ClipInp { + // Index of the draw object. ix: u32, + // This is a packed encoding of an enum with the sign bit as the tag. If positive, + // this entry is a BeginClip and contains the associated path index. If negative, + // it is an EndClip and contains the bitwise-not of the EndClip draw object index. path_ix: i32, } diff --git a/piet-wgsl/shader/shared/drawtag.wgsl b/piet-wgsl/shader/shared/drawtag.wgsl index 3b68c55..432cf1b 100644 --- a/piet-wgsl/shader/shared/drawtag.wgsl +++ b/piet-wgsl/shader/shared/drawtag.wgsl @@ -20,8 +20,8 @@ let DRAWTAG_FILL_COLOR = 0x44u; let DRAWTAG_FILL_LIN_GRADIENT = 0x114u; let DRAWTAG_FILL_RAD_GRADIENT = 0x2dcu; let DRAWTAG_FILL_IMAGE = 0x48u; -let DRAWTAG_BEGIN_CLIP = 0x89u; -let DRAWTAG_END_CLIP = 0xa1u; +let DRAWTAG_BEGIN_CLIP = 0x9u; +let DRAWTAG_END_CLIP = 0x21u; fn draw_monoid_identity() -> DrawMonoid { return DrawMonoid(); diff --git a/piet-wgsl/src/render.rs b/piet-wgsl/src/render.rs index ff8664d..7ca9022 100644 --- a/piet-wgsl/src/render.rs +++ b/piet-wgsl/src/render.rs @@ -324,7 +324,6 @@ pub fn render_full( clip_el_buf, draw_monoid_buf, clip_bbox_buf, - info_buf, ], ); } diff --git a/piet-wgsl/src/shaders.rs b/piet-wgsl/src/shaders.rs index 186340b..a8a4176 100644 --- a/piet-wgsl/src/shaders.rs +++ b/piet-wgsl/src/shaders.rs @@ -212,7 +212,6 @@ pub fn full_shaders(device: &Device, engine: &mut Engine) -> Result