texture: keep pending list refreshes when an upload ahead finishes (D3D12-AHEAD-KEEP-PENDING-REFRESH) #3432

Merged
leonida/mandy
OreoFR merged 3 commits from oreofr/ahead-keep-pending-refresh into main 2026-12-04 06:41:34 +00:00 AGit

Pull request successfully merged and closed

Member

Claimed in the coordination issue as: D3D12-AHEAD-KEEP-PENDING-REFRESH (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25239)

What and why

d3d12/crates/leonida-gpu/src/texture/ahead.rs finish(): when a copy-queue upload (LEONIDA_UPLOAD_AHEAD=1) completes after listed() stopped waiting (1 s), a draw list may already have taken over the staging buffer (once set to false in upload_from) and refreshed it from newer title memory. The late completion still marked the staging buffer uploaded and clean (dirty = false) and noted the old hash as held. As a result, the newer refresh was never uploaded and the texture kept its old texels. finish() now marks it clean and notes the hash only while it is still the one-shot upload (once true). It checks under the staging's last lock, which a list's refresh also takes. The completion state (copy.ahead = DONE, BYTES) is unchanged.

The PR adds a GPU test, texture::ahead::tests::late_completion_keeps_a_newer_list_refresh. It is ignored by default because it needs a D3D12 device and its own process with prelude uploads on, which is Mandy's default (LEONIDA_PRELUDE_UPLOAD not 0). resource::resource_release becomes pub(crate) so the test can release its texture.

Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 28070a252, PR #104 by tyr0nsur. Changes from Darner: crate and switch names; the test uses texture::prelude_upload() (Mandy's default-on switch) instead of Darner's prelude_uploads(); it uses windows_sys for VirtualAlloc and drops Darner's watch::one_view_test() lock, which Mandy does not have.

Tested

Red/green, cargo test --locked -p leonida-gpu --lib late_completion_keeps_a_newer_list_refresh -- --ignored:

  • without the fix (finish() as on main 863694e28):
    panicked at crates\leonida-gpu\src\texture\ahead.rs:554:9: first BC7 byte was 0x1b, expected 0xb7, test result: FAILED. 0 passed; 1 failed
  • with the fix: test texture::ahead::tests::late_completion_keeps_a_newer_list_refresh ... ok, 3 of 3 runs

Also run, all from d3d12/:

  • cargo test --locked -p leonida-gpu: 730 passed, 0 failed, 60 ignored.
  • cargo clippy --locked -p leonida-gpu --all-targets -- -D warnings: clean.
  • cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc: OK.
  • python -I scripts/check_no_game_data.py on both changed files: clean.

There is no in-game run yet. LEONIDA_UPLOAD_AHEAD stays off by default, so the default path does not change.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 621.40, Windows 11 Pro (unit/GPU test only, no game run)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

Claimed in the coordination issue as: `D3D12-AHEAD-KEEP-PENDING-REFRESH` (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25239) ### What and why `d3d12/crates/leonida-gpu/src/texture/ahead.rs` `finish()`: when a copy-queue upload (`LEONIDA_UPLOAD_AHEAD=1`) completes after `listed()` stopped waiting (1 s), a draw list may already have taken over the staging buffer (`once` set to false in `upload_from`) and refreshed it from newer title memory. The late completion still marked the staging buffer `uploaded` and clean (`dirty = false`) and noted the old hash as held. As a result, the newer refresh was never uploaded and the texture kept its old texels. `finish()` now marks it clean and notes the hash only while it is still the one-shot upload (`once` true). It checks under the staging's `last` lock, which a list's refresh also takes. The completion state (`copy.ahead = DONE`, `BYTES`) is unchanged. The PR adds a GPU test, `texture::ahead::tests::late_completion_keeps_a_newer_list_refresh`. It is ignored by default because it needs a D3D12 device and its own process with prelude uploads on, which is Mandy's default (`LEONIDA_PRELUDE_UPLOAD` not 0). `resource::resource_release` becomes `pub(crate)` so the test can release its texture. Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 28070a252, PR #104 by tyr0nsur. Changes from Darner: crate and switch names; the test uses `texture::prelude_upload()` (Mandy's default-on switch) instead of Darner's `prelude_uploads()`; it uses `windows_sys` for `VirtualAlloc` and drops Darner's `watch::one_view_test()` lock, which Mandy does not have. ### Tested Red/green, `cargo test --locked -p leonida-gpu --lib late_completion_keeps_a_newer_list_refresh -- --ignored`: - without the fix (`finish()` as on main 863694e28): `panicked at crates\leonida-gpu\src\texture\ahead.rs:554:9: first BC7 byte was 0x1b, expected 0xb7`, `test result: FAILED. 0 passed; 1 failed` - with the fix: `test texture::ahead::tests::late_completion_keeps_a_newer_list_refresh ... ok`, 3 of 3 runs Also run, all from `d3d12/`: - `cargo test --locked -p leonida-gpu`: 730 passed, 0 failed, 60 ignored. - `cargo clippy --locked -p leonida-gpu --all-targets -- -D warnings`: clean. - `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc`: OK. - `python -I scripts/check_no_game_data.py` on both changed files: clean. There is no in-game run yet. `LEONIDA_UPLOAD_AHEAD` stays off by default, so the default path does not change. GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 621.40, Windows 11 Pro (unit/GPU test only, no game run) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A copy-queue upload (LEONIDA_UPLOAD_AHEAD=1) whose completion arrives after
listed() stopped waiting marked the staging buffer uploaded and clean, even
when a draw list had taken it over (once false) and refreshed it from newer
title memory since: that refresh was never uploaded and the texture kept its
old texels. finish() now marks it clean, under the staging's `last` lock,
only while it is still the one-shot upload.

The GPU test late_completion_keeps_a_newer_list_refresh (ignored by default:
needs a D3D12 device) fails without the fix (first BC7 byte 0x1b, expected
0xb7) and passes with it. resource_release becomes pub(crate) for the test.

Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 28070a252, PR #104 by tyr0nsur.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OreoFR merged commit a700d029e0 into main 2026-12-04 06:41:34 +00:00
Author
Member

Merged by OreoFR (agent) at MoonEyes' request: his judge accepted it after reading the code, with no blocking point. The concurrency with finish holds; at worst a send happens twice. He asked for the local CI only, because the change acts only when LEONIDA_UPLOAD_AHEAD is on, and that is off by default. The judge's two minor comments are addressed in 65d0700b8.

Local CI (normal mode) on head 65d0700b8 merged into main 79bc6f669: PASS.

  • Merge clean; no game data.
  • Python compiles; make_game.py --help.
  • Rust tests on leonida, leonida-gpu and leonida-hle, 163 s.
  • Rust replay test, 93 s.
  • Clippy -D warnings, 53 s.
  • Standard-library Python tests, 621 s.

The forge refused the merge while the head was behind main. So main (79bc6f669) was merged into the head as 837605e7b, with the same tree the CI tested. Merged as a700d029e.

Merged by OreoFR (agent) at MoonEyes' request: his judge accepted it after reading the code, with no blocking point. The concurrency with `finish` holds; at worst a send happens twice. He asked for the local CI only, because the change acts only when `LEONIDA_UPLOAD_AHEAD` is on, and that is off by default. The judge's two minor comments are addressed in `65d0700b8`. Local CI (normal mode) on head `65d0700b8` merged into main `79bc6f669`: PASS. - Merge clean; no game data. - Python compiles; `make_game.py --help`. - Rust tests on `leonida`, `leonida-gpu` and `leonida-hle`, 163 s. - Rust replay test, 93 s. - Clippy `-D warnings`, 53 s. - Standard-library Python tests, 621 s. The forge refused the merge while the head was behind main. So `main` (`79bc6f669`) was merged into the head as `837605e7b`, with the same tree the CI tested. Merged as `a700d029e`.
Sign in to join this conversation.
No description provided.