Skip to content

Bound GPU resource pools and preserve held mip levels with tiles - #3828

Open
1mosce wants to merge 1 commit into
trustno1-coder:mainfrom
1mosce:codex/resource-memory-upstream
Open

1mosce wants to merge 1 commit into
trustno1-coder:mainfrom
1mosce:codex/resource-memory-upstream

Conversation

@1mosce

@1mosce 1mosce commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Completed uploads kept staging ranges quarantined for another two seconds, tile mode disabled held-level trimming even for ordinary textures, and pressure could repeatedly recreate readback resources. This patch corrects those lifetimes, pools readback ranges, and accounts for actual texture-heap growth across concurrent workers.

Resource-lifetime fixes for review. The resource regressions have targeted coverage and the builds have run in game. Stable target frame times, complete leak freedom, and visual equivalence across city traversal are still unverified. This does not replace the shared-memory/coherency model.

What it changes

  • Lease disjoint ranges of persistently mapped readback buffers. Lists retain the leases through their GPU fences; only wholly idle blocks can be trimmed. Driver creation and final release occur outside the arena lock. Remove the redundant second readback pool.
  • Return staging ranges when their last owner has completed, with a GPU regression that holds a copy pending and checks its bytes before allowing reuse. Bound idle CPU-visible pool retention independently of the texture budget.
  • Reserve actual heap/committed allocation sizes across concurrent texture growers, including tile heaps. Optional work remains retryable when deferred and cannot bypass admission via committed fallback or diagnostic pipeline retries. Required draws retain their allocation path, so this is not a hard cap on total DXGI usage.
  • Preserve held-mip trimming for ordinary textures when tiles are enabled. Successfully reserved textures keep base level zero and their full virtual shape. Keep the existing tiled-upload staging policy.
  • Reclaim empty texture, staging and buffer blocks under the metadata lock, then release their driver objects after unlocking and before new growth. Include both TEXTURES and SMALL in the pool census.
  • Index occupied descriptor-owner slots, while rechecking the actual owner under its slot lock. Reuse bounded journal answers and submission-planner scratch without sharing live answers or caching old epochs.
  • Make the benchmark distinguish budget deferral from driver failure and count both host-pipeline failure log formats. Add the ownership and pressure rules in docs/readback-arena.md.

How it was tested

Base: 41adb55167fa778fcaa5dc36fa18a1fa8dacd657 (still upstream main when preparing this PR).

Hardware/profile: Windows, RTX 4070 Laptop 8 GiB, 32 GiB system RAM; Series S, 640x360 internal / 1920x1080 output, DLSS Ultra Performance, frame generation off, RT builder off. Optimized Cargo diag builds with and without the diagnostics feature. No shader translation changes; wave-size validation is not applicable.

  • cargo check --locked -p victory-gpu --all-features: passed.
  • cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1: 1008 passed, 2 failed, 66 ignored. The failures are compose::tests::bgrx_plane_selects_a_typed_view and shader_cache::tests::every_switch_of_the_translator_is_in_the_key; both were reproduced on clean main..
  • Pool filter: 29 passed, 4 ignored. The new final-release regression failed before the fix because the pool mutex was held, then passed for allocation, idle trimming and allocation-backoff paths.
  • Isolated staging_reuses_completed_uploads_without_a_timed_quarantine: passed on the GPU, including pending-copy protection and zeroed reuse after completion.
  • levels_on_demand_on_the_card and levels_reuse_resident_tiles_at_budget: passed on the physical GPU with Windows Graphics Tools / D3D12 debug layer, reported tiled-resources tier 4. Heap-reservation coverage also passed on the adapter.
  • Held-mip adapter regression: exact mip bytes after coarse creation and fine-level regrowth with tiles off/on; reserved-resource base and identity preserved. It failed with tiles enabled before the fix.
  • Memory-pressure reclamation/regrowth byte checks passed with synchronous and relay paths. Replay's picture/buffer comparison passed; the debug layer still emits the same baseline error IDs (538, 1003, 527), so this is not a clean-debug-layer claim for the whole renderer.
  • Benchmark failure-parser Pester regression passed. git diff --check and staged asset policy passed (22 text files).

Game observations, not a matched FPS A/B: the 15.6-minute walk with the held-mip fix reached 5,412 MiB local usage after warm-up and remained at least 1,242 MiB below the OS budget in that interval; staging ended at 192 MiB. A separate clean-base walk retained 1,408 MiB staging and reached 8,019 MiB local usage against a 6,983 MiB budget. Routes/cameras diverged, so these do not establish a percentage speedup. The final pool-release build completed a short muted smoke run: 4,799 MiB local usage / 7,180 MiB budget at the end, median 16.7 FPS, no untranslated shaders, refused host pipelines or crash-log entries. Runs ended through the harness, on copied saves.

Known checks/limitations: full workspace tests stop at the three BCPack oracle-parity failures also reproduced on clean main. Strict default/all-feature Clippy fails in unchanged upstream code; a warning-only audit is not a passing strict gate. Full-tree asset policy reports the existing hex-literal run in victory-loader/src/heap_sites/frame_users.rs; the staged patch passes. Dark character textures reproduce on both baseline and candidate. Ground-level city traversal and other GPUs are unverified. Memory growth while visiting new areas is not sufficient evidence either for or against a leak.

Checked for overlap

Implemented and tested with OpenAI Codex. No game assets, executable bytes, captures, shader dumps or private run logs are included.

Pool readback leases and submission scratch, retire completed staging
without a timed quarantine, and reserve actual texture heap growth.
Preserve ordinary held mip levels with tiled resources enabled, release
empty blocks outside pool locks, and index occupied descriptor owners.

Add regression coverage and document ownership, pressure, and validation
limits. Keep memory deferrals retryable in both rendering and diagnostics.
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-fix] Bound GPU resource pools and preserve held mip levels with tiles Bound GPU resource pools and preserve held mip levels with tiles Nov 30, 2026
@1mosce
1mosce marked this pull request as ready for review November 30, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant