Title textures: small render targets the CPU fills are kept in step (retail game's menu text is complete) #211

Manually merged
github merged 1 commit from gh-pr/211/head into gh-pr/211/base 2026-11-26 04:15:27 +00:00
Owner

@⁠theaustinayers on GitHub · 2026-11-23 21:05 UTC · original
theaustinayers:glyph-cache-targets → main · +23 −2 · 1 files · 1 commits · merged 2026-11-23 21:24 UTC

What this does

On main (2abc562) the newer retail game's menus show their headings and button prompts, but the body text is missing most of its letters: digits, capitals and tall lowercase letters draw, the short lowercase ones (a c e m n o r s u …) do not. With this change the body text is complete (legal terms, settings descriptions, option values).

Cause

The title's glyph caches are small textures it places with ALLOW_RENDER_TARGET and fills from the CPU: 256×256 R8_UNORM (format 61), flags 0x300001, layout 0x100, which xg lays out with two planes. title_textures::register refuses anything that is not single-plane ("a render target / depth buffer"), so these were never uploaded after creation and stayed as they were made. The log line on main:

CreatePlacedResourceX texture at 0x20070ea2000 (dimension 3 256x256x1, 1 mips, format 61, 1 samples, layout 0x100, flags 0x300001): not kept in step with the memory (a render target / depth buffer)

Change

One function, title_textures::register: a small single-sample colour target that has texels is kept in step with the title's memory like any other texture, even with more than one plane. "Small" is 64×64 up to 1024×1024, not a depth buffer (flag 0x2), one sample. Everything else is refused as before. XCL_SYNC_SMALL_TARGETS=0 turns it off.

Uploads still only happen when the write watch reports CPU writes on the texture's pages, so a target the title only renders to is not uploaded over.

Tested

Ryzen 9 9950X3D, RTX 5090, Windows 11, release build of 2abc562 + this change, the retail game with XCL_NETWORK=0:

  • 5 runs through the first menus (account prompt, legal terms, navigation / text size / brightness prompts, finish setup, legal notices): body text complete in all of them. The same screens on 2abc562 without the change have the missing letters.
  • 120 s scripted run: no device removal, 30 fps throughout, 16+ such targets registered in the first 12 s.
  • cargo build --release -p xcl passes. I did not run the test suite.

What I am not sure about

  • The size limits are a guess from one title (its caches are 256×256). I do not know what other titles do.
  • A target the title both renders to and writes from the CPU would have its GPU content replaced by the CPU's view on the next CPU write. I have not seen one, and gpu_written only covers copies, not draws.
  • The second plane is not uploaded; only the texels.
  • I first suspected BCPack for this (see #195). That was wrong for the text: decoding the BC7 chunks with an external decoder changed nothing. The BCPack refusals are real and separate.

AI-assisted (Claude Code); every run above was on my machine and I can re-run anything.

🤖 Generated with Claude Code

**@⁠theaustinayers** on GitHub · 2026-11-23 21:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/211) `theaustinayers:glyph-cache-targets` → `main` · +23 −2 · 1 files · 1 commits · merged 2026-11-23 21:24 UTC ## What this does On `main` (2abc562) the newer retail game's menus show their headings and button prompts, but the body text is missing most of its letters: digits, capitals and tall lowercase letters draw, the short lowercase ones (a c e m n o r s u …) do not. With this change the body text is complete (legal terms, settings descriptions, option values). ## Cause The title's glyph caches are small textures it places with `ALLOW_RENDER_TARGET` and **fills from the CPU**: 256×256 `R8_UNORM` (format 61), flags `0x300001`, layout `0x100`, which `xg` lays out with two planes. `title_textures::register` refuses anything that is not single-plane ("a render target / depth buffer"), so these were never uploaded after creation and stayed as they were made. The log line on `main`: ``` CreatePlacedResourceX texture at 0x20070ea2000 (dimension 3 256x256x1, 1 mips, format 61, 1 samples, layout 0x100, flags 0x300001): not kept in step with the memory (a render target / depth buffer) ``` ## Change One function, `title_textures::register`: a small single-sample colour target that has texels is kept in step with the title's memory like any other texture, even with more than one plane. "Small" is 64×64 up to 1024×1024, not a depth buffer (flag `0x2`), one sample. Everything else is refused as before. `XCL_SYNC_SMALL_TARGETS=0` turns it off. Uploads still only happen when the write watch reports CPU writes on the texture's pages, so a target the title only renders to is not uploaded over. ## Tested Ryzen 9 9950X3D, RTX 5090, Windows 11, release build of 2abc562 + this change, the retail game with `XCL_NETWORK=0`: - 5 runs through the first menus (account prompt, legal terms, navigation / text size / brightness prompts, finish setup, legal notices): body text complete in all of them. The same screens on 2abc562 without the change have the missing letters. - 120 s scripted run: no device removal, 30 fps throughout, 16+ such targets registered in the first 12 s. - `cargo build --release -p xcl` passes. I did not run the test suite. ## What I am not sure about - **The size limits are a guess** from one title (its caches are 256×256). I do not know what other titles do. - **A target the title both renders to and writes from the CPU** would have its GPU content replaced by the CPU's view on the next CPU write. I have not seen one, and `gpu_written` only covers copies, not draws. - The second plane is not uploaded; only the texels. - I first suspected BCPack for this (see #195). That was wrong for the text: decoding the BC7 chunks with an external decoder changed nothing. The BCPack refusals are real and separate. AI-assisted (Claude Code); every run above was on my machine and I can re-run anything. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A retail title places its glyph caches as 256x256 R8 textures with ALLOW_RENDER_TARGET (two planes in the console layout) and fills them from the CPU. register() refused every multi-plane texture as the GPU's, so they were never uploaded and the menus' body text lost most of its letters. A small single-sample colour target with texels (64x64 to 1024x1024, not a depth buffer) is now registered like any texture. XCL_SYNC_SMALL_TARGETS=0 turns it off.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:15:25 +00:00
github manually merged commit f17a5eeb91 into gh-pr/211/base 2026-11-26 04:15:27 +00:00
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-23 21:11 UTC · original

Independent static code audit of f17a5eeb9 (code inspection only — cargo test not run on macOS; no game files):

Summary

Clean, minimal fix for CPU-filled 256×256 ALLOW_RENDER_TARGET glyph caches (R8_UNORM with 2 planes: texels + CMASK). w <= 1024 && h <= 1024 && w * h as u64 >= 64 * 64 avoids overflow and excludes 1D textures (h == 1), and plane 0 (tex.texels()) starts at offset 0 whenever !depth_buffer in xg.rs.

Edge cases worth tightening

  1. Planar depth/stencil formats without ALLOW_DEPTH_STENCIL (flags & 0x2 == 0): In xg.rs, formats 19..=22 (D32_S8X24), 44..=47 (D24_S8), and 118/120 (D16_S8) produce 2 planes (depth + stencil) even when flags & 0x2 == 0 (e.g. SRV-only). Because small_target does not check flags & 0x1 != 0 (ALLOW_RENDER_TARGET) or that the second plane is CMASK (tex.planes.len() == 2 && tex.planes[1].usage == 2), a 64×64–1024×1024 planar depth/stencil texture with flags == 0 would also pass small_target and enter title_textures. Requiring flags & 0x1 != 0 && tex.planes.len() == 2 && tex.planes[1].usage == 2 restricts this strictly to color render targets with CMASK.
  2. CMASK tail in dirty-page watch & merge note with #210:
    • refresh_once checks dirty pages across [e.va, e.va + e.tex.size()), which includes the trailing CMASK plane; combined with note_gpu_write not yet firing on OMSetRenderTargets/ClearRenderTargetView, a neighbouring CPU write sharing a 4 KiB page with the CMASK tail could also trigger a re-upload over a GPU-rendered target.
    • Minor merge overlap with #210 at title_textures.rs:78-82: when combining both, keeping #210's 116 | 117 rejection above small_target ensures small 32-bit console float render targets aren't uploaded into 64-bit PC R16G16B16A16_FLOAT resources.

(AI-assisted)

**@⁠mastrr9** on GitHub · 2026-11-23 21:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/211#issuecomment-7114130674) Independent static code audit of `f17a5eeb9` (code inspection only — `cargo test` not run on macOS; no game files): ### Summary Clean, minimal fix for CPU-filled 256×256 `ALLOW_RENDER_TARGET` glyph caches (`R8_UNORM` with 2 planes: texels + CMASK). `w <= 1024 && h <= 1024 && w * h as u64 >= 64 * 64` avoids overflow and excludes 1D textures (`h == 1`), and plane 0 (`tex.texels()`) starts at offset 0 whenever `!depth_buffer` in `xg.rs`. ### Edge cases worth tightening 1. **Planar depth/stencil formats without `ALLOW_DEPTH_STENCIL` (`flags & 0x2 == 0`):** In `xg.rs`, formats `19..=22` (`D32_S8X24`), `44..=47` (`D24_S8`), and `118`/`120` (`D16_S8`) produce 2 planes (depth + stencil) even when `flags & 0x2 == 0` (e.g. SRV-only). Because `small_target` does not check `flags & 0x1 != 0` (`ALLOW_RENDER_TARGET`) or that the second plane is CMASK (`tex.planes.len() == 2 && tex.planes[1].usage == 2`), a 64×64–1024×1024 planar depth/stencil texture with `flags == 0` would also pass `small_target` and enter `title_textures`. Requiring `flags & 0x1 != 0 && tex.planes.len() == 2 && tex.planes[1].usage == 2` restricts this strictly to color render targets with CMASK. 2. **CMASK tail in dirty-page watch & merge note with #210:** - `refresh_once` checks dirty pages across `[e.va, e.va + e.tex.size())`, which includes the trailing CMASK plane; combined with `note_gpu_write` not yet firing on `OMSetRenderTargets`/`ClearRenderTargetView`, a neighbouring CPU write sharing a 4 KiB page with the CMASK tail could also trigger a re-upload over a GPU-rendered target. - Minor merge overlap with #210 at `title_textures.rs:78-82`: when combining both, keeping #210's `116 | 117` rejection above `small_target` ensures small 32-bit console float render targets aren't uploaded into 64-bit PC `R16G16B16A16_FLOAT` resources. *(AI-assisted)*
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 21:21 UTC · original

This fixes the text, and it can also wipe what the GPU drew into such a target. The write watch covers the whole console resource, including its CMASK plane (title_textures.rs:311), but the upload is built from the texel plane alone (line 554). So a CPU write to CMASK alone re-uploads the texels and replaces every drawn pixel. Two narrowings would keep the fix and drop the risk: watch only the texel plane's pages, and admit only a colour surface (plus its CMASK), not depth/stencil or large arrays (a 1024×1024×65 RGBA8 array passes the size gate today, 260 MiB).

Tested

A CPU write to the CMASK plane alone replaces previously drawn pixels. On a synthetic 256×256 R8_UNORM target (layout 0x100, flags 0x300001), I initialized both copies to 0x22, drew a full-screen triangle producing 0xff, waited for the fence, and read back all 65,536 texels. Refresh with no CPU write preserved them all.

Subsequent CPU write Main 6da33fa Main + #211 9ebbfbb
One CMASK byte at offset 0x10000 All 65,536 drawn texels survived One full upload, 0 drawn texels survived
After a fresh draw, set only texel 0 to 0x77 Draw persisted, CPU edit absent Texel 0 updated, all 65,535 untouched texels lost the drawn value

Direct head f17a5ee showed the same results. XCL_SYNC_SMALL_TARGETS=0 preserved the draw in both cases and suppressed the CPU texel update. The reproducer used the production registration, write-watch and upload code with a native D3D12 draw and fenced readback. At crates/xcl/src/hle/d3d12x/title_textures.rs:311, the watch covers the entire console resource, including CMASK, while line 554 builds the upload from the main texel plane alone.

Two registration cases extend the scope beyond small color targets. At line 92, the lower limit is area: 4×1024 and 64×64 pass, 63×64 and 1025×64 fail. A 1024×1024 RGBA8 array of 65 slices also passes, with 260 MiB of texels before metadata. A flagless 256×256 R24G8_TYPELESS passes with XG plane usages 5 and 6 (depth and stencil). Changing the stencil bytes leaves the sole upload payload identical. Restricting the exception to a color surface followed by CMASK would exclude that case.

RTX 5070 Ti, 610.74, Windows x64. cargo test -p xcl --lib --no-run -j 2, then the library binary with --test-threads=1. Direct head 547/0, eaa36b6 548/0, and #211 merged onto eaa36b6 (9bf1b74) 548/0, each with 19 ignored. On 6da33fa and the local merge 9ebbfbb, the repository library tests returned 582/0/20 ignored on each. Two native-wave64 tests and sample-gated cases returned early. The separate draw-preservation probe failed on both PR builds and passed on both controls.

Not tested

Retail text, AMD, large-array upload performance, or GPU stencil sampling. The array and depth/stencil checks exercised descriptor admission and upload construction.

AI use — Codex, GPT-6.2 Astra.

**@⁠Kalmarv** on GitHub · 2026-11-23 21:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/211#issuecomment-7114353784) This fixes the text, and it can also wipe what the GPU drew into such a target. The write watch covers the whole console resource, including its CMASK plane (`title_textures.rs:311`), but the upload is built from the texel plane alone (line 554). So a CPU write to CMASK alone re-uploads the texels and replaces every drawn pixel. Two narrowings would keep the fix and drop the risk: watch only the texel plane's pages, and admit only a colour surface (plus its CMASK), not depth/stencil or large arrays (a 1024×1024×65 RGBA8 array passes the size gate today, 260 MiB). **Tested** A CPU write to the CMASK plane alone replaces previously drawn pixels. On a synthetic 256×256 R8_UNORM target (layout `0x100`, flags `0x300001`), I initialized both copies to `0x22`, drew a full-screen triangle producing `0xff`, waited for the fence, and read back all 65,536 texels. Refresh with no CPU write preserved them all. | Subsequent CPU write | Main `6da33fa` | Main + #211 `9ebbfbb` | |---|---|---| | One CMASK byte at offset `0x10000` | All 65,536 drawn texels survived | One full upload, 0 drawn texels survived | | After a fresh draw, set only texel 0 to `0x77` | Draw persisted, CPU edit absent | Texel 0 updated, all 65,535 untouched texels lost the drawn value | Direct head `f17a5ee` showed the same results. `XCL_SYNC_SMALL_TARGETS=0` preserved the draw in both cases and suppressed the CPU texel update. The reproducer used the production registration, write-watch and upload code with a native D3D12 draw and fenced readback. At `crates/xcl/src/hle/d3d12x/title_textures.rs:311`, the watch covers the entire console resource, including CMASK, while line 554 builds the upload from the main texel plane alone. Two registration cases extend the scope beyond small color targets. At line 92, the lower limit is area: `4×1024` and `64×64` pass, `63×64` and `1025×64` fail. A 1024×1024 RGBA8 array of 65 slices also passes, with **260 MiB of texels** before metadata. A flagless 256×256 `R24G8_TYPELESS` passes with XG plane usages 5 and 6 (depth and stencil). Changing the stencil bytes leaves the sole upload payload identical. Restricting the exception to a color surface followed by CMASK would exclude that case. RTX 5070 Ti, 610.74, Windows x64. `cargo test -p xcl --lib --no-run -j 2`, then the library binary with `--test-threads=1`. Direct head 547/0, `eaa36b6` 548/0, and #211 merged onto `eaa36b6` (`9bf1b74`) 548/0, each with 19 ignored. On `6da33fa` and the local merge `9ebbfbb`, the repository library tests returned 582/0/20 ignored on each. Two native-wave64 tests and sample-gated cases returned early. The separate draw-preservation probe failed on both PR builds and passed on both controls. **Not tested** Retail text, AMD, large-array upload performance, or GPU stencil sampling. The array and depth/stencil checks exercised descriptor admission and upload construction. **AI use** — Codex, GPT-6.2 Astra.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:24 UTC · original

Merged (main d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on main af20b4b: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 605 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps (720 draws per 2 s). Note: on main a GPU-owned texture at a 64 KiB-aligned address is placed on video-memory pages (vram::place) before register is reached, so this applies to the glyph caches that land elsewhere (not 64 KiB aligned) - if the letters are still missing for you, that routing is the place to look.

**@⁠ivall** on GitHub · 2026-11-23 21:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/211#issuecomment-7114415672) Merged (main d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on main af20b4b: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 605 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps (720 draws per 2 s). Note: on main a GPU-owned texture at a 64 KiB-aligned address is placed on video-memory pages (`vram::place`) before `register` is reached, so this applies to the glyph caches that land elsewhere (not 64 KiB aligned) - if the letters are still missing for you, that routing is the place to look.
This discussion has been locked. Commenting is limited to contributors.
No description provided.