Skip to content

GPU: contain frame-local validation failures (refs #1319) - #1326

Merged
bflatastic merged 7 commits into
storytold:mainfrom
tylerjenningsw:fix/gpu-frame-validation
Oct 29, 2026
Merged

bflatastic merged 7 commits into
storytold:mainfrom
tylerjenningsw:fix/gpu-frame-validation

Conversation

@tylerjenningsw

@tylerjenningsw tylerjenningsw commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1319. This is "refs", not "fixes": the reporter's first failure is still unknown. This PR stops that kind of failure from turning off the GPU compositor for the rest of the session, and makes the next report say which texture failed.

What was wrong

  • Gpu::within_memory (the guard around each viewer frame) only had OutOfMemory and Internal error scopes. A Validation error, like the reported Texture::create_view: Texture with '' label is invalid, escaped as an uncaptured error. The desktop app's handler then retires the GPU compositor, and preview stays on the CPU until restart. One way this happens: a texture allocation fails, the code goes on with the invalid texture, and its create_view is then a validation error that the allocation scopes don't catch.
  • A failed frame's textures could go back into the reuse pool. Its result was dropped only after the pool was emptied, so pooled textures in it went back in. Even in the right order, emptying the pool cleared only its free list. A texture released while another frame's encoder was still open waited in released, and became free (and reusable) when that encoder closed.
  • Working textures had no label, so the error couldn't say which texture failed. The empty label in the report fits these working textures (GpuContext::texture). The viewer's display texture is labelled viewer frame.

Changes

  • within_memory also pushes a Validation scope. On any scoped error it reports every error, allocation errors first (…; then: …). It drops the failed result, then frees everything kept for reuse with a new GpuContext::discard_kept: uploads, staging buffers, the shared zero textures, the particle checkpoints and the texture pool. For the pool, Pool::discard drops the free textures, those waiting for an open encoder, and those kept by a live encoder, and raises a pool generation. A texture taken before the failure is then never handed back to the pool. The encoders' bookkeeping (open, ids) stays, so reuse remains ordered. The compositor stays on, and the next frame tries the GPU again.
  • within_memory returns a FrameError (Retired / Memory / Validation) instead of String. In frames.rs, a plain validation failure no longer logs "the GPU ran out of memory" and no longer halves the RAM preview's GPU frames. Memory failures behave as before.
  • Working textures are labelled working image {w}×{h}.
  • Genuine device loss and uncaptured errors outside the guard still retire the compositor; the retired flag isn't cleared or bypassed.
  • docs/architecture.md describes the new behaviour.

Tests (crates/gpu/src/tests.rs, each on a device of its own)

  • a_view_of_an_invalid_texture_fails_the_frame_not_the_compositor: a texture the device rejected, made beforehand under a scope of its own. Inside the guard only its create_view runs, the reported operation. The test checks that:

    • the frame fails with FrameError::Validation, naming the texture;
    • check_health is still OK;
    • the next frame (a blend scene, 32 bpc) composites on the GPU, is read back and matches the CPU renderer within the usual tolerance.

    The test device's handler panics on an uncaptured Validation error under test. With the old guard, the failure is uncaptured GPU error: Validation Error, the reported one.

  • a_failed_frame_returns_no_texture_to_the_pool: another Enc keeps its encoder open across the failed frame, and an image taken by an earlier frame is handed back after the cleanup. Then the open encoder closes. The next frame takes both sizes and the pool reports no reuse. With the old Pool::clear, both textures were reused (2 hits).

The tests skip without a GPU adapter, like the crate's other GPU tests. No VRAM exhaustion is needed.

Checks run locally

Run on an NVIDIA RTX 3060, Vulkan, Windows:

  • cargo fmt -p effectcraft-gpu -p effectcraft-ui-egui -- --check
  • cargo test -p effectcraft-gpu --lib -- within_memory a_view_of_an_invalid a_failed_frame_returns enc_reuses texture_reuse_does_not readback_staging (6 passed, including the existing pool-reuse tests)
  • cargo test -p effectcraft-ui-egui --lib (257 passed)
  • cargo clippy --no-deps -p effectcraft-gpu --lib --tests -- -D warnings
  • cargo clippy --no-deps -p effectcraft-ui-egui --lib -- -D warnings
  • cargo clippy --no-deps -p effectcraft-gpu --target wasm32-unknown-unknown -- -D warnings

The full cargo xtask ci gate wasn't run locally, including the whole GPU test suite and the ui-egui test binaries. I haven't reproduced the reporter's Linux failure.

Not covered

  • Finding the first error. The new label and the combined error message should show it in the reporter's next GPU Information / log.
  • GPU work outside within_memory. Exports and render-queue frames through Accelerator::comp_frame, and Info-panel readbacks, can still retire the compositor on an uncaptured validation error.
  • Layer cache publication. Unchanged from before this PR. During a GPU attempt, Renderer::content_buf_timed can insert buffers into the shared layer cache, and slow ones are written to the disk cache, before the guard reports a failure. The CPU retry skips the cache, but later frames read it again. I haven't shown that a rejected GPU effect actually leaves wrong pixels there rather than falling back to the CPU. Fixing it properly means staging a GPU attempt's entries and publishing them, in memory and on disk, only when the attempt succeeds. That's a separate change. A RAM-only purge wouldn't cover the disk cache, and would drop other threads' valid entries.
  • Memory-failure classification under test. A plain validation error doesn't trigger the preview backoff, by the code path in frames.rs. There's no test injecting an out-of-memory or internal error.

@tydude001

Copy link
Copy Markdown
Contributor

I can reproduce #1319's exact error on Linux by running out of VRAM, and this PR keeps the compositor on through it.

Setup: RTX 5070 12 GB, NVIDIA 615.78.08, Fedora 44, Vulkan, headless sway. A separate process allocated and held
10–10.5 GB of VRAM before EffectCraft started. Here the driver fails a Vulkan allocation once VRAM is full (that process's own
allocations stop with Out of Memory at about 11 GB, rather than spilling into system memory), so the app's allocations fail too. Then I played the demo project, scrubbed to new
frames, and read help.systemInfo over --control, both under pressure and 20 s after the other process let go.

build runs compositor kept
main 549e9d82 9 0
this PR 2e2d75f0 9 8
this PR 3dca1859 5 5

On main, the first uncaught error was Texture::create_view in 5 runs and Queue::write_texture in 4, always
Texture with '' label is invalid and always on a frame worker. With the PR, most failed frames log the GPU ran out of memory (Out of Memory; then: Validation Error … Texture with 'working image 681×401' label is invalid) and render on the
CPU. So the new label puts #1319's unlabelled texture among the working images, as you expected. All the failures
came within the first ~11 s, and none came later, under pressure or after the release.

On 2e2d75f0, 11 frames in 3 of the 9 runs instead logged the GPU rejected the frame: a create_view of an invalid
working image, with no out-of-memory error in that frame's own scope. That looks like a texture whose allocation
failed in another frame being reused, which is what 864b9e4 stops. On 3dca1859 there were none: 50 failed frames in
5 runs, all out of memory first.

The one run on 2e2d75f0 that lost the compositor didn't fail on a frame worker. The workers' errors were caught, and
47 ms later the main thread's handler received uncaptured GPU error: Out of Memory, with no operation named, and
retired the compositor. wgpu's error scopes are per thread (wgpu 30.0.1, src/api/device.rs:523), so within_memory on a worker
can't catch an allocation that fails on the main thread, presumably one of egui-wgpu's or the viewer's display texture.
It came up in 1 of the 14 PR runs, and in none of the 5 on 3dca1859. The description already says uncaptured errors
outside the guard still retire the compositor. This is one that the same VRAM shortage produces on the main thread, so
it isn't limited to exports, the render queue and Info readbacks.

I couldn't show from outside the app that frames render on the GPU again after the release. There's no per-frame signal
over --control, and CPU time and VRAM don't separate the two cases here. The new test checks that the frame after a
rejected one composites on the GPU, though not after an out-of-memory failure, and it passes here.

On Linux with the RTX 5070: cargo test -p effectcraft-gpu --lib passes 214 / 214 on 3dca1859, including
a_view_of_an_invalid_texture_fails_the_frame_not_the_compositor, which really ran on the NVIDIA device rather than
the no-adapter skip. main passes 212 / 212. effectcraft-ui-egui --lib passes 257 / 257 on 2e2d75f0 and on main.

Not tested: what fills a 12 GB card in the reporter's normal session, X11, KWin, driver 580, and exports or
render-queue frames under VRAM pressure.

@00xJS

00xJS commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Tested on AMD (RX 6900 XT, Windows, Vulkan, EFFECTCRAFT_REQUIRE_GPU=1): 211 passed. The
only 3 failures also fail on main (#1605). No regressions. I didn't reproduce the VRAM
exhaustion scenario.


Generated with Claude Code

@ded-achtung

Copy link
Copy Markdown

Another reproduction of this failure, from #1812 (a 3D parallax project with 21 120 px plates). Windows 11, RTX 4070 Laptop (8 GB), Vulkan, desktop app on main.

During playback, 16 preview workers ran the device out of memory on a cold start. The next use of the failed texture escaped the guard and retired the compositor for the session:

ERROR [ec-frame-12] effectcraft: uncaptured GPU error: Validation Error
  In a CommandEncoder, label = 'effectcraft'
    Texture with '' label is invalid
WARN  [ec-frame-1] effectcraft_ui_egui::frames: the GPU context is retired (...); the frame renders on the CPU

I had opened #1919 with only the Validation scope part of this PR, and I closed it as a duplicate. With that change, 10 playbacks of the project never retired the context, and the few frames that ran out of memory fell back to the CPU. I haven't run this branch itself. The out-of-memory errors themselves were addressed separately in #1917, #1918 and #1928.

🤖 Generated with Claude Code

@matthewcieplak

Copy link
Copy Markdown

I was encountering the same issue on Ubuntu with my RTX4070 Super. I asked Qwen-3.8-Flash to check out this branch and build locally so I could test and grab any new error messages. I reproduced the issue and ran a "pressure test" to fill the VRAM and trigger the error. The AI Summary follows:


At full-card pressure this project retires the compositor on the tip too — via uncaptured Out of Memory, not via the unlabelled create_view validation of #1319.

Setup: RTX 4070 SUPER (12 GB), NVIDIA 595.71.05, Ubuntu 25.10, native Wayland, Vulkan, wgpu 30.0.1, Ryzen 7 9700X (16 preview workers). Builds: main eb510878 (0.16.0) and this branch 3dca1859 merged onto that main (clean merge). dev profile (optimized + debuginfo). Pressure: a separate wgpu-30.0.1 process that creates 256 MiB STORAGE buffers under an OutOfMemory scope on the discrete adapter until the driver refuses (the app's own detection path), then holds ~150 s while the app runs two play bursts driven over --control (playback.toggle + help.systemInfo). Runs use isolated XDG_CACHE_HOME/EFFECTCRAFT_CONFIG_DIR so the disk layer cache can't mask allocations. Workloads: the demo project, and the user project from #1319's class: 1920×1080 @ 29.97, 10 s, 14 layers — six stacked 3D 3506×2370 footage plates under Levels/Bevel Alpha/CC Toner/keyframed CC Light Sweep, plus Glow, Gaussian, Chromatic Aberrations, Add Grain and Lens Flare solids — which keeps ~5.7–6.2 GiB VRAM resident before any filler starts.

A. Demo, fill until refused (~8.5 GiB held, ~0.45 GiB headroom) — the #1319 failure, contained:

build outcome
main first failing frame escapes the guard: 26 uncaptured, 16 CPU-fallback "retired" lines, session lost. ERROR [ec-frame-12] effectcraft: uncaptured GPU error: Validation Error / In Texture::create_view / Texture with '' label is invalid — #1319 verbatim
this PR 164 frames contained, 0 uncaptured, 0 retired; GPU still in help.systemInfo after both bursts: WARN [ec-frame-11] effectcraft_ui_egui::frames: the GPU ran out of memory (Out of Memory; then: Validation Error / In Queue::write_texture / Texture with 'working image 439×439' label is invalid ); the frame renders on the CPU and fewer GPU frames are kept

The label goal of the PR is met: every message names the failing texture's size, including the 960×540 working images.

B. Real project, moderate fill (capped at 5.0 GiB → ~1.3 GiB headroom: workers fail, main-thread allocations survive) — same fix on a heavy real comp:

build outcome
main retired again with the exact #1319 signature: uncaptured GPU error: Validation Error / In Texture::create_view / Texture with '' label is invalid (27 uncaptured, 16 retired)
this PR 14 memory-scoped catches + 2 pure rejections, 0 uncaptured, 0 retired, GPU alive through both bursts: WARN [ec-frame-8] effectcraft_ui_egui::frames: the GPU rejected the frame (Validation Error / In Texture::create_view / Texture with 'working image 1169×790' label is invalid ); it renders on the CPU, the next frame tries the GPU again

Those are the first real-project confirmations I've seen of the FrameError::Validation branch: no false OOM backoff, next frame retries the GPU, pool discard keeps the reuse ordering clean.

C. Real project, extreme fill (refused at 5.5 GiB held → ~0.55 GiB headroom) — the tip still retires, through a different door: ~15 s into each run, while Cache-When-Idle preview prefetch was allocating, on both builds:

ERROR [ec-frame-14] effectcraft: uncaptured GPU error: Out of Memory
WARN  [main] effectcraft_ui_egui: GPU preview retired: uncaptured GPU error: Out of Memory

The guard never engaged first (0 scoped catches before the retire on either build; after it, the PR's workers do report the labeled combined string). Uncaptured count 3 on the PR vs 13 on main — containment helped, the retirement endpoint was the same. One earlier PR run on the demo with a warm shared cache shows the same door: 100 frames contained, then gpu texture readback: uncaptured GPU error: Out of Memory on several workers plus a bare OOM on [main], and the session retired. That is consistent with @tydude001's 1-in-14 loss on 2e2d75f0, but now on the tip (3dca1859, 5/5 for them on the demo): on this hardware and this workload the residual is a plain cross-thread / main-thread allocation failure surfacing as an uncaptured Out of Memory, i.e. the thread-local-scope hole, not a Validation leak. If a follow-up wants to close it, the candidates visible here are the readback staging allocations (polled outside the frame scope) and the idle-prefetch path.

D. Suite on this device (EFFECTCRAFT_REQUIRE_GPU=1 cargo test -p effectcraft-gpu --lib): 232/234 on this branch, including both new tests running on the NVIDIA adapter. The two failures — tests_adv3d::gpu_matches_cpu_wide_penumbrae (15/4159 shadowed pixels beyond 2/255) and tests_init::opengl_adapters_get_cpu_compositing_at_once (required initialization-test device unavailable: Parent device is lost, on the NVIDIA GeForce RTX 4070 SUPER/PCIe/SSE2 (Gl) adapter) — fail with identical messages on plain main. Not regressions; environment-specific.

Not tested: exports and render-queue frames under pressure (the description's other uncovered area), and X11.

Summary: on both the demo and a heavy real project, this branch turns #1319's session-ending unlabelled create_view failure into per-frame CPU fallbacks that say which texture died — and on this card, the thing that can still retire the session at the tip is an uncaptured Out of Memory from work outside the guard, which the description already flags as out of scope.

@bflatastic

Copy link
Copy Markdown
Member

Merged, thank you @tylerjenningsw! It landed on main with a batch of community PRs, after a full workspace build and test run on Windows against the refactored main (fmt, strict clippy, about 4,100 tests, layers, assets and wasm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants