diff --git a/shader/binning.wgsl b/shader/binning.wgsl index 2672bb8ac..83e36a5ee 100644 --- a/shader/binning.wgsl +++ b/shader/binning.wgsl @@ -89,12 +89,18 @@ fn main( let bbox_raw = bbox_intersect(clip_bbox, pb); // TODO(naga): clunky expression a workaround for broken lhs swizzle let bbox = vec4(bbox_raw.xy, max(bbox_raw.xy, bbox_raw.zw)); - intersected_bbox[element_ix] = bbox; - x0 = i32(floor(bbox.x * SX)); - y0 = i32(floor(bbox.y * SY)); - x1 = i32(ceil(bbox.z * SX)); - y1 = i32(ceil(bbox.w * SY)); + + // `bbox_intersect` can result in a zero or negative area intersection if the path bbox lies + // outside the clip bbox. If that is the case, Don't round up the bottom-right corner of the + // and leave the coordinates at 0. This way the path will get clipped out and won't get + // assigned to a bin. + if bbox.x < bbox.z && bbox.y < bbox.w { + x0 = i32(floor(bbox.x * SX)); + y0 = i32(floor(bbox.y * SY)); + x1 = i32(ceil(bbox.z * SX)); + y1 = i32(ceil(bbox.w * SY)); + } } let width_in_bins = i32((config.width_in_tiles + N_TILE_X - 1u) / N_TILE_X); let height_in_bins = i32((config.height_in_tiles + N_TILE_Y - 1u) / N_TILE_Y); diff --git a/shader/tile_alloc.wgsl b/shader/tile_alloc.wgsl index 8ec921768..1f7a4bcc1 100644 --- a/shader/tile_alloc.wgsl +++ b/shader/tile_alloc.wgsl @@ -68,10 +68,15 @@ fn main( var y1 = 0; if drawtag != DRAWTAG_NOP && drawtag != DRAWTAG_END_CLIP { let bbox = draw_bboxes[drawobj_ix]; - x0 = i32(floor(bbox.x * SX)); - y0 = i32(floor(bbox.y * SY)); - x1 = i32(ceil(bbox.z * SX)); - y1 = i32(ceil(bbox.w * SY)); + + // Don't round up the bottom-right corner of the bbox if the area is zero and leave the + // coordinates at 0. This will make `tile_count` zero as the shape is clipped out. + if bbox.x < bbox.z && bbox.y < bbox.w { + x0 = i32(floor(bbox.x * SX)); + y0 = i32(floor(bbox.y * SY)); + x1 = i32(ceil(bbox.z * SX)); + y1 = i32(ceil(bbox.w * SY)); + } } let ux0 = u32(clamp(x0, 0, i32(config.width_in_tiles))); let uy0 = u32(clamp(y0, 0, i32(config.height_in_tiles)));