d3d12: follow descriptor records a title copies into an indexed heap #391

Merged
MathiewMay merged 1 commit from upstream-pr/391 into main 2026-11-28 16:55:02 +00:00
MathiewMay commented 2026-11-28 09:20:20 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by MathiewMay on 2026-11-28T09:20:20Z.


Summary

On console a descriptor heap's memory holds its descriptors, so a title can copy a 32-byte record into the shader-visible heap with ordinary stores, from a CPU heap or from another index. ProjectScarlett fills slots of its 38 MiB heap this way. Root tables already resolve such records each time they are bound (lookup.rs). The resource index map, which direct-indexed programs read, fills an index's slot only when the API writes that index. So such a program kept reading through the view the API last wrote there.

  • Refresh (Arena::refresh_index_map, descriptor_paging/index_map.rs): before a batch whose programs read an arena's index map, the map re-reads the record of every index that has a slot and follows the ones that changed. A record naming another descriptor puts that view in the slot, and an empty one a null view. A record naming a descriptor the title has written again since, and bytes that are not a record, leave the slot as it was. An index the API writes again holds that view once more.
  • Compute dispatches register the arena their map reads (recording.rs), as draws do, so that submission checks and refreshes it for them too. They were not registered before, so check_index_capacity did not run for them either.
  • null_view moves from lookup.rs to Arena so that both use it.

The refresh reads one record per mapped index for each batch that indexes the arena. In ProjectScarlett, with traces I kept out of this branch, it resolved 9,045 copied records and cleared 1,424 in 84 s of one run. A scan took up to 17 ms in another.

The same run left 16,661 records stale. All came from one CPU heap of 3,128 slots: the title writes a descriptor there, copies its 32 bytes into the shader-visible heap, then writes the next descriptor into the same slot before the copy is used. The record then names a view that no longer exists. A follow-up PR keeps replaced views for such records; it builds on this one.

In game I tested this on an older main together with other fixes of mine, not on this branch alone; with all my fixes a 30-minute run had no fault.

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. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

New Lanes scenario bindless-raw-copy (gates lanes-bindless-raw-copy-wide and -constrained, in the lanes-bindless-compute suite). A heap slot holds a view of one window of a buffer, written through the API. The title then copies, with memcpy, a view of another window from a CPU heap over it, and the direct-indexed program must store through the copy. On main both gates fail:

lanes-selftest FAIL bindless-raw-copy: the program stored through the view the slot held before the copy

A unit test, index_map_follows_records_the_title_copies_with_ordinary_stores (runtime/d3d12/src/tests/device/descriptor_paging.rs), covers each case of the refresh: a copy, a copy followed once, a stale copy, an empty record, bytes that are not a record, and the API writing the index again.

GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (--backend proton).

Commands run and their results:

python build.py, with main's runtime/d3d12/src
python tuxbox.py verify --only lanes-bindless-compute --backend proton --adapter 1002:7550
  12 PASS, 2 FAIL: lanes-bindless-raw-copy-wide, lanes-bindless-raw-copy-constrained (above)

python build.py, with the change
python tuxbox.py verify --only guest-frame --only present --only lanes --only lanes-selftest
    --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root
    --only lanes-compute-root-recovery --only lanes-compute-root-srv --only lanes-large-dispatch
    --only lanes-late-pipeline --only lanes-bindless-compute --only lanes-compute-heap-stride
    --only d3d12-exports --only d3d12-features --only d3d12-indirect --only d3d12-queries
    --only d3d12-queues --only d3d12-tables --only d3d12-heaps --only d3d12-placement
    --only d3d12-copy-resource --only d3d12-draw --only d3d12-stream --only d3d12-frame-events
    --only d3d12-guids --only d3d12-signatures --only d3d12-mesh --backend proton --adapter 1002:7550
  80 PASS, 0 FAIL (the two raw-copy gates included)

D3D12 regression controls, all 20 cases
  20 PASS, 0 FAIL

cargo xwin test --no-run --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib, the test executable run under Proton
  225 passed, 0 failed

python tuxbox.py check --no-gpu
  passed   Build the shader compiler, Python tests, Shader compiler tests, DXBC tests,
           XG layout tests, Storage codec tests, D3D12 Windows typecheck

The D3D12 controls ran with the tool's own case table, staging and validate, but outside its Bubblewrap/xvfb-run sandbox, which stalls on this machine (it has no Xvfb).

