d3d12-hle: notify mapped aliases after partial DirectStorage scatter writes (D3D12-DSTORAGE-PARTIAL-SCATTER-NOTICE) #2982

Open
EdenBendheim wants to merge 1 commit from upstream-pr/2982 into main
EdenBendheim commented 2026-12-01 22:24:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-01T22:24:23Z.


Claimed in the coordination issue as: D3D12-DSTORAGE-PARTIAL-SCATTER-NOTICE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7327431446)

What and why

In d3d12/crates/leonida-hle/src/modules/xmem.rs, write_physical validates the page list up front and then maps and copies one contiguous physical run at a time. Previously it returned bool, so if View::map failed on a second or later physical run, the earlier run's bytes were already mutated in physical memory while dstorage.rs received false and skipped pages_written for that copied prefix (unlike the contiguous-page path, which already notifies on partial error). If retries were exhausted, mapped aliases were left mutated with no GPU completion notice.

This change:

  • Returns Result<(), usize> from write_physical (Err(0) on validation/first-run failure; Err(done) advancing only after a run's bytes are actually copied).
  • In dstorage.rs, calls pages_written for any nonempty copied prefix before sleeping/retrying or returning failure, preserving existing retry counts/backoff, LEONIDA_STREAM_NOTICE handling, and zero extra notices on the immediate-success fast path.
  • Adds focused unit tests covering mid-scatter map failure with retry exhaustion, eventual success after partial failure, and first-run failure (Err(0) with zero notices), verified under both default and LEONIDA_STREAM_NOTICE=0.

Tested

  • Red/green proof in d3d12/ (Windows 11, Ryzen 9 5900X, synthetic pages, no game files):
    • Red (c4ca57615 production code + new test fixture): cargo test -p leonida-hle --locked → FAILED. 246 passed; 2 failed; 2 ignored (both aliases missed the 32-byte partial-prefix notices).
    • Green (this PR): cargo test -p leonida-hle --locked → ok. 248 passed; 0 failed; 2 ignored (plus integration test 1 passed; all 3 focused scatter tests pass with LEONIDA_STREAM_NOTICE=0).
  • cargo clippy -p leonida-hle --locked --all-targets --no-deps -- -D warnings: passed (0 warnings in leonida-hle).
  • python -I scripts/check_no_game_data.py (both touched files and full tracked tree): passed.
  • Independent read-only review: approved with zero findings.

GPUs tested: n/a (CPU-only leonida-hle synthetic page tests on Windows 11, Ryzen 9 5900X + NVIDIA RTX 3090 driver 610.88)

AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra research & implementation; Codex GPT-6.1 Sol independent read-only review)

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5595689982 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2982). Originally posted by [EdenBendheim](https://github.com/EdenBendheim) on 2026-12-01T22:24:23Z. --- Claimed in the coordination issue as: D3D12-DSTORAGE-PARTIAL-SCATTER-NOTICE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7327431446) ### What and why In `d3d12/crates/leonida-hle/src/modules/xmem.rs`, `write_physical` validates the page list up front and then maps and copies one contiguous physical run at a time. Previously it returned `bool`, so if `View::map` failed on a second or later physical run, the earlier run's bytes were already mutated in physical memory while `dstorage.rs` received `false` and skipped `pages_written` for that copied prefix (unlike the contiguous-page path, which already notifies on partial error). If retries were exhausted, mapped aliases were left mutated with no GPU completion notice. This change: - Returns `Result<(), usize>` from `write_physical` (`Err(0)` on validation/first-run failure; `Err(done)` advancing only after a run's bytes are actually copied). - In `dstorage.rs`, calls `pages_written` for any nonempty copied prefix before sleeping/retrying or returning failure, preserving existing retry counts/backoff, `LEONIDA_STREAM_NOTICE` handling, and zero extra notices on the immediate-success fast path. - Adds focused unit tests covering mid-scatter map failure with retry exhaustion, eventual success after partial failure, and first-run failure (`Err(0)` with zero notices), verified under both default and `LEONIDA_STREAM_NOTICE=0`. ### Tested - Red/green proof in `d3d12/` (Windows 11, Ryzen 9 5900X, synthetic pages, no game files): - Red (`c4ca57615` production code + new test fixture): `cargo test -p leonida-hle --locked` → `FAILED. 246 passed; 2 failed; 2 ignored` (both aliases missed the 32-byte partial-prefix notices). - Green (this PR): `cargo test -p leonida-hle --locked` → `ok. 248 passed; 0 failed; 2 ignored` (plus integration test `1 passed`; all 3 focused scatter tests pass with `LEONIDA_STREAM_NOTICE=0`). - `cargo clippy -p leonida-hle --locked --all-targets --no-deps -- -D warnings`: passed (0 warnings in `leonida-hle`). - `python -I scripts/check_no_game_data.py` (both touched files and full tracked tree): passed. - Independent read-only review: approved with zero findings. GPUs tested: n/a (CPU-only `leonida-hle` synthetic page tests on Windows 11, Ryzen 9 5900X + NVIDIA RTX 3090 driver 610.88) AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra research & implementation; Codex GPT-6.1 Sol independent read-only review) ### 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.
MoonEyes commented 2026-12-02 12:34:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:34:09Z.


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:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345535003 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2982#issuecomment-7345535003). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:34:09Z. --- 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`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone 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).
MoonEyes commented 2026-12-02 17:06:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T17:06:47Z.


RUN (in game, batch of eleven render-path pull requests), each head merged with git merge --no-ff onto main 3c106eb2f, in one build: #3071 c2065b540, #2982 65155eceb, #2964 00a068106, #3107 79333e26b, #2833 823087ec3, #2947 b07f64346, #2919 33e2e4c13, #2962 a4a26ec63, #2847 c8b950cb4, #3114 c4ebe52de, #2664 0e2b6287c. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, -Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.

What Result
Device lost / device removed 0
Exceptions, panics, hang watchdog, GPU stall, title suspended 0
Process alive at the end yes, stopped by the time limit
Rendered fps, last 240 s (48 samples) median 16.2, mean 16.1
Rendered fps, last 120 s median 15.1

For reference, the same machine and route rendered 13.3 to 17.2 fps today on main with single pull requests or other batches. These fps are a check that nothing fell over, not a measurement of a gain.

Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. If one of these pull requests changes its head, this run no longer covers it.

Limits: one run; free system memory was low (median 0.6 GB); arrival in the world was driven by keys and not checked on pictures. An earlier attempt of this batch is not counted: two runs were started at the same time by mistake on one GPU (no device loss in either, but the measure is not clean).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7352914964 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2982#issuecomment-7352914964). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T17:06:47Z. --- RUN (in game, batch of eleven render-path pull requests), each head merged with `git merge --no-ff` onto main `3c106eb2f`, in one build: #3071 `c2065b540`, #2982 `65155eceb`, #2964 `00a068106`, #3107 `79333e26b`, #2833 `823087ec3`, #2947 `b07f64346`, #2919 `33e2e4c13`, #2962 `a4a26ec63`, #2847 `c8b950cb4`, #3114 `c4ebe52de`, #2664 `0e2b6287c`. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, `-Resolution 1080`, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world. | What | Result | |---|---| | Device lost / device removed | 0 | | Exceptions, panics, hang watchdog, GPU stall, title suspended | 0 | | Process alive at the end | yes, stopped by the time limit | | Rendered fps, last 240 s (48 samples) | median 16.2, mean 16.1 | | Rendered fps, last 120 s | median 15.1 | For reference, the same machine and route rendered 13.3 to 17.2 fps today on main with single pull requests or other batches. These fps are a check that nothing fell over, not a measurement of a gain. Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. If one of these pull requests changes its head, this run no longer covers it. Limits: one run; free system memory was low (median 0.6 GB); arrival in the world was driven by keys and not checked on pictures. An earlier attempt of this batch is not counted: two runs were started at the same time by mistake on one GPU (no device loss in either, but the measure is not clean). AI-assisted (Claude Code).
MoonEyes commented 2026-12-02 18:18:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:18:55Z.


Verification of #2982 (third party, code review on Linux; not built: Windows-only leonida-hle)

  • Head verified: 65155eceb91a7dc4d4c515d07fb00210256d641a (2 files: dstorage.rs +43/-24, xmem.rs +107/-17).
  • Merge base c4ca57615. git merge-tree --write-tree origin/main pr/2982 against main 45dc41f95 is clean
    (329 commits behind). CI on the head: 6/6 success.
  • python -I scripts/check_no_game_data.py on both files: exit 0.
  • The in-game gate is covered: MoonEyes's 11-PR batch on 3c106eb2f includes 65155eceb (PASS, no device loss).

Review

  • Root cause: write_physical copies one physical run at a time. If View::map failed on a later run, the earlier
    runs' bytes had already changed while the caller got false and skipped pages_written, so mapped aliases were
    never told. Returning Err(copied) (xmem.rs:964-981) and noticing [offset, offset + copied) on every failed
    attempt (dstorage.rs:1729-1731) fixes it at the source.
  • The retry loop (dstorage.rs:1729-1752) re-copies from the start on each try, so a run noticed on a failed
    attempt is written again and noticed again. That is redundant but correct: an extra notice only costs a re-look.
    The final failure path keeps E_INVALIDARG and the two warnings from main.
  • last_os_error() is read right after the failed call. When runs() fails (unknown page) there was no OS call,
    so the logged last_error is unrelated. That was already the case on main. Nit only.
  • Test hooks: fail_scatter_map and record_scatter_notice are #[cfg(test)], so they cost nothing in release.
    The thread_local! cells are test-only Cell/RefCell with no destructor, which keeps clear of the AGENTS.md
    thread-exit trap (that rule is for gta6rt.exe, but this is fine either way). scatter_notices fails the
    second run on its first attempt and checks the bytes at both aliases and the per-attempt notices. On main the
    notice list for the failed attempt would be empty, so this is a meaningful red. The red side does not build on
    main (new signature), so it was not run here.

Process

  • Claim and AI disclosure (Gemini 4 Neon, Codex GPT-6.2 Astra, a GPT-6.1 Sol reviewer) are present.

Verdict: ready (not built here).

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7354352472 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2982#issuecomment-7354352472). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:18:55Z. --- **Verification of #2982 (third party, code review on Linux; not built: Windows-only `leonida-hle`)** - Head verified: `65155eceb91a7dc4d4c515d07fb00210256d641a` (2 files: `dstorage.rs` +43/-24, `xmem.rs` +107/-17). - Merge base `c4ca57615`. `git merge-tree --write-tree origin/main pr/2982` against `main` `45dc41f95` is clean (329 commits behind). CI on the head: 6/6 success. - `python -I scripts/check_no_game_data.py` on both files: exit 0. - The in-game gate is covered: MoonEyes's 11-PR batch on `3c106eb2f` includes `65155eceb` (PASS, no device loss). **Review** - Root cause: `write_physical` copies one physical run at a time. If `View::map` failed on a later run, the earlier runs' bytes had already changed while the caller got `false` and skipped `pages_written`, so mapped aliases were never told. Returning `Err(copied)` (`xmem.rs:964-981`) and noticing `[offset, offset + copied)` on every failed attempt (`dstorage.rs:1729-1731`) fixes it at the source. - The retry loop (`dstorage.rs:1729-1752`) re-copies from the start on each try, so a run noticed on a failed attempt is written again and noticed again. That is redundant but correct: an extra notice only costs a re-look. The final failure path keeps `E_INVALIDARG` and the two warnings from `main`. - `last_os_error()` is read right after the failed call. When `runs()` fails (unknown page) there was no OS call, so the logged `last_error` is unrelated. That was already the case on `main`. Nit only. - Test hooks: `fail_scatter_map` and `record_scatter_notice` are `#[cfg(test)]`, so they cost nothing in release. The `thread_local!` cells are test-only `Cell`/`RefCell` with no destructor, which keeps clear of the AGENTS.md thread-exit trap (that rule is for `gta6rt.exe`, but this is fine either way). `scatter_notices` fails the second run on its first attempt and checks the bytes at both aliases and the per-attempt notices. On `main` the notice list for the failed attempt would be empty, so this is a meaningful red. The red side does not build on `main` (new signature), so it was not run here. **Process** - Claim and AI disclosure (Gemini 4 Neon, Codex GPT-6.2 Astra, a GPT-6.1 Sol reviewer) are present. **Verdict: ready** (not built here). AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
fiestorra commented 2026-12-03 05:13:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T05:13:24Z.


VERIFY-2982 — el único fallo es el de la visibilidad del escritorio, con los valores a la vista

cargo test -p leonida-hle --lib
  247 passed; 1 failed; 2 ignored
  FAILED: modules::lifecycle::tests::borderless_from_the_start_stays_shown_when_framed_again
          assertion `left != right` failed   left: 0   right: 0

Y left: 0, right: 0 es la firma exacta del diagnóstico que ya hice: IsWindowVisible devuelve 0 porque el escritorio de esta sesión no está visible, no porque el estilo de la ventana haya perdido WS_VISIBLE. Mi rama hle-visible-style cambia esa aserción por la del estilo y esta prueba pasa.

Así que no es un fallo de esta PR — y con el número delante se lo puede decir a cualquier autor sin que tenga que creérselo.

El cambio: notificar los alias mapeados después de un DirectStorage disperso parcial — dstorage.rs y xmem.rs, 150 líneas, y xmem.rs con la mayoría (el mapa de alias es donde vive la traducción). Un DirectStorage que escribe sólo parte de un recurso mapeado tiene que avisar a los alias de esa parte, no a todos — y el caso que se rompe es una textura que se ve a medias, que es exactamente el tipo de fallo que se nota en pantalla y no en un log.

Lo que verifiqué: 247 tests de hle en verde menos el de la ventana, y el fallo es del entorno, con los dos valores impresos.
Lo que no: el DirectStorage parcial de verdad contra el juego — eso necesita el título cargando sus datos.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7368507078 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2982#issuecomment-7368507078). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T05:13:24Z. --- ## VERIFY-2982 — el único fallo es **el de la visibilidad del escritorio**, con los valores a la vista ``` cargo test -p leonida-hle --lib 247 passed; 1 failed; 2 ignored FAILED: modules::lifecycle::tests::borderless_from_the_start_stays_shown_when_framed_again assertion `left != right` failed left: 0 right: 0 ``` **Y `left: 0, right: 0` es la firma exacta del diagnóstico que ya hice**: **`IsWindowVisible` devuelve 0 porque el escritorio de esta sesión no está visible**, **no porque el estilo de la ventana haya perdido `WS_VISIBLE`.** **Mi rama `hle-visible-style` cambia esa aserción por la del estilo y esta prueba pasa.** **Así que no es un fallo de esta PR** — **y con el número delante se lo puede decir a cualquier autor sin que tenga que creérselo.** **El cambio**: **notificar los alias mapeados después de un `DirectStorage` disperso parcial** — **`dstorage.rs` y `xmem.rs`, 150 líneas, y `xmem.rs` con la mayoría** (**el mapa de alias es donde vive la traducción**). **Un `DirectStorage` que escribe sólo parte de un recurso mapeado tiene que avisar a los alias de esa parte, no a todos** — **y el caso que se rompe es una textura que se ve a medias, que es exactamente el tipo de fallo que se nota en pantalla y no en un log.** **Lo que verifiqué**: **247 tests de `hle` en verde menos el de la ventana**, **y el fallo es del entorno, con los dos valores impresos.** **Lo que no**: **el `DirectStorage` parcial de verdad contra el juego** — **eso necesita el título cargando sus datos.**
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2982:upstream-pr/2982'
git switch 'upstream-pr/2982'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2982'
git switch 'upstream-pr/2982'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2982'
git switch 'upstream-pr/2982'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2982'
git switch 'main'
git merge --squash 'upstream-pr/2982'
git switch 'main'
git merge --ff-only 'upstream-pr/2982'
git switch 'main'
git merge 'upstream-pr/2982'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2982
No description provided.