D3D12.X: XCL_CAST_LIST=1 shares one texture between R32_UINT and R9G9B9E5 #3340

Open
KDenKC wants to merge 6 commits from upstream-pr/3340 into main
KDenKC commented 2026-11-29 09:29:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-29T09:29:32Z.


What and why

The title writes packed light through an R32_UINT UAV and reads the same console address through an R9G9B9E5 texture. With XCL_CAST_LIST=1, when the device supports enhanced barriers, relaxed format casting, and the needed sampled format, the written 2D texture is created with both formats and a matching sampled view is made on that resource. This avoids a separate read texture for this pair. The switch is off by default; unsupported devices and unmatched views keep the existing independent-resource path.

Stacked on #3281. The two commits underneath add the XCL_PAIR_PAGES=1 placement support; the three commits at the top are this PR's cast-list route, lifecycle fixes, and barrier routing.

The follow-ups preserve legacy resource states, handle MipLevels == 0 as the full mip chain, and bind a title-provided cast list to the allocation at its canonical address. The owner lookup selects the newest live compatible writer that is still current in placements, retaining older writers while they remain live. Releasing or superseding a writer updates the view and pair-page cap lifecycle. Barriers submitted on a known cast-list reader are routed to its writer with per-subresource state tracking; after a writer is released, the reader's barriers remain on the reader until a new view establishes another writer. Reader-first resources remain independent. Related: #3094 #3282. The independent-resource path remains available; the copy route in #3094 is a natural fallback if both changes land.

What is in it

  • cast_list.rs: opt-in capability checks, current-writer selection, pair lifecycle, and reader-to-writer barrier routing.
  • vram.rs, placements.rs, title_textures.rs, texture_upload.rs: pair-page placement, view handling, and cap lifecycle.
  • real.rs, list_x.rs, and GPU tests: hook integration and regression coverage.

Tested

RTX 3090 VM, Windows, debug, XCL_NETWORK=0, combined head e435d2d8:

  • cast_list: 9 passed, 0 failed.
  • list_x: 116 passed, 0 failed.
  • vram on parent 1f6c4de0: 79 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing).
  • d3d12x: 1,229 passed, 4 failed, 3 ignored; the four failures are the same title-texture tests that fail on main.
  • Workspace suite: 2,920 passed, 5 failed, 51 ignored; no crash. The five failures match main 1c8b5514 on this VM: placed_title_textures_share_vram_and_preserve_pixels, the three stream_recheck_* tests, and test_title_runs_and_game_folder_is_untouched. The VM skipped 28 tests for unavailable capabilities.

Regression run

Pending: the rig is paused. No smoke blocks are claimed for e435d2d8; older blocks do not validate this head.

Not tested

  • A retail-title run with XCL_CAST_LIST=1 on this head.
  • AMD and Intel hardware.

AI use

An agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen (tools: Claude Code, Codex, Antigravity).

Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

<!-- greyfinch-sync:ivall/xcl:issue:5549420432 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-29T09:29:32Z. --- **What and why** The title writes packed light through an R32_UINT UAV and reads the same console address through an R9G9B9E5 texture. With `XCL_CAST_LIST=1`, when the device supports enhanced barriers, relaxed format casting, and the needed sampled format, the written 2D texture is created with both formats and a matching sampled view is made on that resource. This avoids a separate read texture for this pair. The switch is off by default; unsupported devices and unmatched views keep the existing independent-resource path. Stacked on #3281. The two commits underneath add the `XCL_PAIR_PAGES=1` placement support; the three commits at the top are this PR's cast-list route, lifecycle fixes, and barrier routing. The follow-ups preserve legacy resource states, handle `MipLevels == 0` as the full mip chain, and bind a title-provided cast list to the allocation at its canonical address. The owner lookup selects the newest live compatible writer that is still current in placements, retaining older writers while they remain live. Releasing or superseding a writer updates the view and pair-page cap lifecycle. Barriers submitted on a known cast-list reader are routed to its writer with per-subresource state tracking; after a writer is released, the reader's barriers remain on the reader until a new view establishes another writer. Reader-first resources remain independent. Related: #3094 #3282. The independent-resource path remains available; the copy route in #3094 is a natural fallback if both changes land. **What is in it** - `cast_list.rs`: opt-in capability checks, current-writer selection, pair lifecycle, and reader-to-writer barrier routing. - `vram.rs`, `placements.rs`, `title_textures.rs`, `texture_upload.rs`: pair-page placement, view handling, and cap lifecycle. - `real.rs`, `list_x.rs`, and GPU tests: hook integration and regression coverage. **Tested** RTX 3090 VM, Windows, debug, `XCL_NETWORK=0`, combined head `e435d2d8`: - `cast_list`: 9 passed, 0 failed. - `list_x`: 116 passed, 0 failed. - `vram` on parent `1f6c4de0`: 79 passed, 0 failed, 1 ignored (`churn_update_tile_mappings_timing`). - `d3d12x`: 1,229 passed, 4 failed, 3 ignored; the four failures are the same title-texture tests that fail on main. - Workspace suite: 2,920 passed, 5 failed, 51 ignored; no crash. The five failures match main `1c8b5514` on this VM: `placed_title_textures_share_vram_and_preserve_pixels`, the three `stream_recheck_*` tests, and `test_title_runs_and_game_folder_is_untouched`. The VM skipped 28 tests for unavailable capabilities. **Regression run** Pending: the rig is paused. No smoke blocks are claimed for `e435d2d8`; older blocks do not validate this head. **Not tested** - A retail-title run with `XCL_CAST_LIST=1` on this head. - AMD and Intel hardware. **AI use** An agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen (tools: Claude Code, Codex, Antigravity). Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR
claudetools-gh commented 2026-11-29 16:12:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by claudetools-gh on 2026-11-29T16:12:28Z.


A data point from an RTX 5070 Ti (driver 621.40), retail title, Series X profile: with XCL_CAST_LIST=1 the NVIDIA user-mode driver crashed in 2 of 2 runs at world entry, 143–145 s after start. Both crashes are access violations inside nvwgf2umx.dll:

  • +0x47f82c, a read at 0xe800;
  • +0x4f6835, a read at 0x20.

Both happen on a title thread right after it creates a two-pass argument scratch buffer. Without the switch, 0 of 1 on the same binary: that run reaches the world.

The feature itself works here:

  • your two GPU tests pass on this card (gpu_one_texture_written_r32_uint_reads_as_r9g9b9e5_by_its_cast_list, decode_matches_the_format);
  • in the runs, "cast lists: a format 67 view of the texture … is made on the written texture … at its address" was logged (16 so far by 14 s).

Tree:

  • main 7a649b0e with #3124, #3192, #3179, #3282 (so #3281 underneath), #3306/#3307 and a local PS-export patch, then 5b064eb4 on top. It applied cleanly.
  • Env: XCL_PAIR_PAGES=1 XCL_CAST_LIST=1 XCL_UMA_WINDOWS=16 XCL_UMA_DRIVER=mixed:1536:1792 XCL_TEXTURE_LEVEL_PAGES=1 XCL_CS_PSO_WAIT_MS=0 XCL_TWO_PASS_MB=3072 XCL_PLACE_RETIRE=0 XCL_HEAP_WINDOWS=1.

The same +0x47f82c crash happened once before, without cast lists, in an earlier run with XCL_DEPTH_UAV_TWIN=1. That suggests the driver trips over a resource created through one of the newer paths rather than over this PR's views as such, but I can't tell which resource from here. I don't have a debugger on this machine; XCL's own dump doesn't include the crashing thread's stack.

Not tested: driver 621.24 or earlier, other NVIDIA generations, this PR without the rest of the stack. AI use: Claude Code with Claude Opus 5.5 ran the runs and wrote this. AI-assisted.

<!-- greyfinch-sync:ivall/xcl:comment:7258702596 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7258702596). Originally posted by [claudetools-gh](https://github.com/claudetools-gh) on 2026-11-29T16:12:28Z. --- A data point from an RTX 5070 Ti (driver 621.40), retail title, Series X profile: **with `XCL_CAST_LIST=1` the NVIDIA user-mode driver crashed in 2 of 2 runs** at world entry, 143–145 s after start. Both crashes are access violations inside `nvwgf2umx.dll`: - `+0x47f82c`, a read at 0xe800; - `+0x4f6835`, a read at 0x20. Both happen on a title thread right after it creates a two-pass argument scratch buffer. **Without the switch, 0 of 1** on the same binary: that run reaches the world. The feature itself works here: - your two GPU tests pass on this card (`gpu_one_texture_written_r32_uint_reads_as_r9g9b9e5_by_its_cast_list`, `decode_matches_the_format`); - in the runs, "cast lists: a format 67 view of the texture … is made on the written texture … at its address" was logged (16 so far by 14 s). Tree: - `main` 7a649b0e with #3124, #3192, #3179, #3282 (so #3281 underneath), #3306/#3307 and a local PS-export patch, then 5b064eb4 on top. It applied cleanly. - Env: `XCL_PAIR_PAGES=1 XCL_CAST_LIST=1 XCL_UMA_WINDOWS=16 XCL_UMA_DRIVER=mixed:1536:1792 XCL_TEXTURE_LEVEL_PAGES=1 XCL_CS_PSO_WAIT_MS=0 XCL_TWO_PASS_MB=3072 XCL_PLACE_RETIRE=0 XCL_HEAP_WINDOWS=1`. The same `+0x47f82c` crash happened once before, without cast lists, in an earlier run with `XCL_DEPTH_UAV_TWIN=1`. That suggests the driver trips over a resource created through one of the newer paths rather than over this PR's views as such, but I can't tell which resource from here. I don't have a debugger on this machine; XCL's own dump doesn't include the crashing thread's stack. Not tested: driver 621.24 or earlier, other NVIDIA generations, this PR without the rest of the stack. AI use: Claude Code with Claude Opus 5.5 ran the runs and wrote this. AI-assisted.
KDenKC commented 2026-11-29 16:14:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-29T16:14:39Z.


@claudetools-gh thanks, this is very useful, and the first crash looks familiar: nvwgf2umx.dll+0x47f82c, a read at 0xe800, on a title thread right after a two-pass argument scratch is created, is exactly the crash we saw on plain main 7db2f391 (no cast list, no PR of ours) on an RTX 5090: five title threads created their argument scratch and made the first two-pass ExecuteIndirect(DispatchMesh) calls of the run in the same millisecond, and the crash hit one of them. That moment is the race in #3317 (from your entry 6 on #2952): two threads build the per-device indirect scaling pipeline at once, the second insert drops the first pair, and the first thread's list keeps a freed pipeline. Your tree has #3124, #3192, #3179, #3282, #3306/#3307 but not #3317, and you saw the same +0x47f82c once without cast lists too.

So my reading is that the cast list is not the cause but shifts the timing at world entry enough to hit the race more often. It is a reading, not proof: could you run the same binary with #3317 (d848cc4c, one commit, applies on main) added, with XCL_CAST_LIST=1? If both crashes go away, it is the race; if +0x4f6835 (the read at 0x20) stays, that one is something else and I'll look at the cast list's resources for it.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash.

<!-- greyfinch-sync:ivall/xcl:comment:7258731503 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7258731503). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-29T16:14:39Z. --- @claudetools-gh thanks, this is very useful, and the first crash looks familiar: `nvwgf2umx.dll+0x47f82c`, a read at `0xe800`, on a title thread right after a two-pass argument scratch is created, is exactly the crash we saw on plain `main` `7db2f391` (no cast list, no PR of ours) on an RTX 5090: five title threads created their argument scratch and made the first two-pass `ExecuteIndirect(DispatchMesh)` calls of the run in the same millisecond, and the crash hit one of them. That moment is the race in #3317 (from your entry 6 on #2952): two threads build the per-device indirect scaling pipeline at once, the second insert drops the first pair, and the first thread's list keeps a freed pipeline. Your tree has #3124, #3192, #3179, #3282, #3306/#3307 but not #3317, and you saw the same `+0x47f82c` once without cast lists too. So my reading is that the cast list is not the cause but shifts the timing at world entry enough to hit the race more often. It is a reading, not proof: could you run the same binary with #3317 (`d848cc4c`, one commit, applies on `main`) added, with `XCL_CAST_LIST=1`? If both crashes go away, it is the race; if `+0x4f6835` (the read at 0x20) stays, that one is something else and I'll look at the cast list's resources for it. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash.
KDenKC commented 2026-11-29 19:36:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-29T19:36:21Z.


Follow-up to the crash report above: it was #3317's race, not this change. claudetools-gh reran the same tree with #3317 added and XCL_CAST_LIST=1 instead of the alias copy: no driver crash, and the cast list filled the light probes (the window's sky and yard lit, 1.09 presents/s against 1.02 with the copy; 1 of 1): https://github.com/xcl-dev/xcl/issues/505#issuecomment-7261395245. The description now says so under Not tested and links #3317 as needed with this on NVIDIA.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash.

<!-- greyfinch-sync:ivall/xcl:comment:7261412088 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7261412088). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-29T19:36:21Z. --- Follow-up to the crash report above: it was #3317's race, not this change. claudetools-gh reran the same tree with #3317 added and `XCL_CAST_LIST=1` instead of the alias copy: no driver crash, and the cast list filled the light probes (the window's sky and yard lit, 1.09 presents/s against 1.02 with the copy; 1 of 1): https://github.com/xcl-dev/xcl/issues/505#issuecomment-7261395245. The description now says so under Not tested and links #3317 as needed with this on NVIDIA. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash.
Foniass commented 2026-12-01 09:41:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:41:15Z.


