d3d12: map title memory far past root SRVs and UAVs #389

Merged
MathiewMay merged 2 commits from upstream-pr/389 into main 2026-11-30 20:57:30 +00:00
MathiewMay commented 2026-11-28 09:20:16 +00:00 (Migrated from github.com)

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


Summary

A root SRV or UAV in title memory was bound through a one-page import: root_buffer asked command_buffer_address for one byte, which imports the 64 KiB page holding the address. A root descriptor has no size, and a console shader reads as far past it as the title placed data. ProjectScarlett lost the device on an instanced draw (4 vertices × 4,029 instances) whose per-instance records run about 80 KiB past its root SRV: the fault was a read 32 KiB past the import.

  • Root SRVs and UAVs (root_view_address, runtime/d3d12/src/device/views/addressed.rs) now get an import of up to 4 MiB (ROOT_VIEW_REACH) behind their address. It starts at the 4 MiB boundary below the address when the memory from there is committed, at the address's own page otherwise, and spans 8 MiB clipped to the committed run, so that the bindings after it reuse it. Root CBVs keep their 64 KiB window, and an address outside committed memory is resolved as before.
  • Finding the import again: a lookup checked only the nearest registry entry, which can be a smaller resource placed inside the import, or one already released. covering_buffer checks up to 8 preceding live entries (Views::preceding_entries).
  • Keeping it: a list keeps only the native buffer, so the import's registry entry died with the command, and the next binding imported the pages again: megabytes for a root view, and a separate copy each time where section-backed pages are mirrored. CommandImports keeps the imports commands make (root views, and command_buffer_address's, such as fence labels) in a 1024-entry LRU. It keeps only imports whose pages stay mapped while they live, a host copy or title pages under an xmem hold (ImportedHeap::pages_held). An import of the title's own VirtualAlloc would outlive memory the title may release, and later submissions would name the freed pages.

A kept import holds its pages until 1,024 newer imports replace it, also after the title remaps those pages: lookups skip it then, as they skip every stale import, but the LRU still holds it.

In game I tested this on an older main together with other fixes of mine, not on this branch alone. The fault 32 KiB past a root SRV's import did not recur; every later device loss had the masked-lane pattern of #386 (fixed there), and 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.

Not a Lanes scenario: it is a new D3D12 regression control, root-srv-reach (runtime/d3d12/root_srv_guest.cpp, root_srv.hlsl), next to root-cbv-window, which covers the CBV side of the same function. It binds a root SRV 0x4480 into VirtualAlloced memory with 2 MiB after it, reads 16 bytes at 0, 0xff00, 64 KiB, 80 KiB and 1 MiB past it into a deadbeef-seeded result, and compares them with the memory. On main it fails:

d3d12-root-srv-reach failed: root SRV words=0/20 wrong at offsets 0 65280 65536 81920 1048576
  (read 00000000 00000000 00000000 00000000 00000000, expected 5a0077e0 5a023620 5a0237e0 5a02a7e0 5a1c77e0)

The shader ran (the seed was overwritten) and read zero at every offset, including offset 0, inside the imported page. I don't know why offset 0 reads zero too. The device was not lost and nothing in the test's log reports a fault; I could not read the kernel log on this machine.

