d3d12: give placed textures memory at first GPU use #378

Merged
NathansDomainSolutions merged 1 commit from upstream-pr/378 into main 2026-11-28 11:05:23 +00:00
NathansDomainSolutions commented 2026-11-28 07:37:18 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-11-28T07:37:18Z.


Part of #292. This is the first of the two changes the issue's measurements point to: a native copy of a guest texture now gets graphics memory when GPU work first uses it, not when the title creates a view over it. @JeffreyBytes offered to test a branch in this direction on the RX 6700 XT, so this branch is for that. It does not bound the publication readback. That is the narrowing work in #300 and is separate.

What changes

  • A placed image is created as a reserved resource (64KB_UNDEFINED_SWIZZLE, with the same flags and state as before) and holds no memory.
  • The first time a batch, copy or CPU-write flush touches it, its tiles are mapped onto a heap of its own with UpdateTileMappings. This runs on the placement upload queue, before any upload into the image. The guest queue's existing wait on the upload fence orders its work after the mapping.
  • Every GPU use of a placed texture goes through placement::submit (descriptor-heap reads, render targets, copies and bundles all end up in textures/writes) or through PlacementMemory::flush_textures. Both call Transfer::back first, so the GPU never reads an unmapped tile.
  • Images the driver won't reserve fall back to committed memory, with a bounded log line. That covers 1D, NV12 and 3D below tiled tier 3, plus anything else vkd3d-proton refuses. Castable-format (packed UAV) images also stay committed.
  • TUXBOX_LAZY_TEXTURES=0 makes every placed image committed, as before. It's documented in ENVIRONMENT.md, and the #292 bullet in FOCUS.md is updated.
  • The provider logs counts at powers of two: lazy placed textures after … #N: R reserved (MiB), B backed (MiB). The gap between the two figures is the memory no longer held.

Nothing evicts an image once it is backed. Images the title uses still hold memory as before.

Checks run

RTX 4070 (10de:2786), driver 620.73.04, GE-Proton11-14, Linux 7.3.6, branch on cba382c.

  • python tuxbox.py check --no-gpu: all 7 groups passed.
  • python tuxbox.py verify --only d3d12-placement --only lanes-selftest --only lanes --only guest-frame --only present --only d3d12-heaps --only d3d12-copy-resource: 35 of 35 passed. That includes lanes-selftest-texture-publication, -texture-readback, -shared-texture and -copy-memory, which upload into, write back from and copy through placed images.
  • python tuxbox.py run --app-id Lanes build/lanes --selftest all with the provider log on: passed=26. The log shows the reserved path itself being taken: three images reserved, then each backed on first use, with no refusals.
  • tools/check_d3d12_regressions.py (default cases): tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled all passed.

Still missing:

  • An AMD run. RADV's sparse support differs from NVIDIA's, and the fallback to committed memory has not been seen on a real refusal there.
  • ProjectScarlett numbers. A run on this card is in progress, and I'll add VRAM before and after as a comment.
  • No Lanes scenario fails without this change. The behaviour is about how much memory an image holds, not what it contains, and Lanes has no way to read device memory use. The self-tests above show that content, publication and readback are unchanged on the new path.