merge-check
base: 7d86c5d2b7
head: b25dbd80b0
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2906 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+1084/-19; it carries #3281 under it). With XCL_CAST_LIST unset nothing changes: one OnceLock or atomic load per hook, plus a 0x38-byte description copy per placed texture. Findings: (1) The title's own cast list (#127) is a second, wider change. for_writer (cast_list.rs ~146) applies the title's list to any GPU-owned texture placed through vram::place, depth and render targets included. read_state (~113) then turns every read-only state into COMMON, DEPTH_READ and RESOLVE_SOURCE included, which is wrong for a depth buffer bound read-only or a resolve source. The R32/R9G9B9E5 pair doesn't need it. Whether the title passes a list for a depth texture is unverified. (2) The tests don't drive XCL's code. cast_tests.rs builds the D3D12 route by hand and only calls read_state, so they pass with the vram / real / list_x changes removed. Nothing tests place_on_pages, Pages::settle, the SRV redirect in dev_create_srv_inner or the barrier rewrite. (3) device_can (~118) checks relaxed casting, ID3D12Device10 and R9G9B9E5 sampling, but not enhanced-barrier support. A refused create falls back cleanly, but a failed settle (vram.rs ~2494) leaves the texture in COMMON while the title tracks UNORDERED_ACCESS (unverified). (4) With the switch on, is_writer (~197) takes a global mutex on every transition barrier once a writer exists. (5) Size and stack. It is 1,103 lines with #3281's commits, and those are an older copy of #3281's current head (d427662e / 7233f964 vs 3f252d43 / b0192a85), so it needs a rebase. The description gives the size but not why it can't be split. A split: cast_tests.rs alone; cast_list.rs not yet called; the reserved creator and settle; the hooks; the #127 pass-through. (6) #3094 (XCL_ALIAS_COPY) is another route to the same problem, and a maintainer should pick one. #3136 drops the same #127 arguments in real.rs, so the two conflict. From #3281: pair_pages() (vram.rs ~2322) reads the environment on every placement and every title_textures::register. Fine: both formats are 32 bits per element and the runtime accepted the list on WARP and on the author's card. CastingFullyTypedFormatSupported isn't needed with a cast list. Writers are keyed by canonical address and device, forgotten before recycling, and never pooled. The PR's red CI is standin::...concurrent_shell_miss..., fixed on main.
performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (50ec45d9): 1663 -> 1682 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17627 MB, 0 device removals, 0 crashes. The switch is off in this run, so it checks only that nothing changes by default; the cast-list path is unmeasured.
verdict: not yet: rebase onto #3281's current head (this carries an older copy of it), and split it: 1,103 lines with no reason given for passing 800. The #127 pass-through (finding 1) is a separate, wider change that turns depth reads into COMMON
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7307059266 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7307059266). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:41:15Z. --- merge-check base: 7d86c5d2b7845695031eeea1327aa81b6c439323 head: b25dbd80b0461f7d979d308f283743eb41b250b2 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2906 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (+1084/-19; it carries #3281 under it). With `XCL_CAST_LIST` unset nothing changes: one `OnceLock` or atomic load per hook, plus a 0x38-byte description copy per placed texture. Findings: (1) **The title's own cast list (#127) is a second, wider change.** `for_writer` (`cast_list.rs` ~146) applies the title's list to any GPU-owned texture placed through `vram::place`, depth and render targets included. `read_state` (~113) then turns every read-only state into COMMON, DEPTH_READ and RESOLVE_SOURCE included, which is wrong for a depth buffer bound read-only or a resolve source. The R32/R9G9B9E5 pair doesn't need it. Whether the title passes a list for a depth texture is unverified. (2) **The tests don't drive XCL's code.** `cast_tests.rs` builds the D3D12 route by hand and only calls `read_state`, so they pass with the `vram` / `real` / `list_x` changes removed. Nothing tests `place_on_pages`, `Pages::settle`, the SRV redirect in `dev_create_srv_inner` or the barrier rewrite. (3) `device_can` (~118) checks relaxed casting, `ID3D12Device10` and R9G9B9E5 sampling, but not enhanced-barrier support. A refused create falls back cleanly, but a failed `settle` (`vram.rs` ~2494) leaves the texture in COMMON while the title tracks UNORDERED_ACCESS (unverified). (4) With the switch on, `is_writer` (~197) takes a global mutex on every transition barrier once a writer exists. (5) **Size and stack.** It is 1,103 lines with #3281's commits, and those are an older copy of #3281's current head (d427662e / 7233f964 vs 3f252d43 / b0192a85), so it needs a rebase. The description gives the size but not why it can't be split. A split: `cast_tests.rs` alone; `cast_list.rs` not yet called; the reserved creator and `settle`; the hooks; the #127 pass-through. (6) #3094 (`XCL_ALIAS_COPY`) is another route to the same problem, and a maintainer should pick one. #3136 drops the same #127 arguments in `real.rs`, so the two conflict. From #3281: `pair_pages()` (`vram.rs` ~2322) reads the environment on every placement and every `title_textures::register`. Fine: both formats are 32 bits per element and the runtime accepted the list on WARP and on the author's card. `CastingFullyTypedFormatSupported` isn't needed with a cast list. Writers are keyed by canonical address and device, forgotten before recycling, and never pooled. The PR's red CI is `standin::...concurrent_shell_miss...`, fixed on main. performance: 60 s smoke of a retail title, main 7d86c5d2 vs this merge (50ec45d9): 1663 -> 1682 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17627 MB, 0 device removals, 0 crashes. The switch is off in this run, so it checks only that nothing changes by default; the cast-list path is unmeasured. verdict: not yet: rebase onto #3281's current head (this carries an older copy of it), and split it: 1,103 lines with no reason given for passing 800. The #127 pass-through (finding 1) is a separate, wider change that turns depth reads into COMMON hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 09:49:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:49:58Z.


Triage (#1607) – head b25dbd8

Stacked on #3281: the two XCL_PAIR_PAGES commits under it are #3281's, so only the top commit (cast_list.rs, the vram/real/list_x hooks, cast_tests.rs) belongs here. #3094 fixes the same stale R9G9B9E5-over-R32_UINT read in a different way: it copies the written texture into the sampled one through a buffer (XCL_ALIAS_COPY). This PR makes the two one PC texture through a relaxed-format cast list. Those are different approaches, not duplicates. #3491 (draft) is stacked on this PR and extends it to volumes. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7307271365 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7307271365). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:49:58Z. --- **Triage (#1607)** – head b25dbd8 Stacked on #3281: the two XCL_PAIR_PAGES commits under it are #3281's, so only the top commit (`cast_list.rs`, the `vram`/`real`/`list_x` hooks, `cast_tests.rs`) belongs here. #3094 fixes the same stale R9G9B9E5-over-R32_UINT read in a different way: it copies the written texture into the sampled one through a buffer (XCL_ALIAS_COPY). This PR makes the two one PC texture through a relaxed-format cast list. Those are different approaches, not duplicates. #3491 (draft) is stacked on this PR and extends it to volumes. No problems found in the diff. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Foniass commented 2026-12-01 21:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:06:40Z.


Follow-up review (head 8a2d7518, since b25dbd8, diff read, not a merge-check; checks red):

  • The title's own cast list (#127) is a second, wider change: partly fixed. read_state is gone, so read-only states are no longer sent as COMMON, and widen_state (cast_list.rs ~122) only adds the shader-resource states. But for_writer (~166-189) still gives the title's list to any GPU-owned texture placed in COMMON, RENDER_TARGET, UNORDERED_ACCESS or COPY_DEST, which the R32_UINT/R9G9B9E5 pair does not need.
  • The tests do not drive XCL's code: still open. cast_tests.rs (~162, ~193, ~231) makes the texture in layout COMMON and sends its own legacy barriers; it never calls layout_of, widen_state, place_on_pages or the SRV redirect.
  • device_can does not check enhanced-barrier support: still open (cast_list.rs ~142-162 reads RelaxedFormatCastingSupported but not EnhancedBarriersSupported).
  • is_writer takes a global mutex on every transition barrier once a writer exists: still open (cast_list.rs ~223, from list_x.rs ~6445).
  • Size and stack: still open. 1,040 lines with no reason for going past 800, carrying #3281's old commits rather than its current head; pair_pages() (vram.rs ~2394) still reads the environment on every call.
  • #3094 / #3136 overlap: still open; #3136 adds slots right after #127 and drops their cast lists, while this PR passes #127's list through.

New:

  • The head went back to the route the description says fails. 8a2d7518 is a rebase of a commit from 29 Nov, older than b25dbd80: layout_of (cast_list.rs ~109) makes the written texture in its initial state's layout (UNORDERED_ACCESS, RENDER_TARGET, COPY_DEST), vram.rs ~2490 passes that to CreateReservedResource2, and the title's barriers on it still go out as legacy ones (list_x.rs ~6452). The description's own run shows this route giving debug-layer error 1350 and the 5090 hanging after it.
  • The description and test results no longer match the code. They describe made-in-COMMON, Pages::settle and read_state, none of which exist at 8a2d7518, and the xcl-smoke blocks are for b25dbd80, which is why PR description is red.

Fine: with XCL_CAST_LIST unset every hook stops at a OnceLock or atomic check; a refused CreateReservedResource2 falls back to the old create; writers are keyed by device and canonical address and forgotten in res_release before recycling.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7325761007 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7325761007). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:06:40Z. --- Follow-up review (head 8a2d7518, since b25dbd8, diff read, not a merge-check; checks red): - **The title's own cast list (#127) is a second, wider change:** partly fixed. `read_state` is gone, so read-only states are no longer sent as COMMON, and `widen_state` (`cast_list.rs` ~122) only adds the shader-resource states. But `for_writer` (~166-189) still gives the title's list to any GPU-owned texture placed in COMMON, RENDER_TARGET, UNORDERED_ACCESS or COPY_DEST, which the R32_UINT/R9G9B9E5 pair does not need. - **The tests do not drive XCL's code:** still open. `cast_tests.rs` (~162, ~193, ~231) makes the texture in layout COMMON and sends its own legacy barriers; it never calls `layout_of`, `widen_state`, `place_on_pages` or the SRV redirect. - **`device_can` does not check enhanced-barrier support:** still open (`cast_list.rs` ~142-162 reads `RelaxedFormatCastingSupported` but not `EnhancedBarriersSupported`). - **`is_writer` takes a global mutex on every transition barrier once a writer exists:** still open (`cast_list.rs` ~223, from `list_x.rs` ~6445). - **Size and stack:** still open. 1,040 lines with no reason for going past 800, carrying #3281's old commits rather than its current head; `pair_pages()` (`vram.rs` ~2394) still reads the environment on every call. - **#3094 / #3136 overlap:** still open; #3136 adds slots right after #127 and drops their cast lists, while this PR passes #127's list through. New: - **The head went back to the route the description says fails.** `8a2d7518` is a rebase of a commit from 29 Nov, older than `b25dbd80`: `layout_of` (`cast_list.rs` ~109) makes the written texture in its initial state's layout (UNORDERED_ACCESS, RENDER_TARGET, COPY_DEST), `vram.rs` ~2490 passes that to `CreateReservedResource2`, and the title's barriers on it still go out as legacy ones (`list_x.rs` ~6452). The description's own run shows this route giving debug-layer error 1350 and the 5090 hanging after it. - **The description and test results no longer match the code.** They describe made-in-COMMON, `Pages::settle` and `read_state`, none of which exist at `8a2d7518`, and the `xcl-smoke` blocks are for `b25dbd80`, which is why `PR description` is red. Fine: with `XCL_CAST_LIST` unset every hook stops at a `OnceLock` or atomic check; a refused `CreateReservedResource2` falls back to the old create; writers are keyed by device and canonical address and forgotten in `res_release` before recycling. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 01:13:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:17Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 114

@@ -0,0 +1,353 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The written texture's read-only legacy states also take the shader-resource states
+//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it
+//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+const NPS: u32 = 0x40;
+const PS: u32 = 0x80;
+/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video
+/// encode / decode / process writes
+const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000;
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {
+        Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) }
+    }
+}
+
+struct Writer {
+    res: usize,
+    shape: Shape,
+    format: i32,
+    casts: Vec<i32>,
+}
+
+#[derive(Default)]
+struct Table {
+    /// by (device, canonical address)
+    writers: HashMap<(usize, usize), Writer>,
+    /// the cast-made textures: their barriers are widened
+    made: HashSet<usize>,
+    /// the title's other textures, by resource: (device, canonical address, shape, format)
+    readers: HashMap<usize, (usize, usize, Shape, i32)>,
+}
+
+static TABLE: Mutex<Option<Table>> = Mutex::new(None);
+/// Cast-made textures alive: the gate of every hook.
+static MADE: AtomicUsize = AtomicUsize::new(0);
+static VIEWS: AtomicU64 = AtomicU64::new(0);
+
+thread_local! {
+    /// The cast list of the title's create on this thread (#127), while it runs.
+    static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) };
+}
+
+/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast
+/// list while the guard lives.
+pub(super) struct TitleList;
+
+impl Drop for TitleList {
+    fn drop(&mut self) {
+        TITLE.with(|t| t.borrow_mut().clear());
+    }
+}
+
+pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> {
+    if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) {
+        return None;
+    }
+    let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect();
+    TITLE.with(|t| *t.borrow_mut() = list);
+    Some(TitleList)
+}
+
+/// The barrier layout a writer is made in for the initial state `state`: only states `widen`
+/// leaves as they are (None: made without a cast list).
+fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> {
+    Some(match state {
+        0 => D3D12_BARRIER_LAYOUT_COMMON,
+        0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
+        0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
+        0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,

The pushed head doesn't match the description. The body describes a later head (b25dbd80) that creates the written texture in COMMON, settles it with Pages::settle and sends read states via read_state, but neither function exists on this branch. Here the texture is created in the layout of its initial state (layout_of maps 0x8 to UNORDERED_ACCESS, plus RENDER_TARGET and COPY_DEST). With XCL_CAST_LIST=1 and the light UAV placed in UNORDERED_ACCESS (the usual case), place_on_pages calls CreateReservedResource2 with that layout, and the title then uses legacy ResourceBarrier on it. That's the debug layer error 1350 / RTX 5090 hang route the body says was fixed. What was tested isn't what would merge.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370311 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370311). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:17Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 114 ~~~~diff @@ -0,0 +1,353 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The written texture's read-only legacy states also take the shader-resource states +//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it +//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; +const NPS: u32 = 0x40; +const PS: u32 = 0x80; +/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video +/// encode / decode / process writes +const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { + Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) } + } +} + +struct Writer { + res: usize, + shape: Shape, + format: i32, + casts: Vec<i32>, +} + +#[derive(Default)] +struct Table { + /// by (device, canonical address) + writers: HashMap<(usize, usize), Writer>, + /// the cast-made textures: their barriers are widened + made: HashSet<usize>, + /// the title's other textures, by resource: (device, canonical address, shape, format) + readers: HashMap<usize, (usize, usize, Shape, i32)>, +} + +static TABLE: Mutex<Option<Table>> = Mutex::new(None); +/// Cast-made textures alive: the gate of every hook. +static MADE: AtomicUsize = AtomicUsize::new(0); +static VIEWS: AtomicU64 = AtomicU64::new(0); + +thread_local! { + /// The cast list of the title's create on this thread (#127), while it runs. + static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) }; +} + +/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast +/// list while the guard lives. +pub(super) struct TitleList; + +impl Drop for TitleList { + fn drop(&mut self) { + TITLE.with(|t| t.borrow_mut().clear()); + } +} + +pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> { + if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) { + return None; + } + let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect(); + TITLE.with(|t| *t.borrow_mut() = list); + Some(TitleList) +} + +/// The barrier layout a writer is made in for the initial state `state`: only states `widen` +/// leaves as they are (None: made without a cast list). +fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> { + Some(match state { + 0 => D3D12_BARRIER_LAYOUT_COMMON, + 0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET, + 0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS, + 0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST, ~~~~ --- The pushed head doesn't match the description. The body describes a later head (b25dbd80) that creates the written texture in COMMON, settles it with `Pages::settle` and sends read states via `read_state`, but neither function exists on this branch. Here the texture is created in the layout of its initial state (`layout_of` maps 0x8 to UNORDERED_ACCESS, plus RENDER_TARGET and COPY_DEST). With XCL_CAST_LIST=1 and the light UAV placed in UNORDERED_ACCESS (the usual case), `place_on_pages` calls CreateReservedResource2 with that layout, and the title then uses legacy ResourceBarrier on it. That's the debug layer error 1350 / RTX 5090 hang route the body says was fixed. What was tested isn't what would merge.
bmjask commented 2026-12-02 01:13:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:17Z.

Review: COMMENTED


Review of 8a2d7518: 7 finding(s). 7 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6143106973 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#pullrequestreview-6143106973). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:17Z. **Review:** COMMENTED --- Review of `8a2d7518`: 7 finding(s). 7 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 127

@@ -0,0 +1,353 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The written texture's read-only legacy states also take the shader-resource states
+//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it
+//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+const NPS: u32 = 0x40;
+const PS: u32 = 0x80;
+/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video
+/// encode / decode / process writes
+const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000;
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {
+        Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) }
+    }
+}
+
+struct Writer {
+    res: usize,
+    shape: Shape,
+    format: i32,
+    casts: Vec<i32>,
+}
+
+#[derive(Default)]
+struct Table {
+    /// by (device, canonical address)
+    writers: HashMap<(usize, usize), Writer>,
+    /// the cast-made textures: their barriers are widened
+    made: HashSet<usize>,
+    /// the title's other textures, by resource: (device, canonical address, shape, format)
+    readers: HashMap<usize, (usize, usize, Shape, i32)>,
+}
+
+static TABLE: Mutex<Option<Table>> = Mutex::new(None);
+/// Cast-made textures alive: the gate of every hook.
+static MADE: AtomicUsize = AtomicUsize::new(0);
+static VIEWS: AtomicU64 = AtomicU64::new(0);
+
+thread_local! {
+    /// The cast list of the title's create on this thread (#127), while it runs.
+    static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) };
+}
+
+/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast
+/// list while the guard lives.
+pub(super) struct TitleList;
+
+impl Drop for TitleList {
+    fn drop(&mut self) {
+        TITLE.with(|t| t.borrow_mut().clear());
+    }
+}
+
+pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> {
+    if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) {
+        return None;
+    }
+    let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect();
+    TITLE.with(|t| *t.borrow_mut() = list);
+    Some(TitleList)
+}
+
+/// The barrier layout a writer is made in for the initial state `state`: only states `widen`
+/// leaves as they are (None: made without a cast list).
+fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> {
+    Some(match state {
+        0 => D3D12_BARRIER_LAYOUT_COMMON,
+        0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
+        0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
+        0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,
+        _ => return None,
+    })
+}
+
+/// A state of a cast-made texture in a transition on a list of type `ty`: read-only ones (not
+/// COMMON) take the shader-resource states that list type has (DIRECT both, COMPUTE the
+/// non-pixel one). A COPY list has neither: its states are left as they are.
+pub(super) fn widen_state(s: u32, ty: D3D12_COMMAND_LIST_TYPE) -> u32 {
+    let read = match ty {
+        D3D12_COMMAND_LIST_TYPE_DIRECT => NPS | PS,
+        D3D12_COMMAND_LIST_TYPE_COMPUTE => NPS,
+        _ => 0,
+    };

Read states are still widened (e.g. SRV|COPY_SOURCE), which are the GENERIC_READ-style layouts the PR body says cause debug layer error 1334. If the writer is moved to NPS on a DIRECT list, it's sent as 0xC0. A later submission that reads it with no barrier expects COMMON at the start, so it gets error 1334, and the driver may skip the decompression or cache flushes the next submission needs.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370319 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370319). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 127 ~~~~diff @@ -0,0 +1,353 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The written texture's read-only legacy states also take the shader-resource states +//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it +//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; +const NPS: u32 = 0x40; +const PS: u32 = 0x80; +/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video +/// encode / decode / process writes +const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { + Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) } + } +} + +struct Writer { + res: usize, + shape: Shape, + format: i32, + casts: Vec<i32>, +} + +#[derive(Default)] +struct Table { + /// by (device, canonical address) + writers: HashMap<(usize, usize), Writer>, + /// the cast-made textures: their barriers are widened + made: HashSet<usize>, + /// the title's other textures, by resource: (device, canonical address, shape, format) + readers: HashMap<usize, (usize, usize, Shape, i32)>, +} + +static TABLE: Mutex<Option<Table>> = Mutex::new(None); +/// Cast-made textures alive: the gate of every hook. +static MADE: AtomicUsize = AtomicUsize::new(0); +static VIEWS: AtomicU64 = AtomicU64::new(0); + +thread_local! { + /// The cast list of the title's create on this thread (#127), while it runs. + static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) }; +} + +/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast +/// list while the guard lives. +pub(super) struct TitleList; + +impl Drop for TitleList { + fn drop(&mut self) { + TITLE.with(|t| t.borrow_mut().clear()); + } +} + +pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> { + if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) { + return None; + } + let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect(); + TITLE.with(|t| *t.borrow_mut() = list); + Some(TitleList) +} + +/// The barrier layout a writer is made in for the initial state `state`: only states `widen` +/// leaves as they are (None: made without a cast list). +fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> { + Some(match state { + 0 => D3D12_BARRIER_LAYOUT_COMMON, + 0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET, + 0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS, + 0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST, + _ => return None, + }) +} + +/// A state of a cast-made texture in a transition on a list of type `ty`: read-only ones (not +/// COMMON) take the shader-resource states that list type has (DIRECT both, COMPUTE the +/// non-pixel one). A COPY list has neither: its states are left as they are. +pub(super) fn widen_state(s: u32, ty: D3D12_COMMAND_LIST_TYPE) -> u32 { + let read = match ty { + D3D12_COMMAND_LIST_TYPE_DIRECT => NPS | PS, + D3D12_COMMAND_LIST_TYPE_COMPUTE => NPS, + _ => 0, + }; ~~~~ --- Read states are still widened (e.g. SRV|COPY_SOURCE), which are the GENERIC_READ-style layouts the PR body says cause debug layer error 1334. If the writer is moved to NPS on a DIRECT list, it's sent as 0xC0. A later submission that reads it with no barrier expects COMMON at the start, so it gets error 1334, and the driver may skip the decompression or cache flushes the next submission needs.
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/list_x.rs; line 6445

@@ -6440,6 +6440,18 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
                 b[5] &= !BUFFER_ONLY_STATES;
                 b[6] &= !BUFFER_ONLY_STATES;
             }