Unit tests in runtime/d3d12/src/tests/device/views.rs cover the window (root_view_window: the control's layout, a 4 MiB-aligned start, memory not committed back to it, an allocation that starts above it, the clip to whole pages), the LRU (only held imports are kept; the least recently used goes first) and preceding_entries (it finds live entries behind a released one, where preceding returns nothing).

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 d3d12, with main's runtime/d3d12/src
D3D12 regression controls, --case root-srv-reach
  root-srv-reach  FAIL (words=0/20, above)

python build.py, with the change
D3D12 regression controls, all 21 cases
  21 PASS, 0 FAIL (root-srv-reach words=20/20; root-cbv-window keeps its exact import list)

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

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
  78 PASS, 0 FAIL

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:5538675264 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389). Originally posted by [MathiewMay](https://github.com/MathiewMay) on 2026-11-28T09:20:16Z. --- ## Summary A root SRV or UAV in title memory was bound through a one-page import: `root_buffer` asked `command_buffer_address` for one byte, which imports the 64 KiB page holding the address. A root descriptor has no size, and a console shader reads as far past it as the title placed data. ProjectScarlett lost the device on an instanced draw (4 vertices × 4,029 instances) whose per-instance records run about 80 KiB past its root SRV: the fault was a read 32 KiB past the import. - **Root SRVs and UAVs** (`root_view_address`, `runtime/d3d12/src/device/views/addressed.rs`) now get an import of up to 4 MiB (`ROOT_VIEW_REACH`) behind their address. It starts at the 4 MiB boundary below the address when the memory from there is committed, at the address's own page otherwise, and spans 8 MiB clipped to the committed run, so that the bindings after it reuse it. Root CBVs keep their 64 KiB window, and an address outside committed memory is resolved as before. - **Finding the import again**: a lookup checked only the nearest registry entry, which can be a smaller resource placed inside the import, or one already released. `covering_buffer` checks up to 8 preceding live entries (`Views::preceding_entries`). - **Keeping it**: a list keeps only the native buffer, so the import's registry entry died with the command, and the next binding imported the pages again: megabytes for a root view, and a separate copy each time where section-backed pages are mirrored. `CommandImports` keeps the imports commands make (root views, and `command_buffer_address`'s, such as fence labels) in a 1024-entry LRU. It keeps only imports whose pages stay mapped while they live, a host copy or title pages under an xmem hold (`ImportedHeap::pages_held`). An import of the title's own `VirtualAlloc` would outlive memory the title may release, and later submissions would name the freed pages. A kept import holds its pages until 1,024 newer imports replace it, also after the title remaps those pages: lookups skip it then, as they skip every stale import, but the LRU still holds it. In game I tested this on an older `main` together with other fixes of mine, not on this branch alone. The fault 32 KiB past a root SRV's import did not recur; every later device loss had the masked-lane pattern of #386 (fixed there), and 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.** Not a Lanes scenario: it is a new D3D12 regression control, `root-srv-reach` (`runtime/d3d12/root_srv_guest.cpp`, `root_srv.hlsl`), next to `root-cbv-window`, which covers the CBV side of the same function. It binds a root SRV 0x4480 into `VirtualAlloc`ed memory with 2 MiB after it, reads 16 bytes at 0, 0xff00, 64 KiB, 80 KiB and 1 MiB past it into a `deadbeef`-seeded result, and compares them with the memory. On `main` it fails: ```text d3d12-root-srv-reach failed: root SRV words=0/20 wrong at offsets 0 65280 65536 81920 1048576 (read 00000000 00000000 00000000 00000000 00000000, expected 5a0077e0 5a023620 5a0237e0 5a02a7e0 5a1c77e0) ``` The shader ran (the seed was overwritten) and read zero at every offset, including offset 0, inside the imported page. I don't know why offset 0 reads zero too. The device was not lost and nothing in the test's log reports a fault; I could not read the kernel log on this machine. Unit tests in `runtime/d3d12/src/tests/device/views.rs` cover the window (`root_view_window`: the control's layout, a 4 MiB-aligned start, memory not committed back to it, an allocation that starts above it, the clip to whole pages), the LRU (only held imports are kept; the least recently used goes first) and `preceding_entries` (it finds live entries behind a released one, where `preceding` returns nothing). 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 d3d12, with main's runtime/d3d12/src D3D12 regression controls, --case root-srv-reach root-srv-reach FAIL (words=0/20, above) python build.py, with the change D3D12 regression controls, all 21 cases 21 PASS, 0 FAIL (root-srv-reach words=20/20; root-cbv-window keeps its exact import list) cargo xwin test --no-run --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib, the test executable run under Proton 228 passed, 0 failed 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 78 PASS, 0 FAIL 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.
DrArroway commented 2026-11-28 15:28:07 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-28T15:28:07Z.


Tested in ProjectScarlett 1.0.2.1 on an AMD Radeon RX 6900 XT (1002:73bf, RADV NAVI21), Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14 (--backend proton), warm shader caches.

  • Without #389 and #393 (main at 6f89916): Two runs both faulted immediately on entering the 3D world with radv: GPUVM fault (CLIENT_ID: TCP (0x8), at 0x8007f1c50000 and 0x80011d73c000) and reset the GPU.
  • With #389 (911cc04c) stacked with #373, #393 and #398 on 6f89916: The 3D-world entry GPUVM fault did not occur across a 7m 12s run (2,105 frames total, 13+ world frames, 0 GPUVM faults, 0 device losses; the run ended on a title CPU EXCEPTION_BREAKPOINT in resource loading). Two further world runs rebased onto e380da1 also cleared world entry with no root-view faults.

One small code note while reading root_buffer (runtime/d3d12/src/commands/compute.rs) and root_view_address (runtime/d3d12/src/device/views/addressed.rs): root_buffer calls root_view_address for both BufferView::Srv and BufferView::Uav, and root_view_address imports/reuses buffers with D3D12_RESOURCE_FLAG_NONE. RADV accepts a raw-VA root UAV over that buffer, so it didn't affect our runs, but a host or validation layer that checks D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS on Set*RootUnorderedAccessView targets would need root_view_address to forward D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS when BufferView::Uav is bound (matching command_buffer_address_flags on main and address_uav).

<!-- greyfinch-sync:brcly/TuxBox:comment:7241488720 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7241488720). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-28T15:28:07Z. --- Tested in ProjectScarlett 1.0.2.1 on an AMD Radeon RX 6900 XT (`1002:73bf`, RADV NAVI21), Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14 (`--backend proton`), warm shader caches. - **Without #389 and #393 (`main` at `6f89916`):** Two runs both faulted immediately on entering the 3D world with `radv: GPUVM fault` (`CLIENT_ID: TCP (0x8)`, at `0x8007f1c50000` and `0x80011d73c000`) and reset the GPU. - **With #389 (`911cc04c`) stacked with #373, #393 and #398 on `6f89916`:** The 3D-world entry GPUVM fault did not occur across a 7m 12s run (`2,105` frames total, `13+` world frames, `0` GPUVM faults, `0` device losses; the run ended on a title CPU `EXCEPTION_BREAKPOINT` in resource loading). Two further world runs rebased onto `e380da1` also cleared world entry with no root-view faults. One small code note while reading `root_buffer` (`runtime/d3d12/src/commands/compute.rs`) and `root_view_address` (`runtime/d3d12/src/device/views/addressed.rs`): `root_buffer` calls `root_view_address` for both `BufferView::Srv` and `BufferView::Uav`, and `root_view_address` imports/reuses buffers with `D3D12_RESOURCE_FLAG_NONE`. RADV accepts a raw-VA root UAV over that buffer, so it didn't affect our runs, but a host or validation layer that checks `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS` on `Set*RootUnorderedAccessView` targets would need `root_view_address` to forward `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS` when `BufferView::Uav` is bound (matching `command_buffer_address_flags` on `main` and `address_uav`).
brcly commented 2026-11-28 16:04:23 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-28T16:04:23Z.


Trial results for this PR on NVIDIA. We're holding it back for now because of memory use, pending one confirming run.

Setup: RTX 4070 Ti SUPER 16 GB, driver 620.73.04, Linux 7.3.5, GE-Proton11-14, 30 GB RAM, ProjectScarlett offline. Build: main at 2af42c94 plus #373, #391, #393 and this PR (911cc04c), conflicts in device.rs and views.rs resolved by keeping both export lists.

Checks: all D3D12 regression controls (including root-srv-reach) and the Lanes tests we ran passed. Unit tests: 295 passed, 1 failed (aliases_import_their_private_backing, which also fails on unchanged main here).

Two game runs, against four earlier runs the same day on builds without these four PRs:

Two runs with this PR Four earlier runs
Peak game memory (RSS + swap) 29.4 GB in the first about 25 GB
Peak kernel memory 11.6 and 11.7 GB 7.7 to 8.1 GB
Lowest available system memory 2.4 and 2.8 GB 5.6 to 6.6 GB
Peak adapter non-local usage about 9.5 GB 6.5 to 6.8 GB
  • The growth came within about 10 seconds, late in the run.
  • In the second run we counted the imports made from root_view_address when covering_buffer found nothing: more than 8,700, about 20 GB requested in total. That is cumulative, not live memory. With a 1,024-entry limit, our guess is that the LRU churns and holds a lot of host memory at once.
  • The first run ended with Xid 109 (context switch timeout) at about the time the memory rose. We can't say which caused which, or that this PR caused either. The second run had no Xid and rendered the opening world scene; it ended on an unrelated rejected acceleration structure list.

Not yet confirmed: we haven't run the same build without this PR. That is the next run, and we'll report the numbers here.

Ideas if it holds up: cap the kept imports by bytes as well as count, or reuse a covering import over a wider search than the 8 preceding entries.

<!-- greyfinch-sync:brcly/TuxBox:comment:7241952753 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7241952753). Originally posted by [brcly](https://github.com/brcly) on 2026-11-28T16:04:23Z. --- Trial results for this PR on NVIDIA. We're holding it back for now because of memory use, pending one confirming run. **Setup:** RTX 4070 Ti SUPER 16 GB, driver 620.73.04, Linux 7.3.5, GE-Proton11-14, 30 GB RAM, ProjectScarlett offline. Build: `main` at `2af42c94` plus #373, #391, #393 and this PR (`911cc04c`), conflicts in `device.rs` and `views.rs` resolved by keeping both export lists. **Checks:** all D3D12 regression controls (including `root-srv-reach`) and the Lanes tests we ran passed. Unit tests: 295 passed, 1 failed (`aliases_import_their_private_backing`, which also fails on unchanged `main` here). **Two game runs**, against four earlier runs the same day on builds without these four PRs: | | Two runs with this PR | Four earlier runs | |---|---|---| | Peak game memory (RSS + swap) | 29.4 GB in the first | about 25 GB | | Peak kernel memory | 11.6 and 11.7 GB | 7.7 to 8.1 GB | | Lowest available system memory | 2.4 and 2.8 GB | 5.6 to 6.6 GB | | Peak adapter non-local usage | about 9.5 GB | 6.5 to 6.8 GB | - The growth came within about 10 seconds, late in the run. - In the second run we counted the imports made from `root_view_address` when `covering_buffer` found nothing: more than 8,700, about 20 GB requested in total. That is cumulative, not live memory. With a 1,024-entry limit, our guess is that the LRU churns and holds a lot of host memory at once. - The first run ended with Xid 109 (context switch timeout) at about the time the memory rose. We can't say which caused which, or that this PR caused either. The second run had no Xid and rendered the opening world scene; it ended on an unrelated rejected acceleration structure list. **Not yet confirmed:** we haven't run the same build without this PR. That is the next run, and we'll report the numbers here. Ideas if it holds up: cap the kept imports by bytes as well as count, or reuse a covering import over a wider search than the 8 preceding entries.
MathiewMay commented 2026-11-28 16:19:43 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by MathiewMay on 2026-11-28T16:19:43Z.


Thanks for testing this on the 6900 XT, and for the note on the flags.

Rebased onto 2af42c9 (now 3ea19fe). root_view_address now takes the flags the view needs: a root UAV is mapped in a buffer with D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, as command_buffer_address_flags and address UAVs are, and a root SRV keeps D3D12_RESOURCE_FLAG_NONE (root_view_flags in commands/compute.rs, with a unit test).

After the rebase, on an RX 9070 (RADV GFX1201, Mesa 26.2.7, GE-Proton11-14): 296 crate tests pass, all 22 D3D12 regression cases pass including root-srv-reach, and tuxbox.py check --no-gpu passes.

<!-- greyfinch-sync:brcly/TuxBox:comment:7242156781 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7242156781). Originally posted by [MathiewMay](https://github.com/MathiewMay) on 2026-11-28T16:19:43Z. --- Thanks for testing this on the 6900 XT, and for the note on the flags. Rebased onto `2af42c9` (now `3ea19fe`). `root_view_address` now takes the flags the view needs: a root UAV is mapped in a buffer with `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS`, as `command_buffer_address_flags` and address UAVs are, and a root SRV keeps `D3D12_RESOURCE_FLAG_NONE` (`root_view_flags` in `commands/compute.rs`, with a unit test). After the rebase, on an RX 9070 (RADV GFX1201, Mesa 26.2.7, GE-Proton11-14): 296 crate tests pass, all 22 D3D12 regression cases pass including `root-srv-reach`, and `tuxbox.py check --no-gpu` passes.
gtb-sbe commented 2026-11-29 02:11:06 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-29T02:11:06Z.


Tested this PR in ProjectScarlett 1.0.2.1 (offline) on an RX 9060 XT (1002:7590, RADV GFX1200), Mesa 26.2.6, Linux 6.18.60, GE-Proton11-14, 32 GB RAM.

Without it (b8355fa + #409 + #424 + #428), my run ended at world entry on a gfx-ring fault: TCP, read, MAPPING_ERROR 0x1, at native pages 0x800361e40000-0x800361e47000. #424's trace listed 10 unfinished draws, all with the same vertex/pixel pair. Offline, that vertex shader reads its root SRV (t1, space3, root parameter 2) as a raw buffer: a header at bytes 0/4/12, then per-instance records at ((h >> 7) & 0x1fffffc) + ((h >> 3) & 60) * SV_InstanceID. The faulting range starts on a 64 KiB boundary, which fits a read running off the one-page import that main makes for a root SRV. I've had the same fault kind on two earlier builds.

With it (7d26508 + #409 + #424 + this PR at 3ea19fe + #428's runtime part, all applied cleanly; everything but this PR is on main now, and GitHub still shows it as mergeable), five runs and no GPU fault in any:

  • The first ran about 15 minutes, about 9 of them in the world. It didn't end on its own: the launcher was killed on my side when free system memory dipped. There was no crash log and nothing in the kernel log.
  • The second ended after 8.5 minutes on the title's watchdog (Unsignaled CrossQueueBarrier), at about the same title frame (around 1,400) where the faulting runs had stopped. Before it, the provider held five label waits for writes that hadn't run yet, and #424's trace showed nothing unfinished on the GPU. I've seen the same barrier end a run without this PR, so I don't think it's related.
  • The third, with a temporary trace of held label waits added, got furthest: about 10.5 minutes in the world, driving in the intro. It ended on an access violation in the game's own code (a virtual call through an overwritten object), not on the GPU. I haven't found out yet what overwrote that object.
  • The fourth and fifth had #430 on top as well. The fourth ended on the same kind of access violation after about 6 minutes in the world, the fifth on the title's watchdog after about 7.

root-srv-reach, root-cbv-window, address-uav and buffer-import pass on this card, and so does the Lanes self-test. With #430 added, buffer-unmap-alive, buffer-unmap-released, placement and copy-resource pass too.

Memory, since that's what's holding it. I added a temporary counter, not part of this PR, for the imports root_view_address makes when covering_buffer finds nothing. In the first run:

  • 41,549 root SRV/UAV bindings, 7,000 new imports, 14.1 GiB requested in total (cumulative, not live). Only 1 new import before the world started loading.
  • The kept command imports reached the 1,024 limit after about 3,000 new imports and then stayed at 578-596 MiB.
  • 13,379 bindings had less than 128 KiB of committed memory behind the address, so their window was clipped. None of them faulted.
  • Game process: requested VRAM up to 12.1 GiB, GTT up to 5.5 GiB, RSS up to 15.6 GiB (rising slowly: 12.6 GiB at 6 minutes, 15.4 GiB at 14), lowest MemAvailable 5.3 GiB. Without the PR, the run faulted at 6 minutes with RSS 11.6 GiB, VRAM 11.6 GiB and GTT 5.0 GiB. So at the same point it's about 1 GiB more RSS here, but the longer world time grows memory by itself too, and I can't separate the two from these runs.

Over all five runs the counter ended between 1,024 new imports (2.5 GiB requested, in the short second run) and 19,000 (43.9 GiB requested over 67,823 bindings, in the fifth). The kept imports never went past 667 MiB. Peak requested VRAM was 12.1-12.8 GiB in every run. GTT and swap were higher in the two runs with #430 on top (requested GTT up to 12.3 GiB, swap up to 9.9 GiB), and I can't attribute that to either PR from these runs.

So on this card the LRU itself stays below 0.7 GiB. That's far below what you saw on NVIDIA, though the import churn is of the same order (7,000 imports and 14.1 GiB in the first 15 minutes here, 19,000 and 43.9 GiB in the fifth run, against more than 8,700 and about 20 GB there). If you cap the kept imports by bytes, the churn is what I'd watch: each new import is a fresh mapping of up to 8 MiB.

<!-- greyfinch-sync:brcly/TuxBox:comment:7249263434 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7249263434). Originally posted by [gtb-sbe](https://github.com/gtb-sbe) on 2026-11-29T02:11:06Z. --- Tested this PR in ProjectScarlett 1.0.2.1 (offline) on an RX 9060 XT (`1002:7590`, RADV GFX1200), Mesa 26.2.6, Linux 6.18.60, GE-Proton11-14, 32 GB RAM. **Without it** (`b8355fa` + #409 + #424 + #428), my run ended at world entry on a gfx-ring fault: `TCP`, read, `MAPPING_ERROR 0x1`, at native pages `0x800361e40000`-`0x800361e47000`. #424's trace listed 10 unfinished draws, all with the same vertex/pixel pair. Offline, that vertex shader reads its root SRV (`t1, space3`, root parameter 2) as a raw buffer: a header at bytes 0/4/12, then per-instance records at `((h >> 7) & 0x1fffffc) + ((h >> 3) & 60) * SV_InstanceID`. The faulting range starts on a 64 KiB boundary, which fits a read running off the one-page import that `main` makes for a root SRV. I've had the same fault kind on two earlier builds. **With it** (`7d26508` + #409 + #424 + this PR at `3ea19fe` + #428's runtime part, all applied cleanly; everything but this PR is on `main` now, and GitHub still shows it as mergeable), five runs and no GPU fault in any: - The first ran about 15 minutes, about 9 of them in the world. It didn't end on its own: the launcher was killed on my side when free system memory dipped. There was no crash log and nothing in the kernel log. - The second ended after 8.5 minutes on the title's watchdog (`Unsignaled CrossQueueBarrier`), at about the same title frame (around 1,400) where the faulting runs had stopped. Before it, the provider held five label waits for writes that hadn't run yet, and #424's trace showed nothing unfinished on the GPU. I've seen the same barrier end a run without this PR, so I don't think it's related. - The third, with a temporary trace of held label waits added, got furthest: about 10.5 minutes in the world, driving in the intro. It ended on an access violation in the game's own code (a virtual call through an overwritten object), not on the GPU. I haven't found out yet what overwrote that object. - The fourth and fifth had #430 on top as well. The fourth ended on the same kind of access violation after about 6 minutes in the world, the fifth on the title's watchdog after about 7. `root-srv-reach`, `root-cbv-window`, `address-uav` and `buffer-import` pass on this card, and so does the Lanes self-test. With #430 added, `buffer-unmap-alive`, `buffer-unmap-released`, `placement` and `copy-resource` pass too. **Memory**, since that's what's holding it. I added a temporary counter, not part of this PR, for the imports `root_view_address` makes when `covering_buffer` finds nothing. In the first run: - 41,549 root SRV/UAV bindings, 7,000 new imports, 14.1 GiB requested in total (cumulative, not live). Only 1 new import before the world started loading. - The kept command imports reached the 1,024 limit after about 3,000 new imports and then stayed at 578-596 MiB. - 13,379 bindings had less than 128 KiB of committed memory behind the address, so their window was clipped. None of them faulted. - Game process: requested VRAM up to 12.1 GiB, GTT up to 5.5 GiB, RSS up to 15.6 GiB (rising slowly: 12.6 GiB at 6 minutes, 15.4 GiB at 14), lowest MemAvailable 5.3 GiB. Without the PR, the run faulted at 6 minutes with RSS 11.6 GiB, VRAM 11.6 GiB and GTT 5.0 GiB. So at the same point it's about 1 GiB more RSS here, but the longer world time grows memory by itself too, and I can't separate the two from these runs. Over all five runs the counter ended between 1,024 new imports (2.5 GiB requested, in the short second run) and 19,000 (43.9 GiB requested over 67,823 bindings, in the fifth). The kept imports never went past 667 MiB. Peak requested VRAM was 12.1-12.8 GiB in every run. GTT and swap were higher in the two runs with #430 on top (requested GTT up to 12.3 GiB, swap up to 9.9 GiB), and I can't attribute that to either PR from these runs. So on this card the LRU itself stays below 0.7 GiB. That's far below what you saw on NVIDIA, though the import churn is of the same order (7,000 imports and 14.1 GiB in the first 15 minutes here, 19,000 and 43.9 GiB in the fifth run, against more than 8,700 and about 20 GB there). If you cap the kept imports by bytes, the churn is what I'd watch: each new import is a fresh mapping of up to 8 MiB.
brcly commented 2026-11-29 15:08:15 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T15:08:15Z.


Thanks to everyone who tested this. The AMD reports (RX 6900 XT, RX 9060 XT, RX 9070) of the fault at world entry going away are convincing. Two things hold it back for us, and they apply to #441 too, which carries the same root_view_address code.

1. Memory on our machine. ProjectScarlett, RTX 4070 Ti SUPER, NVIDIA 620.x, GE-Proton11-14, 30 GB RAM; trial branch on main 2af42c94:

Boot With this PR Peak memory Kernel memory Adapter system memory
b28–b31 (before, same machine) no about 25 GB 7.8 GB 6.8 GB
b32 yes 29.4 GB 11.6 GB 9.5 GB
b33 yes — 11.7 GB —
b34 no (removed from the branch) 24.5 GB 6.9 GB —
  • In b33 the provider made 8,704 root-view imports, about 20 GB cumulative. My guess is that the 1,024-entry cache thrashes and pages get imported again and again. I haven't confirmed that.
  • This is one run each way, so it's a correlation and nothing more. But memory is our tightest limit: a run on this machine already sits near the oomd line.

2. The ordering question NickStallman raised on #441: root_view_address queries the regions and picks covering_buffer before anything waits for a pending CopyPageMappings. Is that window safe, or should it wait first, as buffer_at does?

What would help:

  • the number of root-view imports, and the total bytes imported, over a run to world entry, plus kernel memory or the adapter's system memory with and without this PR on any card;
  • an answer to the ordering question.

Please also settle between #389 and #441 which one carries on; we'll only merge one.

<!-- greyfinch-sync:brcly/TuxBox:comment:7257849244 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7257849244). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T15:08:15Z. --- Thanks to everyone who tested this. The AMD reports (RX 6900 XT, RX 9060 XT, RX 9070) of the fault at world entry going away are convincing. Two things hold it back for us, and they apply to #441 too, which carries the same `root_view_address` code. **1. Memory on our machine.** ProjectScarlett, RTX 4070 Ti SUPER, NVIDIA 620.x, GE-Proton11-14, 30 GB RAM; trial branch on `main` `2af42c94`: | Boot | With this PR | Peak memory | Kernel memory | Adapter system memory | |---|---|---|---|---| | b28–b31 (before, same machine) | no | about 25 GB | 7.8 GB | 6.8 GB | | b32 | yes | 29.4 GB | 11.6 GB | 9.5 GB | | b33 | yes | — | 11.7 GB | — | | b34 | no (removed from the branch) | 24.5 GB | 6.9 GB | — | - In b33 the provider made **8,704 root-view imports, about 20 GB cumulative**. My guess is that the 1,024-entry cache thrashes and pages get imported again and again. I haven't confirmed that. - This is one run each way, so it's a correlation and nothing more. But memory is our tightest limit: a run on this machine already sits near the oomd line. **2. The ordering question** NickStallman raised on #441: `root_view_address` queries the regions and picks `covering_buffer` before anything waits for a pending `CopyPageMappings`. Is that window safe, or should it wait first, as `buffer_at` does? What would help: - the number of root-view imports, and the total bytes imported, over a run to world entry, plus kernel memory or the adapter's system memory with and without this PR on any card; - an answer to the ordering question. Please also settle between #389 and #441 which one carries on; we'll only merge one.
NickStallman commented 2026-11-29 15:19:30 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T15:19:30Z.


Counts from my builds that have #441 (RTX 5090, 24 GB, 620.70.10, GE-Proton11-14; main at d2eb99ed or 6e2c5dab with #462, #463, #461 and others; ProjectScarlett past the story load). They are all imports of title memory, not only root views (my ring doesn't separate them), so they bound your number from above and don't answer it:

Run Imports made Length of the run
62a (traced) 109,836 about 500 s
64b (traced) 181,804 about 760 s
65b (traced) 98,122 about 560 s

At the end of 65b, the memory ledger read: card 13.3 of 24 GB, adapter system memory 2.4 of 70.6 GB, title pages 7.1 GB, process commit 9.9 GB. The adapter system memory doesn't show your 9.5 GB, but the machine has more VRAM and I have no run without #441 to compare, so I can't say what it costs. If a counter of root-view imports and bytes would help I can add one and run it, with and without #441.

I don't have an answer on the ordering; it was a question from reading.

<!-- greyfinch-sync:brcly/TuxBox:comment:7257999251 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7257999251). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T15:19:30Z. --- Counts from my builds that have #441 (RTX 5090, 24 GB, 620.70.10, GE-Proton11-14; `main` at d2eb99ed or 6e2c5dab with #462, #463, #461 and others; ProjectScarlett past the story load). They are all imports of title memory, **not only root views** (my ring doesn't separate them), so they bound your number from above and don't answer it: | Run | Imports made | Length of the run | |---|---|---| | 62a (traced) | 109,836 | about 500 s | | 64b (traced) | 181,804 | about 760 s | | 65b (traced) | 98,122 | about 560 s | At the end of 65b, the memory ledger read: card 13.3 of 24 GB, adapter system memory 2.4 of 70.6 GB, title pages 7.1 GB, process commit 9.9 GB. The adapter system memory doesn't show your 9.5 GB, but the machine has more VRAM and I have no run without #441 to compare, so I can't say what it costs. If a counter of root-view imports and bytes would help I can add one and run it, with and without #441. I don't have an answer on the ordering; it was a question from reading.
JeffreyBytes commented 2026-11-29 16:27:05 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-29T16:27:05Z.


Numbers for the two things asked above, from a 12 GB AMD card. RX 6700 XT (1002:73df), RADV, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14, 32 GB RAM, ProjectScarlett offline, warm caches, default XMem mode (section backing). I ran #441's commits since they're the ones on newer main; it's the same root_view_address.

Both builds are on main 6e2c5dab. "With" is #441 at f244a687 merged in. One run each.

Without it, the run ends at world entry on the fault this PR describes, and the address lines up exactly. I added a local trace of root SRV/UAV binds that import their own buffer:

radv: GPUVM fault detected at address 0x80012f050000.
root SRV 2, list 0x76364360, guest 0x218cc000, imported guest [0x218c0000, 0x218d0000) host [0x80012f040000, 0x80012f050000), 0x4000 bytes to its end

Same list as the 17 unfinished draws in the GPU fault trace, all one VS/PS pair. That list binds root SRV 2 dozens of times at addresses 0x17b00 (97 KiB) apart, each with 16 to 58 KiB left in its one page. The ring reset recovered.

With #441 there's no GPU fault. The run goes through world entry and ends at 652 s in the title's own crash handler, which is where runs here end now.

without (6e2c5dab) with #441
Ending GPUVM fault at 734 s title's own exit at 652 s, no GPU fault
Root-view binds 30,336 35,866
...that made a new import 54 (64 KiB each) 680 (8 MiB each)
...that reused one 30,282 35,186 (29,870 from the command cache, 5,316 from another live buffer)
Bytes imported for root views, cumulative 3.4 MiB 5.31 GiB
Adapter system memory, last ledger line 7,348 MiB 7,552 MiB
Peak GTT (mem_info_gtt_used) 7.6 GB 8.2 GB
Peak swap 5.0 GB 5.5 GB

So on this card the cumulative import is large, 5.3 GiB in about five minutes of world, but it doesn't show up as memory: adapter system memory and GTT are within a run's noise of the run without it. I can't say why NVIDIA shows 2.7 GB more; I have no NVIDIA card.

Two details from the counter that bear on the cache question:

  • Before the world there are 2,099 root-view binds and not one new import. All 680 come in the world.
  • All 680 new imports were ones CommandImports doesn't keep (pages_held() false), so the next bind outside a kept window imports its 8 MiB again. 409 of the 680 (3.2 GiB) had been released again by the end. If that reading is right, it's not the 1,024-entry cache thrashing, it's these imports never entering it. The cache itself was full at 1,024 entries by the end, shared with the other command imports. I lost the eviction count to a truncated log line and can rerun for it.

The counter is my own local commit on top of #441, not part of either PR, and this was its first run, so treat the cache breakdown as needing a second look by someone who knows that code. I can share the patch.

One comparison point, in case it helps with the memory side: before I found these PRs I'd tried the same idea with a different window, 32 MiB cells clipped to the committed run and held by the command allocator until Reset, no LRU. Same base, same scene: 11 new imports in the whole run, no fault, adapter system memory 7,499 MiB. I'm not proposing a third PR, just noting that far fewer, larger imports got through the same scene.

I haven't looked at the ordering question.

<!-- greyfinch-sync:brcly/TuxBox:comment:7258913100 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7258913100). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-29T16:27:05Z. --- Numbers for the two things asked above, from a 12 GB AMD card. RX 6700 XT (`1002:73df`), RADV, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14, 32 GB RAM, ProjectScarlett offline, warm caches, default XMem mode (section backing). I ran #441's commits since they're the ones on newer `main`; it's the same `root_view_address`. Both builds are on `main` `6e2c5dab`. "With" is #441 at `f244a687` merged in. One run each. **Without it**, the run ends at world entry on the fault this PR describes, and the address lines up exactly. I added a local trace of root SRV/UAV binds that import their own buffer: ``` radv: GPUVM fault detected at address 0x80012f050000. root SRV 2, list 0x76364360, guest 0x218cc000, imported guest [0x218c0000, 0x218d0000) host [0x80012f040000, 0x80012f050000), 0x4000 bytes to its end ``` Same list as the 17 unfinished draws in the GPU fault trace, all one VS/PS pair. That list binds root SRV 2 dozens of times at addresses 0x17b00 (97 KiB) apart, each with 16 to 58 KiB left in its one page. The ring reset recovered. **With #441** there's no GPU fault. The run goes through world entry and ends at 652 s in the title's own crash handler, which is where runs here end now. | | without (`6e2c5dab`) | with #441 | | --- | --- | --- | | Ending | GPUVM fault at 734 s | title's own exit at 652 s, no GPU fault | | Root-view binds | 30,336 | 35,866 | | ...that made a new import | 54 (64 KiB each) | 680 (8 MiB each) | | ...that reused one | 30,282 | 35,186 (29,870 from the command cache, 5,316 from another live buffer) | | Bytes imported for root views, cumulative | 3.4 MiB | 5.31 GiB | | Adapter system memory, last ledger line | 7,348 MiB | 7,552 MiB | | Peak GTT (`mem_info_gtt_used`) | 7.6 GB | 8.2 GB | | Peak swap | 5.0 GB | 5.5 GB | So on this card the cumulative import is large, 5.3 GiB in about five minutes of world, but it doesn't show up as memory: adapter system memory and GTT are within a run's noise of the run without it. I can't say why NVIDIA shows 2.7 GB more; I have no NVIDIA card. Two details from the counter that bear on the cache question: - Before the world there are 2,099 root-view binds and not one new import. All 680 come in the world. - All 680 new imports were ones `CommandImports` doesn't keep (`pages_held()` false), so the next bind outside a kept window imports its 8 MiB again. 409 of the 680 (3.2 GiB) had been released again by the end. If that reading is right, it's not the 1,024-entry cache thrashing, it's these imports never entering it. The cache itself was full at 1,024 entries by the end, shared with the other command imports. I lost the eviction count to a truncated log line and can rerun for it. The counter is my own local commit on top of #441, not part of either PR, and this was its first run, so treat the cache breakdown as needing a second look by someone who knows that code. I can share the patch. One comparison point, in case it helps with the memory side: before I found these PRs I'd tried the same idea with a different window, 32 MiB cells clipped to the committed run and held by the command allocator until Reset, no LRU. Same base, same scene: 11 new imports in the whole run, no fault, adapter system memory 7,499 MiB. I'm not proposing a third PR, just noting that far fewer, larger imports got through the same scene. I haven't looked at the ordering question.
glovepost commented 2026-11-29 17:01:10 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T17:01:10Z.


