Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Paint fixes for 0.1.11's reports: nested masks in a faded group, inline background images, empty clip-paths, svg overflow: visible (#256)

shane6f96c78a8bbc
diff --git a/systems/page/src/draw.rs b/systems/page/src/draw.rs
index f7b5ca44..77ff470b 100644
--- a/systems/page/src/draw.rs
+++ b/systems/page/src/draw.rs
@@ -159,6 +159,9 @@ pub fn draw(mut scenes: ResMut<Scenes>, mut vello: ResMut<Vello>, device: Res<Re
}
// the image atlas (each filtered element is an image in it) as large as the device can make, not Vello's 8192
vello::low_level::vello_encoding::set_max_atlas_size(device.limits().max_texture_dimension_2d);
+ // and the blend spill, grown for a scene whose layers nest past four (raea #247), within what the device binds
+ let limits = device.limits();
+ vello::low_level::vello_encoding::set_max_buffer_size((limits.max_storage_buffer_binding_size as u64).min(limits.max_buffer_size));
// and an image larger than the atlas (16384 at most, whatever the device allows) decoded at a size that fits it
// (raea#245: an M5's GPU allows 32768, and a 1080x18000 picture was kept whole and refused)
blitz_dom::net::set_max_image_side(vello::low_level::vello_encoding::max_atlas_size());
diff --git a/systems/page/tests/paint_repros.rs b/systems/page/tests/paint_repros.rs
new file mode 100644
index 00000000..c8697b3b
--- /dev/null
+++ b/systems/page/tests/paint_repros.rs
@@ -0,0 +1,124 @@
+//! 0.1.11's paint reports, each the issue's own repro as HTML, painted by blitz-paint into a recording scene and read
+//! back: what is filled, in what colour or brush, and under which clips (no GPU, so every runner checks them).
+use anyrender::recording::RenderCommand;
+use anyrender::{Paint, Scene};
+use bevy::math::UVec2;
+use vello::kurbo::{Point, Rect, Shape};
+use raea_sys_page::{Page, config};
+
+fn painted(html: &str, w: u32, h: u32) -> Scene {
+ let mut doc = blitz_html::HtmlDocument::from_html(html, config(Page { size: UVec2::new(w, h), scale: 1.0 })).into_inner();
+ doc.resolve(0.0);
+ let mut scene = Scene::new();
+ blitz_paint::paint_scene(&mut scene, &mut doc, 1.0, w, h, 0, 0);
+ scene
+}
+
+/// Each fill: its brush, its box on the page, and the boxes of the layers it's clipped by.
+fn fills(scene: &Scene) -> Vec<(Paint, Rect, Vec<Rect>)> {
+ let (mut clips, mut out) = (Vec::new(), Vec::new());
+ for c in &scene.commands {
+ match c {
+ RenderCommand::PushLayer(l) => clips.push(l.transform.transform_rect_bbox(l.clip.bounding_box())),
+ RenderCommand::PushClipLayer(l) => clips.push(l.transform.transform_rect_bbox(l.clip.bounding_box())),
+ RenderCommand::PopLayer => drop(clips.pop()),
+ RenderCommand::Fill(f) => out.push((f.brush.clone(), f.transform.transform_rect_bbox(f.shape.bounding_box()), clips.clone())),
+ _ => {}
+ }
+ }
+ out
+}
+
+fn rgb(p: &Paint) -> Option<[u8; 3]> {
+ match p {
+ Paint::Solid(c) => {
+ let c = c.to_rgba8();
+ (c.a > 0).then_some([c.r, c.g, c.b])
+ }
+ _ => None,
+ }
+}
+
+/// What of `color` is drawn: the fills in it, each cut by its clips (None when a clip leaves none of it).
+fn drawn(scene: &Scene, color: [u8; 3]) -> Vec<Rect> {
+ fills(scene)
+ .into_iter()
+ .filter(|(p, ..)| rgb(p) == Some(color))
+ .filter_map(|(_, r, clips)| {
+ let cut = clips.iter().fold(r, |a, c| a.intersect(*c));
+ (cut.width() > 0.0 && cut.height() > 0.0).then_some(cut)
+ })
+ .collect()
+}
+
+/// raea #250: `clip-path: inset(0 0 0 100%)` clips the element away (it drew whole); 99% leaves a sliver
+#[test]
+fn a_clip_path_inset_that_clips_everything_draws_nothing() {
+ let page = |inset: &str| {
+ format!(
+ r#"<body style="margin:0;background:#fff"><div style="padding:40px"><div style="position:relative;width:400px;height:300px;background:#0f0">
+ <div style="position:absolute;inset:0;background:#f00;clip-path:inset({inset})"></div></div></div></body>"#
+ )
+ };
+ for inset in ["0 0 0 100%", "100% 0 0 0", "0 60% 0 50%", "0 0 0 120%"] {
+ let s = painted(&page(inset), 700, 400);
+ assert_eq!(drawn(&s, [255, 0, 0]), vec![], "inset({inset}) drew red");
+ assert_eq!(drawn(&s, [0, 255, 0]).len(), 1, "inset({inset}) lost the green box");
+ }
+ let sliver = drawn(&painted(&page("0 0 0 99%"), 700, 400), [255, 0, 0]);
+ assert_eq!(sliver.len(), 1);
+ assert!((sliver[0].width() - 4.0).abs() < 0.01 && (sliver[0].height() - 300.0).abs() < 0.01, "{sliver:?}");
+}
+
+/// raea #251: an <svg> with `overflow: visible` draws past its viewport (a 1x1 svg drew nothing); without it, the
+/// UA sheet still clips it to its box, as Chrome does
+#[test]
+fn an_svg_with_overflow_visible_draws_past_its_viewport() {
+ let page = |overflow: &str| {
+ format!(
+ r##"<body style="margin:0;background:#fff"><svg xmlns="http://www.w3.org/2000/svg" style="position:absolute;left:0;top:0;{overflow}" width="1" height="1">
+ <circle cx="200" cy="200" r="80" fill="#ff6600"/><polygon points="0,-40 32,24 -28,20" transform="translate(400 200) rotate(30)" fill="#3366ff"/></svg></body>"##
+ )
+ };
+ let s = painted(&page("overflow:visible"), 700, 400);
+ let circle = drawn(&s, [255, 102, 0]);
+ assert_eq!(circle.len(), 1, "the circle: {circle:?}");
+ assert!(circle[0].contains(Point::new(200.0, 200.0)) && circle[0].width() > 150.0, "{circle:?}");
+ let triangle = drawn(&s, [51, 102, 255]);
+ assert!(triangle.len() == 1 && triangle[0].contains(Point::new(400.0, 200.0)), "the triangle: {triangle:?}");
+ // the UA's clip, and an author's overflow: hidden, keep it in its 1x1 box
+ for overflow in ["", "overflow:hidden"] {
+ let s = painted(&page(overflow), 700, 400);
+ assert_eq!(drawn(&s, [255, 102, 0]), vec![], "{overflow:?} drew the circle past the box");
+ }
+}
+
+/// raea #248: a background-image on an inline element is drawn on each of its line fragments (it drew nothing, its
+/// background-color did), laid out across the fragments side by side, so `background-size: 10% 100%` covers part of the
+/// first line's fragment and nothing of the others'
+#[test]
+fn an_inline_elements_background_image_fills_its_line_fragments() {
+ let page = |size: &str| {
+ format!(
+ r#"<body style="margin:0;background:#fff"><div style="padding:40px;font-size:40px;line-height:50px"><div style="width:300px">Before <span id="m" style="background-image:linear-gradient(#FFD43B, #FFD43B);background-repeat:no-repeat;background-size:{size}">this marked phrase wraps over lines</span> after.</div></div></body>"#
+ )
+ };
+ let gradients = |s: &Scene| -> Vec<Rect> {
+ fills(s)
+ .into_iter()
+ .filter(|(p, ..)| matches!(p, Paint::Gradient(_)))
+ .filter_map(|(_, r, clips)| {
+ let cut = clips.iter().fold(r, |a, c| a.intersect(*c));
+ (cut.width() > 1.0 && cut.height() > 1.0).then_some(cut)
+ })
+ .collect()
+ };
+ let full = gradients(&painted(&page("100% 100%"), 700, 400));
+ assert!(full.len() >= 2, "a fill on each line's fragment: {full:?}");
+ let mut tops: Vec<i64> = full.iter().map(|r| r.y0.round() as i64).collect();
+ tops.dedup();
+ assert!(tops.len() >= 2, "on more than one line: {full:?}");
+ // 10% of the fragments side by side: on the first line alone
+ let half = gradients(&painted(&page("10% 100%"), 700, 400));
+ assert!(!half.is_empty() && half.iter().all(|r| r.y0 < full.iter().map(|f| f.y0).fold(f64::MAX, f64::min) + 1.0), "{half:?} vs {full:?}");
+}
diff --git a/vendor/blitz-dom/assets/default.css b/vendor/blitz-dom/assets/default.css
index e4a6dea0..716db65e 100644
--- a/vendor/blitz-dom/assets/default.css
+++ b/vendor/blitz-dom/assets/default.css
@@ -11,6 +11,12 @@
svg|*:not(svg|svg), svg|*:not(svg|foreignObject) > svg|svg {
transform-origin: 0 0;
}
+/* raea: Chrome's svg.css clips an inner <svg> to its viewport (`svg:not(:root) { overflow: hidden }`), which
+ * `overflow: visible` lifts (raea #251). `clip` rather than `hidden`, so an svg is no scroll container and lays out
+ * as it did (a flex item keeps its automatic minimum size); blitz-paint's draw_svg reads it */
+svg|svg:not(:root) {
+ overflow: clip;
+}
@font-face {
font-family: -moz-bullet-font;
diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rs
index b0310aeb..73b02c40 100644
--- a/vendor/blitz-paint/src/render.rs
+++ b/vendor/blitz-paint/src/render.rs
@@ -882,13 +882,15 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
// The root element's overflow is propagated to the viewport (which is clipped by the
// window/surface bounds), so the root element must not clip its own overflow.
let is_root_element = self.root_element_id == Some(node_id);
+ // raea: an inline <svg>'s overflow clip is drawn by draw_svg, and only when its drawing spills past its
+ // viewport: the UA sheet's `overflow: clip` on every svg would otherwise be a clip layer for every icon (#251)
+ let is_inline_svg = node.element_data().is_some_and(|e| &*e.name.local == "svg" && matches!(e.image_data(), Some(blitz_dom::node::ImageData::Svg(_))));
let should_clip = !is_root_element
&& (is_image
|| is_sub_doc
|| is_text_input
|| contain_paint
- || !matches!(overflow_x, Overflow::Visible)
- || !matches!(overflow_y, Overflow::Visible));
+ || (!is_inline_svg && (!matches!(overflow_x, Overflow::Visible) || !matches!(overflow_y, Overflow::Visible))));
// Apply padding/border offset to inline root
let taffy::Layout {
@@ -1167,6 +1169,11 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
// Compute clip-path (if any) and wrap all rendering in a clip layer
let clip_path_shape = cx.clip_path_shape();
+ // raea: a clip-path with no area (an inset that clips everything, a circle(0)) hides the element and all it
+ // draws, its shadows and outline included, as `clip: rect()` of no area does below (raea #250)
+ if clip_path_shape.as_ref().is_some_and(|(p, _)| p.bounding_box().is_zero_area()) {
+ return;
+ }
let has_clip_path = clip_path_shape.is_some();
let clip_fill = clip_path_shape.as_ref().map_or(peniko::Fill::NonZero, |s| s.1);
let default_clip = cx.frame.border_box_path();
@@ -1865,12 +1872,30 @@ impl ElementCx<'_, '_> {
(pos.y - text_layout.block_offset as f64 - (layout.padding.top + layout.border.top) as f64) * self.scale,
))
* Affine::scale(self.scale);
+ // raea: an inline element's background images (#248), drawn by an ElementCx whose box is `at` (its
+ // fragments side by side, in CSS px from the root's border box), with its own borders and padding (an
+ // inline box has no Taffy layout of its own; a percentage padding is of the root's content width)
+ let content_width = CSSPixelLength::new(layout.content_box_width());
+ let images = |scene: &mut _, id: NodeId, at: Rect| {
+ let Some(node) = self.context.dom.get_node(id) else { return };
+ let Some(st) = node.primary_styles() else { return };
+ let (b, p) = (st.get_border(), st.get_padding());
+ let pad = |v: &style::values::computed::NonNegativeLengthPercentage| v.0.resolve(content_width).px();
+ let mut l = taffy::Layout::new();
+ l.size = taffy::Size { width: at.width() as f32, height: at.height() as f32 };
+ l.border = taffy::Rect { left: b.border_left_width.0.to_f32_px(), right: b.border_right_width.0.to_f32_px(), top: b.border_top_width.0.to_f32_px(), bottom: b.border_bottom_width.0.to_f32_px() };
+ l.padding = taffy::Rect { left: pad(&p.padding_left), right: pad(&p.padding_right), top: pad(&p.padding_top), bottom: pad(&p.padding_bottom) };
+ // the box's corner at device scale: border_box is in CSS px, an ElementCx's transform in device px
+ let t = border_box * Affine::translate((at.x0, at.y0)) * Affine::scale(1.0 / self.scale);
+ self.context.element_cx(node, l, t, None).draw_inline_background_images(scene);
+ };
crate::text::draw_inline_backgrounds(
scene,
text_layout.layout.lines(),
self.context.dom,
border_box,
self.node.id,
+ images,
);
// Render text selection highlight (if any) using cached selection ranges
@@ -2372,6 +2397,15 @@ impl ElementCx<'_, '_> {
let b = tree.root().abs_stroke_bounding_box();
let (sw, sh) = (svg_size.width(), svg_size.height());
let spills = b.left() < -0.01 || b.top() < -0.01 || b.right() > sw + 0.01 || b.bottom() > sh + 0.01;
+ // raea: an inline <svg>'s clip is its `overflow` (the UA sheet's `svg|svg:not(:root) { overflow: clip }`), so
+ // `overflow: visible` draws what reaches past its viewport, as Chrome does: a 1x1 svg drawing particles in page
+ // coordinates drew nothing (raea #251). An SVG image (<img>) is always clipped to its box.
+ let b = self.style.get_box();
+ let clips = !inline || !matches!(b.overflow_x, Overflow::Visible) || !matches!(b.overflow_y, Overflow::Visible);
+ if spills && !clips {
+ anyrender_svg::render_svg_tree_in(scene, &tree, transform, host, in_css);
+ return;
+ }
if spills {
self.context.layer_manager.maybe_with_layer(scene, true, 1.0, self.transform, &self.frame.content_box_path(), None, None, |scene| {
anyrender_svg::render_svg_tree_in(scene, &tree, transform, host, in_css);
diff --git a/vendor/blitz-paint/src/render/background.rs b/vendor/blitz-paint/src/render/background.rs
index d97730c2..f75e3d89 100644
--- a/vendor/blitz-paint/src/render/background.rs
+++ b/vendor/blitz-paint/src/render/background.rs
@@ -137,7 +137,6 @@ impl<'a> ImageLayerStyles<'a> {
impl ElementCx<'_, '_> {
pub(super) fn draw_background(&self, scene: &mut impl PaintScene) {
let bg_styles = &self.style.get_background();
- let image_data = &self.element.background_images;
let layer_count = bg_styles.background_image.0.len();
// The background color is clipped by the clip of the last layer in the list
@@ -156,28 +155,7 @@ impl ElementCx<'_, '_> {
self.context.layer_manager.maybe_with_blend_layer(scene, isolated, 1.0, Some(peniko::Mix::Normal.into()), self.transform, &bounds, None, None, |scene| {
// Draw background color (if any)
self.draw_solid_bg(scene, &background_clip_path);
-
- for idx in (0..layer_count).rev() {
- let layer = ImageLayerStyles::from_background(bg_styles, image_data, idx);
- if layer_paints_nothing(&layer) {
- continue;
- }
- let background_clip_path = self.box_path(layer.clip);
-
- self.context.layer_manager.maybe_with_blend_layer(
- scene,
- true,
- 1.0,
- blends[idx],
- self.transform,
- &background_clip_path,
- None,
- None,
- |scene| {
- self.draw_image_layer(scene, &layer);
- },
- );
- }
+ self.draw_background_layers(scene, &blends);
if text {
let dest_in = peniko::BlendMode::new(peniko::Mix::Normal, peniko::Compose::DestIn);
self.context.layer_manager.maybe_with_blend_layer(scene, true, 1.0, Some(dest_in), self.transform, &bounds, None, None, |scene| self.draw_text_mask(scene));
@@ -185,6 +163,46 @@ impl ElementCx<'_, '_> {
});
}
+ /// The background's image layers, bottom first, each in its clip and blended by `blends` (draw_background's)
+ fn draw_background_layers(&self, scene: &mut impl PaintScene, blends: &[Option<peniko::BlendMode>]) {
+ let bg_styles = &self.style.get_background();
+ let image_data = &self.element.background_images;
+ for idx in (0..bg_styles.background_image.0.len()).rev() {
+ let layer = ImageLayerStyles::from_background(bg_styles, image_data, idx);
+ if layer_paints_nothing(&layer) {
+ continue;
+ }
+ let background_clip_path = self.box_path(layer.clip);
+
+ self.context.layer_manager.maybe_with_blend_layer(
+ scene,
+ true,
+ 1.0,
+ blends.get(idx).copied().flatten(),
+ self.transform,
+ &background_clip_path,
+ None,
+ None,
+ |scene| {
+ self.draw_image_layer(scene, &layer);
+ },
+ );
+ }
+ }
+
+ /// raea: an inline element's background images on one of its fragments (text.rs draw_inline_backgrounds, raea
+ /// #248), its frame the box its fragments make side by side: the layers alone, as the fragments' colour, borders
+ /// and clip are text.rs's; in a group of their own when a layer blends (blended with each other, not its colour)
+ pub(super) fn draw_inline_background_images(&self, scene: &mut impl PaintScene) {
+ let n = self.style.get_background().background_image.0.len();
+ let blends: Vec<_> = (0..n).map(|i| crate::blend::background_blend(&self.style, i)).collect();
+ let bounds = self.frame.border_box_path().bounding_box();
+ let isolated = blends.iter().any(Option::is_some);
+ self.context.layer_manager.maybe_with_blend_layer(scene, isolated, 1.0, Some(peniko::Mix::Normal.into()), self.transform, &bounds, None, None, |scene| {
+ self.draw_background_layers(scene, &blends);
+ });
+ }
+
/// The path of the given CSS box model box for this element
pub(super) fn box_path(&self, css_box: BoxModelBox) -> crate::kurbo_css::BoxShape {
match css_box {
diff --git a/vendor/blitz-paint/src/render/clip_path.rs b/vendor/blitz-paint/src/render/clip_path.rs
index 52ca183d..9ab29561 100644
--- a/vendor/blitz-paint/src/render/clip_path.rs
+++ b/vendor/blitz-paint/src/render/clip_path.rs
@@ -174,8 +174,10 @@ impl ElementCx<'_, '_> {
let x1 = ox + w - right;
let y1 = oy + h - bottom;
+ // raea: an inset that meets or crosses itself clips everything (an empty clip region), not nothing:
+ // None meant no clip-path, so `inset(0 0 0 100%)` drew the whole element (raea #250)
if x1 <= x0 || y1 <= y0 {
- return None;
+ return Some(BezPath::new());
}
// TODO: Support border-radius on inset()
diff --git a/vendor/blitz-paint/src/text.rs b/vendor/blitz-paint/src/text.rs
index e5840222..2f96f039 100644
--- a/vendor/blitz-paint/src/text.rs
+++ b/vendor/blitz-paint/src/text.rs
@@ -115,12 +115,18 @@ fn snap_glyph(x: f32, y: f32, at: Affine) -> (f32, f32) {
///
/// The inline root's own background is painted separately (as a normal block box). `transform` is the root's
/// border box at device scale.
-pub(crate) fn draw_inline_backgrounds<'a>(
- scene: &mut impl PaintScene,
+///
+/// raea: its background images too (raea #248: a highlighter's `linear-gradient` on a phrase drew nothing, its colour
+/// alone did), by `images` (the element, and the box they're laid out in, in the root's CSS px): each fragment clipped
+/// to itself from one box as wide as all its fragments side by side, as Chrome's `box-decoration-break: slice` lays a
+/// background out, so a `background-size` of 0% to 100% sweeps across the lines in turn.
+pub(crate) fn draw_inline_backgrounds<'a, S: PaintScene>(
+ scene: &mut S,
lines: impl Iterator<Item = Line<'a, TextBrush>>,
doc: &BaseDocument,
transform: Affine,
inline_root_id: NodeId,
+ mut images: impl FnMut(&mut S, NodeId, Rect),
) {
let mut seen: Vec<(usize, NodeId)> = Vec::new();
let mut add = |mut id: NodeId| {
@@ -169,12 +175,15 @@ pub(crate) fn draw_inline_backgrounds<'a>(
side(&border.border_bottom_width, &border.border_bottom_color, border.border_bottom_style),
side(&border.border_left_width, &border.border_left_color, border.border_left_style),
];
- if bg == Color::TRANSPARENT && [top, right, bottom, left].iter().all(Option::is_none) {
+ let has_images = styles.get_background().background_image.0.iter().any(|i| !matches!(i, style::values::generics::image::GenericImage::None));
+ if bg == Color::TRANSPARENT && !has_images && [top, right, bottom, left].iter().all(Option::is_none) {
continue;
}
let Some(frags) = node.inline_fragment_boxes() else { continue };
let frags: Vec<_> = frags.collect();
let n = frags.len();
+ let slices = frags.iter().map(|f| (f.right - f.left) as f64).sum::<f64>();
+ let mut before = 0.0;
for (i, f) in frags.into_iter().enumerate() {
let r = Rect::new(f.left as f64, f.top as f64, f.right as f64, f.bottom as f64);
let (first, last) = (i == 0, i + 1 == n);
@@ -196,6 +205,12 @@ pub(crate) fn draw_inline_backgrounds<'a>(
if bg != Color::TRANSPARENT {
scene.fill(Fill::NonZero, transform, bg, None, &shape);
}
+ if has_images {
+ scene.push_clip_layer(Fill::NonZero, transform, &shape);
+ images(scene, id, Rect::new(r.x0 - before, r.y0, r.x0 - before + slices, r.y1));
+ scene.pop_layer();
+ }
+ before += r.width();
if rounded {
scene.push_clip_layer(Fill::NonZero, transform, &shape);
}
diff --git a/vendor/vello_encoding/src/config.rs b/vendor/vello_encoding/src/config.rs
index 2c3a2cff..de03a6e7 100644
--- a/vendor/vello_encoding/src/config.rs
+++ b/vendor/vello_encoding/src/config.rs
@@ -411,7 +411,8 @@ impl BufferSizes {
let seg_counts = BufferSize::new(bump.seg_counts.max(1));
let segments = BufferSize::new(bump.segments.max(1));
// 16 * 16 (1 << 8) is one blend spill, so the default allows for 4096 spills.
- let blend_spill = BufferSize::new(bump.blend_spill.max(1));
+ // raea: and room for every tile to spill as deep as the scene's layers nest (`blend_spill_for`)
+ let blend_spill = BufferSize::new(bump.blend_spill.max(blend_spill_for(n_tiles, LAYER_DEPTH.get())).max(1));
let ptcl = BufferSize::new(bump.ptcl.max(1));
Self {
path_reduced,
@@ -509,6 +510,41 @@ fn grown(base: BumpAllocationSizes, n_tiles: u32) -> BumpAllocationSizes {
}
}
+/// raea: the layers a tile's blend stack holds in the fine stage's registers (shader/shared/config.wgsl's
+/// BLEND_STACK_SPLIT); each layer deeper is a spill of the tile's 16x16 pixels into the blend spill buffer
+pub const BLEND_STACK_SPLIT: u32 = 4;
+
+std::thread_local! {
+ /// raea: the nesting of the scene this thread resolved last (resolve.rs `layer_depth`), which the render's config,
+ /// made from that resolve's layout on the same thread (vello's render_encoding_coarse), sizes its blend spill by
+ static LAYER_DEPTH: std::cell::Cell<u32> = const { std::cell::Cell::new(0) };
+}
+
+pub(crate) fn set_layer_depth(depth: u32) {
+ LAYER_DEPTH.set(depth);
+}
+
+/// raea: the largest storage buffer the device binds, in bytes (`set_max_buffer_size`); wgpu's default limit until the
+/// embedder gives its device's
+static MAX_BUFFER_BYTES: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(128 << 20);
+
+/// raea: the largest storage buffer the device binds (wgpu's `max_storage_buffer_binding_size`), which a blend spill
+/// grown for a deep scene stays within
+pub fn set_max_buffer_size(bytes: u64) {
+ MAX_BUFFER_BYTES.store(bytes.max(1 << 20), std::sync::atomic::Ordering::Relaxed);
+}
+
+/// raea: the blend spill (u32 pixels) a render of `n_tiles` needs when its layers nest `depth` deep: every tile spills
+/// what's deeper than BLEND_STACK_SPLIT, 256 pixels a layer (coarse.wgsl's `scratch_size`), up to the largest buffer
+/// the device binds. Vello's fixed size (1 << 20, raea-page's 1 << 18) holds 4096 spills, and a 1080x1920 page has 8160
+/// tiles, so a single full-frame layer past the fourth (two nested masks in a faded group) overflowed it, and the
+/// frame wasn't drawn even at Vello's own sizes (raea #247).
+pub fn blend_spill_for(n_tiles: u32, depth: u32) -> u32 {
+ let need = n_tiles as u64 * depth.saturating_sub(BLEND_STACK_SPLIT) as u64 * (TILE_WIDTH * TILE_HEIGHT) as u64;
+ let most = MAX_BUFFER_BYTES.load(std::sync::atomic::Ordering::Relaxed) / 4;
+ need.min(most).min(u32::MAX as u64) as u32
+}
+
static BUMP_FULL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
/// raea: these defaults for the renders from now on (true), the embedder's sizes again (false): a frame drawn again
@@ -532,6 +568,27 @@ mod tests {
w.div_ceil(TILE_WIDTH) * h.div_ceil(TILE_HEIGHT)
}
+ /// raea #247: two nested masks in a faded group on a 1080x1920 page are layers seven deep over every tile
+ #[test]
+ fn blend_spill_holds_every_tile_spilling_as_deep_as_the_scene_nests() {
+ let n = tiles(1080, 1920);
+ assert_eq!(n, 8160);
+ // four layers or fewer stay in the fine stage's registers: the set size alone
+ assert_eq!(blend_spill_for(n, 4), 0);
+ // one past four on every tile is 8160 spills of 256 pixels: past Vello's 4096 spills, which refused the frame
+ assert_eq!(blend_spill_for(n, 5), 8160 * 256);
+ assert!(blend_spill_for(n, 5) > BumpAllocationSizes::default().blend_spill);
+ // the config a render makes after resolving a scene of that depth has the room
+ set_layer_depth(7);
+ let layout = Layout::default();
+ let cfg = RenderConfig::new(&layout, 1080, 1920, &peniko::Color::TRANSPARENT);
+ assert_eq!(cfg.gpu.blend_size, 8160 * 3 * 256);
+ assert_eq!(cfg.buffer_sizes.blend_spill.len(), cfg.gpu.blend_size);
+ // and never past the largest buffer the device binds (128 MiB until it's given)
+ assert_eq!(blend_spill_for(tiles(15360, 8640), 40) as u64 * 4, 128 << 20);
+ set_layer_depth(0);
+ }
+
#[test]
fn bump_sizes_grow_past_1080p() {
// up to 1080p the set sizes, ptcl with every tile's initial allocation on top
diff --git a/vendor/vello_encoding/src/lib.rs b/vendor/vello_encoding/src/lib.rs
index 17935bd6..e7682f8b 100644
--- a/vendor/vello_encoding/src/lib.rs
+++ b/vendor/vello_encoding/src/lib.rs
@@ -54,6 +54,7 @@ pub use clip::{Clip, ClipBbox, ClipBic, ClipElement};
pub use config::{
BufferSize, BufferSizes, BumpAllocationSizes, BumpAllocatorMemory, BumpAllocators, ConfigUniform, IndirectCount,
PTCL_INITIAL_ALLOC, RenderConfig, WorkgroupCounts, WorkgroupSize, bump_sizes_for, set_bump_allocation_sizes, set_bump_full, set_blend_linear,
+ BLEND_STACK_SPLIT, blend_spill_for, set_max_buffer_size,
};
pub use draw::{
DRAW_INFO_FLAGS_FILL_RULE_BIT, DrawBbox, DrawBeginClip, DrawBlurRoundedRect, DrawColor,
@@ -69,7 +70,7 @@ pub use path::{
PathTag, SegmentCount, Style, Tile,
};
pub use ramp_cache::Ramps;
-pub use resolve::{Layout, Patch, Resolver, resolve_solid_paths_only, take_images_left_out};
+pub use resolve::{Layout, Patch, Resolver, layer_depth, resolve_solid_paths_only, take_images_left_out};
#[cfg(feature = "bump_estimate")]
pub use estimate::BumpEstimator;
diff --git a/vendor/vello_encoding/src/resolve.rs b/vendor/vello_encoding/src/resolve.rs
index 249a232f..af67a7dc 100644
--- a/vendor/vello_encoding/src/resolve.rs
+++ b/vendor/vello_encoding/src/resolve.rs
@@ -185,6 +185,8 @@ impl Resolver {
encoding: &Encoding,
packed: &mut Vec<u8>,
) -> (Layout, Ramps<'a>, Images<'a>) {
+ // raea: the scene's layer nesting, which sizes its blend spill (config.rs `blend_spill_for`)
+ crate::config::set_layer_depth(layer_depth(&encoding.draw_tags));
let resources = &encoding.resources;
if resources.patches.is_empty() {
let layout = resolve_solid_paths_only(encoding, packed);
@@ -563,6 +565,21 @@ impl Resolver {
}
}
+/// raea: how deep the scene's layers (begin clips, a clip layer or a blended one alike) nest at most: a tile's blend
+/// stack is never deeper, as coarse.wgsl counts a begin clip that touches the tile into its `max_blend_depth`.
+pub fn layer_depth(tags: &[DrawTag]) -> u32 {
+ let (mut depth, mut deepest) = (0u32, 0u32);
+ for tag in tags {
+ if *tag == DrawTag::BEGIN_CLIP {
+ depth += 1;
+ deepest = deepest.max(depth);
+ } else if *tag == DrawTag::END_CLIP {
+ depth = depth.saturating_sub(1);
+ }
+ }
+ deepest
+}
+
static IMAGES_LEFT_OUT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
/// raea: how many images the resolves since the last call left out, the atlas having no room for them at its largest
@@ -688,6 +705,33 @@ mod tests {
use super::*;
use peniko::{Blob, ImageAlphaType, ImageFormat};
+ /// raea #247: the resolve measures how deep the scene's layers nest, and the render's config made after it gives
+ /// the blend spill room for every tile to spill that deep: here layers six deep beside a lone one, two past the
+ /// fine stage's four on each of a 1080x1920 page's 8160 tiles
+ #[test]
+ fn a_resolve_sizes_the_blend_spill_by_how_deep_its_layers_nest() {
+ use crate::{DrawBeginClip, RenderConfig};
+ let mut encoding = Encoding::new();
+ let layer = DrawBeginClip::new(peniko::Mix::Normal.into(), 0.9);
+ for _ in 0..6 {
+ encoding.encode_begin_clip(layer);
+ }
+ for _ in 0..6 {
+ encoding.encode_end_clip();
+ }
+ encoding.encode_begin_clip(layer);
+ encoding.encode_end_clip();
+ assert_eq!(layer_depth(&encoding.draw_tags), 6);
+ let mut packed = Vec::new();
+ let (layout, _, _) = Resolver::new().resolve(&encoding, &mut packed);
+ let cfg = RenderConfig::new(&layout, 1080, 1920, &peniko::Color::TRANSPARENT);
+ assert_eq!(cfg.gpu.blend_size, 8160 * 2 * 256);
+ // a shallow scene after it is back at the set size
+ let (layout, _, _) = Resolver::new().resolve(&Encoding::new(), &mut packed);
+ let cfg = RenderConfig::new(&layout, 1080, 1920, &peniko::Color::TRANSPARENT);
+ assert_eq!(cfg.gpu.blend_size, crate::bump_sizes_for(8160).blend_spill);
+ }
+
/// raea: frame `f`'s `n` images, each new (a blob of its own) and near a 1080p frame's size, a few px apart and
/// differently in each frame: raea-page's layers under a moving camera, each a placeholder the size of its box
fn frame(n: u32, f: u32) -> Encoding {
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index c5ced7ee..f55d8b80 100644
--- a/vendor/vendor.toml
+++ b/vendor/vendor.toml
@@ -70,14 +70,14 @@ exit = "a bevy_ui_widgets release on parley 0.12"
path = "vendor/blitz-paint"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs); a stacking context's out-of-flow boxes from containing blocks above it kept in its layer and not culled (raea #39); a filter's layer over the boxes the element and its descendants draw (up to the overflow clips in their way), not its border box alone; a filter of opacity() functions alone drawn as the layer's alpha, not as an atlas image (raea #96); an inline run whose element is visibility: hidden isn't drawn, though it keeps its place in the line (raea #13); a filter's layer the size of what the element and its descendants draw, a box that draws nothing (a full-frame wrapper) left out of it, as Chrome sizes a filter's input (raea #125)"
+reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs); a stacking context's out-of-flow boxes from containing blocks above it kept in its layer and not culled (raea #39); a filter's layer over the boxes the element and its descendants draw (up to the overflow clips in their way), not its border box alone; a filter of opacity() functions alone drawn as the layer's alpha, not as an atlas image (raea #96); an inline run whose element is visibility: hidden isn't drawn, though it keeps its place in the line (raea #13); a filter's layer the size of what the element and its descendants draw, a box that draws nothing (a full-frame wrapper) left out of it, as Chrome sizes a filter's input (raea #125); a clip-path of no area (an inset that clips everything) hides the element, not draws it unclipped (raea #250); an inline element's background images on its line fragments, laid out over them side by side as box-decoration-break: slice does (raea #248); an inline <svg> clipped to its viewport by its `overflow`, so `overflow: visible` draws past it (raea #251)"
exit = "a Blitz release that draws these"
[blitz-dom]
path = "vendor/blitz-dom"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone; transform-box: view-box's reference box at the origin of user space, not at the viewBox's x and y; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10); an app-bundled svg face of a family the page already gave is left out, as one given before the page's is removed (raea/text loadFont fetches Google's faces at import, LR10); getBoundingClientRect through a perspective's projection (the node's Projection), and transformed_rect for a rect inside a node's box (LR10); an element whose `:has()` was matched is matched again when a node under it is inserted or removed (raea layers LA2a: a caption a <Sequence> put on the page stayed hidden under `:not(:has(...))`); a picture fitted to the raea-w/raea-h its URL asks (net.rs fit)"
+reason = "inline flex/grid baselines, auto table columns, table row rects, inline image load events, SVG text fonts, SVG non-scaling strokes, url() filters; Blitz main's #1244 and #1246; a node removed in a mutation batch dropped from the style, form and title nodes the batch flushes (raea #24); a node in a 3D rendering context (or with a projection) placed again on every resolve, so it follows a preserve-3d parent whose transform a script set (raea #19); a ParseErrorReporter (not_applied.rs) on every author parse, keeping what stylo drops for the render to say once (raea #34); a bevy_text box whose lines are no finite size (an Apple bitmap-only face, which parley scales by a units-per-em of 0) measures 0 by 0, as bevy_text does; a family list ending in ; getBoundingClientRect and the geometry walks stop at a freed containing-block link instead of panicking on its key, and an element in a display: none subtree answers a zero rect (raea #108)"raea-bevy fallback" (bevy_text's FontSource::Family) falls to the collection's fallback families, not to serif nor to the CoreText pick (parley: NO_HOOK_FAMILY); an out-of-flow box painted by the stacking context between it and its containing block, inside its opacity group (raea #39); an SVG's paint properties from CSS written into its serialized source for usvg (raea #45); transform-box: stroke-box as fill-box under non-scaling-stroke, a stylesheet's stroke in the stroke box, and the non-scaling mark on an element with its own id (raea #50); an SVG element's rewritten style attribute without a leading `;` when its own declarations were transforms alone; transform-box: view-box's reference box at the origin of user space, not at the viewBox's x and y; every inline box laid out in full while its line is only measured, since Taffy's measure cache keeps a box's size without its baseline (raea #109); an inline element has a border edge only where its border has a style, so a plain span (border-style none, its width still `medium`) doesn't split the shaping at its edges and lose the kerning across them (docs/layout-reads.feature LR10); an app-bundled svg face of a family the page already gave is left out, as one given before the page's is removed (raea/text loadFont fetches Google's faces at import, LR10); getBoundingClientRect through a perspective's projection (the node's Projection), and transformed_rect for a rect inside a node's box (LR10); an element whose `:has()` was matched is matched again when a node under it is inserted or removed (raea layers LA2a: a caption a <Sequence> put on the page stayed hidden under `:not(:has(...))`); a picture fitted to the raea-w/raea-h its URL asks (net.rs fit); the UA sheet's `svg|svg:not(:root) { overflow: clip }` (Chrome's hidden, as clip so layout is unchanged), which blitz-paint's draw_svg reads (raea #251)"
exit = "a Blitz release with #1244/#1246 and these"
[parley_engine]
@@ -119,7 +119,7 @@ exit = "anyrender_svg drawing these"
path = "vendor/vello_encoding"
upstream = "crates.io:0.11.0"
kind = "patch"
-reason = "bump buffer sizes set by the embedder (vello#1861's BumpAllocationSizes), not 165 MiB of defaults, grown with the target past 1080p (bump_sizes_for: ptcl holds every tile's initial allocation, which alone filled 99% of a fixed 2M at 4K), and back at the defaults while set_bump_full is on (a frame that came out all black drawn again); glyph tops for the CoreGraphics y-map (RAEA_PAGE_CG_YMAP); a resolve with no images keeps the image atlas (resolve.rs: a solid-only scene reported 0x0, the renderer swapped in a 1x1 atlas and every cached image then drew blank); a full image atlas lets go of what the resolve hasn't used, the longest unused first, and is then packed again with the resolve's images alone, before an image is left out, and the images left out are counted (take_images_left_out: raea-page's layers are new images in every frame, the atlas kept the last two frames' and a page of ten frame-sized layers drew without its nearest); the atlas grows to the device's largest texture (set_max_atlas_size: 16384 on Apple silicon), not 8192 (raea #125)"
+reason = "bump buffer sizes set by the embedder (vello#1861's BumpAllocationSizes), not 165 MiB of defaults, grown with the target past 1080p (bump_sizes_for: ptcl holds every tile's initial allocation, which alone filled 99% of a fixed 2M at 4K), and back at the defaults while set_bump_full is on (a frame that came out all black drawn again); glyph tops for the CoreGraphics y-map (RAEA_PAGE_CG_YMAP); a resolve with no images keeps the image atlas (resolve.rs: a solid-only scene reported 0x0, the renderer swapped in a 1x1 atlas and every cached image then drew blank); a full image atlas lets go of what the resolve hasn't used, the longest unused first, and is then packed again with the resolve's images alone, before an image is left out, and the images left out are counted (take_images_left_out: raea-page's layers are new images in every frame, the atlas kept the last two frames' and a page of ten frame-sized layers drew without its nearest); the atlas grows to the device's largest texture (set_max_atlas_size: 16384 on Apple silicon), not 8192 (raea #125); a blend spill with room for every tile to spill as deep as the scene's layers nest (resolve.rs layer_depth, config.rs blend_spill_for, up to set_max_buffer_size): the fixed 4096 spills couldn't hold one full-frame layer past the fourth on a 1080x1920 page (raea #247)"
exit = "vello#1861 in a release; the y-map hook stays ours"
# checked 2026-10-26 for firewheel and its graph, macros and nodes: crates.io 0.14.0 (latest) and Firewheel main 34b35cad stop at glam-32 and bevy_reflect 0.19; bevy_seedling 0.8.0 and its main ab4a88b4 need firewheel 0.12 and Bevy 0.19