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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
Filter layers sized by what they draw, and an atlas as large as the GPU's textures (#125)
shinyobjectzfcbfba57b914
diff --git a/bench/filter-atlas/check.sh b/bench/filter-atlas/check.shnew file mode 100755index 00000000..0cdc6165--- /dev/null+++ b/bench/filter-atlas/check.sh@@ -0,0 +1,37 @@+#!/bin/bash+# #125: a 2160x3840 page with many filtered elements draws, as Chrome draws it.+# squares.tsx: twelve blurred full-frame wrappers, each around a 200 px square (the issue's repro, two rows). Each+# filter's layer is what its element draws, not its box, so all twelve fit; each square's middle is white and the+# page between them #333.+# frames.tsx: ten full-frame filtered layers whose boxes draw, so each is a frame-sized image: the atlas grows to the+# device's largest texture (16384 on Apple silicon). The page's middle is 184 (nine layers would be 176).+# Either refused ("has no room for them") is a failure. Exits 1 on one.+# bench/filter-atlas/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-filter-atlas.XXXXXX")+trap 'rm -rf "${OUT:?}"' EXIT+status=0+for c in squares frames; do+ mkdir -p "$OUT/$c"+ if ! "$BIN" render bench/filter-atlas/$c.tsx --at 0 -o "$OUT/$c" > "$OUT/$c.log" 2>&1 || [ ! -f "$OUT/$c/frame-00000.png" ]; then+ echo "FAIL $c.tsx: $(grep -m1 -E 'REFUSED|error' "$OUT/$c.log" | cut -c1-220)"; status=1+ fi+done+grey() { # FRAME X,Y: the pixel's red channel, 0-255+ magick "$OUT/$1/frame-00000.png" -alpha off -format "%[fx:int(255*p{$2}.r+0.5)]" info:+}+near() { # GOT WANT WHAT+ (( $1 - $2 <= 3 && $2 - $1 <= 3 )) || { echo "FAIL $3: $1, wanted $2"; status=1; }+}+if [ -f "$OUT/squares/frame-00000.png" ]; then+ for i in $(seq 0 11); do+ x=$((200 + (i % 6) * 340)); y=$((1600 + i / 6 * 500))+ near "$(grey squares $x,$y)" 255 "squares.tsx: square $i's middle ($x,$y)"+ done+ near "$(grey squares 1080,3000)" 51 "squares.tsx: the page below the squares"+fi+[ -f "$OUT/frames/frame-00000.png" ] && near "$(grey frames 1080,1920)" 184 "frames.tsx: ten white layers at 10% over #333"+[ $status = 0 ] && echo "PASS a 2160x3840 page of twelve blurred wrappers and ten frame-sized filtered layers draws"+exit $statusdiff --git a/bench/filter-atlas/frames.tsx b/bench/filter-atlas/frames.tsxnew file mode 100644index 00000000..7f5bdfb5--- /dev/null+++ b/bench/filter-atlas/frames.tsx@@ -0,0 +1,16 @@+// #125: ten full-frame layers at 2160x3840 whose own boxes draw (a white background at 10%), each under a filter that+// leaves white as it is. Each is an image the size of the frame in Vello's atlas: 8192 px a side holds six, the+// device's largest texture (16384 on Apple silicon) holds 28. Over #333 the ten make 255 - 204 * 0.9^10 = 184; nine+// would be 176. bench/filter-atlas/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+const N = 10;+function C() {+ return (+ <AbsoluteFill style={{ background: "#333" }}>+ {Array.from({ length: N }, (_, i) => (+ <AbsoluteFill key={i} style={{ filter: "grayscale(1)", background: "rgba(255, 255, 255, 0.1)" }} />+ ))}+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="frames" component={C} width={2160} height={3840} fps={30} durationInFrames={1} />);diff --git a/bench/filter-atlas/squares.tsx b/bench/filter-atlas/squares.tsxnew file mode 100644index 00000000..17887b48--- /dev/null+++ b/bench/filter-atlas/squares.tsx@@ -0,0 +1,18 @@+// #125: twelve full-frame wrappers at 2160x3840, each blurred and each around a 200 px white square. A wrapper's box+// draws nothing, so its filter's layer is the square grown by the blur's reach, as Chrome sizes a filter's input. Made+// from the wrapper's box, each layer was a frame-sized image, Vello's atlas held six and the frame was refused from the+// seventh. bench/filter-atlas/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+const N = 12;+function C() {+ return (+ <AbsoluteFill style={{ background: "#333" }}>+ {Array.from({ length: N }, (_, i) => (+ <AbsoluteFill key={i} style={{ filter: "blur(4px)" }}>+ <div style={{ position: "absolute", left: 100 + (i % 6) * 340, top: 1500 + Math.floor(i / 6) * 500, width: 200, height: 200, background: "white" }} />+ </AbsoluteFill>+ ))}+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="squares" component={C} width={2160} height={3840} fps={30} durationInFrames={1} />);diff --git a/systems/page/src/draw.rs b/systems/page/src/draw.rsindex 342bdaf2..6050150f 100644--- a/systems/page/src/draw.rs+++ b/systems/page/src/draw.rs@@ -157,6 +157,8 @@ pub fn draw(mut scenes: ResMut<Scenes>, mut vello: ResMut<Vello>, device: Res<Reif std::env::var("RAEA_PAGE_CG_YMAP").as_deref() != Ok("0") {vello::low_level::vello_encoding::set_glyph_tops(raea_sys_fonts::coregraphics_tops);}+ // 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);vello::Renderer::new(device,vello::RendererOptions { antialiasing_support: vello::AaSupport::area_only(), num_init_threads: std::num::NonZeroUsize::new(1), ..default() },diff --git a/systems/page/src/skipped.rs b/systems/page/src/skipped.rsindex d346c780..cb5afbd3 100644--- a/systems/page/src/skipped.rs+++ b/systems/page/src/skipped.rs@@ -9,8 +9,8 @@//! at those sizes, or refuses one skipped at them too, so the render fails naming it.//! RAEA_PAGE_DRAWN_CHECK=0 draws without the check (for measuring what it costs; a skipped draw goes unseen again).//! And whether it drew every image: one that finds no room in Vello's image atlas is drawn at no size, again with no-//! error. A layer with a filter or a perspective transform is such an image, the size of its box, so a page of many-//! lost its nearest ones. The resolve counts them (vendor/vello_encoding `take_images_left_out`) and the frame is+//! error. A layer with a filter or a perspective transform is such an image, the size of what it draws, so a page of+//! many lost its nearest ones. The resolve counts them (vendor/vello_encoding `take_images_left_out`) and the frame is//! refused (raea_gpu_device::check::refuse), so the render fails naming it.use std::sync::atomic::{AtomicBool, Ordering};@@ -61,7 +61,8 @@ pub fn render(renderer: &mut vello::Renderer, device: &wgpu::Device, queue: &wgprenderer.render_to_texture(device, queue, scene, &target.create_view(&Default::default()), params).map_err(|e| format!("vello, {what}: {e}"))?;let left_out = vello::low_level::vello_encoding::take_images_left_out();if left_out > 0 {- let why = format!("{what} ({}x{}) was drawn without {left_out} of its images: Vello's image atlas (8192 px a side) has no room for them. Each element with a filter or a perspective transform is an image the size of its box, so fewer of them, or smaller boxes, draw it", params.width, params.height);+ let side = vello::low_level::vello_encoding::max_atlas_size();+ let why = format!("{what} ({}x{}) was drawn without {left_out} of its images: Vello's image atlas ({side} px a side, this GPU's largest texture) has no room for them. Each element with a filter or a perspective transform is an image the size of what it draws, so fewer of them, or smaller ones, draw it", params.width, params.height);bevy::log::error!("raea-page: {why}");raea_gpu_device::check::refuse(why);}diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rsindex 78f4f1e8..63454f03 100644--- a/vendor/blitz-paint/src/render.rs+++ b/vendor/blitz-paint/src/render.rs@@ -690,6 +690,26 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {})}+ /// raea: whether an element's own box draws anything: a background, border, shadow or outline, text of its own (an+ /// inline root draws all of its inline content's text in its box), or replaced or form content. One that doesn't (a wrapper such as a full-frame AbsoluteFill) adds nothing to a filter+ /// layer but its descendants (`drawn_bounds`).+ fn box_paints(&self, node: NodeId) -> bool {+ let tree = self.dom.as_ref().tree();+ let n = &tree[node];+ let Some(s) = n.primary_styles() else { return true };+ let bg = s.get_background();+ let border = n.final_layout().border;+ bg.background_color.resolve_to_absolute(&s.clone_color()).as_srgb_color().components[3] > 0.0+ || bg.background_image.0.iter().any(|i| !matches!(i, style::values::computed::image::Image::None))+ || border.top + border.right + border.bottom + border.left > 0.0+ || !s.get_effects().box_shadow.0.is_empty()+ || s.get_outline().outline_width.0.to_f64_px() > 0.0+ || n.element_data().is_some_and(|e| e.image_data().is_some() || e.sub_doc_data().is_some() || e.text_input_data().is_some())+ || ["input", "select", "button", "textarea", "img", "svg", "canvas", "video", "iframe"].contains(&&**n.local_name())+ || n.flags.is_inline_root()+ || n.children.iter().any(|c| matches!(&tree[*c].data, NodeData::Text(t) if !t.content.trim().is_empty()))+ }+/// raea: the paint phase a child of an element belongs to (Appendix E, see [`Phase`]), and whether it's an in-flow/// block drawn a phase at a time: one in a block formatting context that clips nothing, isn't replaced or a form/// control and isn't a stacking context (which effects, clip-path and mask make) or part of a 3D rendering context@@ -728,10 +748,13 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {/// The overflow itself reaches through every clip, so a layer made from it is as large as content nobody sees: a/// filtered card around a small clipping box with a page of content in it would be drawn into a texture the size/// of the page. With `own_filter`, grown by the reach of the element's own filter, which draws past its boxes (a- /// descendant's drop shadow).- fn drawn_bounds(&self, node_id: NodeId, own_filter: bool) -> Rect {+ /// descendant's drop shadow). An element whose box draws nothing (`box_paints`) gives only its descendants' boxes,+ /// and None when nothing in it draws: a full-frame wrapper around a 200 px square is a layer the square's size, as+ /// Chrome sizes a filter's input by what's drawn. At 2160x3840 every filtered wrapper was a frame-sized image, and+ /// Vello's atlas held six (#125).+ fn drawn_bounds(&self, node_id: NodeId, own_filter: bool) -> Option<Rect> {let dom = self.dom.as_ref();- let Some(node) = dom.get_node(node_id) else { return Rect::ZERO };+ let node = dom.get_node(node_id)?;let size = node.final_layout().size;let own = Rect::new(0.0, 0.0, size.width as f64 * self.scale, size.height as f64 * self.scale);let styles = node.primary_styles();@@ -747,10 +770,11 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {None => r,};let clip = own.inflate(grow.max(0.0), grow.max(0.0));- if clips_x && clips_y {- return filtered(clip);+ let paints = self.box_paints(node_id);+ if clips_x && clips_y && paints {+ return Some(filtered(clip));}- let mut all = own;+ let mut all = paints.then_some(own);let in_flow = node.layout_children.borrow();let in_flow = in_flow.iter().flatten().copied().filter(|&c| dom.get_node(c).is_some_and(|c| !c.is_out_of_flow()));let pseudos = [node.before(), node.after()].into_iter().flatten().filter(|&c| dom.get_node(c).is_some_and(|c| !c.is_out_of_flow()));@@ -761,15 +785,19 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {if let Some(t) = child.transform().as_deref() {to_own *= *t;}- all = all.union(to_own.transform_rect_bbox(self.drawn_bounds(child_id, true)));+ if let Some(b) = self.drawn_bounds(child_id, true) {+ let b = to_own.transform_rect_bbox(b);+ all = Some(all.map_or(b, |a| a.union(b)));+ }}+ let mut all = all?;if clips_x {(all.x0, all.x1) = (all.x0.max(clip.x0), all.x1.min(clip.x1));}if clips_y {(all.y0, all.y1) = (all.y0.max(clip.y0), all.y1.min(clip.y1));}- filtered(all)+ Some(filtered(all))}fn render_element(@@ -1245,6 +1273,8 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {.unwrap_or(Rect::ZERO);let mut effect_layer_clip = cx.frame.border_box_path().bounding_box();+ // the boxes drawn, None when the element and everything in it draws nothing (its border box then stays)+ let mut drawn: Option<Rect> = None;// raea: a filter's input is all the element draws, what its descendants draw outside its box// included, as Chrome filters it (a 0x0 wrapper's absolutely positioned children were cut off at its// box, a blur's reach of them left): its boxes up to the clips in their way (`drawn_bounds`), and the@@ -1252,7 +1282,7 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {// above it (#39's `from_above`: the walk doesn't meet those), where hoisted_content_bbox places it.// The stacking context's other boxes are met by the walk, under the clips they're painted underif filter.is_some() {- effect_layer_clip = effect_layer_clip.union(self.drawn_bounds(node_id, false));+ drawn = self.drawn_bounds(node_id, false);for hoisted in node.stacking_context.iter().flat_map(|sc| sc.children.iter()).filter(|c| cx.from_above(c.node_id)) {let Some(child) = self.dom.as_ref().get_node(hoisted.node_id) else { continue };let (p, at) = (hoisted.position(node.tree(), node_id), child.final_layout().location);@@ -1260,7 +1290,13 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {if let Some(t) = child.transform().as_deref() {to_own *= *t;}- effect_layer_clip = effect_layer_clip.union(to_own.transform_rect_bbox(self.drawn_bounds(hoisted.node_id, true)));+ if let Some(b) = self.drawn_bounds(hoisted.node_id, true) {+ let b = to_own.transform_rect_bbox(b);+ drawn = Some(drawn.map_or(b, |d| d.union(b)));+ }+ }+ if let Some(d) = drawn {+ effect_layer_clip = d;}}effect_layer_clip.x0 += filter_expansion_area.x0;diff --git a/vendor/vello_encoding/src/image_cache.rs b/vendor/vello_encoding/src/image_cache.rsindex a9f6591d..3eaeedeb 100644--- a/vendor/vello_encoding/src/image_cache.rs+++ b/vendor/vello_encoding/src/image_cache.rs@@ -5,9 +5,25 @@ use guillotiere::{AllocId, AtlasAllocator, size2};use peniko::ImageData;use std::collections::HashMap;use std::collections::hash_map::Entry;+use std::sync::atomic::{AtomicI32, Ordering};const DEFAULT_ATLAS_SIZE: i32 = 1024;-const MAX_ATLAS_SIZE: i32 = 8192;+/// raea: the atlas's largest side, Vello's 8192 unless the renderer's device can make a larger texture+/// (`set_max_atlas_size`). Every filtered element is an image in the atlas, and 8192 held six full-frame layers of a+/// 2160x3840 page, so a page with a seventh was refused (#125); 16384 holds 28.+static MAX_ATLAS_SIZE: AtomicI32 = AtomicI32::new(8192);++/// raea: the side image atlases made now grow to (`set_max_atlas_size`)+pub fn max_atlas_size() -> u32 {+ MAX_ATLAS_SIZE.load(Ordering::Relaxed) as u32+}++/// raea: lets image atlases made after this grow to `px` a side (the device's `max_texture_dimension_2d`): the+/// largest power of two up to it, from 1024 to 16384 (a full 16384 atlas is 1 GiB, made only when a page needs it).+pub fn set_max_atlas_size(px: u32) {+ let px = px.clamp(DEFAULT_ATLAS_SIZE as u32, 16384);+ MAX_ATLAS_SIZE.store(1 << (31 - px.leading_zeros()), Ordering::Relaxed);+}const EVICT_AFTER_GENERATIONS: u64 = 2;#[derive(Default)]@@ -61,7 +77,7 @@ impl Default for ImageCache {impl ImageCache {pub(crate) fn new() -> Self {- Self::new_with_sizes(DEFAULT_ATLAS_SIZE, MAX_ATLAS_SIZE)+ Self::new_with_sizes(DEFAULT_ATLAS_SIZE, MAX_ATLAS_SIZE.load(Ordering::Relaxed))}fn new_with_sizes(initial_size: i32, max_size: i32) -> Self {diff --git a/vendor/vello_encoding/src/lib.rs b/vendor/vello_encoding/src/lib.rsindex 0d43f4c6..17935bd6 100644--- a/vendor/vello_encoding/src/lib.rs+++ b/vendor/vello_encoding/src/lib.rs@@ -41,6 +41,7 @@ mod glyph_cache;// raea: the GlyphTops hook, glyph outlines placed in y where the platform rasterizer draws thempub use glyph_cache::{GlyphTops, set_glyph_tops};mod image_cache;+pub use image_cache::{max_atlas_size, set_max_atlas_size};mod mask;pub mod math;mod monoid;diff --git a/vendor/vendor.toml b/vendor/vendor.tomlindex 3677baac..fd51b8cb 100644--- a/vendor/vendor.toml+++ b/vendor/vendor.toml@@ -63,7 +63,7 @@ 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)"+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)"exit = "a Blitz release that draws these"[blitz-dom]@@ -112,7 +112,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)"+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)"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