d3d12: spill placed textures to host-cached memory, out of the BAR #575

Closed
NathansDomainSolutions wants to merge 2 commits from upstream-pr/575 into main
NathansDomainSolutions commented 2026-11-30 06:26:38 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-11-30T06:26:38Z.


Follows @Kayotic1337's finding on #292: on a resizable-BAR card, the "system memory" heap that residency spills placed textures into is CUSTOM + WRITE_COMBINE + L0. vkd3d-proton places that in BAR memory (video memory), so the spill fills the BAR budget and vkd3d falls back. With VKD3D_CONFIG=no_upload_hvv, which keeps it in host memory, their RX 9070 XT run had 0 fallbacks and got further than any other.

Change: residency asks for a CUSTOM + WRITE_BACK + L0 heap first. vkd3d maps that to host-cached memory, which is never in the BAR, so this works without the global no_upload_hvv switch, and upload heaps keep their BAR placement. If the driver refuses that heap (no host-cached memory type its images can use), the first refusal is logged, and from then on residency uses the write-combined heap as before. TUXBOX_SPILL_WRITE_BACK=0 keeps the old heap.

GPU reads of the spilled textures go over PCIe either way. Host-cached memory is snooped, which can be a little slower than write-combined on some platforms. These are textures that didn't fit in VRAM, and the alternative is vkd3d falling back.

Checks: d3d12 builds, and clippy (-D warnings) and fmt are clean. Not run on hardware yet: I'd welcome a run on a ReBAR card (AMD or NVIDIA) with TUXBOX_VRAM_RESERVE_MIB=4096 to force spilling. Watch for the vkd3d fallback count and the host-cached spill heaps refused line.

This contribution was written by an AI agent (Claude Opus 5.5) operating under my supervision. I am accountable for it and will respond to review.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5560225726 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-11-30T06:26:38Z. --- Follows @Kayotic1337's finding on #292: on a resizable-BAR card, the "system memory" heap that residency spills placed textures into is `CUSTOM` + `WRITE_COMBINE` + `L0`. vkd3d-proton places that in BAR memory (video memory), so the spill fills the BAR budget and vkd3d falls back. With `VKD3D_CONFIG=no_upload_hvv`, which keeps it in host memory, their RX 9070 XT run had 0 fallbacks and got further than any other. **Change:** residency asks for a `CUSTOM` + `WRITE_BACK` + `L0` heap first. vkd3d maps that to host-cached memory, which is never in the BAR, so this works without the global `no_upload_hvv` switch, and upload heaps keep their BAR placement. If the driver refuses that heap (no host-cached memory type its images can use), the first refusal is logged, and from then on residency uses the write-combined heap as before. `TUXBOX_SPILL_WRITE_BACK=0` keeps the old heap. GPU reads of the spilled textures go over PCIe either way. Host-cached memory is snooped, which can be a little slower than write-combined on some platforms. These are textures that didn't fit in VRAM, and the alternative is vkd3d falling back. **Checks:** d3d12 builds, and clippy (`-D warnings`) and fmt are clean. Not run on hardware yet: I'd welcome a run on a ReBAR card (AMD or NVIDIA) with `TUXBOX_VRAM_RESERVE_MIB=4096` to force spilling. Watch for the vkd3d fallback count and the `host-cached spill heaps refused` line. This contribution was written by an AI agent (Claude Opus 5.5) operating under my supervision. I am accountable for it and will respond to review. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
brcly commented 2026-11-30 09:39:11 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:39:11Z.


Thanks, this follows @Kayotic1337's finding on #292 neatly: it gets the effect of no_upload_hvv for the spill heap only, without the global switch.

I'm holding it until it has run, because unlike an opt-in diagnostic it changes the default heap every spilled texture lands in. Before merging I'd like:

  1. A run on a resizable-BAR card that spills, with the setup you suggest (TUXBOX_VRAM_RESERVE_MIB=4096). Report vkd3d's fallback count with and without the change, and whether host-cached spill heaps refused appears.
  2. Ideally both vendors, since vkd3d's memory-type choice for CUSTOM + WRITE_BACK + L0 differs between RADV and NVIDIA. If one of them refuses it, the log line and the fallback to the old heap are the part to check.
  3. A frame-time comparison over the spilled textures, if you can get one, since snooped host memory can be slower to read over PCIe.