+            // (a texture made with a cast list: its read-only states can be read through the views
+            // made on it, `cast_list`; both sides, so every list agrees on its state)
+            if super::cast_list::is_writer((b[2] as u64 | (b[3] as u64) << 32) as usize) {

widen_state adds NPS|PS on DIRECT lists but only NPS on COMPUTE lists, so the same texture's tracked state depends on list type. If a DIRECT list moves the writer UA->NPS (sent 0x8->0xC0) and a later COMPUTE list moves it NPS->UA (sent 0x40->0x8), the texture is really in 0xC0, so the before-state mismatches. That's a debug layer error, and the PS read state is never flushed. The reverse order mismatches too, and note_other_list only logs it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370330 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370330). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/list_x.rs`; line 6445 ~~~~diff @@ -6440,6 +6440,18 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3 b[5] &= !BUFFER_ONLY_STATES; b[6] &= !BUFFER_ONLY_STATES; } + // (a texture made with a cast list: its read-only states can be read through the views + // made on it, `cast_list`; both sides, so every list agrees on its state) + if super::cast_list::is_writer((b[2] as u64 | (b[3] as u64) << 32) as usize) { ~~~~ --- `widen_state` adds NPS|PS on DIRECT lists but only NPS on COMPUTE lists, so the same texture's tracked state depends on list type. If a DIRECT list moves the writer UA->NPS (sent 0x8->0xC0) and a later COMPUTE list moves it NPS->UA (sent 0x40->0x8), the texture is really in 0xC0, so the before-state mismatches. That's a debug layer error, and the PS read state is never flushed. The reverse order mismatches too, and `note_other_list` only logs it.
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3276

@@ -3270,6 +3271,15 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const
             c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT;
         }
     }
+    // a texture in the memory of a written one, in a format of its cast list: viewed on that one
+    // (`cast_list`; the slot is noted as the written texture's, so its views go with it)
+    let res = match super::cast_list::view_on_writer(res as usize, copy.as_ref()) {

Views of the sampled (reader) texture are moved onto the writer, but the title's barriers on the reader resource aren't. On the console the title writes the R32_UINT texture as UAV and transitions only the R9G9B9E5 alias to PIXEL_SHADER_RESOURCE before sampling. On the PC that transition goes to the reader object, the writer stays in UNORDERED_ACCESS, and the redirected SRV samples a UA-state resource. That's a debug layer error, and on hardware with compressed or cached UAV data it can read stale texels. Barriers on a redirected reader need to go to the writer.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370336 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370336). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3276 ~~~~diff @@ -3270,6 +3271,15 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT; } } + // a texture in the memory of a written one, in a format of its cast list: viewed on that one + // (`cast_list`; the slot is noted as the written texture's, so its views go with it) + let res = match super::cast_list::view_on_writer(res as usize, copy.as_ref()) { ~~~~ --- Views of the sampled (reader) texture are moved onto the writer, but the title's barriers on the reader resource aren't. On the console the title writes the R32_UINT texture as UAV and transitions only the R9G9B9E5 alias to PIXEL_SHADER_RESOURCE before sampling. On the PC that transition goes to the reader object, the writer stays in UNORDERED_ACCESS, and the redirected SRV samples a UA-state resource. That's a debug layer error, and on hardware with compressed or cached UAV data it can read stale texels. Barriers on a redirected reader need to go to the writer.
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 232

@@ -0,0 +1,353 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The written texture's read-only legacy states also take the shader-resource states
+//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it
+//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+const NPS: u32 = 0x40;
+const PS: u32 = 0x80;
+/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video
+/// encode / decode / process writes
+const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000;
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {
+        Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) }
+    }
+}
+
+struct Writer {
+    res: usize,
+    shape: Shape,
+    format: i32,
+    casts: Vec<i32>,
+}
+
+#[derive(Default)]
+struct Table {
+    /// by (device, canonical address)
+    writers: HashMap<(usize, usize), Writer>,
+    /// the cast-made textures: their barriers are widened
+    made: HashSet<usize>,
+    /// the title's other textures, by resource: (device, canonical address, shape, format)
+    readers: HashMap<usize, (usize, usize, Shape, i32)>,
+}
+
+static TABLE: Mutex<Option<Table>> = Mutex::new(None);
+/// Cast-made textures alive: the gate of every hook.
+static MADE: AtomicUsize = AtomicUsize::new(0);
+static VIEWS: AtomicU64 = AtomicU64::new(0);
+
+thread_local! {
+    /// The cast list of the title's create on this thread (#127), while it runs.
+    static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) };
+}
+
+/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast
+/// list while the guard lives.
+pub(super) struct TitleList;
+
+impl Drop for TitleList {
+    fn drop(&mut self) {
+        TITLE.with(|t| t.borrow_mut().clear());
+    }
+}
+
+pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> {
+    if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) {
+        return None;
+    }
+    let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect();
+    TITLE.with(|t| *t.borrow_mut() = list);
+    Some(TitleList)
+}
+
+/// The barrier layout a writer is made in for the initial state `state`: only states `widen`
+/// leaves as they are (None: made without a cast list).
+fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> {
+    Some(match state {
+        0 => D3D12_BARRIER_LAYOUT_COMMON,
+        0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
+        0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
+        0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,
+        _ => return None,
+    })
+}
+
+/// A state of a cast-made texture in a transition on a list of type `ty`: read-only ones (not
+/// COMMON) take the shader-resource states that list type has (DIRECT both, COMPUTE the
+/// non-pixel one). A COPY list has neither: its states are left as they are.
+pub(super) fn widen_state(s: u32, ty: D3D12_COMMAND_LIST_TYPE) -> u32 {
+    let read = match ty {
+        D3D12_COMMAND_LIST_TYPE_DIRECT => NPS | PS,
+        D3D12_COMMAND_LIST_TYPE_COMPUTE => NPS,
+        _ => 0,
+    };
+    if s != 0 && s & WRITES == 0 { s | read } else { s }
+}
+
+/// A cast-made texture moved on a list that is not DIRECT: its widened states there leave out
+/// what that list type cannot name, so a DIRECT list's state for it may be wider (logged).
+pub(super) fn note_other_list(ty: D3D12_COMMAND_LIST_TYPE) {
+    static N: AtomicU64 = AtomicU64::new(0);
+    let n = N.fetch_add(1, Ordering::Relaxed) + 1;
+    if n <= 4 || n.is_power_of_two() {
+        crate::xlog_info!("D3D12.X: cast lists: a written texture moved on a list of type {} ({n} so far): its read states there have no PIXEL_SHADER_RESOURCE", ty.0);
+    }
+}
+
+/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device).
+unsafe fn device_can(dev: &ID3D12Device) -> bool {
+    static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None);
+    let key = dev.as_raw() as usize;
+    if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) {
+        return c;
+    }
+    let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default();
+    let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool();
+    let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() };
+    let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok()
+        && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0);
+    let device10 = dev.cast::<ID3D12Device10>().is_ok();
+    let can = relaxed && sample && device10;
+    crate::xlog_info!(
+        "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}",
+        if can { "on" } else { "off" },
+        if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" }
+    );
+    CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can);
+    can
+}
+
+/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made
+/// as before). The light pair's written texture, and the title's own list (#127).
+pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> {
+    if !on() || desc.SampleDesc.Count > 1 {
+        return None;
+    }
+    let mut casts = TITLE.with(|t| t.borrow().clone());
+    let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0;
+    if light {
+        casts.extend(LIGHT.iter().map(|f| f.0));
+    }
+    if casts.is_empty() {
+        return None;
+    }
+    let layout = layout_of(state)?;
+    if !device_can(dev) {
+        return None;
+    }
+    if !casts.contains(&desc.Format.0) {
+        casts.push(desc.Format.0);
+    }
+    casts.sort_unstable();
+    casts.dedup();
+    // (one format is no cast list: the texture is made as before)
+    (casts.len() >= 2).then_some((layout, casts))
+}
+
+/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`).
+pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) {
+    let mut g = TABLE.lock().unwrap();
+    let t = g.get_or_insert_with(Table::default);
+    if t.made.insert(res) {
+        MADE.fetch_add(1, Ordering::Relaxed);
+    }
+    t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts });
+}
+
+/// The title placed `res` (PC description `desc`) at `va` (`device_x::create_placed_resource_x`).
+pub(super) fn note_created(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) {
+    if on() {
+        keep_reader(dev, res, super::vram::canonical_va(va), desc);
+    }
+}
+
+/// `note_created` without the switch (`va` canonical). Kept before any writer is made: a view is
+/// put on its writer when it is made, in either order.
+fn keep_reader(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) {
+    if res == 0 || va == 0 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count > 1 {
+        return;
+    }
+    let mut g = TABLE.lock().unwrap();
+    let t = g.get_or_insert_with(Table::default);
+    if !t.made.contains(&res) {
+        t.readers.insert(res, (dev, va, Shape::of(desc), desc.Format.0));
+    }
+}
+
+/// Whether `res` was made with a cast list.
+pub(super) fn is_writer(res: usize) -> bool {
+    MADE.load(Ordering::Relaxed) != 0 && TABLE.lock().unwrap().as_ref().is_some_and(|t| t.made.contains(&res))
+}
+
+/// The written texture to make the title's view `view` of `res` on, and the view (None: `res`'s
+/// own): `res` is at a writer's address with its shape, in another format of its cast list.
+pub(super) fn view_on_writer(res: usize, view: Option<&D3D12_SHADER_RESOURCE_VIEW_DESC>) -> Option<(usize, D3D12_SHADER_RESOURCE_VIEW_DESC)> {
+    if MADE.load(Ordering::Relaxed) == 0 || res == 0 {
+        return None;
+    }
+    let (writer, v) = {

The redirect only happens when the SRV is created. If the title places the reader, creates its R9G9B9E5 SRV and only then places the writer, view_on_writer finds no writer and the view stays on the stale reader for good. If the writer is recreated at the same address (resize/reallocation) while the title keeps its reader descriptor, resource_gone(writer) nulls the descriptor and the title samples zeros (black light), where on the console the alias would see the new writer's data.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370343 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370343). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 232 ~~~~diff @@ -0,0 +1,353 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The written texture's read-only legacy states also take the shader-resource states +//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it +//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; +const NPS: u32 = 0x40; +const PS: u32 = 0x80; +/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video +/// encode / decode / process writes +const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { + Shape { dimension: d.Dimension.0, width: d.Width, height: d.Height, depth: d.DepthOrArraySize.max(1), mips: d.MipLevels.max(1) } + } +} + +struct Writer { + res: usize, + shape: Shape, + format: i32, + casts: Vec<i32>, +} + +#[derive(Default)] +struct Table { + /// by (device, canonical address) + writers: HashMap<(usize, usize), Writer>, + /// the cast-made textures: their barriers are widened + made: HashSet<usize>, + /// the title's other textures, by resource: (device, canonical address, shape, format) + readers: HashMap<usize, (usize, usize, Shape, i32)>, +} + +static TABLE: Mutex<Option<Table>> = Mutex::new(None); +/// Cast-made textures alive: the gate of every hook. +static MADE: AtomicUsize = AtomicUsize::new(0); +static VIEWS: AtomicU64 = AtomicU64::new(0); + +thread_local! { + /// The cast list of the title's create on this thread (#127), while it runs. + static TITLE: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) }; +} + +/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast +/// list while the guard lives. +pub(super) struct TitleList; + +impl Drop for TitleList { + fn drop(&mut self) { + TITLE.with(|t| t.borrow_mut().clear()); + } +} + +pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> { + if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) { + return None; + } + let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect(); + TITLE.with(|t| *t.borrow_mut() = list); + Some(TitleList) +} + +/// The barrier layout a writer is made in for the initial state `state`: only states `widen` +/// leaves as they are (None: made without a cast list). +fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> { + Some(match state { + 0 => D3D12_BARRIER_LAYOUT_COMMON, + 0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET, + 0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS, + 0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST, + _ => return None, + }) +} + +/// A state of a cast-made texture in a transition on a list of type `ty`: read-only ones (not +/// COMMON) take the shader-resource states that list type has (DIRECT both, COMPUTE the +/// non-pixel one). A COPY list has neither: its states are left as they are. +pub(super) fn widen_state(s: u32, ty: D3D12_COMMAND_LIST_TYPE) -> u32 { + let read = match ty { + D3D12_COMMAND_LIST_TYPE_DIRECT => NPS | PS, + D3D12_COMMAND_LIST_TYPE_COMPUTE => NPS, + _ => 0, + }; + if s != 0 && s & WRITES == 0 { s | read } else { s } +} + +/// A cast-made texture moved on a list that is not DIRECT: its widened states there leave out +/// what that list type cannot name, so a DIRECT list's state for it may be wider (logged). +pub(super) fn note_other_list(ty: D3D12_COMMAND_LIST_TYPE) { + static N: AtomicU64 = AtomicU64::new(0); + let n = N.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 4 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: cast lists: a written texture moved on a list of type {} ({n} so far): its read states there have no PIXEL_SHADER_RESOURCE", ty.0); + } +} + +/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device). +unsafe fn device_can(dev: &ID3D12Device) -> bool { + static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None); + let key = dev.as_raw() as usize; + if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) { + return c; + } + let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default(); + let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool(); + let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() }; + let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok() + && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0); + let device10 = dev.cast::<ID3D12Device10>().is_ok(); + let can = relaxed && sample && device10; + crate::xlog_info!( + "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}", + if can { "on" } else { "off" }, + if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" } + ); + CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can); + can +} + +/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made +/// as before). The light pair's written texture, and the title's own list (#127). +pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> { + if !on() || desc.SampleDesc.Count > 1 { + return None; + } + let mut casts = TITLE.with(|t| t.borrow().clone()); + let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0; + if light { + casts.extend(LIGHT.iter().map(|f| f.0)); + } + if casts.is_empty() { + return None; + } + let layout = layout_of(state)?; + if !device_can(dev) { + return None; + } + if !casts.contains(&desc.Format.0) { + casts.push(desc.Format.0); + } + casts.sort_unstable(); + casts.dedup(); + // (one format is no cast list: the texture is made as before) + (casts.len() >= 2).then_some((layout, casts)) +} + +/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`). +pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) { + let mut g = TABLE.lock().unwrap(); + let t = g.get_or_insert_with(Table::default); + if t.made.insert(res) { + MADE.fetch_add(1, Ordering::Relaxed); + } + t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts }); +} + +/// The title placed `res` (PC description `desc`) at `va` (`device_x::create_placed_resource_x`). +pub(super) fn note_created(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) { + if on() { + keep_reader(dev, res, super::vram::canonical_va(va), desc); + } +} + +/// `note_created` without the switch (`va` canonical). Kept before any writer is made: a view is +/// put on its writer when it is made, in either order. +fn keep_reader(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) { + if res == 0 || va == 0 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count > 1 { + return; + } + let mut g = TABLE.lock().unwrap(); + let t = g.get_or_insert_with(Table::default); + if !t.made.contains(&res) { + t.readers.insert(res, (dev, va, Shape::of(desc), desc.Format.0)); + } +} + +/// Whether `res` was made with a cast list. +pub(super) fn is_writer(res: usize) -> bool { + MADE.load(Ordering::Relaxed) != 0 && TABLE.lock().unwrap().as_ref().is_some_and(|t| t.made.contains(&res)) +} + +/// The written texture to make the title's view `view` of `res` on, and the view (None: `res`'s +/// own): `res` is at a writer's address with its shape, in another format of its cast list. +pub(super) fn view_on_writer(res: usize, view: Option<&D3D12_SHADER_RESOURCE_VIEW_DESC>) -> Option<(usize, D3D12_SHADER_RESOURCE_VIEW_DESC)> { + if MADE.load(Ordering::Relaxed) == 0 || res == 0 { + return None; + } + let (writer, v) = { ~~~~ --- The redirect only happens when the SRV is created. If the title places the reader, creates its R9G9B9E5 SRV and only then places the writer, `view_on_writer` finds no writer and the view stays on the stale reader for good. If the writer is recreated at the same address (resize/reallocation) while the title keeps its reader descriptor, `resource_gone(writer)` nulls the descriptor and the title samples zeros (black light), where on the console the alias would see the new writer's data.
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 56

@@ -0,0 +1,353 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The written texture's read-only legacy states also take the shader-resource states
+//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it
+//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+const NPS: u32 = 0x40;
+const PS: u32 = 0x80;
+/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video
+/// encode / decode / process writes
+const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000;
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {

Shape::of treats MipLevels 0 ("full chain") as 1, and whole_view builds a null-desc view with that many mips. A reader or writer created with MipLevels=0 gets a 1-mip shape, so a rebuilt null-desc SRV has MipLevels=1 and every lower mip the title samples reads out of range. MipLevels=0 on one side and an explicit full count on the other also fail to match, so no redirect happens. The non-redirected path uses r.MipLevels or u32::MAX.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370352 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370352). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 56 ~~~~diff @@ -0,0 +1,353 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The written texture's read-only legacy states also take the shader-resource states +//! (`widen`), so the views made on it are read in a state they may be read in. COMMON stays as it +//! is (a read promotes it). The title's views on it go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; +const NPS: u32 = 0x40; +const PS: u32 = 0x80; +/// RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, STREAM_OUT, COPY_DEST, RESOLVE_DEST, the video +/// encode / decode / process writes +const WRITES: u32 = 0x4 | 0x8 | 0x10 | 0x100 | 0x400 | 0x1000 | 0x2_0000 | 0x8_0000 | 0x80_0000; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { ~~~~ --- `Shape::of` treats MipLevels 0 ("full chain") as 1, and `whole_view` builds a null-desc view with that many mips. A reader or writer created with MipLevels=0 gets a 1-mip shape, so a rebuilt null-desc SRV has MipLevels=1 and every lower mip the title samples reads out of range. MipLevels=0 on one side and an explicit full count on the other also fail to match, so no redirect happens. The non-redirected path uses `r.MipLevels` or u32::MAX.
bmjask commented 2026-12-02 01:13:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:13:18Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3849

@@ -3829,12 +3839,14 @@ unsafe extern "system" fn dev_create_committed_resource_layout_x(
     layout: u32,
     clear: usize,
     _protected: usize,
-    _castable: u32,
-    _formats: usize,
+    castable: u32,
+    formats: usize,
     riid: *const GUID,
     ppv: *mut *mut c_void,
 ) -> HRESULT {
     note_newer_device_method(127);
+    // (the title's cast list: a GPU-written texture on the title's pages is made with it)
+    let _casts = super::cast_list::title_list(castable, formats);

Not certain about this one: the #127 cast list stays in a thread-local for the whole of dev_create_committed_resource_layout_x. Any GPU-owned texture XCL itself creates through place_on_pages on that thread during the call (display target path, helper or twin textures) picks up the title's cast list via for_writer, gets registered in made, and has its barriers widened, or CreateReservedResource2 is tried with an incompatible list.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763370356 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4763370356). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:13:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3849 ~~~~diff @@ -3829,12 +3839,14 @@ unsafe extern "system" fn dev_create_committed_resource_layout_x( layout: u32, clear: usize, _protected: usize, - _castable: u32, - _formats: usize, + castable: u32, + formats: usize, riid: *const GUID, ppv: *mut *mut c_void, ) -> HRESULT { note_newer_device_method(127); + // (the title's cast list: a GPU-written texture on the title's pages is made with it) + let _casts = super::cast_list::title_list(castable, formats); ~~~~ --- Not certain about this one: the #127 cast list stays in a thread-local for the whole of `dev_create_committed_resource_layout_x`. Any GPU-owned texture XCL itself creates through `place_on_pages` on that thread during the call (display target path, helper or twin textures) picks up the title's cast list via `for_writer`, gets registered in `made`, and has its barriers widened, or CreateReservedResource2 is tried with an incompatible list.
KDenKC commented 2026-12-02 04:08:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T04:08:36Z.


@bmjask thanks for the review. The refreshed head is 4bb5c9a9, based on main 1c8b5514 and stacked on #3281.

  1. The description now matches this head: it creates the cast-compatible writer resource in the title allocation's initial layout and redirects matching views. It no longer claims COMMON creation or a page-settle path.
    2–3. The follow-up removes read-state widening and the per-list-type widening; the title's legacy state words are preserved. This addresses both the GENERIC_READ-style expansion and the DIRECT/COMPUTE before-state mismatch.
    4–5. Agreed, the reader's barriers have to reach the writer for the redirect to be correct. That routing (barriers on the reader handle applied to the writer it is redirected to) is a follow-up we have written and are testing; it is not a PR yet. Until it lands, the redirect stays behind XCL_CAST_LIST=1, off by default. Views created before the writer exists stay on the independent reader, as on main; the #3094 copy route is the natural fallback for those.
  2. MipLevels == 0 is normalized to the full chain for the texture dimension, covered by zero_mip_count_means_the_full_chain_for_the_texture_dimension.
  3. The #127 cast list is bound to the canonical address of the allocation being created and consumed only for that address, covered by title_cast_list_is_limited_to_its_bound_resource_address.

On the 3090 VM, debug, XCL_NETWORK=0, head 4bb5c9a9: cast_tests 2/2; cast_list 4/4; vram 81 passed, 0 failed, 1 ignored; list_x 114/114. The workspace suite reported 2,920 passed, 5 failed, 51 ignored, with no crash. The five failures match main 1c8b5514: placed_title_textures_share_vram_and_preserve_pixels, the three stream_recheck_* tests, and test_title_runs_and_game_folder_is_untouched. Twenty-eight capability-dependent tests were skipped. No smoke pair has run on this head; the rig is paused.

The cast route is off by default. A title run with XCL_CAST_LIST=1 and the debug layer on this head remains untested.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

<!-- greyfinch-sync:ivall/xcl:comment:7334601775 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7334601775). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-02T04:08:36Z. --- @bmjask thanks for the review. The refreshed head is `4bb5c9a9`, based on main `1c8b5514` and stacked on #3281. 1. The description now matches this head: it creates the cast-compatible writer resource in the title allocation's initial layout and redirects matching views. It no longer claims COMMON creation or a page-settle path. 2–3. The follow-up removes read-state widening and the per-list-type widening; the title's legacy state words are preserved. This addresses both the GENERIC_READ-style expansion and the DIRECT/COMPUTE before-state mismatch. 4–5. Agreed, the reader's barriers have to reach the writer for the redirect to be correct. That routing (barriers on the reader handle applied to the writer it is redirected to) is a follow-up we have written and are testing; it is not a PR yet. Until it lands, the redirect stays behind `XCL_CAST_LIST=1`, off by default. Views created before the writer exists stay on the independent reader, as on `main`; the #3094 copy route is the natural fallback for those. 6. `MipLevels == 0` is normalized to the full chain for the texture dimension, covered by `zero_mip_count_means_the_full_chain_for_the_texture_dimension`. 7. The #127 cast list is bound to the canonical address of the allocation being created and consumed only for that address, covered by `title_cast_list_is_limited_to_its_bound_resource_address`. On the 3090 VM, debug, `XCL_NETWORK=0`, head `4bb5c9a9`: `cast_tests` 2/2; `cast_list` 4/4; `vram` 81 passed, 0 failed, 1 ignored; `list_x` 114/114. The workspace suite reported 2,920 passed, 5 failed, 51 ignored, with no crash. The five failures match main `1c8b5514`: `placed_title_textures_share_vram_and_preserve_pixels`, the three `stream_recheck_*` tests, and `test_title_runs_and_game_folder_is_untouched`. Twenty-eight capability-dependent tests were skipped. No smoke pair has run on this head; the rig is paused. The cast route is off by default. A title run with `XCL_CAST_LIST=1` and the debug layer on this head remains untested. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
Foniass commented 2026-12-02 04:12:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T04:12:37Z.


Follow-up review (head 4bb5c9a9, since 8a2d7518, diff read, not a merge-check; checks red):

  • The head went back to the route the description says fails: partly fixed. The description now describes this route (made in the initial state's layout, legacy barriers) and the GPU test makes its texture in UNORDERED_ACCESS, but no title run with XCL_CAST_LIST=1 on this head shows the earlier debug-layer error and the 5090 hang are gone.
  • is_writer takes a global mutex on every transition barrier: fixed; the list_x.rs hook is gone and is_writer is test-only (cast_list.rs ~225).
  • The title's own cast list (#127) is a second, wider change: partly fixed. The list is tied to the #127 texture's address (title_address, real.rs ~2029; take_title_formats, cast_list.rs ~123) and the state widening is gone, but for_writer (~168-190) still gives every GPU-owned #127 texture in COMMON, RENDER_TARGET, UNORDERED_ACCESS or COPY_DEST its list and records it as a writer readers are redirected to.
  • The tests do not drive XCL's code: still open. cast_tests.rs still makes its own resource and moves the writer itself (~262, ~288, ~292), never calling for_writer, place_on_pages or view_on_writer, and never sends a barrier on a separate reader.
  • device_can does not check enhanced-barrier support: still open (~144-165).
  • Size and stack: partly fixed. pair_pages() reads the environment once (vram.rs ~2412). 42efa87b is #3281's first commit, but b383ccfb is an older copy of #3281's head b02b2c34 (without the own_tiles_of fallback and the capped publish_download), so a rebase onto #3281 is still needed.
  • #3094 / #3136 overlap: still open; #3136 now merges cleanly with this head.
  • Description and test results vs the code: partly fixed. The text and counts are for 4bb5c9a9, but Regression run has no xcl-smoke blocks (the reason PR description is red).

New:

  • The redirected view reads the writer in the state of the R32_UINT texture. With the barrier hook and the widening removed, a barrier the title sends on the R9G9B9E5 texture goes to the reader resource, which the redirected SRV (real.rs ~3277) no longer uses, so the writer stays in whatever state the title last gave the R32_UINT texture, e.g. UNORDERED_ACCESS after its compute writes; and a writer in NON_PIXEL_SHADER_RESOURCE is wrong for a pixel-shader read. With the switch on that is a debug-layer error and can read stale texels; the PR thread agrees the reader's barriers must reach the writer.
  • 4bb5c9a9 is a fixup of a07d7403. It deletes the list_x.rs hook and widen_state that a07d7403 adds, so a07d7403's message still describes the widening and its tests, and the made comment in cast_list.rs ~78 still says "their barriers are widened". It should be squashed with the message rewritten.
  • #3491 is stacked on the old commit. Its 010007f2 is a07d7403 without 4bb5c9a9, so it still has the widening and the per-barrier is_writer, and it conflicts with this head in cast_tests.rs, cast_list.rs and vram.rs.

Fine: with XCL_CAST_LIST unset every hook stops at a OnceLock or atomic check; the #127 list is taken only at its own canonical address and cleared by the guard; MipLevels == 0 is the full chain for the dimension, with a test; a refused CreateReservedResource2 falls back to the old create.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7334672436 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7334672436). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T04:12:37Z. --- Follow-up review (head 4bb5c9a9, since 8a2d7518, diff read, not a merge-check; checks red): - **The head went back to the route the description says fails:** partly fixed. The description now describes this route (made in the initial state's layout, legacy barriers) and the GPU test makes its texture in UNORDERED_ACCESS, but no title run with `XCL_CAST_LIST=1` on this head shows the earlier debug-layer error and the 5090 hang are gone. - **`is_writer` takes a global mutex on every transition barrier:** fixed; the `list_x.rs` hook is gone and `is_writer` is test-only (`cast_list.rs` ~225). - **The title's own cast list (#127) is a second, wider change:** partly fixed. The list is tied to the #127 texture's address (`title_address`, `real.rs` ~2029; `take_title_formats`, `cast_list.rs` ~123) and the state widening is gone, but `for_writer` (~168-190) still gives every GPU-owned #127 texture in COMMON, RENDER_TARGET, UNORDERED_ACCESS or COPY_DEST its list and records it as a writer readers are redirected to. - **The tests do not drive XCL's code:** still open. `cast_tests.rs` still makes its own resource and moves the writer itself (~262, ~288, ~292), never calling `for_writer`, `place_on_pages` or `view_on_writer`, and never sends a barrier on a separate reader. - **`device_can` does not check enhanced-barrier support:** still open (~144-165). - **Size and stack:** partly fixed. `pair_pages()` reads the environment once (`vram.rs` ~2412). `42efa87b` is #3281's first commit, but `b383ccfb` is an older copy of #3281's head `b02b2c34` (without the `own_tiles_of` fallback and the capped `publish_download`), so a rebase onto #3281 is still needed. - **#3094 / #3136 overlap:** still open; #3136 now merges cleanly with this head. - **Description and test results vs the code:** partly fixed. The text and counts are for `4bb5c9a9`, but **Regression run** has no `xcl-smoke` blocks (the reason `PR description` is red). New: - **The redirected view reads the writer in the state of the R32_UINT texture.** With the barrier hook and the widening removed, a barrier the title sends on the R9G9B9E5 texture goes to the reader resource, which the redirected SRV (`real.rs` ~3277) no longer uses, so the writer stays in whatever state the title last gave the R32_UINT texture, e.g. UNORDERED_ACCESS after its compute writes; and a writer in NON_PIXEL_SHADER_RESOURCE is wrong for a pixel-shader read. With the switch on that is a debug-layer error and can read stale texels; the PR thread agrees the reader's barriers must reach the writer. - **`4bb5c9a9` is a fixup of `a07d7403`.** It deletes the `list_x.rs` hook and `widen_state` that `a07d7403` adds, so `a07d7403`'s message still describes the widening and its tests, and the `made` comment in `cast_list.rs` ~78 still says "their barriers are widened". It should be squashed with the message rewritten. - **#3491 is stacked on the old commit.** Its `010007f2` is `a07d7403` without `4bb5c9a9`, so it still has the widening and the per-barrier `is_writer`, and it conflicts with this head in `cast_tests.rs`, `cast_list.rs` and `vram.rs`. Fine: with `XCL_CAST_LIST` unset every hook stops at a `OnceLock` or atomic check; the #127 list is taken only at its own canonical address and cleared by the guard; `MipLevels == 0` is the full chain for the dimension, with a test; a refused `CreateReservedResource2` falls back to the old create. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 04:19:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:46Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 231

@@ -0,0 +1,344 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The title's legacy resource states are preserved. The title's views on the written resource
+//! go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {
+        let extent = match d.Dimension {
+            D3D12_RESOURCE_DIMENSION_TEXTURE1D => d.Width,
+            D3D12_RESOURCE_DIMENSION_TEXTURE3D => d.Width.max(d.Height as u64).max(d.DepthOrArraySize as u64),
+            _ => d.Width.max(d.Height as u64),
+        };
+        let full_mips = (u64::BITS - extent.max(1).leading_zeros()) as u16;
+        Shape {
+            dimension: d.Dimension.0,
+            width: d.Width,
+            height: d.Height,
+            depth: d.DepthOrArraySize.max(1),
+            mips: if d.MipLevels == 0 { full_mips } else { d.MipLevels },
+        }
+    }
+}
+
+struct Writer {
+    res: usize,
+    shape: Shape,
+    format: i32,
+    casts: Vec<i32>,
+}
+
+#[derive(Default)]
+struct Table {
+    /// by (device, canonical address)
+    writers: HashMap<(usize, usize), Writer>,
+    /// the cast-made textures: their barriers are widened
+    made: HashSet<usize>,
+    /// the title's other textures, by resource: (device, canonical address, shape, format)
+    readers: HashMap<usize, (usize, usize, Shape, i32)>,
+}
+
+static TABLE: Mutex<Option<Table>> = Mutex::new(None);
+/// Cast-made textures alive: the gate of every hook.
+static MADE: AtomicUsize = AtomicUsize::new(0);
+static VIEWS: AtomicU64 = AtomicU64::new(0);
+
+thread_local! {
+    /// The cast list from #127, restricted to the resource at the title allocation's address.
+    static TITLE: RefCell<TitleCasts> = const { RefCell::new(TitleCasts { formats: Vec::new(), va: None }) };
+}
+
+struct TitleCasts { formats: Vec<i32>, va: Option<usize> }
+
+/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast
+/// list while the guard lives.
+pub(super) struct TitleList;
+
+impl Drop for TitleList {
+    fn drop(&mut self) {
+        TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: Vec::new(), va: None });
+    }
+}
+
+pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> {
+    if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) {
+        return None;
+    }
+    let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect();
+    TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: list, va: None });
+    Some(TitleList)
+}
+
+/// Bind #127's cast list to the allocation that its committed-resource hook is about to place.
+pub(super) fn title_address(va: usize) {
+    TITLE.with(|t| {
+        let mut t = t.borrow_mut();
+        if !t.formats.is_empty() && t.va.is_none() { t.va = Some(super::vram::canonical_va(va)); }
+    });
+}
+
+fn take_title_formats(va: usize) -> Vec<i32> {
+    TITLE.with(|t| {
+        let mut t = t.borrow_mut();
+        if t.va == Some(super::vram::canonical_va(va)) {
+            std::mem::take(&mut t.formats)
+        } else { Vec::new() }
+    })
+}
+
+/// The barrier layout a writer is made in for the initial state `state` (None: made without a cast list).
+fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> {
+    Some(match state {
+        0 => D3D12_BARRIER_LAYOUT_COMMON,
+        0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
+        0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
+        0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,
+        _ => return None,
+    })
+}
+
+/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device).
+unsafe fn device_can(dev: &ID3D12Device) -> bool {
+    static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None);
+    let key = dev.as_raw() as usize;
+    if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) {
+        return c;
+    }
+    let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default();
+    let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool();
+    let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() };
+    let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok()
+        && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0);
+    let device10 = dev.cast::<ID3D12Device10>().is_ok();
+    let can = relaxed && sample && device10;
+    crate::xlog_info!(
+        "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}",
+        if can { "on" } else { "off" },
+        if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" }
+    );
+    CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can);
+    can
+}
+
+/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made
+/// as before). The light pair's written texture, and the title's own list (#127).
+pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32, va: usize) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> {
+    if !on() || desc.SampleDesc.Count > 1 {
+        return None;
+    }
+    let mut casts = take_title_formats(va);
+    let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0;
+    if light {
+        casts.extend(LIGHT.iter().map(|f| f.0));
+    }
+    if casts.is_empty() {
+        return None;
+    }
+    let layout = layout_of(state)?;
+    if !device_can(dev) {
+        return None;
+    }
+    if !casts.contains(&desc.Format.0) {
+        casts.push(desc.Format.0);
+    }
+    casts.sort_unstable();
+    casts.dedup();
+    // (one format is no cast list: the texture is made as before)
+    (casts.len() >= 2).then_some((layout, casts))
+}
+
+/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`).
+pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) {
+    let mut g = TABLE.lock().unwrap();
+    let t = g.get_or_insert_with(Table::default);
+    if t.made.insert(res) {
+        MADE.fetch_add(1, Ordering::Relaxed);
+    }
+    t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts });
+}
+
+/// The title placed `res` (PC description `desc`) at `va` (`device_x::create_placed_resource_x`).
+pub(super) fn note_created(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) {
+    if on() {
+        keep_reader(dev, res, super::vram::canonical_va(va), desc);
+    }
+}
+
+/// `note_created` without the switch (`va` canonical). Kept before any writer is made: a view is
+/// put on its writer when it is made, in either order.
+fn keep_reader(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) {
+    if res == 0 || va == 0 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count > 1 {
+        return;
+    }
+    let mut g = TABLE.lock().unwrap();
+    let t = g.get_or_insert_with(Table::default);
+    if !t.made.contains(&res) {
+        t.readers.insert(res, (dev, va, Shape::of(desc), desc.Format.0));
+    }
+}
+
+/// Whether `res` was made with a cast list.
+#[cfg(test)]
+fn is_writer(res: usize) -> bool {
+    MADE.load(Ordering::Relaxed) != 0 && TABLE.lock().unwrap().as_ref().is_some_and(|t| t.made.contains(&res))
+}
+
+/// The written texture to make the title's view `view` of `res` on, and the view (None: `res`'s
+/// own): `res` is at a writer's address with its shape, in another format of its cast list.
+pub(super) fn view_on_writer(res: usize, view: Option<&D3D12_SHADER_RESOURCE_VIEW_DESC>) -> Option<(usize, D3D12_SHADER_RESOURCE_VIEW_DESC)> {

view_on_writer redirects to any live writer at (dev, va) of the same shape without checking that it's still current in placements. With XCL_CAST_LIST=1 and XCL_PAIR_PAGES unset, the 1280x720 R9G9B9E5 reader (0x3c0000, 60 pages) is placed over the R32_UINT writer (0x384000, 57 pages). The overlap is Around, so the writer is superseded and its tiles go to late_release::hold_unmap, yet the reader's SRV is still made on the writer and samples tiles being unmapped (zeros). The same stale redirect happens when the title has reused that memory for another texture while holding the old writer.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764688580 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4764688580). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:19:46Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 231 ~~~~diff @@ -0,0 +1,344 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The title's legacy resource states are preserved. The title's views on the written resource +//! go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { + let extent = match d.Dimension { + D3D12_RESOURCE_DIMENSION_TEXTURE1D => d.Width, + D3D12_RESOURCE_DIMENSION_TEXTURE3D => d.Width.max(d.Height as u64).max(d.DepthOrArraySize as u64), + _ => d.Width.max(d.Height as u64), + }; + let full_mips = (u64::BITS - extent.max(1).leading_zeros()) as u16; + Shape { + dimension: d.Dimension.0, + width: d.Width, + height: d.Height, + depth: d.DepthOrArraySize.max(1), + mips: if d.MipLevels == 0 { full_mips } else { d.MipLevels }, + } + } +} + +struct Writer { + res: usize, + shape: Shape, + format: i32, + casts: Vec<i32>, +} + +#[derive(Default)] +struct Table { + /// by (device, canonical address) + writers: HashMap<(usize, usize), Writer>, + /// the cast-made textures: their barriers are widened + made: HashSet<usize>, + /// the title's other textures, by resource: (device, canonical address, shape, format) + readers: HashMap<usize, (usize, usize, Shape, i32)>, +} + +static TABLE: Mutex<Option<Table>> = Mutex::new(None); +/// Cast-made textures alive: the gate of every hook. +static MADE: AtomicUsize = AtomicUsize::new(0); +static VIEWS: AtomicU64 = AtomicU64::new(0); + +thread_local! { + /// The cast list from #127, restricted to the resource at the title allocation's address. + static TITLE: RefCell<TitleCasts> = const { RefCell::new(TitleCasts { formats: Vec::new(), va: None }) }; +} + +struct TitleCasts { formats: Vec<i32>, va: Option<usize> } + +/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast +/// list while the guard lives. +pub(super) struct TitleList; + +impl Drop for TitleList { + fn drop(&mut self) { + TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: Vec::new(), va: None }); + } +} + +pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> { + if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) { + return None; + } + let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect(); + TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: list, va: None }); + Some(TitleList) +} + +/// Bind #127's cast list to the allocation that its committed-resource hook is about to place. +pub(super) fn title_address(va: usize) { + TITLE.with(|t| { + let mut t = t.borrow_mut(); + if !t.formats.is_empty() && t.va.is_none() { t.va = Some(super::vram::canonical_va(va)); } + }); +} + +fn take_title_formats(va: usize) -> Vec<i32> { + TITLE.with(|t| { + let mut t = t.borrow_mut(); + if t.va == Some(super::vram::canonical_va(va)) { + std::mem::take(&mut t.formats) + } else { Vec::new() } + }) +} + +/// The barrier layout a writer is made in for the initial state `state` (None: made without a cast list). +fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> { + Some(match state { + 0 => D3D12_BARRIER_LAYOUT_COMMON, + 0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET, + 0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS, + 0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST, + _ => return None, + }) +} + +/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device). +unsafe fn device_can(dev: &ID3D12Device) -> bool { + static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None); + let key = dev.as_raw() as usize; + if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) { + return c; + } + let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default(); + let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool(); + let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() }; + let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok() + && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0); + let device10 = dev.cast::<ID3D12Device10>().is_ok(); + let can = relaxed && sample && device10; + crate::xlog_info!( + "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}", + if can { "on" } else { "off" }, + if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" } + ); + CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can); + can +} + +/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made +/// as before). The light pair's written texture, and the title's own list (#127). +pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32, va: usize) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> { + if !on() || desc.SampleDesc.Count > 1 { + return None; + } + let mut casts = take_title_formats(va); + let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0; + if light { + casts.extend(LIGHT.iter().map(|f| f.0)); + } + if casts.is_empty() { + return None; + } + let layout = layout_of(state)?; + if !device_can(dev) { + return None; + } + if !casts.contains(&desc.Format.0) { + casts.push(desc.Format.0); + } + casts.sort_unstable(); + casts.dedup(); + // (one format is no cast list: the texture is made as before) + (casts.len() >= 2).then_some((layout, casts)) +} + +/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`). +pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) { + let mut g = TABLE.lock().unwrap(); + let t = g.get_or_insert_with(Table::default); + if t.made.insert(res) { + MADE.fetch_add(1, Ordering::Relaxed); + } + t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts }); +} + +/// The title placed `res` (PC description `desc`) at `va` (`device_x::create_placed_resource_x`). +pub(super) fn note_created(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) { + if on() { + keep_reader(dev, res, super::vram::canonical_va(va), desc); + } +} + +/// `note_created` without the switch (`va` canonical). Kept before any writer is made: a view is +/// put on its writer when it is made, in either order. +fn keep_reader(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC) { + if res == 0 || va == 0 || desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.SampleDesc.Count > 1 { + return; + } + let mut g = TABLE.lock().unwrap(); + let t = g.get_or_insert_with(Table::default); + if !t.made.contains(&res) { + t.readers.insert(res, (dev, va, Shape::of(desc), desc.Format.0)); + } +} + +/// Whether `res` was made with a cast list. +#[cfg(test)] +fn is_writer(res: usize) -> bool { + MADE.load(Ordering::Relaxed) != 0 && TABLE.lock().unwrap().as_ref().is_some_and(|t| t.made.contains(&res)) +} + +/// The written texture to make the title's view `view` of `res` on, and the view (None: `res`'s +/// own): `res` is at a writer's address with its shape, in another format of its cast list. +pub(super) fn view_on_writer(res: usize, view: Option<&D3D12_SHADER_RESOURCE_VIEW_DESC>) -> Option<(usize, D3D12_SHADER_RESOURCE_VIEW_DESC)> { ~~~~ --- `view_on_writer` redirects to any live writer at (dev, va) of the same shape without checking that it's still current in placements. With XCL_CAST_LIST=1 and XCL_PAIR_PAGES unset, the 1280x720 R9G9B9E5 reader (0x3c0000, 60 pages) is placed over the R32_UINT writer (0x384000, 57 pages). The overlap is `Around`, so the writer is superseded and its tiles go to `late_release::hold_unmap`, yet the reader's SRV is still made on the writer and samples tiles being unmapped (zeros). The same stale redirect happens when the title has reused that memory for another texture while holding the old writer.
bmjask commented 2026-12-02 04:19:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:46Z.

