d3d12: keep texture-upload staging out of vkd3d's ReBAR budget #595

Merged
Kayotic1337 merged 1 commit from upstream-pr/595 into main 2026-11-30 19:16:39 +00:00
Kayotic1337 commented 2026-11-30 19:03:35 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-30T19:03:35Z.


vkd3d-proton gives UPLOAD heaps a fixed ReBAR budget: 1/16 of VRAM, 1019 MiB on a 16 GB card. In ProjectScarlett, the texture-upload staging buffers in placement/upload.rs (Transfer::begin) are committed UPLOAD buffers of up to 528 MiB. They fill that budget, and the next one falls back to system memory. That is the vkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory line discussed on #292. The attribution with logs is in https://github.com/brcly/TuxBox/issues/292#issuecomment-7286748306: every refused request was a staging create of exactly that size.

This change creates staging in a CUSTOM heap with WRITE_COMBINE on L0 instead of UPLOAD. That is the same memory UPLOAD uses without ReBAR (write-combined system memory). For an L0 custom heap, vkd3d asks only for HOST_VISIBLE | HOST_COHERENT and drops the device-local types, so these buffers stay out of the BAR. The CPU writes them the same way, the copy queue reads them the same way, and the ledger still counts them as system memory. committed in placement.rs gets a committed_in sibling that takes heap properties. The other callers are unchanged.

Game runs

RX 9070 XT (1002:7550), RADV, Mesa 26.3.1, GE-Proton11-14, vkd3d-proton 71cae091, Linux 7.3.6. Same settings in every run: TUXBOX_VRAM_RESERVE_MIB=4096, TUXBOX_SPILL_WRITE_BACK=0, TUXBOX_XMEM_PRIVATE_VIEWS=1, VKD3D_CONFIG=log_memory_budget, no no_upload_hvv, warm shader cache.

Run Build ReBAR refusals Fallbacks to system memory Peak ReBAR use Staging buffers ≥ 32 MiB
D without this change 3 3 969 MiB 8 in ReBAR, 3 fell back
E with this change 0 0 514 MiB 10, all in system memory
F with this change (repeat) 0 0 883 MiB 9, all in system memory
G with this change (repeat) 0 0 883 MiB 10, all in system memory
H with this change (repeat) 0 0 835 MiB 27, all in system memory

