mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
* RM0: each App's meshes and images, CPU and GPU bytes, after every RAEA_MEM_MARKS mark (raea-sys-memtally); docs/render-memory.feature RM0-RM4 * RM1-RM10: halcyon r109's sequence from killed at 24-25 GB to a 7.8 GB peak (footprint 5.5 GB), the look within run-to-run noise - RM1: materials' maps and Solari's traced meshes on the GPU only (RAEA_KEEP_CPU_ASSETS=1: the control) - RM2: a sequence's first 3D engine let go before a second opens - RM5: JS solids deduplicated by expression, their Manifolds in a two-generation cache (192 MB each); solid.free - RM6: a map whose picture changes by frame is one part and one material, its picture swapped as frames show it (raea-sys-material swapped.rs): the pool's 96 water maps were 96 meshes and 186 textures - RM7: Manifold shapes welded into indexed meshes (4.65 corners a vertex in halcyon; RAEA_NO_WELD=1: the control); a held frame settles to the same picture, boiling 0.30% against 0.38% - the shape text kept out of the store and the Edit (the engine spawns from the program's rows) - RM8: a BufferMesh of 64 KB or more kept on disk by its content (buffer:@NAME, raea's caches/buffers): shape text 274 MB -> 11.8 MB - RM9: material maps as BC7 with their mips (intel_tex_2), cached by content in raea's caches/maps, any size resampled to whole blocks (RAEA_NO_BC=1: the control): GPU images 733 MB -> 282 MB - RM10: raea-sys-contact's solids as bytes, a count and u16 surface points: 1.27 GB -> 0.37 GB mid-render - memtally names the biggest GPU images; RAEA_MEM_MARKS prints the program's text by column and shape call - tools/memprobe: memseq, heapwho/heapseq (malloc stack logging, holders.py), abenv/abseq/steadyab (A/B on one binary) docs/render-memory.feature has each step's numbers and gates. * raea-sys-memtally in tools/layers.toml: a system, as the layers gate asks * Size: render-memory's eight over-limit crates and files allowed once at today's sizes (Shane 11-29, for 0.1.13): the folders hold other lanes' uncommitted GI/RT work, so they're split once that lands * Fold render-memory's copies into what they copied (the dupes gate, 297/60 back to 293/57): one two-generation cache, raea_core_shape::Generations, for core/shape's meshes and runtime/calls' built Manifolds; swapped maps load their pictures with maps.rs's panel_picture; raea_io_home::write_whole for a file written whole or not at all (the BC7 maps first); spawn_sig(it, swapped) one function, its callers saying which; the store's spawn given its columns. Size allowances taken down to the folded sizes (solid.rs is back under 500) * Split the five crates render-memory took past 2000 lines, each where it parts cleanly, so the next lane has room (the size and rask gates; the one-time allowance is gone): - raea-core-tables (core/tables): a row's per-frame tables, from raea-sys-frame (re-exported there as tables) - raea-runtime-ecs (runtime/ecs): raea/ecs on Bevy's ECS, from raea-runtime-calls (ecs.rs re-exports it) - raea-sys-toon (systems/toon): toon surfaces and outlines, from raea-sys-material; its shaders keep the embedded path compositions name (raea_sys_material/toon.wesl) - raea-render-plugins (engine/render/plugins): RaeaPlugins, from raea-render (engine.rs re-exports it as raea_plugins; the imports only it used are gone) - raea-runtime-kinds (runtime/kinds): the rows of models, panels, decals, plates, fog, fire, splats, mesh sequences and grass, with placement and name_column, from raea-runtime-scene maps.rs's inline and panel pictures move to maps/pictures.rs (re-exported, 422 lines left) * Engine::open_in: a live engine (re)opened in its slot, the one there let go first (RM2 in one place, docs/render-memory.feature). raea-runtime-export's five opens go through it, so a fed render stepped again in the page's box keeps its AOVs as its first engine did; aov_on takes the engine in place. raea-runtime-export is back under its planned 2000 (LT1 and LX6 hold the rest) * Drop the dependencies render-memory's splits left behind (cargo shear, CI's unused-dependencies gate): raea-render's eleven systems crates went with RaeaPlugins to raea-render-plugins, raea-runtime-calls's bevy with raea/ecs to raea-runtime-ecs, raea-sys-material's raea-core-shape with toon to raea-sys-toon. raea-render's cargo-shear ignore goes too: spawn.rs reads a mesh buffer through raea_core_shape::buffer_json now --------- Co-authored-by: shinyobjectz <[email protected]>
170 lines
14 KiB
Gherkin
170 lines
14 KiB
Gherkin
@spec
|
|
Feature: Render memory: a realistic set renders well under 16 GB
|
|
Shane, 2026-11-26, as memguard's 24 GB cap killed the halcyon reel's shots one after another: "why are those renders
|
|
so big... how do we keep them down?". Shots of a realistic set ran at 20.5-22.7 GB all morning, with no single
|
|
regression: any small addition tipped one over the cap.
|
|
|
|
Why: raea's brand is local work on consumer hardware, a 16 GB Mac first. A render that needs 24 GB can't run there at
|
|
all, and on a 64 GB machine it leaves no room for a second job.
|
|
|
|
The model this file sets:
|
|
1. Memory is cut at the cause: a copy nobody reads after it was made is not made, or is let go once read. Nothing
|
|
here changes what a frame looks like: every step is checked frame for frame against the binary before it.
|
|
2. Every step is measured on the same probe, the halcyon reel's shot r109 (a walkway, a door, a bicycle; no pool
|
|
water), as a still (frame 106) and as a sequence, with tools/memprobe (macOS `footprint` by category) and raea's
|
|
own marks (RAEA_MEM_MARKS), on a binary built from the same tree with and without the step.
|
|
3. The measures stay: RAEA_MEM_MARKS prints each world's meshes and images with the bytes they hold on the CPU and
|
|
on the GPU, so a copy that comes back shows up as a number, not as a killed render.
|
|
|
|
Background:
|
|
Given the halcyon motel project (~/Documents/raea/raea/projects/halcyon-motel, compositions/reel.tsx, shot-r109)
|
|
And tools/memprobe/memprobe.sh (a still) and memseq.sh (a sequence), run under antsy with --mem 20G
|
|
And the numbers of 11-26 on the 11-25 binary: the still peaks at 14.9 GB (malloc large 6.4, malloc small 4.3,
|
|
graphics 3.9); the sequence opens its 3D at 10.3 GB of graphics and is killed at 24-25 GB before frame 0
|
|
|
|
Rule: the bar
|
|
The r109 sequence peaks under 16 GB of footprint and the still under 9 GB, with the same frames as before.
|
|
|
|
@done
|
|
Scenario: RM0. Each world's assets after every mark
|
|
Given the plan
|
|
| crate | file | lines | job |
|
|
| raea-sys-memtally | systems/memtally/src/lib.rs | 140 | after each mark (raea-render's `mem_mark`) one `mem_assets` line per App: its main world's meshes, images and storage buffers with their CPU bytes, its render world's meshes and images with their GPU bytes |
|
|
When a render runs with RAEA_MEM_MARKS=1
|
|
Then each mark is followed, at each App's next update, by "mem_assets app N main: meshes M (K on the CPU) X MB,
|
|
images ... MB, buffers ... MB" and "mem_assets app N render: meshes M X MB, images M Y MB"
|
|
And the Apps are numbered in the order they opened, so a sequence that holds two 3D worlds shows two
|
|
|
|
@needs:RM0 @done
|
|
Scenario: RM1. Meshes and maps on the GPU only, once nothing on the CPU reads them
|
|
Then a mesh raea builds (systems/mesh, its indexed buffers, meshseq) and a material's maps (systems/material maps.rs)
|
|
keep no main-world copy after they are uploaded, where nothing in the main world reads them after: their bounds
|
|
are taken at spawn, and picking, the end checks' clipping, raea-sys-contact, LOD and Solari's traced copy are
|
|
each checked to read what they need first
|
|
And Solari's traced copy of a mesh is made from the CPU copy before that copy is let go, or the mesh is built in
|
|
Solari's layout from the start so one mesh serves both (engine/render/raytrace/src/solari.rs traceable)
|
|
And the mem_assets lines show the main world's image bytes near zero once the scene has settled (r109: 19.5 MB,
|
|
9 of 87 images, all of them pictures raea-sys-sampler and the page read back)
|
|
And a mesh raea builds keeps its main-world copy, because main-world systems read meshes after their first frame:
|
|
picking (runtime/input pick.rs), a render's layers (systems/frame layer.rs), toon hulls (systems/material
|
|
toon.rs), the screen's UVs, sprite3d, and the GI lane's emitters and cells (systems/rt). What it keeps is welded
|
|
(RM7): r109's 618 meshes on the CPU hold 198 MB, where the 11-25 build's held 1.38 GB. Solari's traced copy
|
|
(traceable's Copy) is on the GPU only
|
|
|
|
@needs:RM0 @done
|
|
Scenario: RM2. One 3D world at a time in a sequence
|
|
Then a render never holds two 3D engines at once: where a camera in a page element makes the 3D's rows be stepped
|
|
again (runtime/export render.rs, fed.rs), the first engine is let go before the second opens
|
|
And the mem_assets lines of a sequence show one 3D App's render world at a time (r109's sequence: app 0 alone)
|
|
|
|
@needs:RM0
|
|
Scenario: RM3. The growth while a frame settles
|
|
Then the CPU heap's growth while a held frame settles (about 350 MB/s, still and sequence alike) is found and cut
|
|
And the still's footprint after its frame is written is within 10% of its footprint after warm-up
|
|
|
|
@needs:RM0
|
|
Scenario: RM4. A texture whose path changes each frame is let go
|
|
Then a texture a frame names (halcyon's pool: water/n-NN.png, g-NN.jpg, 96 of each) is let go, CPU and GPU, once
|
|
no part shows it, so a sequence holds the frames in view and not every frame it passed
|
|
And a pool shot's sequence (its caustics) holds as many textures at its last frame as at its first
|
|
|
|
# 11-26, later: Shane widened the goal ("reduce rendering memory footprint as much as possible ... no boiling and
|
|
# amazing rendering realism ... the fastest, best looking, most efficient rendering engine for gametime performance
|
|
# and film rendering performance"), the halcyon motel as the benchmark. The scenarios below RM4 carry it on; each is
|
|
# measured on the same probes, and none may move the look or add boiling (raea light steady under 1.5%).
|
|
|
|
Rule: the measured state, 11-26 (r109, 1080x1920)
|
|
| build | still peak | sequence peak | main-world maps | main-world meshes |
|
|
| 11-25 frozen | 14.9 GB | killed at 24-25 GB before frame 0 | 2.4 GB | 1.38 GB |
|
|
| RM1 | 14.6 GB | 16.1 GB, all 107 frames written | 0.02 GB | 0.56 GB |
|
|
| RM1+RM5+RM6 | | 11.4 GB; 93 images (was 277), GPU 3.7 GB (was 5.5) | 0.02 GB | |
|
|
| + RM7 weld, shape text out of the store | | 10.2 GB (footprint 7.1 GB), 0 errors | 0.02 GB | 0.20 GB (618 of 1226 meshes) |
|
|
| + RM8 kept buffers | | 8.8 GB (footprint 6.7 GB), 0 errors; shape text 11.8 MB (was 274) | 0.02 GB | 0.20 GB |
|
|
| + RM9 BC7 maps | | 8.4 GB (footprint 5.7 GB), 0 errors; GPU images 282 MB (was 733) | 0.02 GB | 0.20 GB |
|
|
| + RM10 contact solids | | 7.8 GB (footprint 5.5 GB), 0 errors, the same findings | 0.02 GB | 0.20 GB |
|
|
The pool's caustics shot (196 frames), from before RM6 to the weld build: peak 18.8 GB to 9.9 GB, every 8th frame
|
|
within run-to-run noise (pixels off by more than 2 levels 0.2-1.5%, by more than 16 at most 0.03%; this tree's
|
|
noise between two runs of one binary is about 1%).
|
|
The weld against RAEA_NO_WELD=1 on one binary (r109 f106): a frame held 96 frames (`raea light steady`) settles to
|
|
the same picture either way (pixels off by more than 16 levels 0.008%), boiling 0.30% welded against 0.38%
|
|
(worst tile 1.53% against 2.98%), and two runs of the welded build differ in 0.11% of pixels against 1.2%. In the
|
|
shot's own render, one small emitter's wash (the room sconce's light on the wall, above and below its can) has
|
|
built up less by f106 when welded: a difference in how fast it settles, not in where it settles.
|
|
RM9 against RAEA_NO_BC=1 on one binary (r109 f106, caustics f60, the facade's 8776-wide wear maps and the pool's
|
|
96 water normal maps among them): pixels off by more than 16 levels 0.057% and 0.097%, all of it the bicycle's
|
|
sub-pixel spokes' glints and a chair's shadow edge on the deck; nothing on the facade or the water (two runs of
|
|
either build: about 0.03%).
|
|
Still held after the weld (before RM8): shape text 274 MB in 2,526 rows, 263 MB of it 88 BufferMesh shapes (the palms' vertex
|
|
arrays as JSON, two of them 51 MB each), half of it the same text in another row (RM8).
|
|
|
|
@needs:RM1 @done
|
|
Scenario: RM5. The CPU heap, named by who holds it
|
|
Then a still's live heap after warm-up is attributed by call tree (macOS malloc stack logging, malloc_history
|
|
-callTree; tools/memprobe/heapwho.sh) to the crate that allocated it, and each holder over 250 MB is either cut,
|
|
let go once read, or written here with why it stays
|
|
And the shape cache (raea-core-shape `cached`, `solid`), the React world, wgpu's staging and the end checks' solids
|
|
are each given a number
|
|
And after RM5 to RM10 (tools/memprobe/heapseq.sh, r109's sequence mid-render; holders.py) what is over 250 MB stays
|
|
for a reason: MetalFX's denoising scaler 317 MB (Apple's framework, made once a view, the denoiser's own
|
|
working memory); JavaScriptCore's heap 300 MB in a still, up to 870 MB mid-sequence (the composition's live
|
|
objects; collecting after every frame, RAEA_JSC_EDEN=1, frees the small heap later but not the peak); the
|
|
contact check's solids 366 MB (RM10, every part in view the whole shot); wgpu's Metal command encoding
|
|
250-360 MB in the first frames (inside wgpu-hal). Gone from the list: Manifold's solids (2.4 GB, RM5's cache),
|
|
the shape text (977 MB of clones, RM8 and the store), the names cache (297 MB, RM8)
|
|
|
|
@needs:RM4
|
|
Scenario: RM6. A picture sequence is one texture, streamed
|
|
Then a map whose picture changes each frame (a water normal map, a caustic) is one GPU texture written each frame
|
|
from the frame's file (decoded ahead on a thread), not one texture per picture made at load
|
|
And a pool shot's sequence holds one texture per such map, its GPU bytes flat from its first frame to its last
|
|
|
|
@needs:RM1 @done
|
|
Scenario: RM7. A mesh as few vertices as its corners need
|
|
Then a Manifold shape's mesh is indexed (U32) and welded where corners share a place and a normal exactly
|
|
(systems/mesh welded): halcyon's shapes had 4.65 corners to each vertex, so the raster mesh, its main-world copy
|
|
and Solari's traced copy are each about a third of what they were (r109's main-world meshes 0.56 GB to 0.20 GB)
|
|
And a shape with its own UVs or colours a corner (a <BufferMesh>) is left as it is; RAEA_NO_WELD=1 is the control
|
|
And a frame held 96 frames settles to the same picture welded or not, with no more boiling (numbers above)
|
|
And it is not built in Solari's layout to spare the traced copy: the main-world copy stays (RM1's readers), so
|
|
the layout's tangents and colours would make every vertex 64 bytes on the CPU and the GPU, where today it is 32
|
|
on the CPU and 32 + 64 on the GPU: bytes moved from the GPU to the CPU, not saved
|
|
|
|
@needs:RM7 @done
|
|
Scenario: RM8. A long BufferMesh is held as a name, its text kept on disk by its content
|
|
Given a <BufferMesh> whose shape text is 64 KB or longer (raea-core-shape KEEP_BUFFER_AT)
|
|
Then the React read (runtime/react read.rs names3d) writes its JSON once to raea's caches (buffers/NAME.json, NAME
|
|
its BLAKE3) and passes `buffer:@NAME` on, so the scene, every frame's row, the store and the evaluator hold 40
|
|
characters, not the vertex arrays
|
|
And the part is known again each frame by the text's length and xxh3 without naming it again
|
|
And every reader of a buffer shape (raea-sys-mesh shape_mesh, the three shader's fit, interchange's export) reads
|
|
the kept file through raea_core_shape::buffer_json, so what is drawn and exported is the same
|
|
|
|
@needs:RM1 @done
|
|
Scenario: RM9. A material's maps are block-compressed on the GPU
|
|
Given a device that samples BC textures (wgpu TEXTURE_COMPRESSION_BC: Apple silicon and Intel Macs, and desktop
|
|
GPUs on Windows and Linux)
|
|
Then every map raea-sys-material makes (map_image: colour as BC7 sRGB, normal, metallic-roughness, occlusion and
|
|
emissive as BC7 linear) is BC7 with its whole mip chain, 16 bytes for each 4x4 texels, a quarter of RGBA8's
|
|
And the blocks are encoded once (intel_tex_2's ISPC kernels, on every core) and kept in raea's caches by the
|
|
picture's content (maps/NAME.bc7), so a later run reads them and makes no mips
|
|
And a map whose side isn't a multiple of 4, a device without BC, or RAEA_NO_BC=1 is RGBA8 as before
|
|
And BC7 keeps all four channels, so Bevy's and Solari's shaders read every map as they did
|
|
|
|
@done
|
|
Scenario: RM10. The contact check's solids hold what it reads
|
|
Given a sequence's parts are checked for clipping as its frames come (raea-sys-contact), every part in view held
|
|
as a solid until the end checks let them go: in r109, 603 MB of depth grids, 368 MB of inside-cell lists and 301
|
|
MB of surface points (the heap's biggest holder mid-render, by malloc stack logging)
|
|
Then a cell's depth is a byte (at most half a grid's side; held at 255 past it), the inside cells are a count
|
|
(the check reads only how many), and the surface points are three u16s across the part's box with no spare
|
|
capacity: about 366 MB where there were 1,272, the findings the same (the crate's 18 tests)
|
|
|
|
Still open (11-26): a transient 1 GB of heap inside the first frame (after "resources prepared", gone within 10 s)
|
|
sets the warm sequence's footprint peak (6.5 GB at about 49 s); JavaScriptCore collecting after every frame
|
|
(RAEA_JSC_EDEN=1, RAEA_JSC_RELEASE_S=1) flattens the small heap later (990 to 330 MB) but not that peak. The GPU's
|
|
2.6 GB: 282 MB of images, 455 MB of meshes, the rest Solari's and the views' own buffers and MetalFX.
|
|
|
|
Rule: speed and quality are measured beside memory
|
|
Each step reports, on the r109 still and sequence: peak footprint, seconds per frame once warm, and `raea light
|
|
steady` boiling at a held frame. A step that cuts memory and costs time or adds boiling is not done.
|