Code review location: crates/xcl/src/hle/d3d12x/cast_list.rs; line 200

@@ -0,0 +1,344 @@
+//! One memory, two formats, by relaxed format casting.
+//!
+//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot
+//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same
+//! address. On the console the two are one memory; here they are two PC textures,
+//! and what is read through the sampled one is not what the GPU wrote.
+//!
+//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written
+//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a
+//! texture the title gives a cast list of its own, console device #127, with that list too).
+//! A view the title makes of a sampled texture at the same address, of the same shape, in a
+//! format of that list, is made on the written texture: one PC texture under both descriptions.
+//!
+//! The title's legacy resource states are preserved. The title's views on the written resource
+//! go with it (`console_heap::resource_gone`).
+//!
+//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops
+//! at one atomic load or a `OnceLock` read.
+
+use std::cell::RefCell;
+use std::collections::{HashMap, HashSet};
+use std::ffi::c_void;
+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
+use std::sync::{Mutex, OnceLock};
+
+use windows::core::Interface;
+use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::Common::*;
+
+/// The pair the title packs light in: written as the first, read as the second.
+const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP];
+
+/// `XCL_CAST_LIST=1` (read once).
+pub(super) fn on() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1"))
+}
+
+/// What a writer's views and barriers need.
+#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
+struct Shape {
+    dimension: i32,
+    width: u64,
+    height: u32,
+    depth: u16,
+    mips: u16,
+}
+
+impl Shape {
+    fn of(d: &D3D12_RESOURCE_DESC) -> Self {
+        let extent = match d.Dimension {
+            D3D12_RESOURCE_DIMENSION_TEXTURE1D => d.Width,
+            D3D12_RESOURCE_DIMENSION_TEXTURE3D => d.Width.max(d.Height as u64).max(d.DepthOrArraySize as u64),
+            _ => d.Width.max(d.Height as u64),
+        };
+        let full_mips = (u64::BITS - extent.max(1).leading_zeros()) as u16;
+        Shape {
+            dimension: d.Dimension.0,
+            width: d.Width,
+            height: d.Height,
+            depth: d.DepthOrArraySize.max(1),
+            mips: if d.MipLevels == 0 { full_mips } else { d.MipLevels },
+        }
+    }
+}
+
+struct Writer {
+    res: usize,
+    shape: Shape,
+    format: i32,
+    casts: Vec<i32>,
+}
+
+#[derive(Default)]
+struct Table {
+    /// by (device, canonical address)
+    writers: HashMap<(usize, usize), Writer>,
+    /// the cast-made textures: their barriers are widened
+    made: HashSet<usize>,
+    /// the title's other textures, by resource: (device, canonical address, shape, format)
+    readers: HashMap<usize, (usize, usize, Shape, i32)>,
+}
+
+static TABLE: Mutex<Option<Table>> = Mutex::new(None);
+/// Cast-made textures alive: the gate of every hook.
+static MADE: AtomicUsize = AtomicUsize::new(0);
+static VIEWS: AtomicU64 = AtomicU64::new(0);
+
+thread_local! {
+    /// The cast list from #127, restricted to the resource at the title allocation's address.
+    static TITLE: RefCell<TitleCasts> = const { RefCell::new(TitleCasts { formats: Vec::new(), va: None }) };
+}
+
+struct TitleCasts { formats: Vec<i32>, va: Option<usize> }
+
+/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast
+/// list while the guard lives.
+pub(super) struct TitleList;
+
+impl Drop for TitleList {
+    fn drop(&mut self) {
+        TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: Vec::new(), va: None });
+    }
+}
+
+pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> {
+    if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) {
+        return None;
+    }
+    let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect();
+    TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: list, va: None });
+    Some(TitleList)
+}
+
+/// Bind #127's cast list to the allocation that its committed-resource hook is about to place.
+pub(super) fn title_address(va: usize) {
+    TITLE.with(|t| {
+        let mut t = t.borrow_mut();
+        if !t.formats.is_empty() && t.va.is_none() { t.va = Some(super::vram::canonical_va(va)); }
+    });
+}
+
+fn take_title_formats(va: usize) -> Vec<i32> {
+    TITLE.with(|t| {
+        let mut t = t.borrow_mut();
+        if t.va == Some(super::vram::canonical_va(va)) {
+            std::mem::take(&mut t.formats)
+        } else { Vec::new() }
+    })
+}
+
+/// The barrier layout a writer is made in for the initial state `state` (None: made without a cast list).
+fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> {
+    Some(match state {
+        0 => D3D12_BARRIER_LAYOUT_COMMON,
+        0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
+        0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
+        0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,
+        _ => return None,
+    })
+}
+
+/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device).
+unsafe fn device_can(dev: &ID3D12Device) -> bool {
+    static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None);
+    let key = dev.as_raw() as usize;
+    if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) {
+        return c;
+    }
+    let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default();
+    let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool();
+    let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() };
+    let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok()
+        && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0);
+    let device10 = dev.cast::<ID3D12Device10>().is_ok();
+    let can = relaxed && sample && device10;
+    crate::xlog_info!(
+        "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}",
+        if can { "on" } else { "off" },
+        if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" }
+    );
+    CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can);
+    can
+}
+
+/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made
+/// as before). The light pair's written texture, and the title's own list (#127).
+pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32, va: usize) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> {
+    if !on() || desc.SampleDesc.Count > 1 {
+        return None;
+    }
+    let mut casts = take_title_formats(va);
+    let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0;
+    if light {
+        casts.extend(LIGHT.iter().map(|f| f.0));
+    }
+    if casts.is_empty() {
+        return None;
+    }
+    let layout = layout_of(state)?;
+    if !device_can(dev) {
+        return None;
+    }
+    if !casts.contains(&desc.Format.0) {
+        casts.push(desc.Format.0);
+    }
+    casts.sort_unstable();
+    casts.dedup();
+    // (one format is no cast list: the texture is made as before)
+    (casts.len() >= 2).then_some((layout, casts))
+}
+
+/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`).
+pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) {
+    let mut g = TABLE.lock().unwrap();
+    let t = g.get_or_insert_with(Table::default);
+    if t.made.insert(res) {
+        MADE.fetch_add(1, Ordering::Relaxed);
+    }
+    t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts });

made() overwrites writers[(dev, va)] when a newer cast writer is placed at the same address, and drop_res of the newer one removes the only (dev, va) entry while the older writer is still in made. With writer A at va, writer B placed at the same va, and then B released while A is kept, later R9G9B9E5 readers at va are no longer redirected to A. They fall back to the independent texture, which reads the wrong data.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764688584 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4764688584). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:19:46Z. **Code review location:** `crates/xcl/src/hle/d3d12x/cast_list.rs`; line 200 ~~~~diff @@ -0,0 +1,344 @@ +//! One memory, two formats, by relaxed format casting. +//! +//! A retail title packs light as R9G9B9E5 into R32_UINT textures (its compute programs cannot +//! store R9G9B9E5) and samples the same memory through an R9G9B9E5 texture it places at the same +//! address. On the console the two are one memory; here they are two PC textures, +//! and what is read through the sampled one is not what the GPU wrote. +//! +//! Where the device has relaxed format casting (OPTIONS12) and ID3D12Device10, a GPU-written +//! R32_UINT 2D texture is made with [R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (and a +//! texture the title gives a cast list of its own, console device #127, with that list too). +//! A view the title makes of a sampled texture at the same address, of the same shape, in a +//! format of that list, is made on the written texture: one PC texture under both descriptions. +//! +//! The title's legacy resource states are preserved. The title's views on the written resource +//! go with it (`console_heap::resource_gone`). +//! +//! Behind `XCL_CAST_LIST=1` (off by default); with it off nothing is kept and every hook stops +//! at one atomic load or a `OnceLock` read. + +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::ffi::c_void; +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::{Mutex, OnceLock}; + +use windows::core::Interface; +use windows::Win32::Graphics::Direct3D12::*; +use windows::Win32::Graphics::Dxgi::Common::*; + +/// The pair the title packs light in: written as the first, read as the second. +const LIGHT: [DXGI_FORMAT; 2] = [DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R9G9B9E5_SHAREDEXP]; + +/// `XCL_CAST_LIST=1` (read once). +pub(super) fn on() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| std::env::var("XCL_CAST_LIST").is_ok_and(|v| v.trim() == "1")) +} + +/// What a writer's views and barriers need. +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] +struct Shape { + dimension: i32, + width: u64, + height: u32, + depth: u16, + mips: u16, +} + +impl Shape { + fn of(d: &D3D12_RESOURCE_DESC) -> Self { + let extent = match d.Dimension { + D3D12_RESOURCE_DIMENSION_TEXTURE1D => d.Width, + D3D12_RESOURCE_DIMENSION_TEXTURE3D => d.Width.max(d.Height as u64).max(d.DepthOrArraySize as u64), + _ => d.Width.max(d.Height as u64), + }; + let full_mips = (u64::BITS - extent.max(1).leading_zeros()) as u16; + Shape { + dimension: d.Dimension.0, + width: d.Width, + height: d.Height, + depth: d.DepthOrArraySize.max(1), + mips: if d.MipLevels == 0 { full_mips } else { d.MipLevels }, + } + } +} + +struct Writer { + res: usize, + shape: Shape, + format: i32, + casts: Vec<i32>, +} + +#[derive(Default)] +struct Table { + /// by (device, canonical address) + writers: HashMap<(usize, usize), Writer>, + /// the cast-made textures: their barriers are widened + made: HashSet<usize>, + /// the title's other textures, by resource: (device, canonical address, shape, format) + readers: HashMap<usize, (usize, usize, Shape, i32)>, +} + +static TABLE: Mutex<Option<Table>> = Mutex::new(None); +/// Cast-made textures alive: the gate of every hook. +static MADE: AtomicUsize = AtomicUsize::new(0); +static VIEWS: AtomicU64 = AtomicU64::new(0); + +thread_local! { + /// The cast list from #127, restricted to the resource at the title allocation's address. + static TITLE: RefCell<TitleCasts> = const { RefCell::new(TitleCasts { formats: Vec::new(), va: None }) }; +} + +struct TitleCasts { formats: Vec<i32>, va: Option<usize> } + +/// The title's create (#127) with `n` castable formats at `formats`: they are its texture's cast +/// list while the guard lives. +pub(super) struct TitleList; + +impl Drop for TitleList { + fn drop(&mut self) { + TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: Vec::new(), va: None }); + } +} + +pub(super) unsafe fn title_list(n: u32, formats: usize) -> Option<TitleList> { + if !on() || n == 0 || n > 16 || formats == 0 || !crate::gpu::shader::readable(formats, n as usize * 4) { + return None; + } + let list: Vec<i32> = (0..n as usize).map(|k| super::device_x::pc_view_format(((formats + 4 * k) as *const u32).read_unaligned()) as i32).filter(|&f| f != 0).collect(); + TITLE.with(|t| *t.borrow_mut() = TitleCasts { formats: list, va: None }); + Some(TitleList) +} + +/// Bind #127's cast list to the allocation that its committed-resource hook is about to place. +pub(super) fn title_address(va: usize) { + TITLE.with(|t| { + let mut t = t.borrow_mut(); + if !t.formats.is_empty() && t.va.is_none() { t.va = Some(super::vram::canonical_va(va)); } + }); +} + +fn take_title_formats(va: usize) -> Vec<i32> { + TITLE.with(|t| { + let mut t = t.borrow_mut(); + if t.va == Some(super::vram::canonical_va(va)) { + std::mem::take(&mut t.formats) + } else { Vec::new() } + }) +} + +/// The barrier layout a writer is made in for the initial state `state` (None: made without a cast list). +fn layout_of(state: u32) -> Option<D3D12_BARRIER_LAYOUT> { + Some(match state { + 0 => D3D12_BARRIER_LAYOUT_COMMON, + 0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET, + 0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS, + 0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST, + _ => return None, + }) +} + +/// Whether `dev` casts a texture's formats and samples R9G9B9E5 (asked once per device). +unsafe fn device_can(dev: &ID3D12Device) -> bool { + static CAN: Mutex<Option<HashMap<usize, bool>>> = Mutex::new(None); + let key = dev.as_raw() as usize; + if let Some(&c) = CAN.lock().unwrap().as_ref().and_then(|m| m.get(&key)) { + return c; + } + let mut o12 = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default(); + let relaxed = dev.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &mut o12 as *mut _ as *mut c_void, std::mem::size_of_val(&o12) as u32).is_ok() && o12.RelaxedFormatCastingSupported.as_bool(); + let mut fs = D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: DXGI_FORMAT_R9G9B9E5_SHAREDEXP, ..Default::default() }; + let sample = dev.CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &mut fs as *mut _ as *mut c_void, std::mem::size_of_val(&fs) as u32).is_ok() + && (fs.Support1.0 & (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0)) == (D3D12_FORMAT_SUPPORT1_TEXTURE2D.0 | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE.0); + let device10 = dev.cast::<ID3D12Device10>().is_ok(); + let can = relaxed && sample && device10; + crate::xlog_info!( + "D3D12.X: cast lists {}: relaxed format casting {relaxed}, R9G9B9E5 sampled {sample}, ID3D12Device10 {device10}{}", + if can { "on" } else { "off" }, + if can { " (XCL_CAST_LIST=1: a GPU-written R32_UINT texture is made with R9G9B9E5 in its cast list)" } else { "" } + ); + CAN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, can); + can +} + +/// The layout and cast list to make the GPU-owned texture `desc` with, in `state` (None: made +/// as before). The light pair's written texture, and the title's own list (#127). +pub(super) unsafe fn for_writer(dev: &ID3D12Device, desc: &D3D12_RESOURCE_DESC, state: u32, va: usize) -> Option<(D3D12_BARRIER_LAYOUT, Vec<i32>)> { + if !on() || desc.SampleDesc.Count > 1 { + return None; + } + let mut casts = take_title_formats(va); + let light = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.Format == LIGHT[0] && desc.Flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 != 0; + if light { + casts.extend(LIGHT.iter().map(|f| f.0)); + } + if casts.is_empty() { + return None; + } + let layout = layout_of(state)?; + if !device_can(dev) { + return None; + } + if !casts.contains(&desc.Format.0) { + casts.push(desc.Format.0); + } + casts.sort_unstable(); + casts.dedup(); + // (one format is no cast list: the texture is made as before) + (casts.len() >= 2).then_some((layout, casts)) +} + +/// `res` was made at the canonical address `va` with the cast list `casts` (`vram`). +pub(super) fn made(dev: usize, res: usize, va: usize, desc: &D3D12_RESOURCE_DESC, casts: Vec<i32>) { + let mut g = TABLE.lock().unwrap(); + let t = g.get_or_insert_with(Table::default); + if t.made.insert(res) { + MADE.fetch_add(1, Ordering::Relaxed); + } + t.writers.insert((dev, va), Writer { res, shape: Shape::of(desc), format: desc.Format.0, casts }); ~~~~ --- `made()` overwrites `writers[(dev, va)]` when a newer cast writer is placed at the same address, and `drop_res` of the newer one removes the only (dev, va) entry while the older writer is still in `made`. With writer A at va, writer B placed at the same va, and then B released while A is kept, later R9G9B9E5 readers at va are no longer redirected to A. They fall back to the independent texture, which reads the wrong data.
bmjask commented 2026-12-02 04:19:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:46Z.

Code review location: crates/xcl/src/hle/d3d12x/vram.rs; line 2588

@@ -2471,6 +2574,31 @@ unsafe fn place_on_pages(
         dev.GetResourceTiling(res, Some(&mut total), None, None, None, 0, std::ptr::null_mut());
         None
     };
+    // (the size kept in the `Target` is the capped one: lazy levels, `unmap_levels` and the
+    // range handed to `placements` go by the same pages as `bind`)
+    let writer = gpu_owned(desc.Flags.0 as u32);
+    let given_bytes = console_bytes;
+    let console_bytes = if pair {
+        let partners = match PAGES.lock().unwrap().get(&dev_key) {
+            Some(Some(pages)) => pair_partners(&pages.targets, va, total, writer),
+            _ => Vec::new(),
+        };
+        // (asked with `PAGES` released: the registry's lock is the outer one of the two,
+        // `placements::unmap_if_superseded`)
+        let capped = pair_bytes(&partners, |res| super::placements::current_view(res, desc), console_bytes);

The XCL_PAIR_PAGES cap is decided once at placement (Target.capped, Entry.cap) and never lifted when the partner writer is released or superseded. If a view capped to 57 of 60 tiles keeps being CPU-filled after the title releases the writer, written_in/dirty_on still ignore pages past the cap and own_tiles_of still stops every upload at tile 57. The view's last 3 tiles keep whatever the shared extra pages hold for the rest of its life.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764688592 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#discussion_r4764688592). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:19:46Z. **Code review location:** `crates/xcl/src/hle/d3d12x/vram.rs`; line 2588 ~~~~diff @@ -2471,6 +2574,31 @@ unsafe fn place_on_pages( dev.GetResourceTiling(res, Some(&mut total), None, None, None, 0, std::ptr::null_mut()); None }; + // (the size kept in the `Target` is the capped one: lazy levels, `unmap_levels` and the + // range handed to `placements` go by the same pages as `bind`) + let writer = gpu_owned(desc.Flags.0 as u32); + let given_bytes = console_bytes; + let console_bytes = if pair { + let partners = match PAGES.lock().unwrap().get(&dev_key) { + Some(Some(pages)) => pair_partners(&pages.targets, va, total, writer), + _ => Vec::new(), + }; + // (asked with `PAGES` released: the registry's lock is the outer one of the two, + // `placements::unmap_if_superseded`) + let capped = pair_bytes(&partners, |res| super::placements::current_view(res, desc), console_bytes); ~~~~ --- The XCL_PAIR_PAGES cap is decided once at placement (Target.capped, Entry.cap) and never lifted when the partner writer is released or superseded. If a view capped to 57 of 60 tiles keeps being CPU-filled after the title releases the writer, `written_in`/`dirty_on` still ignore pages past the cap and `own_tiles_of` still stops every upload at tile 57. The view's last 3 tiles keep whatever the shared extra pages hold for the rest of its life.
bmjask commented 2026-12-02 04:19:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:46Z.

Review: COMMENTED


Review of 4bb5c9a9: 3 finding(s).

Re-review at 4bb5c9a9. The state widening is gone, which resolves my earlier points about widened read states and states that differ by list type. Still open from my earlier review: the title's barriers on the reader still don't reach the writer its SRVs now sample (real.rs ~3277). With the widening removed there's now no UAV->SRV transition at all, so the redirected SRV reads the writer in UNORDERED_ACCESS/COPY_SOURCE. Also still open: releasing the writer nulls views of a reader the title still holds (cast_list.rs ~277, via console_heap::resource_gone(writer)). New findings: 3 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6144702255 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#pullrequestreview-6144702255). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:19:46Z. **Review:** COMMENTED --- Review of `4bb5c9a9`: 3 finding(s). Re-review at `4bb5c9a9`. The state widening is gone, which resolves my earlier points about widened read states and states that differ by list type. Still open from my earlier review: the title's barriers on the reader still don't reach the writer its SRVs now sample (`real.rs` ~3277). With the widening removed there's now no UAV->SRV transition at all, so the redirected SRV reads the writer in UNORDERED_ACCESS/COPY_SOURCE. Also still open: releasing the writer nulls views of a reader the title still holds (`cast_list.rs` ~277, via `console_heap::resource_gone(writer)`). New findings: 3 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
KDenKC commented 2026-12-02 05:57:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T05:57:52Z.


@bmjask @Foniass thanks for the follow-ups; this covers both reviews. This revision is rebased on #3281's current head b02b2c34 and main 1c8b5514.

The registry now selects the newest live compatible writer only while it is still current in placements, and retains older live writers so releasing a newer one falls back correctly. It narrows cast-list use to the title's bound #127 address and compatible resource, and checks enhanced-barrier support alongside relaxed casting, sampled-format support, and Device10. Pair-page caps expand when their partner is released or superseded, but only if the tail is free.

The barrier-routing commit is included in e435d2d8: barriers on a reader whose view resolves to a writer route through that writer with per-subresource state tracking; a released writer stops receiving the reader's barriers until a new view resolves again. The tests cover that path through the fake resource_barrier_x harness and ensure a released writer's reader stays independent.

Regression coverage includes casting_requires_enhanced_barriers_relaxed_casting_sampling_and_device10, title_cast_list_is_limited_to_its_bound_resource_address, view_uses_a_current_writer_and_falls_back_to_an_older_live_one, a_released_pair_cap_expands_only_when_its_tail_is_free, gpu_register_takes_the_cap_from_the_pair, a_readers_read_moves_are_its_owners, a_readers_owner_follows_release_and_a_new_view, a_barrier_on_a_cast_list_reader_moves_its_writer, and a_barrier_on_a_reader_of_a_released_writer_stays_on_the_reader.

On the RTX 3090 VM, focused results were cast_list 9/0, list_x 116/0, vram 79/0/1 ignored, and d3d12x 1,229 passed / 4 failed / 3 ignored. The workspace suite was 2,920 passed / 5 failed / 51 ignored, with the same five failures as main 1c8b5514 and no crash. The rig smoke pair for this head is queued; no retail-title result is claimed yet.

The independent-resource path remains available when the cast list is unsupported. Related: #3094 #3136 #3282; the copy path in #3094 remains a natural fallback if both land.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

<!-- greyfinch-sync:ivall/xcl:comment:7336479371 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7336479371). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-02T05:57:52Z. --- @bmjask @Foniass thanks for the follow-ups; this covers both reviews. This revision is rebased on #3281's current head `b02b2c34` and main `1c8b5514`. The registry now selects the newest live compatible writer only while it is still current in placements, and retains older live writers so releasing a newer one falls back correctly. It narrows cast-list use to the title's bound #127 address and compatible resource, and checks enhanced-barrier support alongside relaxed casting, sampled-format support, and Device10. Pair-page caps expand when their partner is released or superseded, but only if the tail is free. The barrier-routing commit is included in `e435d2d8`: barriers on a reader whose view resolves to a writer route through that writer with per-subresource state tracking; a released writer stops receiving the reader's barriers until a new view resolves again. The tests cover that path through the fake `resource_barrier_x` harness and ensure a released writer's reader stays independent. Regression coverage includes `casting_requires_enhanced_barriers_relaxed_casting_sampling_and_device10`, `title_cast_list_is_limited_to_its_bound_resource_address`, `view_uses_a_current_writer_and_falls_back_to_an_older_live_one`, `a_released_pair_cap_expands_only_when_its_tail_is_free`, `gpu_register_takes_the_cap_from_the_pair`, `a_readers_read_moves_are_its_owners`, `a_readers_owner_follows_release_and_a_new_view`, `a_barrier_on_a_cast_list_reader_moves_its_writer`, and `a_barrier_on_a_reader_of_a_released_writer_stays_on_the_reader`. On the RTX 3090 VM, focused results were `cast_list` 9/0, `list_x` 116/0, `vram` 79/0/1 ignored, and `d3d12x` 1,229 passed / 4 failed / 3 ignored. The workspace suite was 2,920 passed / 5 failed / 51 ignored, with the same five failures as main `1c8b5514` and no crash. The rig smoke pair for this head is queued; no retail-title result is claimed yet. The independent-resource path remains available when the cast list is unsupported. Related: #3094 #3136 #3282; the copy path in #3094 remains a natural fallback if both land. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
Foniass commented 2026-12-02 06:00:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T06:00:44Z.


Follow-up review (head e435d2d8, since 4bb5c9a9, diff read, not a merge-check; checks red):

  • The redirected view reads the writer in the R32_UINT texture's state: partly fixed. A reader's read-only move now reaches the writer, but only when the title moved that writer in this recording or an earlier closed one: the creation state is never recorded (made, cast_list.rs ~263), so a writer made in UNORDERED_ACCESS that the title never moves has no known state, every reader barrier on it is dropped (~402), and it is still sampled in UNORDERED_ACCESS.
  • Stack: fixed; the branch is on #3281's current 1a38d2c6 / b02b2c34.
  • device_can does not check enhanced-barrier support: fixed (~219, ~235, with a test).
  • is_writer takes a global mutex on every transition barrier: open again. Once a cast-made texture exists, route_transition (~360, from list_x.rs ~6445) locks TABLE in owner_of (~94) and again in is_writer (~296) on every transition.
  • The tests do not drive XCL's code: partly fixed. a_barrier_on_a_cast_list_reader_moves_its_writer goes through resource_barrier_x and view_uses_a_current_writer_and_falls_back_to_an_older_live_one through view_on_writer, but cast_tests.rs still never calls for_writer, place_on_pages or the SRV redirect.
  • Fixup commits; size; title run; #3094 / #3136; #3491: still open. 20d1d945 is still separate, and 73f24089's message and the cast_list.rs ~80 comment still describe the widening; this PR's own commits are 1,277 lines with no reason given; Not tested still lists a title run with XCL_CAST_LIST=1; the smoke blocks are missing (the reason PR description is red); #3491 still sits on the old commits.

New:

  • A routed move is never undone, so the writer's own barriers go out with a stale before state. route_with moves the writer into the reader's read state and records it (~394-398), but the writer's own transitions are sent unchanged (~379 keeps b[5]). If the title moved the writer to UNORDERED_ACCESS once, writes it by compute every frame and moves only the R9G9B9E5 texture to PIXEL_SHADER_RESOURCE, the next compute pass writes the writer through a UAV while it is in PIXEL_SHADER_RESOURCE, and its next transition names UNORDERED_ACCESS as the before state: debug-layer errors and missing synchronisation.
  • The R32_UINT/R9G9B9E5 pair is no longer made. 1f6c4de0 drops the LIGHT list from for_writer (~245; LIGHT is now #[cfg(test)]), so a texture gets a cast list only when the title passes one through #127. The PR title, description and the device_can log line (~229) still say a written R32_UINT texture is made with R9G9B9E5, and nothing shows the title passes R9G9B9E5 through #127 for that texture.
  • One state map for all queues, in close order. CLOSED_STATES (~149) is merged in the order lists close (real.rs ~4148), not the order they run, and for every queue at once, so to = s | b[6] (~396) can carry PIXEL_SHADER_RESOURCE from a direct list into a move on a COMPUTE list, or shader-resource states onto a COPY list, where they are invalid.
  • A reader's move into or out of a write state stays on the reader (~382), so after a routed read move the reader's own PC texture is in a state the next kept move does not expect.
  • 1f6c4de0 also changes #3281's cap. vram::pair_cap (~723) recomputes the cap from current partners and refresh_pair_caps (title_textures.rs ~778) is called from placements.rs ~520 / ~535 / ~612, which changes behaviour with XCL_PAIR_PAGES=1 alone; that belongs in #3281.

Fine: with XCL_CAST_LIST unset, route_transition, closed and reset stop at the MADE atomic; writers are kept per address, newest current first with fallback to an older live one, with a test; per-subresource tracking and a reader split's first half are handled and tested; drop_res clears the writer from the reader map and both state maps.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7336535138 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3340#issuecomment-7336535138). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T06:00:44Z. --- Follow-up review (head e435d2d8, since 4bb5c9a9, diff read, not a merge-check; checks red): - **The redirected view reads the writer in the R32_UINT texture's state:** partly fixed. A reader's read-only move now reaches the writer, but only when the title moved that writer in this recording or an earlier closed one: the creation state is never recorded (`made`, `cast_list.rs` ~263), so a writer made in UNORDERED_ACCESS that the title never moves has no known state, every reader barrier on it is dropped (~402), and it is still sampled in UNORDERED_ACCESS. - **Stack:** fixed; the branch is on #3281's current `1a38d2c6` / `b02b2c34`. - **`device_can` does not check enhanced-barrier support:** fixed (~219, ~235, with a test). - **`is_writer` takes a global mutex on every transition barrier:** open again. Once a cast-made texture exists, `route_transition` (~360, from `list_x.rs` ~6445) locks `TABLE` in `owner_of` (~94) and again in `is_writer` (~296) on every transition. - **The tests do not drive XCL's code:** partly fixed. `a_barrier_on_a_cast_list_reader_moves_its_writer` goes through `resource_barrier_x` and `view_uses_a_current_writer_and_falls_back_to_an_older_live_one` through `view_on_writer`, but `cast_tests.rs` still never calls `for_writer`, `place_on_pages` or the SRV redirect. - **Fixup commits; size; title run; #3094 / #3136; #3491:** still open. `20d1d945` is still separate, and `73f24089`'s message and the `cast_list.rs` ~80 comment still describe the widening; this PR's own commits are 1,277 lines with no reason given; **Not tested** still lists a title run with `XCL_CAST_LIST=1`; the smoke blocks are missing (the reason `PR description` is red); #3491 still sits on the old commits. New: - **A routed move is never undone, so the writer's own barriers go out with a stale before state.** `route_with` moves the writer into the reader's read state and records it (~394-398), but the writer's own transitions are sent unchanged (~379 keeps `b[5]`). If the title moved the writer to UNORDERED_ACCESS once, writes it by compute every frame and moves only the R9G9B9E5 texture to PIXEL_SHADER_RESOURCE, the next compute pass writes the writer through a UAV while it is in PIXEL_SHADER_RESOURCE, and its next transition names UNORDERED_ACCESS as the before state: debug-layer errors and missing synchronisation. - **The R32_UINT/R9G9B9E5 pair is no longer made.** `1f6c4de0` drops the `LIGHT` list from `for_writer` (~245; `LIGHT` is now `#[cfg(test)]`), so a texture gets a cast list only when the title passes one through #127. The PR title, description and the `device_can` log line (~229) still say a written R32_UINT texture is made with R9G9B9E5, and nothing shows the title passes R9G9B9E5 through #127 for that texture. - **One state map for all queues, in close order.** `CLOSED_STATES` (~149) is merged in the order lists close (`real.rs` ~4148), not the order they run, and for every queue at once, so `to = s | b[6]` (~396) can carry PIXEL_SHADER_RESOURCE from a direct list into a move on a COMPUTE list, or shader-resource states onto a COPY list, where they are invalid. - **A reader's move into or out of a write state stays on the reader** (~382), so after a routed read move the reader's own PC texture is in a state the next kept move does not expect. - **`1f6c4de0` also changes #3281's cap.** `vram::pair_cap` (~723) recomputes the cap from current partners and `refresh_pair_caps` (`title_textures.rs` ~778) is called from `placements.rs` ~520 / ~535 / ~612, which changes behaviour with `XCL_PAIR_PAGES=1` alone; that belongs in #3281. Fine: with `XCL_CAST_LIST` unset, `route_transition`, `closed` and `reset` stop at the `MADE` atomic; writers are kept per address, newest current first with fallback to an older live one, with a test; per-subresource tracking and a reader split's first half are handled and tested; `drop_res` clears the writer from the reader map and both state maps. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3340:upstream-pr/3340'
git switch 'upstream-pr/3340'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3340'
git switch 'upstream-pr/3340'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3340'
git switch 'upstream-pr/3340'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3340'
git switch 'main'
git merge --squash 'upstream-pr/3340'
git switch 'main'
git merge --ff-only 'upstream-pr/3340'
git switch 'main'
git merge 'upstream-pr/3340'
git push origin 'main'
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
xcl-dev/xcl!3340
No description provided.