d3d12: lazy publication gives back a page's protection from deferral time, undoing the title's later VirtualProtect (Lanes texture-publication crashes) #625

Closed
opened 2026-12-01 15:41:44 +00:00 by 1093i3511 · 4 comments
1093i3511 commented 2026-12-01 15:41:44 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-01T15:41:44Z.


What fails

After e40d8052 (lazy publication on by default), lanes-selftest-texture-publication fails every time. Every other selftest passes. Found on 4cc17f52; nothing in runtime/d3d12/src/device/placement/ changed up to fb17e160.

Setting (4cc17f52) texture-publication
defaults 5/5 FAIL (exit 5, no receipt)
TUXBOX_LAZY_PUBLICATION=0 4/4 PASS
TUXBOX_READ_RESIDENCY=0 1/1 FAIL
TUXBOX_CHECK_ONCE_PER_FRAME=0 1/1 FAIL

Host: RX 6600 (1002:73ff, RDNA2), Mesa 26.3.1 RADV, GE-Proton11-15.

What happens

Exit 5 is not the scenario's own failure path, which writes a receipt and exits 1. The guest dies on an unhandled read fault. With WINEDEBUG=+seh,+debugstr:

  1. The texture is placed at 0x37ac000 (8 pages). The scenario closes its third page (0x37ae000) with PAGE_NOACCESS before the GPU writes. It opens the page again with VirtualProtect(..., old) after the label wait.
  2. The first read of the texture faults at 0x37ac000, and the lazy handler publishes it (lazy publication: 1 published on access (... from lanes.exe+0x24135, nested false)). Inside that, a syscall faults on 0x37ae000.
  3. The scenario then reads 0x37ae000, the page it has opened again. The read faults, the lazy handler passes it on (the page is no longer held), and nothing else handles it: Unhandled page fault on read access to 0x00000000037ae000 at lanes.exe+0x24135.

Cause

  • lazy::defer (from heap_writes.rs) protects every page of the texture and records each page's protection at that moment in Pages::held. For the third page that is PAGE_NOACCESS, because the title had closed it.
  • The title then opens that page again with its own VirtualProtect. Nothing updates Pages::held.
  • On the first access, handler → publish_now → publish_texture calls lazy::release, and drop_hold restores the recorded PAGE_NOACCESS. That undoes the title's change, and the page stays closed after publication.

For a title, this would show as an access violation in title code, not as a GPU fault.

Proposed fix (draft PR in the works)

I have a fix on a local branch:

  • Pages::release still restores each page's protection from deferral time, so the write-back sees the pages as an eager publication would have (the page the title had closed is skipped, as the scenario expects).
  • It also returns the pages whose protection the title changed while they were held, with that protection. lazy::release wraps them in a guard. publish_texture holds the guard across the write-back and sets the title's protection again when it drops. The handler and the texture's teardown set it at once.

Checks so far, on 4cc17f52:

  • New unit test in tests/device/placement/lazy.rs: a page the title reopened while held is closed during the write-back and handed back with the title's protection. It failed before the change. All 9 lazy tests pass (run under Wine with cargo xwin test, since CI only typechecks this crate).
  • lanes-selftest with lazy publication on: 3/3 runs, texture-publication passes and nothing else fails.
  • tuxbox.py check --no-gpu: 13/13.
  • Not run yet: ProjectScarlett with the fix, and NVIDIA (I only have an AMD card).

Not covered: a page the title closes while it is held looks the same as one lazy publication closed (PAGE_NOACCESS), so release would still open it again. I have nothing that reproduces that and left it out.

I'd like to claim this and open the PR after a game run on current main, unless you'd rather handle it yourself, @brcly, since lazy publication is part of your frame-time work. Happy to hand over the test and the patch either way.