Checks

No evidence JSON changes.

<!-- greyfinch-sync:brcly/TuxBox:issue:5538675721 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/391). Originally posted by [MathiewMay](https://github.com/MathiewMay) on 2026-11-28T09:20:20Z. --- ## Summary On console a descriptor heap's memory holds its descriptors, so a title can copy a 32-byte record into the shader-visible heap with ordinary stores, from a CPU heap or from another index. ProjectScarlett fills slots of its 38 MiB heap this way. Root tables already resolve such records each time they are bound (`lookup.rs`). The resource index map, which direct-indexed programs read, fills an index's slot only when the API writes that index. So such a program kept reading through the view the API last wrote there. - **Refresh** (`Arena::refresh_index_map`, `descriptor_paging/index_map.rs`): before a batch whose programs read an arena's index map, the map re-reads the record of every index that has a slot and follows the ones that changed. A record naming another descriptor puts that view in the slot, and an empty one a null view. A record naming a descriptor the title has written again since, and bytes that are not a record, leave the slot as it was. An index the API writes again holds that view once more. - **Compute dispatches** register the arena their map reads (`recording.rs`), as draws do, so that submission checks and refreshes it for them too. They were not registered before, so `check_index_capacity` did not run for them either. - `null_view` moves from `lookup.rs` to `Arena` so that both use it. The refresh reads one record per mapped index for each batch that indexes the arena. In ProjectScarlett, with traces I kept out of this branch, it resolved 9,045 copied records and cleared 1,424 in 84 s of one run. A scan took up to 17 ms in another. The same run left 16,661 records stale. All came from one CPU heap of 3,128 slots: the title writes a descriptor there, copies its 32 bytes into the shader-visible heap, then writes the next descriptor into the same slot before the copy is used. The record then names a view that no longer exists. A follow-up PR keeps replaced views for such records; it builds on this one. In game I tested this on an older `main` together with other fixes of mine, not on this branch alone; with all my fixes a 30-minute run had no fault. ## 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 - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: **NVIDIA still needs to run them.** New Lanes scenario `bindless-raw-copy` (gates `lanes-bindless-raw-copy-wide` and `-constrained`, in the `lanes-bindless-compute` suite). A heap slot holds a view of one window of a buffer, written through the API. The title then copies, with `memcpy`, a view of another window from a CPU heap over it, and the direct-indexed program must store through the copy. On `main` both gates fail: ```text lanes-selftest FAIL bindless-raw-copy: the program stored through the view the slot held before the copy ``` A unit test, `index_map_follows_records_the_title_copies_with_ordinary_stores` (`runtime/d3d12/src/tests/device/descriptor_paging.rs`), covers each case of the refresh: a copy, a copy followed once, a stale copy, an empty record, bytes that are not a record, and the API writing the index again. GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (`--backend proton`). Commands run and their results: ```text python build.py, with main's runtime/d3d12/src python tuxbox.py verify --only lanes-bindless-compute --backend proton --adapter 1002:7550 12 PASS, 2 FAIL: lanes-bindless-raw-copy-wide, lanes-bindless-raw-copy-constrained (above) python build.py, with the change python tuxbox.py verify --only guest-frame --only present --only lanes --only lanes-selftest --only lanes-shader-cache --only lanes-raster-tables --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-compute-root-srv --only lanes-large-dispatch --only lanes-late-pipeline --only lanes-bindless-compute --only lanes-compute-heap-stride --only d3d12-exports --only d3d12-features --only d3d12-indirect --only d3d12-queries --only d3d12-queues --only d3d12-tables --only d3d12-heaps --only d3d12-placement --only d3d12-copy-resource --only d3d12-draw --only d3d12-stream --only d3d12-frame-events --only d3d12-guids --only d3d12-signatures --only d3d12-mesh --backend proton --adapter 1002:7550 80 PASS, 0 FAIL (the two raw-copy gates included) D3D12 regression controls, all 20 cases 20 PASS, 0 FAIL cargo xwin test --no-run --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib, the test executable run under Proton 225 passed, 0 failed python tuxbox.py check --no-gpu passed Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, Storage codec tests, D3D12 Windows typecheck ``` The D3D12 controls ran with the tool's own case table, staging and `validate`, but outside its Bubblewrap/`xvfb-run` sandbox, which stalls on this machine (it has no Xvfb). ## Checks No evidence JSON changes.
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!391
No description provided.