You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GPU memory management: gap inventory, measurements, and where the in-flight PRs fit
#24870
GPU memory management: gap inventory, measurements, and where the in-flight PRs fit
This is an inventory of how Ruffle manages GPU memory over a resource's lifetime, with measurements from a reproduction of a real 4 GB-VRAM OOM on the desktop app. It is not a bug report — the concrete crash and its root-cause analysis live in #24864. The point of writing it down is that several open PRs and a long tail of "game X crashes" issues each touch one layer of this, and it would help to have one place that says what exists, what does not, and what each PR actually covers.
1. What the measurements show
A scene-based game (scene SWFs of 68–106 MB compressed, 1100–1900 embedded JPEGs each, i.e. up to ~3.9 GB decoded RGBA for a single scene) on a 4 GB GTX 1050 Ti, Vulkan backend, wgpu 30.0.1:
build
behaviour
nightly (baseline)
VRAM climbs monotonically across Loader.load()/unload() cycles; wgpu error: Out of Memory after 13 cycles
+ release GPU resources on unload only
same OOM at the same point (scene preload), ~3.4 GB uploaded at load
+ lazy mesh registration
49 cycles, VRAM plateaus at ~1.8 GB
+ age-stamped eviction and a byte budget
full 8-scene soak, system-wide VRAM ≤2.15 GB, no crash
Three failure modes produce the same error signature, and they need different fixes:
Preload-time eager upload — Graphic::from_swf_tag calls renderer.register_shape during MovieClip::preload; mesh construction resolves bitmap fills, uploading every referenced bitmap before a frame is drawn. Immune to GC/eviction/unload-release work.
Unloaded-movie retention — MovieLibraries (core/src/library.rs) only ever grows; LoaderInfo::unload detaches the display object but the per-movie library (and the GPU handles cached in its characters) stays.
In-movie accumulation — textures of a live movie are cached on first render and never released while the movie lives.
2. Gap inventory
resource class
upload timing
lifecycle handling today
gap
library bitmap textures
preload (eager) → on first render, if #24864's prototype is applied
unload-release + age/budget eviction (prototype)
upstream: none yet; #23071/#22908 address the library's own lifetime, not the eager upload
library shape meshes
same
same
same
morph-shape meshes
lazy (as designed)
unload-release only in the prototype
not covered by age sweeps (no timestamp)
BitmapData textures
lazy
freed when the AS3 object is collected (gc-arena does drop require_static fields on sweep) or on explicit dispose()
no pressure-based eviction; objects pinned by AS3 (canvas pools, Dictionary caches) hold textures indefinitely. Note #23897 fixes the AS3 side of "pinned by AS3" (weak Dictionary, weak listeners, System.gc())
font glyph meshes
lazy, per glyph
cached on the glyph (font/glyph.rs), never released
no lifecycle at all
tessellation cache (multi-scale variants)
first render per scale
up to 4 meshes per GraphicShared, cleared only on explicit release
not swept while "hot"
render targets / offscreen pools
per frame
reused per frame (TexturePool reset each frame)
ok
upload throttling
—
none: a scene's first rendered frame can upload hundreds of textures in one frame
frame-time spikes on scene entry
VRAM accounting
—
none upstream; wgpu::Device::generate_allocator_report() is available on Vulkan/DX12
see §3.4
3. What a pipeline would need (layers, and where each belongs)
Lazy/queued upload (core, small): don't upload what has not been displayed; amortize the first frame's uploads across frames. Fixes failure mode 1.
Eviction policy (core, small-medium): evict by age and/or a byte budget; everything is re-creatable on demand (bitmap_handle, render_self, morph get_shape are all lazy already, so re-creation is transparent). Fixes mode 3.
Real measurement (backend trait + wgpu impl, small): Device::generate_allocator_report() gives total_allocated_bytes / total_reserved_bytes / per-allocation labels on Vulkan and DX12 (None on GL/WebGL), so budgets do not have to be heuristics. wgpu: Include memory report in debug info #17483 is the same idea from 2024 using the older GlobalReport API.
⚠️ One gotcha worth recording: budget against total_allocated_bytes, nottotal_reserved_bytes. Suballocated blocks are not returned to the driver when individual textures are freed, so reserved stays flat while allocated falls — a budget keyed on reserved never appears satisfied and evicts everything on every pass (observed: all textures released each sweep, own accounting pinned at 0, until the metric was switched).
The still-open items (need design, not just code): BitmapData pressure eviction (needs GC integration or ownership inversion — the renderer holding textures and objects holding ids), upload amortization, glyph-mesh lifecycle.
So of the four "which layer" questions above, upstream has work in flight for layer 2 and an idea for layer 4, but nothing for layer 1 — which is the one that makes these two games OOM at load, before any of the lifecycle work gets a chance to matter.
5. How the numbers were obtained
FFDec was used to import a small auto-scene-cycler into the game's own loader class (same code path as a real scene switch: Loader.unloadAndStop() + load() into the same Loader), then the desktop app was run with RUST_BACKTRACE=full and a per-process VRAM logger (\GPU Process Memory(*)\Dedicated Usage). A/B runs differ only in the binary under test. The symbolic backtrace above comes from a debug = true release build. Caveats: one game, one GPU, Vulkan only; the sweep numbers are from a prototype, not from upstream code.
I am not proposing a design as final — I would just rather have this written down than have each of these layers rediscovered from a fresh crash report. Happy to hand over the prototype diff, or to test any of the in-flight PRs against the harness.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
GPU memory management: gap inventory, measurements, and where the in-flight PRs fit
This is an inventory of how Ruffle manages GPU memory over a resource's lifetime, with measurements from a reproduction of a real 4 GB-VRAM OOM on the desktop app. It is not a bug report — the concrete crash and its root-cause analysis live in #24864. The point of writing it down is that several open PRs and a long tail of "game X crashes" issues each touch one layer of this, and it would help to have one place that says what exists, what does not, and what each PR actually covers.
1. What the measurements show
A scene-based game (scene SWFs of 68–106 MB compressed, 1100–1900 embedded JPEGs each, i.e. up to ~3.9 GB decoded RGBA for a single scene) on a 4 GB GTX 1050 Ti, Vulkan backend, wgpu 30.0.1:
Loader.load()/unload()cycles;wgpu error: Out of Memoryafter 13 cyclesThree failure modes produce the same error signature, and they need different fixes:
Graphic::from_swf_tagcallsrenderer.register_shapeduringMovieClip::preload; mesh construction resolves bitmap fills, uploading every referenced bitmap before a frame is drawn. Immune to GC/eviction/unload-release work.MovieLibraries(core/src/library.rs) only ever grows;LoaderInfo::unloaddetaches the display object but the per-movie library (and the GPU handles cached in its characters) stays.2. Gap inventory
preload (eager)→ on first render, if #24864's prototype is appliedBitmapDatatexturesgc-arenadoes droprequire_staticfields on sweep) or on explicitdispose()Dictionarycaches) hold textures indefinitely. Note #23897 fixes the AS3 side of "pinned by AS3" (weakDictionary, weak listeners,System.gc())font/glyph.rs), never releasedGraphicShared, cleared only on explicit releaseTexturePoolreset each frame)wgpu::Device::generate_allocator_report()is available on Vulkan/DX123. What a pipeline would need (layers, and where each belongs)
Lazy/queued upload (core, small): don't upload what has not been displayed; amortize the first frame's uploads across frames. Fixes failure mode 1.
Ownership/lifetime of movie libraries (core, architectural): what core: Fix memory leaks by making MovieLibrary garbage-collectable #23071 and core: Wrap Library and SwfMovie in Gc #22908 are doing — a weak-keyed registry so a dead movie's library is collectable. Fixes mode 2, and enables eviction.
Eviction policy (core, small-medium): evict by age and/or a byte budget; everything is re-creatable on demand (
bitmap_handle,render_self, morphget_shapeare all lazy already, so re-creation is transparent). Fixes mode 3.Real measurement (backend trait + wgpu impl, small):
Device::generate_allocator_report()givestotal_allocated_bytes/total_reserved_bytes/ per-allocation labels on Vulkan and DX12 (Noneon GL/WebGL), so budgets do not have to be heuristics. wgpu: Include memory report in debug info #17483 is the same idea from 2024 using the olderGlobalReportAPI.total_allocated_bytes, nottotal_reserved_bytes. Suballocated blocks are not returned to the driver when individual textures are freed, soreservedstays flat whileallocatedfalls — a budget keyed onreservednever appears satisfied and evicts everything on every pass (observed: all textures released each sweep, own accounting pinned at 0, until the metric was switched).The still-open items (need design, not just code):
BitmapDatapressure eviction (needs GC integration or ownership inversion — the renderer holding textures and objects holding ids), upload amortization, glyph-mesh lifecycle.4. Relationship to open PRs
System.gc())So of the four "which layer" questions above, upstream has work in flight for layer 2 and an idea for layer 4, but nothing for layer 1 — which is the one that makes these two games OOM at load, before any of the lifecycle work gets a chance to matter.
5. How the numbers were obtained
FFDec was used to import a small auto-scene-cycler into the game's own loader class (same code path as a real scene switch:
Loader.unloadAndStop()+load()into the sameLoader), then the desktop app was run withRUST_BACKTRACE=fulland a per-process VRAM logger (\GPU Process Memory(*)\Dedicated Usage). A/B runs differ only in the binary under test. The symbolic backtrace above comes from adebug = truerelease build. Caveats: one game, one GPU, Vulkan only; the sweep numbers are from a prototype, not from upstream code.I am not proposing a design as final — I would just rather have this written down than have each of these layers rediscovered from a fresh crash report. Happy to hand over the prototype diff, or to test any of the in-flight PRs against the harness.
All reactions