@Kayotic1337, if you have your RX 9070 XT setup handy, you're the one best placed to confirm it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7274501572 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575#issuecomment-7274501572). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T09:39:11Z. --- Thanks, this follows @Kayotic1337's finding on #292 neatly: it gets the effect of `no_upload_hvv` for the spill heap only, without the global switch. I'm holding it until it has run, because unlike an opt-in diagnostic it changes the default heap every spilled texture lands in. Before merging I'd like: 1. **A run on a resizable-BAR card that spills**, with the setup you suggest (`TUXBOX_VRAM_RESERVE_MIB=4096`). Report vkd3d's fallback count with and without the change, and whether `host-cached spill heaps refused` appears. 2. **Ideally both vendors**, since vkd3d's memory-type choice for `CUSTOM` + `WRITE_BACK` + `L0` differs between RADV and NVIDIA. If one of them refuses it, the log line and the fallback to the old heap are the part to check. 3. **A frame-time comparison over the spilled textures**, if you can get one, since snooped host memory can be slower to read over PCIe. @Kayotic1337, if you have your RX 9070 XT setup handy, you're the one best placed to confirm it.
Kayotic1337 commented 2026-11-30 13:23:37 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-30T13:23:37Z.


Thanks, this follows @Kayotic1337's finding on #292 neatly: it gets the effect of no_upload_hvv for the spill heap only, without the global switch.

I'm holding it until it has run, because unlike an opt-in diagnostic it changes the default heap every spilled texture lands in. Before merging I'd like:

1. **A run on a resizable-BAR card that spills**, with the setup you suggest (`TUXBOX_VRAM_RESERVE_MIB=4096`). Report vkd3d's fallback count with and without the change, and whether `host-cached spill heaps refused` appears.

2. **Ideally both vendors**, since vkd3d's memory-type choice for `CUSTOM` + `WRITE_BACK` + `L0` differs between RADV and NVIDIA. If one of them refuses it, the log line and the fallback to the old heap are the part to check.

3. **A frame-time comparison over the spilled textures**, if you can get one, since snooped host memory can be slower to read over PCIe.

@Kayotic1337, if you have your RX 9070 XT setup handy, you're the one best placed to confirm it.

i'm currently in school and dont have any remote access setup to that machine. i'll report back this evening

<!-- greyfinch-sync:brcly/TuxBox:comment:7279779830 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575#issuecomment-7279779830). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T13:23:37Z. --- > Thanks, this follows [@Kayotic1337](https://github.com/Kayotic1337)'s finding on [#292](https://github.com/brcly/TuxBox/issues/292) neatly: it gets the effect of `no_upload_hvv` for the spill heap only, without the global switch. > > I'm holding it until it has run, because unlike an opt-in diagnostic it changes the default heap every spilled texture lands in. Before merging I'd like: > > 1. **A run on a resizable-BAR card that spills**, with the setup you suggest (`TUXBOX_VRAM_RESERVE_MIB=4096`). Report vkd3d's fallback count with and without the change, and whether `host-cached spill heaps refused` appears. > > 2. **Ideally both vendors**, since vkd3d's memory-type choice for `CUSTOM` + `WRITE_BACK` + `L0` differs between RADV and NVIDIA. If one of them refuses it, the log line and the fallback to the old heap are the part to check. > > 3. **A frame-time comparison over the spilled textures**, if you can get one, since snooped host memory can be slower to read over PCIe. > > > [@Kayotic1337](https://github.com/Kayotic1337), if you have your RX 9070 XT setup handy, you're the one best placed to confirm it. i'm currently in school and dont have any remote access setup to that machine. i'll report back this evening
Kayotic1337 commented 2026-11-30 17:43:28 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-30T17:43:28Z.


Ran #575 (be15fac8) on an RX 9070 XT (1002:7550, RDNA 4, RADV, ReBAR, GE-Proton11-14), with TUXBOX_VRAM_RESERVE_MIB=4096 and without no_upload_hvv. Run A had TUXBOX_SPILL_WRITE_BACK=0. Run B used the new default. One run each. A was the first run on this build, so it was still translating shaders. B ran with a warm cache.

