fix(gpu): by_address leaks its cap and inflates WINDOW_CARD_BYTES #2981
Closed
github-bot
wants to merge 1 commit from
github-bot/gh-2981 into main
AGit
pull from: github-bot/gh-2981
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2981
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2981"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Luislariosss on GitHub · 2026-12-01 22:22 UTC · original
Luislariosss:fix/p2a-bvh-accounting→main· +297 −25 · 1 files · 1 commits · closed without mergingClaimed in the coordination issue as: D3D12-GPU-BY-ADDRESS-ACCOUNTING (#2570)
What and why
shadow::by_address()kept the card-memory cap (LEONIDA_MEMORY_CARD_MB) in a function-localUSEDcounter:uav_buffer()returnedNone, so headroom leaked for the rest of the session;WINDOW_CARD_BYTES, so by-address copies ateLEONIDA_CARD_WINDOWS_MBand the window roomcard_room_kept()keeps for real windows.This moves the counter to module scope (
BY_ADDRESS_USED), reserves it withfetch_update+checked_add(rollback only when the allocation fails) and releases it on drop.Card::account(CardAccount) picks which counterDropreleases, so a shadow cannot be in two accounting buckets at once. By-address arenas no longer touchWINDOW_CARD_BYTES;BY_ADDRESS_USEDis included inlive_span_bytes()andcard_stats().Behaviour change, both behind opt-in switches: by-address arenas no longer consume
LEONIDA_CARD_WINDOWS_MBnorcard_room_kept(), and PC-memory fallbacks drop out of the span and the card stats.Tested
cargo test -p leonida-gpu --offline --lib -- --test-threads=1: 647 passed, 0 failed, 59 ignored.cargo test -p leonida-gpu --offline --lib --features diagnostics -- --test-threads=1: 728 passed, 0 failed, 59 ignored.cargo clippy -p leonida-gpu --all-targets --offline: clean (one pre-existing warning outside this file).New tests: cap boundary (
used + len == most),u64::MAXoverflow, rollback, all fourCardAccountvariants on release and drop;land_testsnow balancesCARD_BYTES[0]; the shared counter tests take one lock so they can run in parallel.GPUs tested: n/a (unit tests only; no in-game run).
AI-assisted: yes — implementation and review by coding agents, reviewed by the submitter.
Checklist
mainand merges cleanly (rebased onc4ca5761).@andrew-ai on GitHub · 2026-12-01 22:27 UTC · original
Verified the cap and fallback through by_address() with actual D3D12 allocations on an RTX 5070, driver 616.92, at
b020637ac. I set LEONIDA_MEMORY_CARD_MB=1 in a fresh process and requested three 1 MiB arenas backed by distinct synthetic CPU ranges.The first arena used card memory. The second used the shared fallback while the first was held. Dropping the first returned BY_ADDRESS_USED, live_span_bytes() and card_stats()[8] to zero even with the fallback still live. The third arena then used card memory. Dropping the fallback left all three counters at 1 MiB, and dropping the third returned them to zero. WINDOW_CARD_BYTES stayed zero throughout. I checked the actual CardAccount selected for each allocation and resolved the card name from the D3D12 device LUID.
This covers exact-cap allocation, fallback, and reuse on hardware. The test used small allocations to exercise the configured cap. Codex-assisted for #2570.
@merzleckeier on GitHub · 2026-12-01 22:31 UTC · original
Real by-address allocations regain the device heap after dropping the previous allocation.
I called production
by_addresswithLEONIDA_MEMORY_CARD_MB=1on mainc4ca5761andb020637ac09182f12fe0e8f70e279666e27b3676integrated with #2975. The testedshadow.rsis identical with #2981 alone, and the D3D12 trees match after merging current main1abef08d. Three fresh runs per tree and GPU agreed on RTX 4070 SUPER (620.73.4) and AMD Raphael (RADV 26.3.1), with Wine 11.22 and VKD3D-Proton 3.1.0.With the first two live, main added 1,310,720 bytes to both window and total live-span accounting. The PR added zero window bytes and counted 1,048,576 bytes in the aggregate. Oversized shared fallback added no card bytes on the PR, and all deltas were zero after drops. The three stock by-address tests passed on each GPU.
The test uses actual D3D12 resource heap properties at a small configured cap, with the separate DXGI video-memory budget check satisfied. AI-assisted, independently checked against the raw results.
@MoonEyes on GitHub · 2026-12-02 12:34 UTC · original
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
@Kal0s-design on GitHub · 2026-12-02 14:41 UTC · original
Ran natively on Windows 11, head
b020637acmerged into currentmain(69cd4106c, merges cleanly and builds;maingained the ray tracing commits inshadow.rssince this was rebased), on WARP and on one NVIDIA desktop card. The earlier comments covered a few arenas on hardware. This adds the suites on the current merge and two throwaway stress tests (not pushed) that call the realby_address()thousands of times, including from 8 threads at once.Suites on the merge
cargo test -p leonida-gpu --lib(default features), WARPcargo test -p leonida-gpu --lib --features diagnostics, WARPby_addresstests, WARP and NVIDIAcargo clippy -p leonida-gpu --all-targets --features diagnosticsshadow.rsThe failures are unrelated to this PR. Two texture
aheadtests passed when rerun alone.timeline::report::tests::real_waits_are_recorded_with_who_ended_themandframe::tests::waits_end_on_ticks_and_count_framesfailed when rerun alone, and they fail the same way onmainalone on this machine right now. The merge only changesshadow.rs.Stress through the real
by_address(),LEONIDA_MEMORY_CARD_MB=8, each test alone in its own process, 2 runs each on WARP and NVIDIANoneBY_ADDRESS_USEDWhat I checked after each allocation and at the end:
BY_ADDRESS_USED,WINDOW_CARD_BYTES,CARD_BYTES[0],LIVE,live_span_bytes()andcard_stats()[8].fetch_updatereservation never let concurrent threads overshoot. At most 8 card-side 1 MiB arenas were live at once, a lower bound I counted from the test side.WINDOW_CARD_BYTESstayed at 0 for the whole run, card and fallback alike.BY_ADDRESS_USED,live_span_bytes()andcard_stats()[8]with 12 arenas held).Paths I looked at in the code
uav_bufferreturnsNone. If the stagingshared_bufferfails, that happens before the reservation. If the fallbackshared_bufferfails, no reservation is held. I could not makeuav_bufferfail on demand, so this path is covered only by the PR's unit test with a closure.Cardout of a liveShadow(cardis set once, at creation), so release happens only inDrop.CounterGuardwrites the three counters back to their starting values on drop. A leak inside those tests would therefore be wiped before the next test sees it. The stress tests above don't reset anything.Overlap with #3139
Both PRs edit
shadow.rs, and they conflict when merged together (5 hunks). Three hunks are only the two new test modules at the end of the file. The other two are real: #3139 moves the buffer and window copy construction out of the table locks and rewrites bothCard { .. }literals there, without this PR'saccountfield. Whichever lands second has to addaccount: CardAccount::Buffer(buffer copy) andaccount: CardAccount::Window(window). Otherwise it won't compile, andDropwould release from the wrong counter. I did not resolve or build the combination.Not checked: the in-game run requested above; the combination with #3139; a real
uav_bufferfailure; the debug layer.GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
@MoonEyes on GitHub · 2026-12-02 18:00 UTC · original
Triage of head
b020637ac(merge basec4ca57615, 329 commits behind;git merge-treeagainst currentmain45dc41f95: no conflicts).1 file:
d3d12/crates/leonida-gpu/src/shadow.rs(+297/-25).CI is at
action_requiredon this head (fork workflow approval).Existing verification: Verified on this head with real D3D12 allocations by @andrew-ai (RTX 5070), @merzleckeier, and natively by @Kal0s-design on
69cd4106c(WARP and an NVIDIA card).This check: Not re-reviewed in depth. It merges cleanly both with
mainand with #3163, the other openshadow.rschange (merge-treeof the two heads: no conflict), so the order between them does not matter textually; a combined test run after the first lands would be prudent since both touchshadow.rs.I did not build it: the crate is Windows-only (or the C++ runtime's Windows build), so no red/green was run here.
Verdict: ready (verified three times on this head; needs CI approval).
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@fiestorra on GitHub · 2026-12-03 05:20 UTC · original
VERIFY-2981 — 69 tests de
shadowpasan, y el cambio es un contador que se quedaba altoEl título: «
by_addressleaks its cap and inflatesWINDOW_CARD_BYT…» — o sea, una tabla cuyo límite de capacidad se pierde y un contador que crece de más.Y es el mismo género que cinco PRs de esta noche:
#3003,#2994,#2946,#2947,#2587— estado que se libera mal. La diferencia es que este no es unHANDLE: es una capacidad — un número que decide cuánto se reserva y que, si sólo crece, convierte una tabla acotada en una que nunca encoge.Por qué importa y por qué es difícil de ver: un contador que se queda alto no rompe nada — no hay un crash, no hay un test rojo, sólo una asignación que crece con el tiempo. En un juego de sesiones largas es el tipo de fuga que se nota a la hora y se atribuye a otra cosa. Y 297 líneas en un fichero para arreglarlo sugiere que el autor tuvo que instrumentar la tabla antes de poder verlo.
Lo que verifiqué: 69 tests de
shadowen verde con el cambio.Lo que no: la fuga de verdad — necesita una sesión con el juego cargando y descargando sombras durante horas, y ese es precisamente el caso que ningún test de 1,4 segundos ejerce. Si el autor midió el contador con el título y tiene el número antes/después, ese número vale más que los 69 tests juntos, y no está en el comentario de la PR.
@EdenBendheim on GitHub · 2026-12-03 10:16 UTC · original
RTX 3090 exact-head compatibility report — Series S/title RT passed (one completed run per arm).
PR head
b020637ac09182f12fe0e8f70e279666e27b3676was merged locally onto maind9b618f10150f275c30088e4769c1acbf1d8d689, producingbb356fc5c8145354d32b0e00fffff4e6f3a4212f(tree1e4d92f002a63d795c624d98ad2333e6b9a234f0). Nothing was pushed or merged upstream. Existing claim: D3D12-GPU-BY-ADDRESS-ACCOUNTING.Machine/recipe: Windows 11 Home build 26200, Ryzen 9 5900X, 32 GiB RAM, RTX 3090 24 GiB, NVIDIA 610.88. Rust 1.98.1; diag build with
diagnostics,dlss,mimalloc. Stock game gate and prepared local freeroam/idle driver;-SeriesS -RayTracing -NoFrameGen -NoPrecompile, 1920×1080 output,LEONIDA_MEMORY_CARD_MB=128. Separate processes, identical 10-file pipeline seeds (1,882,183,380 bytes), shared warm shader cache; the later arm inherits driver-cache warmth. Existing glyph files were used. Native control and destination readback were verified. A supported timed native teleport at 300 seconds after launch recovered placement after loading.FPS uses present intervals from world+60 seconds until the target stop (2,236 / 2,152 intervals). Both processes suspended and saved their caches cleanly. Hard-fault telemetry was unavailable.
Placement scope: Loading overwrote the candidate's first placement; the timed second teleport restored it. The final consecutive near-target suffix was 19 / 20 marks, at most 0.3 / 0.2 m from the destination, covering 188.134 / 195.749 seconds from the first such mark to stop. The 300-second world durations include time before final placement; this is not a claim of 300 seconds continuously at the destination.
Accounting mechanism: Real title structure-builder/by-address activity was observed. Final samples were 17,420 / 20,260 pages (1,088 / 1,266 MiB) in 19 / 21 arenas. The source uses 64 MiB arenas and a 16 MiB directory: the configured 128 MiB card cap permits the directory plus one arena, while total arena demand exceeded it. This exercises by-address allocation with cap pressure and fallback demand. Per-resource heap/account selection and hardware drop/reuse transitions were not instrumented; no claim of hardware cap reuse is made. The unit tests cover the cap boundary, overflow, rollback and release accounting.
Verification: Serial
shadow::diagnostics tests: 69 passed, 2 ignored, including all three by-address accounting tests. Both locked/offline builds, clean-room scan and diff check passed. Independent read-only source review found no production blocker; a separate agent recomputed the reported numbers from private evidence. The pre-existing dirty submodule was preserved.Earlier attempts retained: Main-only Series X/title RT exited
0xC0000409after 61.346 world seconds, with 138 MiB last/minimum sampled commit headroom and no reported device loss; the cause was not established. A Series S main placement-recovery attempt was deliberately stopped after 99.680 world seconds (clean exit 0) when loading moved it off route. Neither is counted as a pass. This report establishes the completed Series S compatibility passes, not Series X stability or a speed/memory improvement: one pair, different draw workloads and loading/camera behavior prevent attribution.Executable SHA-256:
e044c701e9876d2087e3f14dadf7f9427adaca4120c627d7ea6a53fb5926290aa88e9671315b2376855dd456f3c756a8da6dbddc02e1275f36cbfba224cfc163CI on this head still has three workflows awaiting maintainer approval. No game content, logs, screenshots or machine-local paths are attached.
AI-assisted testing/source integration: GPT-6.1 Sol (high reasoning). Independent read-only source and numerical review: GPT-6.2 Sol.
@merzleckeier on GitHub · 2026-12-03 10:22 UTC · original
Combined check with #3163 on current
maind9b618f10. Exact headsb020637acandf063f5b33merge without conflicts in either order and yield the same tree (e7ebf93ca986).git diff --checkpassed.The combined
leonida-gpudiagnostics build passed theshadow::suite on Wine 11.22 with vkd3d-proton 3.1.0 and AMD Radeon Graphics (RADV 26.3.1). 71 passed, 0 failed, 2 ignored. This includes the PC-memory copy-back regression from #3163. I reran the drop-accounting test with a local test-only change that makes missing D3D12 initialization or a failed buffer allocation fail the test. All four accounting cases ran and passed.This used synthetic unit tests with no game data. AI-assisted combined verification.
@Luislariosss on GitHub · 2026-12-03 17:58 UTC · original
Paused to free the one open pull request an account without write access may have, for the image work on this host. The branch stays as it is; the change was verified on hardware by two reviewers above.
Pull request closed