Without this change, every comparable run I have had fallbacks (2 to 5, see #292). With it, none of the four runs had any, including H with 27 staging buffers of 32 MiB or more. F and H got further into the game than E (4,096 placed textures spilled vs 1,024), and their peaks are higher for that reason. In F, 488 MiB of that peak is one internal vkd3d allocation made at device creation, and the rest is 16 MiB UPLOAD chunks. So with this change the title's own UPLOAD heaps still have only about 136 MiB of headroom there. This change removes TuxBox's staging from the budget. It doesn't make the budget larger.

These runs were on #575's head (be15fac8) with this diff applied, not on this branch's head. placement.rs and upload.rs are identical on be15fac8 and on bbc26254, so the diff is the same. I didn't run the game on bbc26254: its launcher now prepares first after a translator change (e9147f2a), and that preparation ran at about 100 shaders per minute here, roughly 4 hours for 25,889 shaders. I'll look at that separately.

Every run still ends in a crash. That is the separate problem I've reported before, and this change doesn't affect it: D and E ended on the compute-queue TCP write fault (0x641041), F and G on a gfx-ring fault (0x70113A, 0x50113A), and H on the title watchdog with no kernel fault logged. I didn't measure frame times, because the game doesn't get far enough to have a stable stretch.

Checks

On this branch's head, RX 9070 XT, GE-Proton11-14:

python tuxbox.py check --changed --backend proton --proton GE-Proton11-14-x86_64 --prefix PREFIX --windows-dxc DXC/bin/x64
Evidence: TuxBox check of 9bde51efcbf7, no uncommitted changes, GPU default adapter: 16 passed, 0 failed, 0 not run

That covers 113 of 113 Lanes and fixture gates, including the placement ones (d3d12-placement, lanes-selftest-texture-publication). I haven't traced which gates create a staging buffer through Transfer::begin. Also 22 of 22 D3D12 regression controls. Not run on NVIDIA. I don't have one.

No Lanes scenario: the bug only shows once staging buffers fill vkd3d's ReBAR budget, which takes hundreds of MiB of texture uploads in flight. Lanes doesn't upload that much, and the fallback only shows up as a vkd3d log line, not as a result a scenario could check.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5571849089 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/595). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T19:03:35Z. --- vkd3d-proton gives `UPLOAD` heaps a fixed ReBAR budget: 1/16 of VRAM, 1019 MiB on a 16 GB card. In ProjectScarlett, the texture-upload staging buffers in `placement/upload.rs` (`Transfer::begin`) are committed `UPLOAD` buffers of up to 528 MiB. They fill that budget, and the next one falls back to system memory. That is the `vkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory` line discussed on #292. The attribution with logs is in https://github.com/brcly/TuxBox/issues/292#issuecomment-7286748306: every refused request was a staging create of exactly that size. This change creates staging in a `CUSTOM` heap with `WRITE_COMBINE` on `L0` instead of `UPLOAD`. That is the same memory `UPLOAD` uses without ReBAR (write-combined system memory). For an `L0` custom heap, vkd3d asks only for `HOST_VISIBLE | HOST_COHERENT` and drops the device-local types, so these buffers stay out of the BAR. The CPU writes them the same way, the copy queue reads them the same way, and the ledger still counts them as system memory. `committed` in `placement.rs` gets a `committed_in` sibling that takes heap properties. The other callers are unchanged. ### Game runs RX 9070 XT (`1002:7550`), RADV, Mesa 26.3.1, GE-Proton11-14, vkd3d-proton 71cae091, Linux 7.3.6. Same settings in every run: `TUXBOX_VRAM_RESERVE_MIB=4096`, `TUXBOX_SPILL_WRITE_BACK=0`, `TUXBOX_XMEM_PRIVATE_VIEWS=1`, `VKD3D_CONFIG=log_memory_budget`, no `no_upload_hvv`, warm shader cache. | Run | Build | ReBAR refusals | Fallbacks to system memory | Peak ReBAR use | Staging buffers ≥ 32 MiB | | --- | --- | ---: | ---: | ---: | --- | | D | without this change | 3 | 3 | 969 MiB | 8 in ReBAR, 3 fell back | | E | with this change | 0 | 0 | 514 MiB | 10, all in system memory | | F | with this change (repeat) | 0 | 0 | 883 MiB | 9, all in system memory | | G | with this change (repeat) | 0 | 0 | 883 MiB | 10, all in system memory | | H | with this change (repeat) | 0 | 0 | 835 MiB | 27, all in system memory | Without this change, every comparable run I have had fallbacks (2 to 5, see #292). With it, none of the four runs had any, including H with 27 staging buffers of 32 MiB or more. F and H got further into the game than E (4,096 placed textures spilled vs 1,024), and their peaks are higher for that reason. In F, 488 MiB of that peak is one internal vkd3d allocation made at device creation, and the rest is 16 MiB `UPLOAD` chunks. So with this change the title's own `UPLOAD` heaps still have only about 136 MiB of headroom there. This change removes TuxBox's staging from the budget. It doesn't make the budget larger. **These runs were on #575's head (be15fac8) with this diff applied, not on this branch's head.** `placement.rs` and `upload.rs` are identical on be15fac8 and on bbc26254, so the diff is the same. I didn't run the game on bbc26254: its launcher now prepares first after a translator change (e9147f2a), and that preparation ran at about 100 shaders per minute here, roughly 4 hours for 25,889 shaders. I'll look at that separately. Every run still ends in a crash. That is the separate problem I've reported before, and this change doesn't affect it: D and E ended on the compute-queue TCP write fault (`0x641041`), F and G on a gfx-ring fault (`0x70113A`, `0x50113A`), and H on the title watchdog with no kernel fault logged. I didn't measure frame times, because the game doesn't get far enough to have a stable stretch. ### Checks On this branch's head, RX 9070 XT, GE-Proton11-14: ``` python tuxbox.py check --changed --backend proton --proton GE-Proton11-14-x86_64 --prefix PREFIX --windows-dxc DXC/bin/x64 Evidence: TuxBox check of 9bde51efcbf7, no uncommitted changes, GPU default adapter: 16 passed, 0 failed, 0 not run ``` That covers 113 of 113 Lanes and fixture gates, including the placement ones (`d3d12-placement`, `lanes-selftest-texture-publication`). I haven't traced which gates create a staging buffer through `Transfer::begin`. Also 22 of 22 D3D12 regression controls. Not run on NVIDIA. I don't have one. No Lanes scenario: the bug only shows once staging buffers fill vkd3d's ReBAR budget, which takes hundreds of MiB of texture uploads in flight. Lanes doesn't upload that much, and the fallback only shows up as a vkd3d log line, not as a result a scenario could check. 🤖 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!595
No description provided.