We're carrying on with this pull request and closing #441, which carried the same root_view_address change. #441 differed from this one by about 30 lines in runtime/d3d12/src/device/views/addressed.rs; the other 12 files are identical. @MathiewMay, here are the two additions in case you want to fold them in.

1. Wait for a pending CopyPageMappings before choosing the window. This is the ordering question @NickStallman raised and @brcly repeated. For a non-null address, root_view_address calls this before VirtualQuery and covering_buffer:

let start = address & !(ROOT_VIEW_REACH - 1);
crate::commands::page_mapping::GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH)?;

Without it, a mapping that is still pending leaves VirtualQuery seeing the old state, so the window can be one page or end early, and an import the remap is about to retire can be reused.

2. Bind an existing buffer when the address is a GetGPUVirtualAddress value. Widening such an address to the 8 MiB window imports whatever committed range that host number happens to fall in. On NVIDIA that made lanes-selftest-thread-dimensions fail with close list failed: 0x80070057. #441 first looks through up to 8 preceding registry entries (preceding_entries) for a live buffer that is not an import, has matching flags and contains the address, and binds that buffer directly.

On that version, root-srv-reach (20/20 words) and root-cbv-window (120/120 words) passed, and so did the 72 guest and Lanes checks of tuxbox.py verify. This was on an RTX 2070 SUPER (10de:1e84, driver 620.73.04) and on RADV (1002:13c0, Mesa 26.3.1), both with GE-Proton11-14.

