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.

RR0: the re-render overhaul planned as docs/rerender.feature (RR0-RR15), with its research: why agents stitch clips with ffmpeg (docs/rerender.md) and the GPU layer on Mac, Windows and Linux (docs/gpu.md)

shinyobjectz3a705253dea6
diff --git a/docs/gpu.md b/docs/gpu.md
new file mode 100644
index 00000000..56200a13
--- /dev/null
+++ b/docs/gpu.md
@@ -0,0 +1,151 @@
+# The GPU layer on Mac, Windows and Linux: what raea should own (research, 2026-11-10)
+
+Reader: whoever decides how much of the GPU layer raea owns. The question (Shane, 11-10): Vork and Rune each built
+their own Metal layer; should raea write its own Metal shaders or GPU kernels, and render as fast as possible? His
+follow-up the same day: plan for Mac and Windows users (and Linux), not the iPhone first. The companion note
+`docs/rerender.md` covers why agents re-render less than they should. Its finding comes first: the biggest render
+costs today are features (looks held for a whole render, no partial re-render), not the GPU layer.
+
+**Verdict: keep wgpu as the base on every platform (Metal on Mac, DX12 or Vulkan on Windows, Vulkan on Linux), and own
+no backend. Own kernels and platform accelerators behind one interface, each with a portable fallback, on the one
+shared device.** wgpu 30 already accepts each platform's own shader code (MSL on Metal, HLSL or DXIL on DX12, SPIR-V
+on Vulkan, as passthrough) and hands out the native device for interop (`as_hal`, as `raytrace/metalfx.rs` does).
+Rune's own research priced owning Vulkan and DX12 at 5-7x the size of owning Metal, and kept wgpu there. An owned Metal
+backend stays an option for the Mac only, on a measured trigger.
+
+## The platforms, seam by seam
+
+| Seam | Mac | Windows | Linux | Portable fallback |
+|---|---|---|---|---|
+| Graphics API (wgpu) | Metal | DX12 (Vulkan possible) | Vulkan | n/a |
+| Hardware video encode | VideoToolbox (have) | Media Foundation: NVIDIA, AMD and Intel encoders through one API (to build) | VAAPI / NVENC (to build) | openh264, rav1e (have; CPU) |
+| Upscaling for previews | MetalFX temporal scaler | DLSS on NVIDIA (Bevy's `dlss` feature; NVIDIA's SDK terms to check, `docs/render-thirdparty.md`) | DLSS on NVIDIA | a lower render scale, plain resample |
+| Denoising ray-traced light | MetalFX denoised scaler (have, RT4) | DLSS Ray Reconstruction on NVIDIA | same | Open Image Denoise (Apache-2.0; CPU, CUDA, HIP, SYCL, Metal), for offline film frames |
+| Owned kernels | MSL when Apple-only hardware pays (f16 simdgroup matrices, Metal 4 tensors) | HLSL/DXIL or WGSL | SPIR-V or WGSL | WGSL through K: runs on all three |
+| Pipeline cache across launches | none in wgpu: precompile `.metallib`s | driver cache | wgpu `PIPELINE_CACHE` (Vulkan only) | n/a |
+
+## What raea already does natively
+
+- `gpu/device`: one shared wgpu device for Bevy, Vello and K kernels. On Apple it uses `objc2-metal` for the canary
+ command buffer's status (`check.rs`) and its own `CAMetalLayer` (`present.rs`).
+- `engine/render/raytrace/src/metalfx.rs`: MetalFX's denoiser on Solari's light, in a command buffer of its own
+ recorded through wgpu's Metal backend. This is the pattern for every seam above.
+- Zero-copy video on Apple: decoder IOSurfaces wrapped by `CVMetalTextureCache` as wgpu textures
+ (`engine/render/docs/g8.feature`).
+- `systems/k`: K kernels compiled to WGSL, bit-exact against their CPU interpreter, so they already run on every
+ platform.
+- The native target (`engine/rune`) draws through Rune's own Metal backend on macOS (Rune's default features).
+
+## The two precedents
+
+| | Rune (anomalyco, MIT; in raea's Cargo.lock) | Vork (voyager-so, source-available research preview) |
+|---|---|---|
+| What it is | Native UI framework | Headless 3D and VFX engine for agents |
+| What it owns | A Metal backend under `wgpu::custom` on macOS; wgpu on Windows, Linux, web and (by default) iOS | Its renderer and its shaders, not the GPU layer. It runs on a vendored wgpu 29 with about 20 patches (`vendor/PATCHES.md`). Its kernels are Slang compiled to SPIR-V (Vulkan, Windows included) and MSL (Metal), loaded through wgpu's passthrough shaders; agents' Slang programs go to WGSL. `ash` and `objc2-metal` handle native interop (OIDN shares Vulkan memory) |
+| Size | 4,872 lines in `crates/rune/src/gpu/metal` and `backend.rs`, tests included | 238 `.slang` files; about 20 wgpu patches |
+| Why | CPU per frame. 120 Hz HUD on an M2 Max: 894 vs 1,395 kinstr/frame with no buffer writes, 897 vs 1,668 with one; 1 command buffer vs 6-7 | Offline film quality: raster visibility plus hardware ray-traced light, 1.1-2.3x faster than EEVEE (its own timings, not equal quality), with OIDN |
+| Left out | Depth and stencil, MSAA, indirect draws, render bundles, binding arrays: all panic and name the wgpu fallback | Volumes; iOS; GPUs without ray queries |
+
+Rune's win is ~0.14-0.5 ms of CPU a frame on light UI frames. Vork's win is offline ray-traced quality on desktop and
+datacenter GPUs. A raea film frame costs about 1.6 s per render process (`docs/rerender.md`), so neither win is where
+raea's time goes. Rune also tested the claim that its Metal backend used 330 MB against wgpu's 1.5 GB, and it didn't
+hold. In paired runs the two were within a few MB; the gap came from an unpaced headless loop.
+
+## Vork's wgpu patches are raea's to-do list
+
+Vork hit the same wgpu gaps raea has, and patched them in its vendored copy rather than leaving wgpu. Its licence is a
+source-available preview licence, so raea writes its own fixes (upstream first, `vendor/` if needed) instead of
+copying Vork's:
+
+- **Metal command-buffer errors go unchecked.** raea hit this as GPU faults that never reported. Vork checks every
+ buffer and reports the device loss from `poll` instead of panicking.
+- **Fast math in MSL.** Vork compiles naga's and passthrough MSL with safe math, so frames don't depend on how a
+ variant was compiled. This matters for raea's Q5 (Mac = iPhone, byte for byte).
+- **No Metal pipeline cache.** Vork persists Metal pipelines as an `MTLBinaryArchive` through wgpu's `PipelineCache`.
+ That's G3.
+- **Buffer binding arrays on Metal** (Tier-2 argument buffers). This is the bindless feature that once blocked Solari
+ on Metal.
+- **Passthrough MSL invariance**, so a depth prepass and the forward pass agree exactly.
+
+## Alternatives to wgpu, and why none fits raea
+
+Bevy's renderer is built on wgpu, so any of these means leaving Bevy's renderer, against "completely Bevy":
+
+- **Each platform's own API**: `ash` (Vulkan), `objc2-metal` (Metal), `windows` (D3D12). This is full control and a
+ backend per platform to own. Zed and Rune do it on the Mac only.
+- **Blade** (Vulkan, Metal, GLES; thin). Zed used it on Linux and returned to wgpu in January 2026.
+- **Vulkan everywhere, translated to Metal by MoltenVK.** This loses Metal-only features (MetalFX, memoryless tile
+ memory, Metal 4).
+- **C/C++ hardware layers** (SDL3 GPU, slang-rhi, The Forge, bgfx, Diligent, Dawn). Each needs FFI and gives up
+ Rust-side safety. Dawn is another WebGPU implementation, so it has the same model as wgpu.
+
+The route both Vork and Rune took is to keep wgpu and go native underneath it where it pays. That's this note's plan.
+
+## What wgpu 30 already reaches (checked in wgpu-hal / wgpu-types 30.0.1)
+
+| Feature | Where | Used by Bevy 0.20.1 / raea |
+|---|---|---|
+| Passthrough shaders (`PASSTHROUGH_SHADERS`) | MSL or `.metallib` on Metal; HLSL or DXIL on DX12; SPIR-V on Vulkan | No |
+| `TRANSIENT_ATTACHMENT` | Memoryless tile memory on Apple GPUs: depth and MSAA with no backing store | No Bevy crate sets it |
+| `PIPELINE_CACHE` | Vulkan only | n/a |
+| `EXPERIMENTAL_COOPERATIVE_MATRIX` | Metal: 8x8 f32 only; Vulkan where the driver offers 8x8 f32 | No |
+| `SHADER_F16`, `SUBGROUP`, `EXPERIMENTAL_MESH_SHADER`, ray queries | Varies by backend | Solari uses ray queries |
+| Metal 4 (new command model, ML in shaders) | wgpu-hal detects the family but drives the classic API | Only through our own Metal calls |
+| MSL compile options | Left at Metal's default (fast math) | Owned kernels can choose |
+
+## Plan, with gates
+
+**G0. Profile a heavy film frame on the Mac and on the Windows PC (NVIDIA).** This is `docs/rerender.md` S0: a few
+hundred frames with `RAEA_FRAME_LOG` and `RAEA_TIMES`, split into start-up, React/JS, Bevy CPU, wgpu, GPU per pass,
+readback and encode. Everything below is ordered by that table.
+
+**G1. A preview tier.** Render at a lower scale and upscale with the platform's upscaler (MetalFX on Mac, DLSS on
+NVIDIA, a plain resample elsewhere), for agents' look-checks and drafts. Full quality stays the default for delivery.
+- Done when: a draft of a heavy shot renders at least 3x faster on both machines, and the agent's checks still flag
+ the same problems on it.
+
+**G2. Owned kernels, portable first.** Image and look kernels go in K, which compiles to WGSL and runs everywhere
+with its CPU interpreter as the reference. A kernel that needs hardware-specific operations (the neural-shading net:
+f16 matrix tiles on Apple, cooperative matrices or tensor cores elsewhere) is written once in Slang. Slang compiles to
+MSL, HLSL and SPIR-V, each loaded as wgpu passthrough on its backend, with a slow WGSL or CPU reference beside it. Every
+kernel runs on `gpu/device`'s device and queue.
+- Done when, per kernel: it beats its reference by at least 1.5x on both the Mac and the Windows PC, or it's deleted.
+
+**G3. No cold pipeline compiles.** On Metal, capture the MSL naga writes for each pipeline a project uses (Rune's
+capture approach), compile `.metallib`s at bundle time, and look them up at pipeline creation. That needs a small
+wgpu-hal patch carried in `vendor/` with its reason written down. On Vulkan, turn on wgpu's `PIPELINE_CACHE`. On DX12,
+measure first: the driver cache may be enough.
+- Done when: a cold first render or first play of an exported game is at least 5x faster to its first frame on each
+ platform.
+
+**G4. Denoising for offline film frames.** Open Image Denoise on every platform as the portable denoiser for
+ray-traced film light. MetalFX (have) and DLSS Ray Reconstruction stay as the fast paths where they exist.
+
+**G5. An owned Metal backend: Mac only, only on a trigger.** Start it only if G0 shows wgpu-core + wgpu-hal + driver
+dispatch at 25% or more of a render's CPU on the Mac after G1-G3. Start from Rune's MIT backend, and keep wgpu as the
+fallback and oracle in the same binary. Bevy needs depth, MSAA, indirect draws, binding arrays, timestamps and
+acceleration structures, which Rune's backend lacks. No owned DX12 or Vulkan backend: Rune measured those at 5-7x
+Metal's size, and Zed returned to wgpu on Linux.
+
+## Later: phones and tablets
+
+The same seams carry over to iOS: the iPhone 13 Pro Max (A15) has run raea (golden scenes at 43-88 ms a frame on
+10-16, titles at 525 ms, peak 373 MB against a 200 MB target). The phone-specific levers are memoryless depth and MSAA
+(`TRANSIENT_ATTACHMENT`, which Bevy doesn't set yet), MetalFX upscaling, a lighter post stack, and precompiled
+pipelines (G3). Hardware ray tracing starts at A17 Pro / M3. A15 profiling waits until Mac and Windows are done.
+
+## Gotchas
+
+- One device: owned kernels and accelerators run on `gpu/device`'s device and queue, never a second device, or
+ textures can't be shared without copies.
+- wgpu's Metal backend reports no command-buffer error, and a GPU fault on this Mac has needed a reboot (10-26). Every
+ owned command buffer checks its status, as `check.rs`'s canary does. Test failures by injecting them.
+- Determinism: wgpu compiles MSL with Metal's default fast math, so cross-device byte equality (Q5) can only be chased
+ in kernels whose compile options we set.
+- The Mac's GPU is shared by every session: keep kernel benches small and run them one at a time.
+- `as_hal` is unstable API: each wgpu bump re-checks the seams.
+
+Sources: github.com/voyager-so/vork (README, `Cargo.toml`, `crates/vork-render`, `crates/vork-slang`,
+`vendor/PATCHES.md`, `vendor/wgpu-hal/PROVENANCE.md`, read 2026-11-10); github.com/anomalyco/rune `research/34-own-gpu-plan.md` and
+`crates/rune/src/gpu/metal/mod.rs` at 7ead7d6; wgpu-hal 30.0.1 `src/metal/{adapter,device}.rs`; wgpu-types 30.0.1
+`src/features.rs`; github.com/RenderKit/oidn (Apache-2.0; Metal since 2.2).
diff --git a/docs/rerender.feature b/docs/rerender.feature
new file mode 100644
index 00000000..f8188271
--- /dev/null
+++ b/docs/rerender.feature
@@ -0,0 +1,211 @@
+@spec
+Feature: Re-render, don't stitch: one render changes anything per frame, redraws only what changed, and encodes on every platform's hardware
+ Shane, 11-10: "when using the raea engine the agent always ends up using ffmpeg and stitching clips together again. so
+ how do we actually make it so we optimize so fast it can rerender clips easily and not worry about using ffmpeg. or
+ maybe investigate why that would be the case beyond my assumptions. also i dont specifically want iphone we have lots
+ of mac and windows users so we have to plan for something that can use all of those". Then: keep wgpu, and make this
+ the complete overhaul for v0.1.1.
+
+ The research is docs/rerender.md (why agents stitch) and docs/gpu.md (the GPU layer on Mac, Windows and Linux). In
+ short: a raea render holds its first frame's look and camera for its whole length, and can't redraw part of a video,
+ so agents split films into chunk renders and join them with ffmpeg (the launch film: 80 chunks, 31-33 min a pass).
+ Speed matters second. This feature fixes the causes first, then the speed, on macOS, Windows and Linux alike.
+
+ Bars for every scenario: the same frames as before wherever nothing was meant to change (SSIM 1.000000 on decoded
+ frames, or the exact bound a scenario names); every number measured on this Mac (M5 Pro) and on the Windows PC
+ (cuda-box, RTX 4070), and on Linux where a scenario says so; a gate that can't be met goes to Shane with its
+ measurements, never loosened in place. GPU-heavy runs check `antsy board` first and run one at a time.
+
+ Rule: Measure first
+
+ Scenario: RR0. A heavy multi-shot film to measure, and today's numbers on Mac and Windows
+ Given the plan
+ | crate | file | lines | job |
+ | - | bench/rerender/film.tsx | 220 | six shots of content/rome's sets, about 30 s at 1920x1080, a different look on each (grade, fog, bloom, depth of field, tonemapping) and two cameras; also each shot as its own composition, as agents render today |
+ | - | bench/rerender/bench.sh | 160 | renders it with RAEA_FRAME_LOG and RAEA_TIMES and writes run.json: wall time, and per frame the split into start-up, React/JS, Bevy CPU, wgpu submit, GPU by pass, readback and encode |
+ | - | bench/rerender/change.sh | 80 | the "one note" case: changes shot 4's grade and lights, then times what it takes to get the whole film again |
+ Then bench.sh runs on the Mac and on the Windows PC, and this scenario records both splits
+ And it records today's two ways to get the film: six chunk renders joined with ffmpeg (what agents do), and
+ what one render would cost if it could hold six looks (the chunks' frame costs without their start-ups)
+ And it records change.sh today: the changed chunk re-rendered and re-joined by hand
+ And the two biggest costs in each split are named; RR11, RR12 and RR13's gates are read against them
+
+ Rule: One render can change anything, every frame
+
+ Scenario: RR1. Every look changes per frame
+ Given the plan
+ | crate | file | lines | job |
+ | raea-runtime-look | runtime/look/src/frame.rs | 240 | the look as per-frame columns: atmosphere, bloom, fog, depth of field, every Grade field, SSAO, anti-aliasing, shadows, volumetric fog and tonemapping, as aberration already is |
+ | raea-runtime-look | runtime/look/src/apply.rs | 260 | each frame's look applied to the camera's Bevy components; moved out of raea-runtime-scene3d (camera.rs, sync.rs), which is at its 2,000-line limit |
+ | raea-runtime-look | runtime/look/src/variants.rs | 140 | the pipeline variants a render's looks will need (tonemapper, AA mode, shadow filter, SSAO on or off), prepared before its first frame so a switch mid-render never stalls |
+ Then runtime/look/src/camera.rs stops reading these "as the first frame that has each asks"
+ And a value (a grade's saturation, bloom's strength, fog's colour, the focus distance) is keyframed like any prop
+ And RR0's film rendered as one composition equals its six chunk renders frame for frame (SSIM 1.000000)
+ And a grade ramp over 60 frames equals 60 stills each rendered alone with that frame's grade
+ And a play of the film (raea play) shows the same look changes as its render (render = play)
+
+ Scenario: RR2. The camera changes per frame
+ Given the plan
+ | crate | file | lines | job |
+ | raea-runtime-look | runtime/look/src/active.rs | 120 | which camera draws the output, per frame: `<Camera3d active>` keyed, or a cut list |
+ Then a film can cut between several cameras inside one render
+ And RR0's two-camera shot rendered once equals the same shot rendered as one render per camera, frame for frame
+
+ Rule: Redraw only what changed
+
+ Scenario: RR3. A video is made of shot segments, assembled without re-encoding
+ Given the plan
+ | crate | file | lines | job |
+ | raea-runtime-segments | runtime/segments/src/lib.rs | 120 | the crate: a render as segments (raea-runtime-export is at its limit) |
+ | raea-runtime-segments | runtime/segments/src/split.rs | 160 | where a video splits: at every cut the timeline knows (a Sequence's start, a camera change), never inside a shot, merging shots under a minimum length |
+ | raea-runtime-segments | runtime/segments/src/encode.rs | 180 | each segment encoded as its own run starting on a keyframe, on every backend (VideoToolbox, openh264, rav1e, RR8's) |
+ | raea-runtime-segments | runtime/segments/src/join.rs | 200 | segments muxed into one MP4 by stream copy (io/codec's remux, muxide), the sound laid under once from the render's own mix |
+ | raea-runtime-segments | runtime/segments/src/warm.rs | 120 | a segment's warm-up: the frames before it that temporal effects need (TAA, motion blur, MetalFX), drawn and not kept |
+ Then `raea render` makes every video this way
+ And a segmented render's decoded frames match a single-run render at the same --quality: SSIM >= 0.999 on every
+ frame, and VMAF >= 99 over the film
+ And joining a two-minute 1080p film's segments takes under 1 s
+
+ @needs:RR3
+ Scenario: RR4. Segments are cached by what made them
+ Given the plan
+ | crate | file | lines | job |
+ | raea-runtime-segments | runtime/segments/src/key.rs | 220 | a segment's key: its frames' baked rows (the state at its first frame included, so physics and particles count), the assets they read, the render's settings, raea's version |
+ | raea-runtime-segments | runtime/segments/src/store.rs | 160 | segments on disk by key, beside the whole-video export cache (runtime/bundle/src/cache.rs), with a size cap and the oldest dropped first |
+ Then a render reuses every segment whose key is unchanged and prints "N of M shots redrawn"
+ And after change.sh's note, getting the whole film again costs shot 4's frames plus under 1 s
+ And the film it gives equals a fresh full render with the cache off (SSIM 1.000000 on reused segments, RR3's
+ bound on redrawn ones)
+ And a change to a shared asset (a texture both shots use) redraws exactly the shots that use it
+
+ @needs:RR3
+ Scenario: RR5. Ranges and parallel workers inside one render
+ Given the plan
+ | crate | file | lines | job |
+ | raea-runtime-segments | runtime/segments/src/workers.rs| 240 | segments drawn by several workers at once, sized from the GPU's memory and the machine's free memory, never past antsy's floor; one worker on a GPU too small for two |
+ Then `raea render EDIT.tsx --frames A-B -o OUT.mp4` renders that range as a video
+ And a long render splits itself across workers and joins them with RR3; `--workers N` overrides the count
+ And the default worker count is the one measured fastest for RR0's film on each machine, recorded here
+ And no agent needs `xargs -P` or a chunk composition to render a film in parallel
+
+ Rule: Assemble and look at renders without ffmpeg
+
+ @needs:RR3
+ Scenario: RR6. The media verbs agents reach ffmpeg for
+ Given the plan
+ | crate | file | lines | job |
+ | raea-app-assemble | apps/assemble/src/lib.rs | 80 | the crate (raea-app-media is at 1,776 lines), reached through `raea media` |
+ | raea-app-assemble | apps/assemble/src/concat.rs | 180 | `raea media concat` by stream copy when the inputs match (codec, size, rate), re-encoding only when they don't and saying so |
+ | raea-app-assemble | apps/assemble/src/compare.rs | 200 | `raea media compare A B [C ...] -o OUT` side by side or in a grid, labelled, as a still, a sheet or a video: the commonest ffmpeg use in agents' sessions (2,627 commands) |
+ | raea-app-assemble | apps/assemble/src/frames.rs | 160 | `raea media encode DIR -o OUT.mp4|OUT.mov --fps N`: a PNG folder to H.264, HEVC or AV1 on every platform, ProRes 4444 with alpha on the Mac |
+ Then concat of RR3's segments, or of any matching MP4s, takes under 1 s for two minutes of 1080p
+ And every flag is in `raea help`, and docs/manual's CLI reference is regenerated
+
+ @needs:RR1,RR2,RR4,RR5,RR6
+ Scenario: RR7. The skill and the manual teach re-rendering
+ Then the raea skill's "one camera, one set of effects" rule (3d.md rule 6, 3d/limits.md, 3d/post.md) says looks
+ and cameras change per frame
+ And it says how to change one shot of a film: edit it and render again, with the redraw count to check
+ And its ffmpeg share line (SKILL.md) is a raea command, and it says raea's own renders never need ffmpeg
+ And the change goes through raea-skills' own process (its SOP, `just ci`), and docs/manual's rendering concept
+ page says the same
+
+ Rule: Every platform encodes on its own hardware
+
+ Scenario: RR8a. Windows: Media Foundation's hardware encoders
+ Given the plan
+ | crate | file | lines | job |
+ | raea-io-windows | io/windows/src/lib.rs | 120 | the backend behind raea-io-codec's Backend trait, picked first on Windows |
+ | raea-io-windows | io/windows/src/encode.rs | 320 | H.264 and HEVC through Media Foundation's hardware encoder (NVIDIA, AMD and Intel behind one API), rate control as `--quality` asks, keyframes where RR3 asks |
+ | raea-io-windows | io/windows/src/texture.rs | 220 | frames handed over as GPU textures through the DXGI device manager (wgpu's DX12 device by as_hal), no CPU copy where the driver allows; a copy where it doesn't, said once |
+ | raea-io-windows | io/windows/src/decode.rs | 200 | hardware decode for footage, through the same API |
+ Then on the Windows PC, RR0's film is not encoder-bound: encode is under 20% of its frame time
+ And its export scores VMAF >= 95 against the Mac's at `--quality high`, and its colours meet docs/lightspeed
+ Q3's floors
+ And a machine without a hardware encoder falls back to openh264 and says so once
+
+ Scenario: RR8b. Linux: VAAPI and NVENC
+ Given the plan
+ | crate | file | lines | job |
+ | raea-io-linux | io/linux/src/lib.rs | 100 | the backend, picked first on Linux when a device answers |
+ | raea-io-linux | io/linux/src/vaapi.rs | 300 | H.264 and HEVC through VAAPI (Intel and AMD) |
+ | raea-io-linux | io/linux/src/nvenc.rs | 300 | H.264 and HEVC through NVENC (NVIDIA, as on Modal), its headers' licence checked first (docs: permissive-licences) |
+ Then RR0's film renders on a Linux NVIDIA machine (Modal or the Sprite's GPU path) not encoder-bound, with the
+ same VMAF bound as RR8a
+ And without a device it falls back to openh264 and says so once
+
+ Rule: The GPU layer: keep wgpu, go native underneath where it pays (docs/gpu.md)
+
+ Scenario: RR9. The wgpu fixes raea needs, ours, sent upstream
+ Given the plan
+ | crate | file | lines | job |
+ | - | vendor/wgpu-hal/PROVENANCE.md | 60 | each local change, the test that holds it, and when it goes (upstream merged) |
+ | - | vendor/wgpu/PROVENANCE.md | 30 | likewise |
+ Then the Metal backend checks every command buffer's status, and a failed one reaches raea as a device loss
+ from `poll` with its label, instead of a silent fault; tested by injection, never by provoking the GPU
+ And MSL compiles with safe math where raea asks (naga's output and passthrough alike), so a frame doesn't depend
+ on how its variant was compiled
+ And each change is written by us (Vork's are under its preview licence and aren't copied), opened as a PR on
+ gfx-rs/wgpu with a hand-written description, and carried in vendor/ until it merges
+ And one-version, dupes and the size gates pass with the vendored crates
+
+ @needs:RR9
+ Scenario: RR10. No cold pipeline compiles, on any platform
+ Given the plan
+ | crate | file | lines | job |
+ | raea-gpu-device | gpu/device/src/pipelines.rs | 220 | one pipeline cache across launches: Metal as an MTLBinaryArchive through wgpu's PipelineCache (RR9's vendored change), Vulkan through wgpu's own, DX12 measured first (the driver's may be enough); keyed by adapter, driver and raea's version |
+ Then Bevy's pipelines, Vello's and K's are made with it (a vendored bevy_render change if Bevy has no hook)
+ And a cold first frame of RR0's film, and of an exported game's first play, is at least 5x faster on the Mac
+ and on the Windows PC, measured with the OS's own shader cache cleared
+ And RR5's workers share it, so N workers don't compile N times
+
+ @needs:RR0
+ Scenario: RR11. A draft tier, rendered small and upscaled
+ Given the plan
+ | crate | file | lines | job |
+ | raea-sys-upscale | systems/upscale/src/lib.rs | 100 | `--quality draft` (and the app's live preview, when asked): render at a lower scale, upscale with the platform's best |
+ | raea-sys-upscale | systems/upscale/src/metalfx.rs| 220 | MetalFX's temporal scaler on the Mac, on the shared device as raytrace/metalfx.rs runs its denoiser |
+ | raea-sys-upscale | systems/upscale/src/dlss.rs | 120 | DLSS on NVIDIA through Bevy's `dlss` feature, only after NVIDIA's SDK terms are checked (docs/render-thirdparty.md) |
+ | raea-sys-upscale | systems/upscale/src/resample.rs| 140 | the portable fallback: a WGSL upscale every GPU runs |
+ Then a draft of RR0's film renders at least 3x faster than `--quality high` on the Mac and on the Windows PC
+ And raea check and the render's findings flag the same problems on the draft as on the full render
+ And delivery quality stays the default; a draft says it's a draft in its manifest
+
+ @needs:RR0,RR9
+ Scenario: RR12. Our own kernels, written once for every platform
+ Given the plan
+ | crate | file | lines | job |
+ | raea-gpu-kernels | gpu/kernels/src/lib.rs | 160 | a kernel loaded as wgpu passthrough on the shared device: MSL on Metal, DXIL on DX12, SPIR-V on Vulkan, from the files below |
+ | raea-gpu-kernels | gpu/kernels/src/check.rs | 140 | each kernel against its reference (WGSL, or K's interpreter): exact where K demands it, a stated bound elsewhere |
+ | - | gpu/kernels/slang/README.md | 40 | the sources are Slang; the compiled files are committed and a test fails when a source changed without them |
+ | - | tools/kernels.sh | 80 | slangc to MSL, SPIR-V and DXIL for each kernel (Slang's licence checked first) |
+ Then the first kernel is the most expensive raea-owned pass in RR0's split (traced AO, the paint look, the composite or what the split names)
+ And it beats its WGSL reference by at least 1.5x on the Mac and on the Windows PC, or it's deleted and this
+ scenario says why
+ And K kernels stay WGSL: they already run everywhere
+
+ Rule: Proof, on the machines our users have
+
+ @needs:RR1,RR2,RR4,RR5,RR8a,RR10,RR11,RR12
+ Scenario: RR13. The film, end to end, against RR0
+ Then on the Mac and on the Windows PC, RR0's film renders as one composition with `raea render` alone
+ And getting the film again after change.sh's note costs shot 4's frames plus under 1 s
+ And a full render's wall time is at most half of RR0's chunked baseline on each machine
+ And each of the two biggest costs RR0 named is at least halved, or this scenario carries the measurement that
+ shows why it can't be, for Shane
+ And docs/lightspeed.feature's scoreboard gains the rows: one-shot re-render, full film, draft, cold first frame
+
+ @needs:RR7,RR13
+ Scenario: RR14. Agents stop stitching
+ Then the feed's agent (Kimi) and a Claude Code session with the raea skill each get the same brief three times:
+ a six-shot film with three looks and two cameras, then one note that changes one shot
+ And across all six runs no tool call runs ffmpeg or ffprobe on raea's own renders, no chunk composition is made,
+ and each note's render says "1 of 6 shots redrawn"
+ And spend is logged with antsy against the feed eval budget
+
+ @needs:RR8b,RR14
+ Scenario: RR15. It ships in v0.1.1
+ Then every RR scenario is @done on origin/main, L1 green
+ And a v0.1.1 rc's release run passes on macOS, Windows and Linux, RL3 included on the Windows PC
+ And the v0.1.1 launch thread (releases/0.1.1) has a post showing a one-shot change re-rendered in seconds
+ And the readiness list goes to Shane, who alone gives the release its go
diff --git a/docs/rerender.md b/docs/rerender.md
new file mode 100644
index 00000000..91f37bf4
--- /dev/null
+++ b/docs/rerender.md
@@ -0,0 +1,121 @@
+# Why agents stitch clips with ffmpeg, and what makes re-rendering the easy path (research, 2026-11-10)
+
+Reader: whoever plans raea's render and export work. Shane's note (11-10): agents using raea keep rendering clips and
+joining them with ffmpeg. Should raea get fast enough that re-rendering is easier, or is something else going on?
+
+**Finding: speed is only part of it. The main cause is that one raea render can't change its look or camera, and it
+can't re-render part of a video.** A film with more than one look has to be several renders, and the only partial
+re-render is one the agent builds by hand: a composition per chunk, a folder of finished chunks, and ffmpeg to join
+them. An infinitely fast renderer wouldn't remove the first cause. Without a partial cache, a fast renderer still
+redraws every frame for a one-shot change.
+
+## The evidence
+
+**What agents use ffmpeg for.** 5,833 distinct ffmpeg command lines in Claude Code sessions on raea (~/raea, ~/Studio,
+the feed test projects). The raea app's own agents' transcripts aren't included. One command can count under several
+purposes:
+
+| Purpose | Commands | Native raea today |
+|---|---:|---|
+| Contact sheets and side-by-sides (tile, hstack, vstack, xstack) | 2,627 | `raea media sheet`; no side-by-side compare |
+| Pulling frames to look at | 1,778 | `raea media still`, `raea render --at` |
+| Seeking and trimming (`-ss`) | 796 | `raea media trim` |
+| ffprobe | 546 | `raea media probe` |
+| Encoding a PNG sequence into a video | 412 | none: `--alpha`, `--aov` and neural passes write PNG folders |
+| Re-encoding (x264, x265, ProRes) | 357 | `--quality` on the render |
+| Loudness | 319 | `raea media loudness`, `<Mix>` mastering |
+| **Joining clips** (concat, xfade) | 122 | `raea media concat`, which re-encodes; ffmpeg's `-c copy` doesn't |
+| Colour changes over time (eq, hue, curves) | 114 | none inside one render (below) |
+| Laying sound under picture | 109 | `raea render --audio` and `-o OUT.wav` (landed 11-10) |
+| Text and overlays | 79 | the composition itself |
+
+Most of the ffmpeg use is agents **looking at** their output, not assembling it. The stitching is a smaller count, but
+every multi-shot film project has it.
+
+**The clearest case: the launch film** (`~/Studio/raea/projects/v0-1-launch/promo/stage`, 120.6 s, 3,618 frames at
+1920x1080). Its source explains itself:
+
+- `camera.ts`: "an engine render holds its first frame's look (grade, tones, haze) for its whole length, so the chunks
+ split at every cut, every change of look and every light cue." That gave 80 chunk compositions (`fm-0` to `fm-79`).
+- `film.sh`: renders the chunks three at a time (`xargs -P 3`), keeps any chunk already on disk ("a chunk already
+ rendered is kept unless FRESH=1"), joins them with `ffmpeg -f concat -c copy`, then uses ffmpeg again for the sound,
+ a limiter, and the colour drain on "black and white", "since the engine holds Grade for a render, so the drain is
+ ffmpeg's hue". The final encode is x264 at CRF 16.
+- Cost (antsy history): a full pass took 31-33 min with three renders at once, about 0.55 s of wall time a frame.
+ Redoing three chunks took 2-5 min. 27 runs, 14% failed, peak 14.2 GB.
+
+The anything film and the opening cuts did the same: each shot rendered to its own MP4, joined with ffmpeg, or placed
+in a cut composition that plays the rendered MP4s.
+
+## The causes, checked in the code
+
+1. **A render holds one look and one camera.** `runtime/look/src/camera.rs` reads atmosphere, bloom, fog, depth of
+ field, grade, SSAO, anti-aliasing, shadows, volumetric fog and tonemapping "as the first frame that has each asks",
+ once for the whole render. Only `<Grade aberration>` was moved to a per-frame column, and only after it bit someone
+ ("it was the first frame's, for every frame"). The skill teaches agents the same rule: "One camera (the first), one
+ set of effects (the first frame's)" (skills `3d.md` rule 6, `3d/limits.md`, `3d/post.md`). Any film whose look
+ changes therefore has to be split into renders.
+2. **No partial re-render.** The export cache is keyed on the whole video (`runtime/bundle/src/cache.rs`), so changing
+ one shot redraws every frame. `raea render` has no frame range for a video (`--at` writes stills only). Agents got a
+ range by making each chunk a `<Composition>` and a cache by keeping the chunk files.
+3. **Heavy 3D frames are slow, so partial redo matters.** Motion graphics are fast (a 20 s edit in 2.5 s, capped by
+ the encoder), but a film's 3D frame costs about 1.6 s per render process. That's an estimate from the launch film's
+ 33 min for 3,618 frames on three processes, and it includes 80 process start-ups. Where the time goes inside a
+ frame hasn't been measured (step S0 below).
+4. **No parallelism across a render.** One render is one process. Agents parallelize with `xargs -P`.
+5. **raea's join re-encodes.** `raea media concat` decodes and re-encodes (`apps/media/src/encode.rs`). ffmpeg's
+ `-c copy` joins in a moment with no quality loss, so agents pick ffmpeg.
+6. **Off the Mac, raea encodes in software.** `io/media` has a hardware encoder only for Apple (VideoToolbox); on
+ Windows and Linux H.264 is openh264 on the CPU ("other platforms slot in behind the same trait"). Windows renders
+ are encoder-bound and lower quality, which gives agents another reason to reach for ffmpeg there.
+7. **Habit, and the skill points there.** The skill's share-copy line is an ffmpeg command (`SKILL.md:249`), and
+ models know ffmpeg's flags better than raea's verbs.
+
+## What to build, in order
+
+Each step has a test that says it's done. The order follows the causes: features before speed.
+
+**S0. Measure a heavy frame on Mac and Windows.** Render a few hundred frames of a heavy 3D scene with
+`RAEA_FRAME_LOG` and `RAEA_TIMES`, on the Mac and on the Windows PC (NVIDIA). Split the time into start-up, React/JS,
+Bevy CPU, GPU, readback and encode. This decides S6's order. Needs no new code.
+
+**S1. Looks and cameras change per frame.** Move every effect in `camera.rs` from read-once to a per-frame column, as
+aberration already is. Values like grade, bloom strength, fog colour and depth of field are per-view uniforms in Bevy,
+so they're cheap to change. Mode switches like the tonemapper, AA mode or shadow filter are pipeline variants: build
+them ahead of time so a mid-render switch doesn't stall. Let the active camera change per frame. Update the skill's
+rules to match.
+- Done when: one composition with a look change at every cut renders frame-equal (SSIM 1.0) to the same film rendered
+ as chunks, and a colour ramp is keyframes, not ffmpeg.
+
+**S2. Shot-level incremental renders.** Key each shot (a `<Sequence>`, or a range between cuts) on what its frames
+depend on: the baked rows for those frames, the assets, the render settings. Encode each shot as its own segment
+starting on a keyframe, and assemble the MP4 by remuxing segments without re-encoding (raea has a remuxer in
+`io/codec` and muxide). A changed shot redraws only its frames, and the join takes milliseconds. This depends on frames
+being pure functions of their number, which raea already holds itself to (render = play).
+- Done when: changing one shot of a 120 s film costs that shot's frames plus under a second, and the result equals a
+ full render.
+
+**S3. Ranges and parallel work inside one render.** `raea render --frames A-B` for videos. A long render splits
+itself into workers at shot boundaries, sized to the GPU and memory, and joins them with S2's remux. No more
+`xargs -P`.
+
+**S4. Native verbs for the rest, and a skill that uses them.** `raea media concat` stream-copies when the inputs
+match. Add a side-by-side compare (before/after, A/B takes), since that's the commonest ffmpeg use. Sound goes under
+picture through `--audio` and `<Mix>`. The skill's ffmpeg share line becomes a raea command. The skill change follows
+raea-skills' own process (its SOP and checks).
+- Done when: a replayed film session needs no ffmpeg command.
+
+**S5. Hardware encode on Windows and Linux.** On Windows, Media Foundation's H.264/HEVC encoders, which cover
+NVIDIA, AMD and Intel GPUs through one API. On Linux, VAAPI or NVENC. Feed them GPU textures without a CPU copy, as
+L2 (lightspeed) wants on the Mac.
+- Done when: a Windows 1080p render is no longer encoder-bound, at the Mac's export quality.
+
+**S6. Raw frame speed, after S0.** The GPU work in `docs/gpu.md`, ordered by S0's split. A proposed target to set
+after measuring: a 5 s shot of a heavy scene re-renders in under 30 s on an M-series Mac and on a mid-range NVIDIA PC,
+and a half-resolution preview with upscaling in a few seconds.
+
+## What this doesn't solve
+
+- Footage and other people's video still come in as files, and raea's media verbs handle those. This is about raea's
+ own renders.
+- Agents will still use ffmpeg out of habit for a while. S4's replay check is what shows the habit is gone.