D3D12.X: textures the GPU writes never reach title memory; a title reading them on the CPU gets stale data #2663

Open
opened 2026-11-26 06:14:55 +00:00 by github-bot · 1 comment
Owner

@⁠joeypercia on GitHub · 2026-11-26 05:30 UTC · original

What the GPU writes into a title texture never reaches the title's memory, so a title that reads such a texture on the CPU gets stale bytes. On the console the CPU and the GPU share memory, so a compute pass can write a texture that the title's own code then reads.

Why it matters for the retail title: the same title on VIctory forks, which got this far into the world, had its boats sinking in every run (and the sea plane going under). The ocean's height and displacement maps are textures that compute passes write and the title's physics samples on the CPU. Reading them back to title memory fixed it (avatarmanz/VIctory-7900XTX docs/findings.md, "Faults found", credited there to Geckomacabre's read-back). VIctory is GPL-3.0, so this is the idea only; no code from it.

What XCL does today (main b49be183):

  • UAV-written textures: a texture written by shaders through a UAV is a GPU-owned placement (vram::place, vram::gpu_owned). Nothing copies its contents to the title's memory at its address.
  • Copy destinations: title_textures::note_gpu_write marks textures that a CopyTextureRegion / CopyResource writes, and stops uploading over them. It doesn't copy what the GPU wrote back either (title_textures.rs, around line 466; called from list_x.rs copy_texture_region_x / copy_resource_x).
  • Buffers: buffers in the sparse windows do come back (sparse read-back), but textures live on vram pages, not in the windows.
  • Tiler: the inverse of the detiler exists already: gpu::tiling::Layout::tile (only tests use it now).

Proposal, split as AGENTS.md asks. I'll take it unless someone already has it.

  1. Read-back primitive, no behaviour change: copy a placed / kept-in-step texture's subresources to a readback buffer at a fence, re-tile them with Layout::tile into the console layout of its console description, and write them to its title address. GPU test: a compute pass writes known texels, and the title memory then holds them in console tiling, checked against detile and a CPU reference, for 2D and BCn, mips and array slices.
  2. When to read back, behind XCL_TEXTURE_READBACK=1: make the CPU read cheap to notice by guarding the title pages under GPU-written textures (PAGE_NOACCESS until the next GPU write after the read-back). On the fault, wait for the texture's last writing submission, read it back and restore access. Counters in the activity log: textures guarded, faults, bytes read back, wait time.
  3. On by default, if the cost on the retail title is small, measured on runs that reach the world.

What I can't show yet: on Windows / NVIDIA, XCL doesn't reach the boat missions, so part 1 is checked by GPU tests and part 2 by synthetic tests plus the counters in title runs. Which other textures the title reads on the CPU, I'll log with part 2.

AI use: Claude Code (Claude Opus 5.5) read the code and wrote this.

**@⁠joeypercia** on GitHub · 2026-11-26 05:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/2663) **What the GPU writes into a title texture never reaches the title's memory, so a title that reads such a texture on the CPU gets stale bytes.** On the console the CPU and the GPU share memory, so a compute pass can write a texture that the title's own code then reads. **Why it matters for the retail title:** the same title on VIctory forks, which got this far into the world, had its boats sinking in every run (and the sea plane going under). The ocean's height and displacement maps are textures that compute passes write and the title's physics samples on the CPU. Reading them back to title memory fixed it ([avatarmanz/VIctory-7900XTX docs/findings.md](https://github.com/avatarmanz/VIctory-7900XTX/blob/HEAD/docs/findings.md), "Faults found", credited there to Geckomacabre's read-back). VIctory is GPL-3.0, so this is the idea only; no code from it. **What XCL does today** (`main` `b49be183`): - **UAV-written textures:** a texture written by shaders through a UAV is a GPU-owned placement (`vram::place`, `vram::gpu_owned`). Nothing copies its contents to the title's memory at its address. - **Copy destinations:** `title_textures::note_gpu_write` marks textures that a `CopyTextureRegion` / `CopyResource` writes, and stops uploading over them. It doesn't copy what the GPU wrote back either (`title_textures.rs`, around line 466; called from `list_x.rs` `copy_texture_region_x` / `copy_resource_x`). - **Buffers:** buffers in the sparse windows do come back (sparse read-back), but textures live on `vram` pages, not in the windows. - **Tiler:** the inverse of the detiler exists already: `gpu::tiling::Layout::tile` (only tests use it now). **Proposal**, split as AGENTS.md asks. I'll take it unless someone already has it. 1. **Read-back primitive, no behaviour change:** copy a placed / kept-in-step texture's subresources to a readback buffer at a fence, re-tile them with `Layout::tile` into the console layout of its console description, and write them to its title address. GPU test: a compute pass writes known texels, and the title memory then holds them in console tiling, checked against `detile` and a CPU reference, for 2D and BCn, mips and array slices. 2. **When to read back, behind `XCL_TEXTURE_READBACK=1`:** make the CPU read cheap to notice by guarding the title pages under GPU-written textures (`PAGE_NOACCESS` until the next GPU write after the read-back). On the fault, wait for the texture's last writing submission, read it back and restore access. Counters in the activity log: textures guarded, faults, bytes read back, wait time. 3. **On by default**, if the cost on the retail title is small, measured on runs that reach the world. **What I can't show yet:** on Windows / NVIDIA, XCL doesn't reach the boat missions, so part 1 is checked by GPU tests and part 2 by synthetic tests plus the counters in title runs. Which other textures the title reads on the CPU, I'll log with part 2. **AI use:** Claude Code (Claude Opus 5.5) read the code and wrote this.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:56 +00:00
Author
Owner

@⁠joeypercia on GitHub · 2026-11-26 06:24 UTC · original

A first measurement of whether the newer retail title's CPU touches textures the GPU owns: render targets, depth buffers and UAV textures, which vram::place puts in video memory.

How: a diagnostic, XCL_GPU_TEXTURE_TOUCH=1 (c6f37e96; a PR follows). The committed pages wholly inside such a texture's console memory get PAGE_GUARD when it is placed, and a lazily committed page counts when its first access commits it. The first access to each texture is logged with the code address.

Run: RTX 4070 Ti (12 GB, driver 621.40), nvidia-dev c044dc6d plus that commit. The run went through the menus and into the world load, and ended at 123 s with the usual 0x887a0005 removal (#2403). That's the same 122–168 s as the runs before it without the switch.

Result: 720 textures the GPU owns, 13,344 pages (52 MB) guarded, 0 touched by the CPU: no reads, no writes, no lazy-page commits.

So up to the start of the world load, the title doesn't read back what its GPU writes into these textures. The case from the VIctory forks' findings (ocean height maps read by the physics) is further into the world than this run gets. #2678, which copies a texture back, stays useful for that. I'm not wiring it into the title until a run that reaches the world shows a texture being touched. Someone who gets further in, on a 24–32 GB card, could rerun with the switch: one log line per touched texture names the texture and the code that reads it.

(Claude Code, Claude Opus 5.5)

**@⁠joeypercia** on GitHub · 2026-11-26 06:24 UTC · [original](https://github.com/xcl-dev/xcl/issues/2663#issuecomment-7184404331) A first measurement of whether the newer retail title's CPU touches textures the GPU owns: render targets, depth buffers and UAV textures, which `vram::place` puts in video memory. **How:** a diagnostic, `XCL_GPU_TEXTURE_TOUCH=1` (`c6f37e96`; a PR follows). The committed pages wholly inside such a texture's console memory get `PAGE_GUARD` when it is placed, and a lazily committed page counts when its first access commits it. The first access to each texture is logged with the code address. **Run:** RTX 4070 Ti (12 GB, driver 621.40), `nvidia-dev` `c044dc6d` plus that commit. The run went through the menus and into the world load, and ended at 123 s with the usual `0x887a0005` removal (#2403). That's the same 122–168 s as the runs before it without the switch. **Result:** 720 textures the GPU owns, 13,344 pages (52 MB) guarded, **0 touched by the CPU**: no reads, no writes, no lazy-page commits. So up to the start of the world load, the title doesn't read back what its GPU writes into these textures. The case from the VIctory forks' findings (ocean height maps read by the physics) is further into the world than this run gets. #2678, which copies a texture back, stays useful for that. I'm not wiring it into the title until a run that reaches the world shows a texture being touched. Someone who gets further in, on a 24–32 GB card, could rerun with the switch: one log line per touched texture names the texture and the code that reads it. (Claude Code, Claude Opus 5.5)
This discussion has been locked. Commenting is limited to contributors.
No description provided.