On the memory question: from reading the code, CommandImports is limited by entry count (1,024) but not by bytes, and each kept import can span up to 8 MiB. A byte budget next to the count limit, and/or a wider search than the 8 preceding entries in covering_buffer, would be the first things I'd try. I can re-run the NVIDIA checks on this branch once it's updated.

<!-- greyfinch-sync:brcly/TuxBox:comment:7259355559 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7259355559). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T17:01:10Z. --- We're carrying on with this pull request and closing #441, which carried the same `root_view_address` change. #441 differed from this one by about 30 lines in `runtime/d3d12/src/device/views/addressed.rs`; the other 12 files are identical. @MathiewMay, here are the two additions in case you want to fold them in. **1. Wait for a pending `CopyPageMappings` before choosing the window.** This is the ordering question @NickStallman raised and @brcly repeated. For a non-null address, `root_view_address` calls this before `VirtualQuery` and `covering_buffer`: ```rust let start = address & !(ROOT_VIEW_REACH - 1); crate::commands::page_mapping::GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH)?; ``` Without it, a mapping that is still pending leaves `VirtualQuery` seeing the old state, so the window can be one page or end early, and an import the remap is about to retire can be reused. **2. Bind an existing buffer when the address is a `GetGPUVirtualAddress` value.** Widening such an address to the 8 MiB window imports whatever committed range that host number happens to fall in. On NVIDIA that made `lanes-selftest-thread-dimensions` fail with `close list failed: 0x80070057`. #441 first looks through up to 8 preceding registry entries (`preceding_entries`) for a live buffer that is not an import, has matching flags and contains the address, and binds that buffer directly. On that version, `root-srv-reach` (20/20 words) and `root-cbv-window` (120/120 words) passed, and so did the 72 guest and Lanes checks of `tuxbox.py verify`. This was on an RTX 2070 SUPER (`10de:1e84`, driver 620.73.04) and on RADV (`1002:13c0`, Mesa 26.3.1), both with GE-Proton11-14. On the memory question: from reading the code, `CommandImports` is limited by entry count (1,024) but not by bytes, and each kept import can span up to 8 MiB. A byte budget next to the count limit, and/or a wider search than the 8 preceding entries in `covering_buffer`, would be the first things I'd try. I can re-run the NVIDIA checks on this branch once it's updated.
DrArroway commented 2026-11-29 19:26:59 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T19:26:59Z.