<!-- greyfinch-sync:brcly/TuxBox:issue:6724300790 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/625). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-12-01T15:41:44Z. --- ## What fails After e40d8052 (lazy publication on by default), `lanes-selftest-texture-publication` fails every time. Every other selftest passes. Found on 4cc17f52; nothing in `runtime/d3d12/src/device/placement/` changed up to fb17e160. | Setting (4cc17f52) | `texture-publication` | | --- | --- | | defaults | 5/5 FAIL (exit 5, no receipt) | | `TUXBOX_LAZY_PUBLICATION=0` | 4/4 PASS | | `TUXBOX_READ_RESIDENCY=0` | 1/1 FAIL | | `TUXBOX_CHECK_ONCE_PER_FRAME=0` | 1/1 FAIL | Host: RX 6600 (1002:73ff, RDNA2), Mesa 26.3.1 RADV, GE-Proton11-15. ## What happens Exit 5 is not the scenario's own failure path, which writes a receipt and exits 1. The guest dies on an unhandled read fault. With `WINEDEBUG=+seh,+debugstr`: 1. The texture is placed at `0x37ac000` (8 pages). The scenario closes its third page (`0x37ae000`) with `PAGE_NOACCESS` before the GPU writes. It opens the page again with `VirtualProtect(..., old)` after the label wait. 2. The first read of the texture faults at `0x37ac000`, and the lazy handler publishes it (`lazy publication: 1 published on access (... from lanes.exe+0x24135, nested false)`). Inside that, a syscall faults on `0x37ae000`. 3. The scenario then reads `0x37ae000`, the page it has opened again. The read faults, the lazy handler passes it on (the page is no longer held), and nothing else handles it: `Unhandled page fault on read access to 0x00000000037ae000 at lanes.exe+0x24135`. ## Cause - `lazy::defer` (from `heap_writes.rs`) protects every page of the texture and records each page's protection at that moment in `Pages::held`. For the third page that is `PAGE_NOACCESS`, because the title had closed it. - The title then opens that page again with its own `VirtualProtect`. Nothing updates `Pages::held`. - On the first access, `handler` → `publish_now` → `publish_texture` calls `lazy::release`, and `drop_hold` restores the recorded `PAGE_NOACCESS`. That undoes the title's change, and the page stays closed after publication. For a title, this would show as an access violation in title code, not as a GPU fault. ## Proposed fix (draft PR in the works) I have a fix on a local branch: - `Pages::release` still restores each page's protection from deferral time, so the write-back sees the pages as an eager publication would have (the page the title had closed is skipped, as the scenario expects). - It also returns the pages whose protection the title changed while they were held, with that protection. `lazy::release` wraps them in a guard. `publish_texture` holds the guard across the write-back and sets the title's protection again when it drops. The handler and the texture's teardown set it at once. Checks so far, on 4cc17f52: - New unit test in `tests/device/placement/lazy.rs`: a page the title reopened while held is closed during the write-back and handed back with the title's protection. It failed before the change. All 9 `lazy` tests pass (run under Wine with `cargo xwin test`, since CI only typechecks this crate). - `lanes-selftest` with lazy publication on: 3/3 runs, `texture-publication` passes and nothing else fails. - `tuxbox.py check --no-gpu`: 13/13. - Not run yet: ProjectScarlett with the fix, and NVIDIA (I only have an AMD card). Not covered: a page the title closes *while* it is held looks the same as one lazy publication closed (`PAGE_NOACCESS`), so release would still open it again. I have nothing that reproduces that and left it out. I'd like to claim this and open the PR after a game run on current main, unless you'd rather handle it yourself, @brcly, since lazy publication is part of your frame-time work. Happy to hand over the test and the patch either way.
brcly commented 2026-12-01 15:46:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-01T15:46:33Z.


Hey there,

I'm more than happy for you to handle it if you'd like.

My frametime work has just been a starting point to build on.

Being in-game at 0.1 FPS wasn't fun; however, at 2fps, it gives us a better base to work from.

I'm going to focus on shaders and compilation time, though avoiding the ray tracing work that others handling.

I'm confident that as soon as all our branches connect, we'll have a really good working bit of kit.

<!-- greyfinch-sync:brcly/TuxBox:comment:7316485040 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/625#issuecomment-7316485040). Originally posted by [brcly](https://github.com/brcly) on 2026-12-01T15:46:33Z. --- Hey there, I'm more than happy for you to handle it if you'd like. My frametime work has just been a starting point to build on. Being in-game at 0.1 FPS wasn't fun; however, at 2fps, it gives us a better base to work from. I'm going to focus on shaders and compilation time, though avoiding the ray tracing work that others handling. I'm confident that as soon as all our branches connect, we'll have a really good working bit of kit.
1093i3511 commented 2026-12-01 16:03:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-01T16:03:18Z.


Thanks, I'll take it. I'll open the PR after a ProjectScarlett run with the fix on current main, next to the default-settings run for #603, so the two can be compared.

<!-- greyfinch-sync:brcly/TuxBox:comment:7316958752 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/625#issuecomment-7316958752). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-12-01T16:03:18Z. --- Thanks, I'll take it. I'll open the PR after a ProjectScarlett run with the fix on current main, next to the default-settings run for #603, so the two can be compared.
1093i3511 commented 2026-12-01 22:30:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-01T22:30:53Z.


Status: the fix is ready and rebased onto main 2a850114, but I'm holding the PR until a ProjectScarlett run with lazy publication on, which on RADV first needs #640 (DrArroway's fix for #634).

  • I tested both together on a local branch: main 2a850114 + #640 + this fix. They touch different parts of lazy.rs but conflict in two places: #640's userptr check sits right before the protect call this fix shortens, and #640's new pages.release for dead textures has to give the title's protection back at once (Reopen dropped immediately). #640's new unit test needed the same adjustment. Whichever lands first, the other needs that small rebase.
  • RX 6600 (RDNA2), on that branch with default settings (lazy publication on): Lanes 31/31 pass, including lanes-selftest-texture-publication. d3d12 unit tests under Wine: 577 pass (the 3 scene_publication tests need a hardware device and fail the same way on main).
  • The Series S prepare for that branch is running now; the game run follows. I'll open the PR with its result.
<!-- greyfinch-sync:brcly/TuxBox:comment:7327961930 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/625#issuecomment-7327961930). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-12-01T22:30:53Z. --- Status: the fix is ready and rebased onto main 2a850114, but I'm holding the PR until a ProjectScarlett run with lazy publication on, which on RADV first needs #640 (DrArroway's fix for #634). - I tested both together on a local branch: main 2a850114 + #640 + this fix. They touch different parts of `lazy.rs` but conflict in two places: #640's userptr check sits right before the `protect` call this fix shortens, and #640's new `pages.release` for dead textures has to give the title's protection back at once (`Reopen` dropped immediately). #640's new unit test needed the same adjustment. Whichever lands first, the other needs that small rebase. - RX 6600 (RDNA2), on that branch with default settings (lazy publication on): Lanes 31/31 pass, including `lanes-selftest-texture-publication`. d3d12 unit tests under Wine: 577 pass (the 3 `scene_publication` tests need a hardware device and fail the same way on main). - The Series S prepare for that branch is running now; the game run follows. I'll open the PR with its result.
1093i3511 commented 2026-12-02 06:45:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-02T06:45:56Z.


The fix is up as #647 (rebased onto main 3e2839b1, so it includes #640).

Since my last status: the same Series S run on main 3e2839b1 without the fix reached the world and ended after 446 s on the #603 TCP read fault, with no SQC fault. Lazy publication published nothing on access in that run. With one run each, I can't tie the SQC instruction-fetch fault from the joint run to this change. Details are in the PR.

<!-- greyfinch-sync:brcly/TuxBox:comment:7337382397 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/625#issuecomment-7337382397). Originally posted by [1093i3511](https://github.com/1093i3511) on 2026-12-02T06:45:56Z. --- The fix is up as #647 (rebased onto main 3e2839b1, so it includes #640). Since my last status: the same Series S run on main 3e2839b1 without the fix reached the world and ended after 446 s on the #603 TCP read fault, with no SQC fault. Lazy publication published nothing on access in that run. With one run each, I can't tie the SQC instruction-fetch fault from the joint run to this change. Details are in the PR.
Sign in to join this conversation.
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
brcly/TuxBox#625
No description provided.