d3d12: do not follow a record into a slot being written #448

Merged
NickStallman merged 1 commit from upstream-pr/448 into main 2026-11-29 08:58:07 +00:00
NickStallman commented 2026-11-29 05:17:51 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T05:17:51Z.


Summary

A title copies a descriptor's record and then writes the next descriptor into the same CPU slot. A thread that resolved the record between the host's write and the moment the new view is authored was given the slot. It could then copy the new view, or a half-written one, and the table slot or index-map entry kept that view because its record hadn't changed.

preserve now takes the version off the slot, after saving the replaced view and before the host writes, so the record resolves to the kept view from then on. A copy that began before that resolves its record again when done, and copies again if the view has moved.

How it was found

By reading, and confirmed only in unit tests that interleave the threads deterministically. It hasn't been seen in ProjectScarlett. It needs a record lagging the slots by about one wrap, so I expect it to be rare; where it does happen, the wrong view stays until the record changes. I don't claim it causes any reported fault.

It covers the same pattern 0ae06f52 describes (a title reusing a CPU heap whose records it copied). CopyDescriptors has the same shape and isn't changed here; neither are hosts with no history heap.

Cost

Two extra mutex operations per materialised record. Not measured in a game.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both

Unit tests: two new ones; both fail (resolved to 0x30000000) when the two behaviour lines are disabled. They need History without a device, hence a small struct split. The project's checks only typecheck the D3D12 crate, so run them by name; 285 device-free D3D12 tests pass in Wine with Vulkan off.

Lanes: none. The race is a window of microseconds between two CPU threads, which a guest can't make deterministic.

GPU, driver and backend:

  • RTX 5090 (10de:2b85), NVIDIA 620.70.10
  • AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8
  • both on GE-Proton11-14
python tuxbox.py check --no-gpu
  passed
python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
  all steps passed
python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
  all steps passed (guest-present-4k-splash skipped: this GPU presents to the test display through software)

Run on a machine loading a game's shaders at the same time. Not run in the game, or on Windows.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5547842231 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/448). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T05:17:51Z. --- ## Summary A title copies a descriptor's record and then writes the next descriptor into the same CPU slot. A thread that resolved the record between the host's write and the moment the new view is authored was given the slot. It could then copy the new view, or a half-written one, and the table slot or index-map entry kept that view because its record hadn't changed. `preserve` now takes the version off the slot, after saving the replaced view and before the host writes, so the record resolves to the kept view from then on. A copy that began before that resolves its record again when done, and copies again if the view has moved. ## How it was found By reading, and **confirmed only in unit tests that interleave the threads deterministically.** It hasn't been seen in ProjectScarlett. It needs a record lagging the slots by about one wrap, so I expect it to be rare; where it does happen, the wrong view stays until the record changes. I don't claim it causes any reported fault. It covers the same pattern `0ae06f52` describes (a title reusing a CPU heap whose records it copied). `CopyDescriptors` has the same shape and isn't changed here; neither are hosts with no history heap. ## Cost Two extra mutex operations per materialised record. Not measured in a game. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both **Unit tests:** two new ones; both fail (`resolved to 0x30000000`) when the two behaviour lines are disabled. They need `History` without a device, hence a small struct split. The project's checks only typecheck the D3D12 crate, so run them by name; 285 device-free D3D12 tests pass in Wine with Vulkan off. **Lanes:** none. The race is a window of microseconds between two CPU threads, which a guest can't make deterministic. GPU, driver and backend: - RTX 5090 (10de:2b85), NVIDIA 620.70.10 - AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8 - both on GE-Proton11-14 ```text python tuxbox.py check --no-gpu passed python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 all steps passed python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 all steps passed (guest-present-4k-splash skipped: this GPU presents to the test display through software) ``` Run on a machine loading a game's shaders at the same time. Not run in the game, or on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!448
No description provided.