@MathiewMay @glovepost While testing #389 alongside #501 (TUXBOX_XMEM_PRIVATE_VIEWS=1) on an RX 6900 XT, I ran into an interaction in root_view_address (runtime/d3d12/src/device/views/addressed.rs) that is worth considering alongside #441's additions during the rebase onto main:

What happens with single-VirtualQuery in root_view_address

  1. Per-page protection splits: Under write-watched MEM_PRIVATE (mix of PAGE_READONLY / PAGE_READWRITE, plus PAGE_NOACCESS on unpromoted secondary aliases), a single VirtualQuery(address) stops at the first protection boundary, so run_end can clip well short of 2 * ROOT_VIEW_REACH (even to a single 64 KiB page) even though the surrounding pages are committed and backed.
  2. PrivateSpan AllocationBase boundaries: Under TUXBOX_XMEM_PRIVATE_VIEWS=1, XMem commits MEM_PRIVATE ranges in separate PrivateSpan OS allocations (aligned up to 4 MiB chunks via PRIVATE_SPAN_CHUNK, each with its own AllocationBase; and #501 splits BackingOrigin::PrivateView(span_id) per PrivateSpan so userptr runs never cross VMAs). Clamping to a single region.AllocationBase stops an 8 MiB (2 * ROOT_VIEW_REACH) window at the PrivateSpan boundary even when adjacent PrivateSpans are contiguous and XMem-backed.

Approach tested (walk_committed_run)

Replacing the single VirtualQuery end calculation in root_view_address with a small walk_committed_run helper resolved both cases cleanly:

  • Non-XMem addresses: Walk contiguous MEM_COMMIT segments up to limit while next_alloc == alloc (crosses protection splits within the same AllocationBase, stops at a different AllocationBase).
  • XMem-backed addresses (super::super::heap::backing::is_backed_range(page, page + 0x10000)): Walk contiguous MEM_COMMIT segments across adjacent PrivateSpan AllocationBases up to limit, verifying is_backed_range (binary-searching to the last backed 64 KiB page if a segment extends past backed XMem) and passing allocation = 0 into root_view_window so start can extend backward across a preceding backed PrivateSpan as well.
  • This composes directly with import_scattered_buffer and #501's PrivateSpan backing-run split: the root view still spans the full 8 MiB ROOT_VIEW_REACH window while import_scattered_buffer imports each 4 MiB PrivateSpan backing piece separately.

(Note: when folding in #441's GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH)? before querying, waiting first is also needed so is_backed_range and VirtualQuery see the settled mapping state.)

On main + #389 (3ea19fe, rebased locally with #441's two additions + walk_committed_run) + #501 (TUXBOX_XMEM_PRIVATE_VIEWS=1), an offline ProjectScarlett run on RX 6900 XT (1002:73bf, RADV, GE-Proton11-14) ran 555.1s (15,497 presents) with 0 GPUVM faults, 0 heap import failures, 0 secondary alias errors, and section=0/0.0MiB throughout.

<!-- greyfinch-sync:brcly/TuxBox:comment:7261288617 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7261288617). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-29T19:26:59Z. --- @MathiewMay @glovepost While testing #389 alongside #501 (`TUXBOX_XMEM_PRIVATE_VIEWS=1`) on an RX 6900 XT, I ran into an interaction in `root_view_address` (`runtime/d3d12/src/device/views/addressed.rs`) that is worth considering alongside #441's additions during the rebase onto `main`: ### What happens with single-`VirtualQuery` in `root_view_address` 1. **Per-page protection splits:** Under write-watched `MEM_PRIVATE` (mix of `PAGE_READONLY` / `PAGE_READWRITE`, plus `PAGE_NOACCESS` on unpromoted secondary aliases), a single `VirtualQuery(address)` stops at the first protection boundary, so `run_end` can clip well short of `2 * ROOT_VIEW_REACH` (even to a single 64 KiB page) even though the surrounding pages are committed and backed. 2. **`PrivateSpan` `AllocationBase` boundaries:** Under `TUXBOX_XMEM_PRIVATE_VIEWS=1`, XMem commits `MEM_PRIVATE` ranges in separate `PrivateSpan` OS allocations (aligned up to 4 MiB chunks via `PRIVATE_SPAN_CHUNK`, each with its own `AllocationBase`; and #501 splits `BackingOrigin::PrivateView(span_id)` per `PrivateSpan` so userptr runs never cross VMAs). Clamping to a single `region.AllocationBase` stops an 8 MiB (`2 * ROOT_VIEW_REACH`) window at the `PrivateSpan` boundary even when adjacent `PrivateSpan`s are contiguous and XMem-backed. ### Approach tested (`walk_committed_run`) Replacing the single `VirtualQuery` end calculation in `root_view_address` with a small `walk_committed_run` helper resolved both cases cleanly: - **Non-XMem addresses:** Walk contiguous `MEM_COMMIT` segments up to `limit` while `next_alloc == alloc` (crosses protection splits within the same `AllocationBase`, stops at a different `AllocationBase`). - **XMem-backed addresses** (`super::super::heap::backing::is_backed_range(page, page + 0x10000)`): Walk contiguous `MEM_COMMIT` segments across adjacent `PrivateSpan` `AllocationBase`s up to `limit`, verifying `is_backed_range` (binary-searching to the last backed 64 KiB page if a segment extends past backed XMem) and passing `allocation = 0` into `root_view_window` so `start` can extend backward across a preceding backed `PrivateSpan` as well. - This composes directly with `import_scattered_buffer` and #501's `PrivateSpan` backing-run split: the root view still spans the full 8 MiB `ROOT_VIEW_REACH` window while `import_scattered_buffer` imports each 4 MiB `PrivateSpan` backing piece separately. *(Note: when folding in #441's `GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH)?` before querying, waiting first is also needed so `is_backed_range` and `VirtualQuery` see the settled mapping state.)* On `main` + #389 (`3ea19fe`, rebased locally with #441's two additions + `walk_committed_run`) + #501 (`TUXBOX_XMEM_PRIVATE_VIEWS=1`), an offline ProjectScarlett run on RX 6900 XT (`1002:73bf`, RADV, GE-Proton11-14) ran **555.1s** (`15,497` presents) with **0** GPUVM faults, **0** `heap import failure`s, **0** `secondary alias` errors, and `section=0/0.0MiB` throughout.
brcly commented 2026-11-29 19:56:00 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T19:56:00Z.


Thanks again to everyone who tested and traced this. The fault is clearly real, and JeffreyBytes's trace ties it to the one-page import at the exact faulting address. Where we stand:

Before we can merge it

  1. Rebase onto main. Only one hunk in runtime/d3d12/src/tests/device/views.rs conflicts now.

  2. Fold in glovepost's two additions from #441:

    • the GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH) before VirtualQuery and covering_buffer (the ordering question);
    • binding the existing buffer when the address is a GetGPUVirtualAddress value. Without it, lanes-selftest-thread-dimensions fails on NVIDIA.

    DrArroway's walk_committed_run, for windows clipped at protection splits and PrivateSpan boundaries, would be welcome too.

  3. The memory cost. From JeffreyBytes's counter: the imports made in the world don't enter CommandImports (pages_held() is false). So every bind outside a kept window imports its 8 MiB again: 680 new imports and 5.3 GiB in about five minutes of world on an RX 6700 XT, more than 8,700 on our RTX 4070 Ti SUPER. On NVIDIA that came with about +2.7 GB of adapter system memory and +4 GB of kernel memory (one run each way). That points at the import lifetime more than at the 1,024-entry limit. JeffreyBytes's comparison, with 32 MiB cells clipped to the committed run and held by the command allocator until Reset, made 11 imports in the whole run, with no fault and no memory rise. Something along those lines, tied to the allocator rather than an LRU, would address our concern.

@MathiewMay, are you able to pick this up? If we don't hear back in a few days, @JeffreyBytes, would you post your allocator-lifetime version as its own PR? We'd review it in place of this one. We'll only merge one of them.

<!-- greyfinch-sync:brcly/TuxBox:comment:7261673599 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7261673599). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T19:56:00Z. --- Thanks again to everyone who tested and traced this. The fault is clearly real, and JeffreyBytes's trace ties it to the one-page import at the exact faulting address. Where we stand: **Before we can merge it** 1. **Rebase onto `main`.** Only one hunk in `runtime/d3d12/src/tests/device/views.rs` conflicts now. 2. **Fold in glovepost's two additions from #441:** - the `GPU_APERTURE.wait(start, 2 * ROOT_VIEW_REACH)` before `VirtualQuery` and `covering_buffer` (the ordering question); - binding the existing buffer when the address is a `GetGPUVirtualAddress` value. Without it, `lanes-selftest-thread-dimensions` fails on NVIDIA. DrArroway's `walk_committed_run`, for windows clipped at protection splits and `PrivateSpan` boundaries, would be welcome too. 3. **The memory cost.** From JeffreyBytes's counter: the imports made in the world don't enter `CommandImports` (`pages_held()` is false). So every bind outside a kept window imports its 8 MiB again: 680 new imports and 5.3 GiB in about five minutes of world on an RX 6700 XT, more than 8,700 on our RTX 4070 Ti SUPER. On NVIDIA that came with about +2.7 GB of adapter system memory and +4 GB of kernel memory (one run each way). That points at the import lifetime more than at the 1,024-entry limit. JeffreyBytes's comparison, with 32 MiB cells clipped to the committed run and held by the command allocator until `Reset`, made 11 imports in the whole run, with no fault and no memory rise. Something along those lines, tied to the allocator rather than an LRU, would address our concern. @MathiewMay, are you able to pick this up? If we don't hear back in a few days, @JeffreyBytes, would you post your allocator-lifetime version as its own PR? We'd review it in place of this one. We'll only merge one of them.
brcly commented 2026-11-30 04:12:29 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:29Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268564927 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7268564927). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:29Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
brcly commented 2026-11-30 20:53:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T20:53:21Z.


