D3D12-GPU-BOOK-NEIGHBOURS-U64-MAX: prevent u64::MAX overflow and wrap in Book::neighbours #3005
Open
github-bot
wants to merge 1 commit from
github-bot/gh-3005 into main
AGit
pull from: github-bot/gh-3005
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!3005
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3005"
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?
@bobcatchris on GitHub · 2026-12-01 23:17 UTC · original
bobcatchris:fix/d3d12-gpu-book-neighbours-u64max→main· +21 −6 · 1 files · 1 commits · openFixes
D3D12-GPU-BOOK-NEIGHBOURS-U64-MAX(claim comment 7328994859).Summary
Book::neighbours(d3d12/crates/leonida-gpu/src/book.rs): Replacedself.by_start.range((at + 1, 0)..).next()withat.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next()). Callingneighbours(u64::MAX)(for instance fromat_loss(u64::MAX)) previously panicked with integer overflow in debug builds or wrapped to(0, 0)..in release builds and returned the lowest live allocation as the upper neighbour.bases(base.saturating_add(bytes.saturating_sub(1))),walksuspect expiry (s.2.saturating_add(400)), andat_losswindow length calculations (e.start.saturating_add(e.size).saturating_sub(base)and.saturating_add(64 << 10)) with saturating arithmetic so extreme addresses/timestamps cannot panic or wrap.neighbours_handles_u64_max_without_overflow_or_wrap.Verification
Book::neighbours(u64::MAX)panicked in debug (RED_BOOK_EXIT=101, attempt to add with overflow).cargo test --package leonida-gpu --features diagnostics --lib book::tests->4 passed; 0 failed(including GPU testa_pooled_texture_and_its_block_are_in_the_bookon RX 7900 XTX).leonida-gpucompile &tools/d3d12_switches.py --checkexit0.APPROVE).AI-assisted
@andrew-ai on GitHub · 2026-12-01 23:20 UTC · original
Verified the neighbour lookup at
a708b08fdagainst an independently sorted list of live entries. I compiled the unchanged Book add/remove/neighbours methods from parent and head. The matrix included duplicate starts at 0 and u64::MAX, interior gaps, and removals of the most recent and older entries sharing an address.With one live entry at zero, the parent panicked on a u64::MAX query with overflow checks enabled. With checks disabled it returned that same entry as both neighbours. The PR matched the reference on all 130 lookups in each build, including after removing entries at the maximum address. This checks the indexed lookup only. Codex-assisted.
@imShangLi on GitHub · 2026-12-02 07:56 UTC · original
VERIFY-3005 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game files
Verdict: PASS, with one thing the maintainer should know about the test's reach. The change fixes a real overflow in
Book::neighbours(a panic in a debug build, a wrapped address in a release build) and makes three other arithmetic spots saturating. The new test fails on the merge base with exactly "attempt to add with overflow" and passes with the pull request; nothing regressed. The thing to know:book.rsis behind#[cfg(all(windows, feature = "diagnostics"))], and the repository's CI runscargo test --workspace --lockedwithout that feature, so the new test is never executed by CI as the workflow stands — it only runs when someone builds the crate with--features diagnostics(I had to use a scratch copy of the harness to do that).head
a708b08fdc5283d56da3ea04217ec280953d9dcf("d3d12/gpu: prevent u64::MAX overflow/wrap in Book::neighbours and loss spans"), baseorigin/main=0ae5a2664b9cd2fd30abfb1f6096f1c07b030f39, merge base1abef08d09f6c085efbd47de4cc9e2010bb70793(124 commits behindmain;book.rsitself has not been touched onmainsince that merge base, so the diff still applies tomain'sbook.rsunchanged). One file, +21/−6:d3d12/crates/leonida-gpu/src/book.rs.1. What it changes
book.rsis the diagnostics-only book of what the title has mapped (lib.rs:52:#[cfg(all(windows, feature = "diagnostics"))] mod book;). Four arithmetic expressions are made overflow-safe:Book::neighbours(at)(book.rs:149) — the important one. Old:let above = self.by_start.range((at + 1, 0)..).next();. Withat == u64::MAX,at + 1overflows: a panic ("attempt to add with overflow") in a debug build, and a wrapped0in a release build, which would then ask for "the entry starting at or above 0" — a completely unrelated entry. New:let above = at.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next());— atu64::MAXthere is no address above, so the answer is "no entry above".neighboursis whatat_loss(va)uses to answer "what was at this address" for a faulting address.bases()(book.rs:474) —base + bytes - 1becomesbase.saturating_add(bytes.saturating_sub(1)), for the "buffer's end" entry. Thebytes - 1underflow is unreachable in practice (decodereturnsNames::Nothingfor a zero-length buffer, book.rs:432), and thebase + bytesoverflow is conceivable only for a descriptor whose base sits at the top of memory; the change makes both harmless.walk()(book.rs:527) —now >= s.2 + 400becomesnow >= s.2.saturating_add(400).s.2is a timestamp in milliseconds, so the overflow is unreachable; the change is defensive.at_loss()(book.rs:626-634) —e.start + e.size - basebecomese.start.saturating_add(e.size).saturating_sub(base)(twice), andlen.unwrap_or(64 << 20) + (64 << 10)becomeslen.unwrap_or(64 << 20).saturating_add(64 << 10). Same values in every reachable case; no overflow.So one change fixes a reachable bug and three make unreachable arithmetic safe. All four are in the file's own style (the file already uses
saturating_*andchecked_*elsewhere).2. The new test checks the property that matters
book::tests::neighbours_handles_u64_max_without_overflow_or_wrapis exactly the property that was broken:u64::MAXthere is no address above, so "no entry above" is the correct answer — and it is the answer the release build of the old code got wrong (it wrapped to 0 and would have reported the entry at the lowest address). The first assertion also checks that the fix did not break the ordinary case: the entry at0x1000_0000is still the one belowu64::MAX.The test body really runs here; it is not a no-op. I built the red side alone (merge base + the PR's test hunks) with
--features diagnosticsand ran the new test by name under Wine (lane/red_3005.log): the binary reported1 failed; 784 filtered outwithLine 149 column 42 is the
at + 1ofself.by_start.range((at + 1, 0)..)— the overflow the pull request removes. The test needs no GPU, no device and no game files: it is aBook(a map of what the title mapped) built in memory.What the test does not cover. The other three changes (
bases,walk,at_loss) have no test; onlyneighboursis tested. That is defensible — they are unreachable arithmetic — but it means a future edit could reintroduce a non-saturating expression there without any test noticing.The test's reach is limited by the feature gate.
book.rsis compiled only with--features diagnostics, so this test exists only in that build. The repository's CI (d3d12/.github/workflows/ci.yml) runscargo test --workspace --locked(line 33) with no features, so thebookmodule — and this test — is not part of the test run CI does. The only CI job that compiles it is the clippy job with--all-features(line 30), which compiles but does not run the test. The new test therefore never fails onmainin CI, and never passes in CI either: the maintainer's checklist item "a new test that fails onmainand passes with the pull request" is satisfied in the source but is not exercised by the workflow. Moving the test out of the gated module, or adding--features diagnosticsto the test job, would close that gap.3. What the tests do here
The crate has to be built twice for this pull request to mean anything, because the whole change lives behind a feature gate. I cross-compiled for
x86_64-pc-windows-gnuand ran the test binaries under Wine in both builds.With
--features diagnostics(the build in which the change exists) —python3 tools/wine_red_green.py 3005 --crate leonida-gpuwith a scratch copy of the harness that accepts--features(/tmp/opencode/wine_rg_feat.py; the same red-side rule as the repository'sscripts/red_green.py):1abef08d+ the PR's test hunksbook.rs:149:42a708b08f(PR head)The tool's verdict: "red then green" — 1 red→green (the new test), 0 regressions, 4 failing on both sides, 722 passing on both sides, no test on one side only.
With the default feature set (what CI runs) the
bookmodule is not compiled at all, so there is no book test on either side: the plain run is 703 tests per side with nobook::test among them. I checked the two sides of that build by hand as well, running the base's and the head's test binary under Wine single-threaded:1abef08d(plain)watchtests)a708b08f(plain)watchtests)Identical. That is what one expects: the pull request's whole diff is inside
#[cfg(all(windows, feature = "diagnostics"))] mod book;, so in the default build the change is not compiled at all and cannot alter anything.4. Any failure I saw and why it is not this PR
diagnosticsbuild:timeline::report::tests::real_waits_are_recorded_with_who_ended_them,watch::many_askers_tests::holes_are_known_until_the_runtime_tells,watch::many_askers_tests::no_mapping_is_lost_between_askers,watch::tests::what_is_left_alone_is_no_known_hole. None of them is inbook.rs, which is the only file this pull request touches; the threewatchones fail identically on the base of the other three pull requests I verified (same merge base family) and are environment failures of the guard-page machinery under Wine without a real GPU.timeline::report::tests::real_waits_are_recorded_with_who_ended_themis a timing-sensitive test that also fails on the base (it is one of the four "fail on both sides" of the run).tools/wine_red_green.py 3005 --crate leonida-gpusat in a spinningleonida_gpu-*.exefor 30 minutes and had to be killed (the tool's own timeout is one hour). I identified what it was: the binary was the red side — the base's code — and I copied it out and ran it under Wine on its own, where it finished in 14.8 s (parallel) and 38.8 s (single-threaded) with the same 3 failures as every other run. So the hang is a pre-existing flake of the base's test suite under Wine, in code this pull request does not touch and, in that build, does not even compile into. An earlier run of the same command reported the verdict "NOT red-then-green" with threewatchregressions, which the repeat runs show to be the usualwatchflakiness (those same tests fail at the same rates on the base).main. The reviewer checklist asks formainto be merged into the branch before merging, and that is the maintainer's step, not the author's. I checked thatmainhas not changedbook.rssince that merge base (0 commits touch it), so the diff still applies tomain'sbook.rsas it stands; I did not mergemaininto the branch and did not test the merged result.5. What I did not check
cargo test --workspace --locked) is read fromd3d12/.github/workflows/ci.yml; I did not run the workflow itself, and I did not check whether some other job in the repository runs the crate's tests with the feature enabled.bases,walk,at_loss) are unexercised by any test, here or in the pull request; I checked them by reading and by reasoning about where their operands come from (decode, a millisecond timestamp, mapping sizes), not by measurement.book.rsexists to explain a faulting address in a running title ("what was at this address"). I could not check that the diagnostics answer is right for a real fault at the top of the address space, only that the arithmetic no longer overflows.cargo test --target x86_64-pc-windows-gnuunder Wine 11.21 on Fedora 45, in both the default and thediagnosticsfeature set. The release-build half of the "no wrap" claim (the old code wrapping to 0 instead of panicking) is reasoning from the code — I only ran the debug build.at_losstext output: the change alters only the arithmetic inside the string the diagnostics print; I did not compare the printed text before and after for any address.leonida-gpuwas, because the change is confined to it.Depends on:line) was not read: I was asked not to touch GitHub.@MoonEyes on GitHub · 2026-12-02 18:02 UTC · original
Code review only, not built (Windows-only
leonida-gpu). Ready.a708b08fd, merge base1abef08d0, 326 behind currentmain45dc41f95. A trial merge is clean. CI on the head: all 6 checks pass.neighbours.Review of
d3d12/crates/leonida-gpu/src/book.rs:neighbours:at.checked_add(1).and_then(..)is the root-cause fix. Atu64::MAXthere is no "above". The oldat + 1panicked in debug and wrapped to 0 in release, which returned the lowest entry as "above".bases(Names::Buffer):base.saturating_add(bytes.saturating_sub(1))also coversbytes == 0, which underflowed before.walk(s.2.saturating_add(400)) andat_loss(saturating_addandsaturating_subon extents) are defensive. They only run on the device-loss and diagnostics path, so the cost does not matter.neighbours_handles_u64_max_without_overflow_or_wrappins the real bug. The other saturating spots have no test, which is acceptable for diagnostics arithmetic.Verdict: ready.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@MoonEyes on GitHub · 2026-12-02 22:01 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).
@fiestorra on GitHub · 2026-12-02 22:13 UTC · original
VERIFY-3005 — Windows nativo:
red then green, y el módulo solo existe con la featurediagnostics(this PR)1abef08d0(well behindmainb41763227)main—merge-treeclean,git merge --no-ffcleanRan
The trap that costs ten minutes and is worth writing down:
mod bookis#[cfg(all(windows, feature = "diagnostics"))](lib.rs:52). Without--features diagnosticsthe module — and this pull request's test — is not compiled at all, andcargo test -p leonida-gpu --lib u64_maxreports0 passed; 762 filtered outwith exit 0. A verifier who runs the obvious command would record "no test" for a test that exists.Negative control (synthetic — the test ships with the change, in the same file): I put the old
self.by_start.range((at + 1, 0)..).next()back and rebuilt:The test bites on exactly the arithmetic this PR replaces with
checked_add/saturating_add.What the change is, from the diff: five expressions that could wrap at
u64::MAX— a buffer's end (base + bytes - 1), a suspect's due frame, twoend - basedistances, and a size cap — now go throughchecked_add/saturating_add. The new test drivesneighbours(..)atu64::MAX. The other three tests in the module still pass.What I could not test
u64::MAX: the fixture asks the book about it synthetically; no game run, and no such address exists in a real process.diagnostics: only the module was run (840 filtered out), not the whole suite under that feature.Written with an AI assistant.
@EdenBendheim on GitHub · 2026-12-03 11:48 UTC · original
RUN (in game, RTX 3090 24 GB) — stock compatibility PASS, with two earlier present-gap failures retained.
a708b08fdc5283d56da3ea04217ec280953d9dcfmerged locally onto main6e979905054be3ba9737883fe8e205501a2183b7as9f07ff0f6e1585a0007a80c544db11b4e629092e. Executable SHA-25694caed878bc47034257cf09a76a4d7585aab73dc9163fcc162ec787403f4f0e9, diagnostics,dlss,mimalloc. Clean-room scan passed.LEONIDA_BOOK=1in all runs. Stock gate.The initial two runs accidentally copied the large pipeline seed into the cache root rather than its expected pipelines subdirectory, so they were effectively cold. The third run corrected the seed layout. It measured 3,119 present intervals from world+60 s, p5 FPS 5.98, p95/p99 167.36/350.15 ms, VRAM peak 5,058 MiB against 23,558 MiB budget. All three completed a target stop and actual clean exit; no loss marker.
Book activity was confirmed in the first two runs by 143/131 slot-check rounds, with alive/gone counts advancing 21/1→11135/2496 and 19/1→11902/2941. The third run had Book enabled but no slot-check telemetry. Initial native placement succeeded in the first two legs and was later lost; control and placement were not established in the third. This is renderer compatibility evidence with those limitations; workload, cache and instrumentation differ, and no matched main live control was run.
Synthetic red/green: all four diagnostics book tests passed before and after restoration. Replacing only the checked neighbour increment with the old increment made the exact maximum-address test panic with integer overflow (exit 101); fixed source restored byte-for-byte then four passed. The conditional pooled-texture ownership assertion had no reported address on this NVIDIA adapter, so that assertion was not exercised. No real hardware fault was induced.
AI-assisted: Codex GPT-6.2 Sol (tester and independent numerical verification). No game content attached.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.