fix(gpu): by_address leaks its cap and inflates WINDOW_CARD_BYTES #2981
Closed
leonida/mandy
Luislariosss wants to merge 0 commits from
fix/p2a-bvh-accounting into main
pull from: fix/p2a-bvh-accounting
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2981
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/p2a-bvh-accounting"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: D3D12-GPU-BY-ADDRESS-ACCOUNTING (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7327718532)
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).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.
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.
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).
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).
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
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.
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.
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.
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.