AI-assisted: written with Claude Code (Claude Opus 5.5). I reviewed the change and ran the checks above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5537960550 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/378). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-11-28T07:37:18Z. --- Part of #292. This is the first of the two changes [the issue's measurements](https://github.com/brcly/TuxBox/issues/292) point to: a native copy of a guest texture now gets graphics memory when GPU work first uses it, not when the title creates a view over it. @JeffreyBytes offered to test a branch in this direction on the RX 6700 XT, so this branch is for that. It does not bound the publication readback. That is the narrowing work in #300 and is separate. ## What changes - A placed image is created as a **reserved** resource (`64KB_UNDEFINED_SWIZZLE`, with the same flags and state as before) and holds no memory. - The first time a batch, copy or CPU-write flush touches it, its tiles are mapped onto a heap of its own with `UpdateTileMappings`. This runs on the placement upload queue, before any upload into the image. The guest queue's existing wait on the upload fence orders its work after the mapping. - Every GPU use of a placed texture goes through `placement::submit` (descriptor-heap reads, render targets, copies and bundles all end up in `textures`/`writes`) or through `PlacementMemory::flush_textures`. Both call `Transfer::back` first, so the GPU never reads an unmapped tile. - Images the driver won't reserve fall back to committed memory, with a bounded log line. That covers 1D, NV12 and 3D below tiled tier 3, plus anything else vkd3d-proton refuses. Castable-format (packed UAV) images also stay committed. - `TUXBOX_LAZY_TEXTURES=0` makes every placed image committed, as before. It's documented in `ENVIRONMENT.md`, and the #292 bullet in `FOCUS.md` is updated. - The provider logs counts at powers of two: `lazy placed textures after … #N: R reserved (MiB), B backed (MiB)`. The gap between the two figures is the memory no longer held. Nothing evicts an image once it is backed. Images the title uses still hold memory as before. ## Checks run RTX 4070 (`10de:2786`), driver 620.73.04, GE-Proton11-14, Linux 7.3.6, branch on `cba382c`. - `python tuxbox.py check --no-gpu`: all 7 groups passed. - `python tuxbox.py verify --only d3d12-placement --only lanes-selftest --only lanes --only guest-frame --only present --only d3d12-heaps --only d3d12-copy-resource`: 35 of 35 passed. That includes `lanes-selftest-texture-publication`, `-texture-readback`, `-shared-texture` and `-copy-memory`, which upload into, write back from and copy through placed images. - `python tuxbox.py run --app-id Lanes build/lanes --selftest all` with the provider log on: `passed=26`. The log shows the reserved path itself being taken: three images reserved, then each backed on first use, with no refusals. - `tools/check_d3d12_regressions.py` (default cases): tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled all passed. **Still missing:** - An AMD run. RADV's sparse support differs from NVIDIA's, and the fallback to committed memory has not been seen on a real refusal there. - ProjectScarlett numbers. A run on this card is in progress, and I'll add VRAM before and after as a comment. - No Lanes scenario fails without this change. The behaviour is about how much memory an image holds, not what it contains, and Lanes has no way to read device memory use. The self-tests above show that content, publication and readback are unchanged on the new path. AI-assisted: written with Claude Code (Claude Opus 5.5). I reviewed the change and ran the checks above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NathansDomainSolutions commented 2026-11-28 09:32:12 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-11-28T09:32:12Z.


In-game numbers from ProjectScarlett 1.0.2.1 on the RTX 4070 (12 GB, driver 620.73.04, GE-Proton11-14) with this branch's provider staged. The run reached the title screen ("ACCOUNT PICKER / SCREEN NARRATION / TUXBOX") and accepted A there. The provider's own counters at that point:

lazy placed textures after reservation #1024: 1024 reserved (1350 MiB), 5 backed (6 MiB)

The title had created 1,024 placed images worth 1.35 GB of graphics memory, and only 5 of them (6 MB) had been touched by GPU work. On main, all 1.35 GB would be committed at this point. No reserved-image refusals were logged, and no placed-texture errors.

That's as far as the run got. After A, it stayed on the title screen at one frame per second with the GPU idle, which isn't related to this change (it happens before any of these images are used). So I don't have numbers for the world yet, where #292's table says most of the memory is.

(Measured with Claude Code assisting.)

<!-- greyfinch-sync:brcly/TuxBox:comment:7237302787 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/378#issuecomment-7237302787). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-11-28T09:32:12Z. --- In-game numbers from ProjectScarlett 1.0.2.1 on the RTX 4070 (12 GB, driver 620.73.04, GE-Proton11-14) with this branch's provider staged. The run reached the title screen ("ACCOUNT PICKER / SCREEN NARRATION / TUXBOX") and accepted A there. The provider's own counters at that point: ``` lazy placed textures after reservation #1024: 1024 reserved (1350 MiB), 5 backed (6 MiB) ``` The title had created 1,024 placed images worth 1.35 GB of graphics memory, and only 5 of them (6 MB) had been touched by GPU work. On `main`, all 1.35 GB would be committed at this point. No reserved-image refusals were logged, and no placed-texture errors. That's as far as the run got. After A, it stayed on the title screen at one frame per second with the GPU idle, which isn't related to this change (it happens before any of these images are used). So I don't have numbers for the world yet, where #292's table says most of the memory is. (Measured with Claude Code assisting.)
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!378
No description provided.