Repository navigation
Conversation
Before every CreateHeap in the texture pool, check whether adding one more 64 MiB block would push the card's current use past 95 % of its DXGI budget (LEONIDA_VRAM_GUARD_PCT, 80–99; default 95). If so, return None from the block-maker so the pool falls back to the non-pooled path rather than allocating over budget. pool::room() already receives [budget, used, ..] from QueryVideoMemoryInfo once a second; the new VRAM_BUDGET/VRAM_USED atomics cache those values at zero cost so vram_block_refused() needs no extra API call on the hot path. On 8 GiB cards (RTX 3060 Ti budget ≈ 7.8 GiB) the guard engages above ~7.4 GiB, preventing the over-budget MakeResident delays of up to 961 ms documented in pool.rs and the device losses reported on those cards (driver fault ~7 min, device removal ~9 min into a session). The six pre-existing compile errors in leonida-gpu (toggled, texture, host, behind, line_on, host_resource) are unrelated to this change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KVBEuPKuxL62bomCJgwLg
KelboLive
left a comment
There was a problem hiding this comment.
Two P0s, two different problems, and neither one does what the title says on its own.
P0.2 (pipeline stack) duplicates open #2588, which already gives pipeline workers a 64 MiB stack and adds a GetCurrentThreadStackLimits test plus a Wine guard. Please drop this half and land #2588 instead — 18 workers × 64 MiB is ~1.1 GiB committed under Wine, which is exactly what #2588's guard avoids.
P0.1 (VRAM guard) does not cap VRAM. A refused block falls straight through to a per-texture committed allocation of the same resource (pool.rs:896-898 → resource.rs:3329, via the miss at :3294-3306), so the bytes are still spent and peak is unchanged — only the allocation path changes. Worse, VRAM_USED is written only in room() (pool.rs:50-52), called once a second from sweep() (host.rs:518-532), and is not incremented when a block is approved: between samples the guard re-approves against the same stale value, so one interval can create many 64 MiB blocks past 95 %. Staging (pool.rs:676), small, shadow/targets and buffers are ungated entirely. And LEONIDA_SWEEP=0 or a failed DXGI query leaves VRAM_BUDGET == 0, silently disabling it.
Neither change targets the failure mode we measured on this machine: the device removal is a driver-requested adapter PnP stop, not memory exhaustion — LEONIDA_D3D12_BACKGROUND=0 roughly doubles survival, while a 95 % threshold and a bigger thread stack do not address it. That does not mean the PR is wrong, but "P0 stability fixes for 8 GiB cards" needs an A/B run (or logs) showing which failure it removes; the 7–9 minute result is one card and two confounded changes.
Two concrete gaps:
- No test covers
vram_block_refused: disabling its decision leaves all 17 pool tests green. A pure threshold test (likespares()) would pin it. d3d12/docs/switches.mdwas not regenerated:tools/d3d12_switches.py --checkreportsLEONIDA_PIPELINE_STACK_MIBandLEONIDA_VRAM_GUARD_PCTmissing. Run--outbefore merge.
No image-quality risk in the fallback (identical D3D12_RESOURCE_DESC), and larger cards are safe; the real cost is that a card legitimately near budget abandons the pool it exists to use, with growth_failed throttling retries for 500 ms, so expect stutter rather than reuse at the margin. Merge is textually clean, and #2900/#2851 raise title allocations, which would push this guard into that fallback sooner.
|
Thanks for looking at 8 GiB cards, that's a real problem (I test on an RTX 4070 Laptop 8 GB). A review before anyone can merge this, read from the diff on head
AI-assisted review (Claude Code agent |
|
Live texture-pool and worker-stack check on
MEASURED with synthetic inputs. AI-assisted with OpenAI Codex and a separate read-only review. |
LoadPipeline returns ERROR_INVALID_PARAMETER (0x80070057) for pipeline state stream subobject types the driver cannot round-trip through the library (mesh shaders on NVIDIA, some compute variants). Previously these pipelines were stored anyway via StorePipeline, corrupting the library file: on the next session LoadPipeline rejects the stored entry with the same 0x80070057, forcing a recompile, and the driver may read zeroed pages from a replaced mapped file and remove the device with DXGI_ERROR_DRIVER_INTERNAL_ERROR (documented in library.rs lines 43-50). Fix: detect 0x80070057 on load and skip StorePipeline for that pipeline. The library file stays clean; the driver's own PSO cache handles these pipelines across sessions as before. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KVBEuPKuxL62bomCJgwLg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KVBEuPKuxL62bomCJgwLg
d463b6b to
686c112
Compare
|
Cache regression on the updated head with a working pipeline library Recording the actual API results on I then restored only MEASURED with OpenAI Codex and a separate read-only review. |
KelboLive
left a comment
There was a problem hiding this comment.
Re-checked 686c1124c. Two of the four are resolved:
- Point 1 fixed. The stack half is gone —
make.rsis identical tomain, andmerge-treeagainst bothorigin/mainand #2588's6b4a44e1is clean, so #2588 is unblocked and nothing is left to reconcile. - Point 4 fixed.
tools/d3d12_switches.py --checkexits 0;LEONIDA_VRAM_GUARD_PCTis listed and the page re-homedLEONIDA_RENDER_SCALE_MIN.
Two are unchanged, and they are the substance:
- The guard still does not cap peak.
pool.rs:590-605decides fromVRAM_USED, written only inroom()(pool.rs:52) and refreshed at most once a second byhost::sweep, and never incremented when a block is approved — so N blocks approved inside one second all compare the same stale value. A refusal atpool.rs:896makestake_texture(..)?returnNone, andresource.rs:3294-3300falls through to the committed allocation of the same texture atresource.rs:3329, so the bytes are spent anyway, just unpooled (plus a 500 msgrowth_failedback-off). Staging, small, shadow and targets remain ungated. vram_block_refusedis still untested. Forcing its decision tofalseleaves all 17pool::tests green.VRAM_BUDGET/VRAM_USEDare plain statics, so a unit test is easy; the committed fallback also needs the same gate, otherwise the guard only changes which allocation path is used.
Separately, the new pipeline/library.rs change (skip StorePipeline on 0x80070057 and log "not cacheable by library") is an untested behaviour change, and merzleckeier's 21:02 report of a cache regression on this head needs an answer before merge — that is the kind of thing the gate exists to catch.
pipeline/library.rs: the previous fix checked LoadPipeline's E_INVALIDARG to skip StorePipeline, but LoadPipeline always returns E_INVALIDARG for a cold miss (name not yet in cache). This meant nothing was ever stored and the cache was broken. Fix: always call StorePipeline; only skip if StorePipeline itself returns 0x80070057 (the driver refuses to cache this subobject stream type, e.g. mesh shaders on NVIDIA). pool.rs: VRAM_PRESSURE was only triggered by vram_block_refused() when a new block was requested. But VRAM can be over budget from committed fallback allocations without any new block request. Fix: room() now also triggers aggressive eviction when used > budget * pct/100 on every sweep tick, so sustained over-budget VRAM is drained every second. Also extracts vram_guard_pct() so the PCT OnceLock is shared between room() and vram_block_refused(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012KVBEuPKuxL62bomCJgwLg
|
Independent verification on an RTX 4090, driver 621.24 (Windows 11) - by the It applies cleanly ( 1. The second P0 in the body is not in the code. The body says:
The branch touches no That is also the half with the interesting NVIDIA claim (the 2. Its own stat says
3. A new clippy warning: Two questions I could not answer without an 8 GiB card, and would like the PR to address:
AI-assisted: yes - DeepSeek v4.1 (flash). Written with an AI assistant. |
Claimed in the coordination issue as: n/a
Depends on: none
Fixes: none
What and why
P0.1 — VRAM guard (
pool.rs): refuse new 64 MiB texture heaps whenused + BLOCK > budget × 95%. Prevents over-budget MakeResident delays(up to 961 ms) and device losses on 8 GiB cards at ~7–9 min.
Configurable via
LEONIDA_VRAM_GUARD_PCT(80–99, default 95).P0.2 — Pipeline stack (
pipeline/make.rs): give each pipeline worker64 MiB stack instead of OS default 2 MiB.
nvgpucomp64.dlloverflowsat ~7 min on Ampere/Wave32 (RTX 3060 Ti). Matches upstream PR #2588.
Configurable via
LEONIDA_PIPELINE_STACK_MIB(2–256, default 64).Tested
GPUs tested: NVIDIA RTX 3060 Ti, 8 GiB VRAM, Windows 11
AI-assisted: yes
Checklist
mainand merges cleanlydocs/design.md, with how it was confirmed.