Skip to content

Bound texture metadata and read buffers; fence presentation teardown - #3966

Open
1mosce wants to merge 2 commits into
trustno1-coder:mainfrom
1mosce:codex/owned-memory
Open

1mosce wants to merge 2 commits into
trustno1-coder:mainfrom
1mosce:codex/owned-memory

Conversation

@1mosce

@1mosce 1mosce commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Cached placed-texture identities and per-worker read buffers can retain their high-water marks indefinitely. This gives texture identities explicit owners through GPU use, collects unused metadata, bounds idle CPU read storage, and fixes a swap-chain buffer being released while a preceding Present still uses it.

Stacked on #3828; merge that dependency first. The new commit is 46fe6f81330507adbd9e9008c82114c1521490a1, on top of de352e668a3c62ce68d3706909c769ba1676ffac. Upstream main was refreshed before publication and remains 41adb55167fa778fcaa5dc36fa18a1fa8dacd657. Until #3828 lands, GitHub's main comparison includes both commits.

What it changes

  • Adapt the portable ownership/cache changes from lobomfz/VIctory-xmem 9f573f8e, using this renderer's existing Held type. Lookups retain under registry locks; placed views, upload jobs/preludes, list identity keys, and mirror/ambient lookups keep resources alive for their use. List keys release ownership after submission completion and reset.
  • Collect only cache-owned placed metadata with no host copy and no GPU-written contents. The 65,536-entry target (16,384 under host-RAM pressure) is a soft limit. Each maintenance pass checks at most 8,192 entries, releases at most 256, unlocks every 128 checks, and destroys objects outside registry locks. Recreating view metadata does not invalidate readback of a surviving title allocation. Remove the unbounded diagnostic raw-description set.
  • Index filled textures with a host copy for eviction scans; update the index on creation, mip replacement, eviction and destruction. This is a host-copy index, not a claim about DXGI residency.
  • Keep at most 64 KiB of read scratch per worker and two shared buffers per size class, 128 KiB through 16 MiB: 63.75 MiB idle retention. Larger reads are transient; active concurrent leases are separate from this cap. Allocation, reads and excess frees happen outside pool locks.
  • Fence the queue after preceding presents before swap-chain resize or teardown. The former rendering fence preceded Present and did not cover its queued work. Ordinary frames acquire no extra wait. The packed-format presentation regression covers format transitions and teardown.
  • Include the preceding copy-path work used by the tested candidate: bounded range/epoch invalidation, with writes still recorded when guard shortcuts apply; opt-in grouped small-read gathering; and opt-in raw CBVs in their original descriptor slot on 1M-descriptor adapters, including byte/halfword lowering and resource retention. VICTORY_CARD_STEPS_GATHER and VICTORY_PORT_CBV remain off by default. The raw-CBV path overlaps fix(gpu,shader): support VICTORY_PORT_CBV=1 on capped 1M-descriptor GPUs (raw_views == 0) and fix subword raw CBV load #3396 and must be reconciled if both are merged.

VICTORY_PLACED_OBJECTS=0, VICTORY_RESIDENT_SWEEP=0 and VICTORY_READ_POOL=0 disable the corresponding memory policies for comparison; ownership guarantees remain enabled. See docs/owned-texture-memory.md for lifetime and lock-order rules.

The Linux RADV/Wine/vkd3d alias-mapping backend is not ported here. This does not remove every shadow copy or establish complete VRAM leak remediation.

How it was tested

Windows, RTX 4070 Laptop 8 GiB / 32 GiB system RAM, Series S, DLSS Ultra Performance, frame generation off. Optimized diag builds with diagnostics. The archived game candidate SHA-256 is D67AB69545113A1A3922E3405E968CDEAF22B1FA34652D71698B2856B3578DB6; the published source was checked against its frozen source patch before committing.

  • Eight new ownership/collection/index/read-pool tests passed, including actual GPU submission/reset and mip replacement, concurrent disjoint reads, all retained size classes, oversized reads and unwinding.
  • All-target/all-feature Cargo check passed. Warning-only Clippy passed; strict Clippy remains failing on three existing shader issues. It is not a passing strict gate.
  • Final GPU suite with the D3D12 debug layer: 1020 passed, 3 failed, 68 ignored, with no fatal exception. Two failures are the existing BGRX typed-view expectation and obsolete VICTORY_SCALAR_SPLITS key test. The pool test consumed an earlier invalid-pipeline-library InfoQueue message; its fresh-process debug rerun passed. The full renderer/debug suite is not claimed clean.
  • Before the presentation fix, the debug layer raised message 921, OBJECT_DELETED_WHILE_STILL_IN_USE, and exception 0x87D inside ResizeBuffers, also with the new memory policies disabled. Afterward the isolated packed-format test passed with no D3D12/DXGI errors, and it passed in the final full suite.
  • Prior checks of the unchanged copy/CBV additions: 24 card-step tests including GPU byte comparisons; descriptor cases with PORT_CBV off/on, 73 passed and 1 ignored each; shader library suite, 462 passed and 9 ignored. Generated raw-CBV execution cases passed. Separate end-to-end Wave32 and Wave64 gameplay qualification was not performed.
  • Three muted six-minute indoor runs completed without crash-log entries: candidate, prior copy/CBV build, and candidate with metadata collection disabled. Each used the same copied save and timed input schedule, with two minutes of warm-up followed by four measured minutes. Candidate collection released 24,688 entries; idle read-pool storage stayed within 63.75 MiB.
  • Candidate/control median frame lines were 61.65/72.45 ms and p99 was 143.3/205.2 ms, but camera positions, interactions and draw counts diverged. These are not a matched FPS improvement claim. Copy preparation still costs about 39 ms. The opt-in gather and CBV experiments also have no established gameplay FPS benefit.
  • git diff --check and the actual staged asset policy passed for all 19 new-commit text files. Full-tree policy still finds the unchanged long hex run in victory-loader/src/heap_sites/frame_users.rs.

Remaining limits: dark arm/neck artifacts persist, including with metadata collection disabled; visual equivalence has not been established. City traversal, other GPUs and an extended leak/soak test remain unverified. The normal local executable was not replaced.

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 texture metadata and read buffers; fence presentation teardown Bound texture metadata and read buffers; fence presentation teardown Nov 30, 2026
@tyr0nsur

Copy link
Copy Markdown
Contributor

I tested a small follow-up on top of 46fe6f8 to let the CPU texture-read pool give memory back after a burst. The current cap is 63.75 MiB across eight classes, and idle buffers stay cached after streaming subsides. The follow-up ages each slot from its return to the pool. The existing host sweep releases slots idle for 10 seconds, or 2 seconds under host memory pressure. A hot slot can still be reused and a checked-out buffer remains owned by its reader. Frees happen outside the bin mutex.

In three fresh-process A/B runs on Windows, I touched two buffers in every size class and advanced the test clock to the pressure sweep. Idle pool bytes stayed at 63.75 MiB on this PR head and fell to 0 with the follow-up. Windows private commit fell by about 62.9 MiB from the filled state in each patched run. This is an isolated CPU-memory measurement. In-game frame time and VRAM still need separate measurements.

The diagnostic build passed 17 texture tests on the RTX 4060 and 17 under WARP, plus 21 related residency, spare-cache and readback tests. The new regression exercises a cold slot alongside a warm slot in the same bin, a sweep while a lease is active, and a sweep whose timestamp predates a return.

The tested, cherry-pickable commit is tyr0nsur@28ea2fd.

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.

2 participants