I've rebased this onto main and pushed it here, so it can go in. What changed:

  • Rebase: onto main after the formatting and lint cleanup. The conflicts were in the regression lists (both kept), the exports, and buffer_at, which now uses your covering_buffer.
  • From #441: the GPU_APERTURE.wait over the whole window before the query, and recorded_buffer, which binds the existing buffer when the address is a GetGPUVirtualAddress value.
  • Lints: SAFETY comments, a # Safety section on root_view_address, and a checked usize conversion.

Measured on an RTX 4070 Ti SUPER, GE-Proton11-15:

  • root-srv-reach, cbv-views and root-cbv-window pass.
  • All 30 lanes-selftest scenarios pass, including thread-dimensions, and so does lanes-compute-root-srv.
  • One ProjectScarlett world run: the scope peaked at 9.6 GB RAM plus 10.6 GB swap, against 10 plus 11.2 GB without this change. The memory growth measured on 11-28 didn't show this time.
  • The DistantLights root SRV fault (VS 281b4977, reading past its import) didn't recur in that run. The run was too short to prove it's gone.

Still open: graphics and mesh root views keep the one-page import, because this change resolves compute root views only. That run ended on a mesh-draw fault, which may be the same kind of read. I'll follow that up separately.

<!-- greyfinch-sync:brcly/TuxBox:comment:7291610815 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/389#issuecomment-7291610815). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T20:53:21Z. --- I've rebased this onto `main` and pushed it here, so it can go in. What changed: - **Rebase:** onto `main` after the formatting and lint cleanup. The conflicts were in the regression lists (both kept), the exports, and `buffer_at`, which now uses your `covering_buffer`. - **From #441:** the `GPU_APERTURE.wait` over the whole window before the query, and `recorded_buffer`, which binds the existing buffer when the address is a `GetGPUVirtualAddress` value. - **Lints:** `SAFETY` comments, a `# Safety` section on `root_view_address`, and a checked `usize` conversion. Measured on an RTX 4070 Ti SUPER, GE-Proton11-15: - `root-srv-reach`, `cbv-views` and `root-cbv-window` pass. - All 30 `lanes-selftest` scenarios pass, including `thread-dimensions`, and so does `lanes-compute-root-srv`. - One ProjectScarlett world run: the scope peaked at 9.6 GB RAM plus 10.6 GB swap, against 10 plus 11.2 GB without this change. The memory growth measured on 11-28 didn't show this time. - The DistantLights root SRV fault (`VS 281b4977`, reading past its import) didn't recur in that run. The run was too short to prove it's gone. Still open: graphics and mesh root views keep the one-page import, because this change resolves compute root views only. That run ended on a mesh-draw fault, which may be the same kind of read. I'll follow that up separately.
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!389
No description provided.