A: write-combined (old) B: write-back (#575)
vkd3d fallbacks 4 5
host-cached spill heaps refused n/a not logged (heaps accepted)
Placed textures put in system memory 16,384 (3,983 MiB) 8,192 (2,154 MiB)
How it ended kernel TCP write fault (0x641041), then VK_ERROR_DEVICE_LOST kernel TCP write fault (0x641041), then title watchdog

RADV accepts the host-cached heap, but it doesn't change the fallback count. So #575 doesn't fix the fallbacks, as @JeffreyBytes predicted: the write-combined L0 spill already stays out of the BAR.

I followed up on #292 with two more runs (log_memory_budget plus one diagnostic log line). The fallbacks are TuxBox's own texture-upload staging buffers (placement/upload.rs, committed UPLOAD). They go over vkd3d's fixed ReBAR budget, and each refused request matches a staging create of exactly that size. Details and a correction of my earlier claim: https://github.com/brcly/TuxBox/issues/292#issuecomment-7286748306 So the fallbacks come from the staging path, not from the spill heap.

<!-- greyfinch-sync:brcly/TuxBox:comment:7286748855 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575#issuecomment-7286748855). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T17:43:28Z. --- Ran #575 (be15fac8) on an RX 9070 XT (`1002:7550`, RDNA 4, RADV, ReBAR, GE-Proton11-14), with `TUXBOX_VRAM_RESERVE_MIB=4096` and without `no_upload_hvv`. Run A had `TUXBOX_SPILL_WRITE_BACK=0`. Run B used the new default. One run each. A was the first run on this build, so it was still translating shaders. B ran with a warm cache. | | A: write-combined (old) | B: write-back (#575) | | --- | ---: | ---: | | vkd3d fallbacks | 4 | 5 | | `host-cached spill heaps refused` | n/a | not logged (heaps accepted) | | Placed textures put in system memory | 16,384 (3,983 MiB) | 8,192 (2,154 MiB) | | How it ended | kernel TCP write fault (0x641041), then `VK_ERROR_DEVICE_LOST` | kernel TCP write fault (0x641041), then title watchdog | RADV accepts the host-cached heap, but it doesn't change the fallback count. So #575 doesn't fix the fallbacks, as @JeffreyBytes predicted: the write-combined L0 spill already stays out of the BAR. I followed up on #292 with two more runs (`log_memory_budget` plus one diagnostic log line). The fallbacks are TuxBox's own texture-upload staging buffers (`placement/upload.rs`, committed `UPLOAD`). They go over vkd3d's fixed ReBAR budget, and each refused request matches a staging create of exactly that size. Details and a correction of my earlier claim: https://github.com/brcly/TuxBox/issues/292#issuecomment-7286748306 So the fallbacks come from the staging path, not from the spill heap.
brcly commented 2026-11-30 19:12:46 +00:00 (Migrated from github.com)

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


Thanks @Kayotic1337, that answers it: RADV accepts the host-cached heap, but the fallback count doesn't move (4 against 5), and your follow-up on #292 traces the fallbacks to the upload staging buffers in placement/upload.rs, not the spill heap.

@NathansDomainSolutions so I'm not merging this as it stands: it changes the default heap for every spilled texture without a measured gain. If you want to take the next step, the staging buffers are where the fallbacks come from (#292). A change that keeps those inside vkd3d's ReBAR budget, with a run showing the fallback count drop, would be welcome. It also needs a rebase on main.

<!-- greyfinch-sync:brcly/TuxBox:comment:7289022204 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575#issuecomment-7289022204). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T19:12:46Z. --- Thanks @Kayotic1337, that answers it: RADV accepts the host-cached heap, but the fallback count doesn't move (4 against 5), and your follow-up on #292 traces the fallbacks to the upload staging buffers in `placement/upload.rs`, not the spill heap. @NathansDomainSolutions so I'm not merging this as it stands: it changes the default heap for every spilled texture without a measured gain. If you want to take the next step, the staging buffers are where the fallbacks come from (#292). A change that keeps those inside vkd3d's ReBAR budget, with a run showing the fallback count drop, would be welcome. It also needs a rebase on `main`.
NathansDomainSolutions commented 2026-12-01 00:28:40 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-12-01T00:28:40Z.


Closing this one. Kayotic's run traced the fallbacks to the upload staging buffers, and #595 (merged) already keeps those out of vkd3d's ReBAR budget, so the spill-heap change would be redundant. Thanks both. (AI-assisted: Claude Code.)

<!-- greyfinch-sync:brcly/TuxBox:comment:7296379018 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/575#issuecomment-7296379018). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-12-01T00:28:40Z. --- Closing this one. Kayotic's run traced the fallbacks to the upload staging buffers, and #595 (merged) already keeps those out of vkd3d's ReBAR budget, so the spill-heap change would be redundant. Thanks both. (AI-assisted: Claude Code.)

Pull request closed

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!575
No description provided.