Skip to content

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

Draft
KDenKC wants to merge 6 commits into
xcl-dev:mainfrom
KDenKC:pr/cast-list
Draft

KDenKC wants to merge 6 commits into
xcl-dev:mainfrom
KDenKC:pr/cast-list

Conversation

@KDenKC

@KDenKC KDenKC commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@KDenKC
KDenKC marked this pull request as ready for review November 29, 2026 13:20
@claudetools-gh

Copy link
Copy Markdown

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:

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

KDenKC commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@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

KDenKC commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

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): #505 (comment). 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.

@github-actions github-actions Bot added gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) and removed gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-rebase Has merge conflicts with its base branch labels Nov 30, 2026
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 7d86c5d
head: b25dbd8
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 (d427662 / 7233f96 vs 3f252d4 / b0192a8), 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 7d86c5d 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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

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.

…s pages

A title can place two descriptions at one address: a 1280x720 R32_UINT
UAV and a 1280x720 R9G9B9E5 SRV. XG sizes them 0x384000 (57 pages) and
0x3c0000 (60 pages), so the one placed second owns 3 pages more than the
first, and those are the shared pages of the texture the title put
0x390000 after them. The sampled alias then reads that neighbour's memory
(a step in the captured frame), and placements sees it Around the target
and supersedes it.

With XCL_PAIR_PAGES=1 (off by default) place_on_pages caps a sampled
texture placed at the address and tile count of a live mapped texture
the GPU writes, and that it is a view of, to the smaller of the two
(pair_bytes) and keeps the
capped size in its Target, so the later texture shares exactly the
written partner's pages and its other tiles are private (va, i) tiles.
Placed first, the larger texture is not changed (its tiles are bound
already). The cap is made before the range is handed to placements, so a
capped pair is Same, not Around. The log line is printed for the first
two and powers of two.

Only a written texture is a partner (pair_partners), and only while it
is the current placement: mapped, held by the title and not superseded
in placements (placements::current_view; a superseded target stays
mapped in vram until its deferred unmap, late_release::hold_unmap), to a
sampled texture with the same size and levels and a texel of the same
size (Desc::same_texels, the rule placements keeps the two on one memory
by; a texture of another shape with as many tiles is something else the
title put in that memory, and keeps its size), with the size
CreatePlacedResourceX passes (console_bytes: XG's, or for a 3-D texture XG
cannot lay out the bytes of its texels; not the least_texture_bytes lower
bound). A sampled texture caps
nothing, capped or not. A texture the GPU writes is never capped: on the
console it has all of its own size, and its readback into the title's
memory (title_textures::publish_download) goes by its whole layout. The
registry is asked with PAGES released: its lock is the outer one of the
two (placements::unmap_if_superseded).

The cap is not the byte layout of the console. Measured with the GDK's
XG library: the two layouts (0x102 and 2) put texel (x, y) at different
offsets (first difference at (8,0); 920896 of 921600 texels differ), and
the SRV's 3-page overrun is real on the console (36864 texels past the
UAV's end). The cap is what the PC alias shows.

Tests: pair_bytes on targets (a written partner; a sampled one or one of
unknown size caps nothing and a written texture is not capped; a
superseded partner before and after its unmap), placements::current and
current_view on a registry (another shape, other levels and another
texel size are not a view), a placements test that the capped pair is
Same, and GPU tests
with the real descriptions: a neighbour at +0x390000 (80 of 128
neighbour rows are overwritten without the cap, with pair_bytes
returning its own size), and a written texture made after a smaller
sampled one and then superseded (with every mapped texture a partner it
is capped to 0x384000; with the registry not asked, the sampled texture
made after it is capped to the superseded one; a sampled 720x1280
texture at the address of a written 1280x720 one has as many tiles and
keeps its size).

Assisted-by: Claude Code (Claude Sonnet 5.5)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 2, 2026
Cache positive and negative R9G9B9E5 volume support queries per device, and only ask for that support after the format/UAV eligibility checks. Add focused tests for cache behavior and query gating.

Checked: xcl-dev#3491, xcl-dev#3340.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

0 => D3D12_BARRIER_LAYOUT_COMMON,
0x4 => D3D12_BARRIER_LAYOUT_RENDER_TARGET,
0x8 => D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS,
0x400 => D3D12_BARRIER_LAYOUT_COPY_DEST,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pushed head doesn't match the description. The body describes a later head (b25dbd8) 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.

Comment thread crates/xcl/src/hle/d3d12x/cast_list.rs Outdated
D3D12_COMMAND_LIST_TYPE_DIRECT => NPS | PS,
D3D12_COMMAND_LIST_TYPE_COMPUTE => NPS,
_ => 0,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/xcl/src/hle/d3d12x/list_x.rs Outdated
}
// (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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}
// 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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/xcl/src/hle/d3d12x/cast_list.rs Outdated
if MADE.load(Ordering::Relaxed) == 0 || res == 0 {
return None;
}
let (writer, v) = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}

impl Shape {
fn of(d: &D3D12_RESOURCE_DESC) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

) -> 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

The title places an R9G9B9E5 view by address over a live R32_UINT
texture (1280x720, 0x384000 bytes). XG sizes the view 0x3c0000 and the
title's next resource starts at the view's address + 0x384000.
Table::insert saw that resource inside the view's range, called the view
superseded by a different range, and vram::unmap_superseded mapped all
60 of its tiles to NULL: the compute pass that read the view got zeros
and wrote zeros over the R32_UINT. XCL_PAIR_PAGES=1 capped only the
vram extent (pair_bytes), not the table's.

The entry of a sampled texture now keeps the capped extent
(vram::pair_capped_bytes reads it from the placed Target, so pair_bytes
stays the one place that computes it) and insert, retire_range, remove,
the source links and the hot range use it. So do the test for written
pages (Entry::written_in), the pages a partial upload compares
(dirty_on) and the fingerprint of a view whose memory is not watched: a
write to the neighbour's first bytes is in a 1 MiB source piece of the
view, and with the view's whole size it sent the view up again.

Every upload of a capped view, its first whole one too, now stops at
its cap (texture_upload::Item::own_tiles from vram::pair_capped_tiles,
the tiles owned_pages gives it; texture_upload::owned_parts clips each
piece to them). The view's tiles past the cap are the extra pages keyed
(va, 57..59) it shares with the R32_UINT, whose last texels they hold:
a whole upload of the view wrote the neighbour's bytes over them, and
the view's first upload after register is always a whole one
(pending; gpu_written is only set on the writer's entry). A level in
the packed mips or a 3D level goes up whole when the view owns all of
its tiles, else not at all. Each array slice has its own packed mips,
D3D12_PACKED_MIP_INFO's start (slice 0's) plus the slice times the
tiles of a slice, and a level from NumStandardMips on is packed: WARP
gives the packed subresources of slice 1 slice 0's start and no tiles,
not D3D12_PACKED_TILE (256x256, 2 slices, 9 mips: start 5, 0x0). A
capped view whose tiles vram does not give owns none: nothing of it
goes up rather than all of it. The hashes of its pages are still those
of the whole layout.

A capped view a list writes (gpu_written, as a copy destination) is
read back into the title's memory up to its cap only
(publish_download): past it is the next texture's memory, and its
tiles there are the pages it shares with the written texture. The entry of
a texture the GPU writes (register_gpu_owned) has no cap: vram never
caps one, and publish_download writes its whole layout back into the
title's memory, so its range in the table is its whole size. Only under
XCL_PAIR_PAGES=1.

Tests: gpu_register_takes_the_cap_from_the_pair (register's range stops
at the capped extent, the written texture keeps its own size; skip_test
without reserved textures); capped_placed_view_is_not_superseded_by_its_neighbour
fails with the cap ignored (the insert at address + 0x384000 returns the
view to unmap), and with the whole size in written_in (a written page at
address + 0x384000 selects the view); a_capped_views_fingerprint_ends_at_its_cap
fails with the whole size fingerprinted, in the baseline
(seed_stream_recheck) or in the recheck (a write past the cap, in the
end slice of a whole-size fingerprint, queues the view);
gpu_a_capped_views_first_upload_leaves_the_tiles_past_its_cap places the
pair on pages, registers the view, sends its first upload through
upload_all and fails with the clip off or with no own_tiles from
upload_all (the view writes 30720 texels of tiles 57..59 of the
R32_UINT); gpu_a_capped_arrays_first_upload_stops_at_its_cap_in_a_later_slice
caps a 2-slice array with packed mips one tile into slice 1 and fails
with slice 0's packed start for every slice, with the packed levels
taken from D3D12_PACKED_TILE alone, or with no own_tiles from
upload_all (slice 1's packed mips get the view's bytes), and skips on
an adapter that makes no reserved array with packed mips (GitHub's
runner: E_INVALIDARG); a_capped_view_without_its_tiles_owns_none fails
with a capped view without a Target uploaded whole;
gpu_a_capped_views_download_ends_at_its_cap fails with the whole layout
written back (the bytes past the cap get the GPU's).

The GPU tests read a texture back through the one that wrote it, after an
aliasing barrier; the 1280x720 one also reads the view's own tiles through
the R32_UINT (both 32 bpp, standard tiles: the title's case). Packed mips
of two descriptions are not compared: on PC their layout on the same
tiles (64KB_UNDEFINED_SWIZZLE) is not guaranteed alike, and reading the
view's packed mips through the R32_UINT failed about 2 runs in 30.

Assisted-by: Claude Code (Claude Sonnet 5.5)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 2, 2026
Preserve the title's resource states, honor zero-mip full-chain views, and bind its cast list to the allocation being created. Exercise repeated reads and writes in the 2D route test.

Checked: xcl-dev#3340 review 6143106973; xcl-dev#3491 follow-up 7331505470.
@github-actions github-actions Bot added gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) and removed gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Dec 2, 2026
@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@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 D3D12.X: a sampled texture in the memory of a written one of another format is copied from it (XCL_ALIAS_COPY=1) #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 Runtime: CPU check at start, bounded reads in the exception logger, t… #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

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 4bb5c9a, since 8a2d751, diff read, not a merge-check; checks 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.
  • D3D12.X: XCL_CAST_LIST=1 gives R32_UINT volumes the cast list too #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.

KDenKC and others added 2 commits December 1, 2026 21:15
…9B9E5 one texture

The retail title packs light as R9G9B9E5 into R32_UINT textures its compute
programs write, and samples the same memory through an R9G9B9E5 texture it
places at the same address. On the console that is one memory; here the
sampled texture is a PC texture of its own that nothing writes.

With XCL_CAST_LIST=1, where the device has relaxed format casting
(OPTIONS12), ID3D12Device10 and samples R9G9B9E5, a GPU-written R32_UINT 2D
texture on the title's pages is made with CreateReservedResource2 and
[R32_UINT, R9G9B9E5_SHAREDEXP] as its cast list (a texture the title gives a
cast list of its own, device xcl-dev#127, with that list). A view the title makes
of a texture at the same address, of the same shape, in another format of
the list, is made on the written texture. Its read-only legacy states (not
COMMON) also take the shader-resource states the list type has (DIRECT
both, COMPUTE the non-pixel one, COPY none), on both sides of every
transition. The views go with the written texture
(console_heap::resource_gone); a recycled sampled texture is forgotten
before it is parked. It is made only in the initial states whose layout is
the same state (COMMON, RENDER_TARGET, UNORDERED_ACCESS, COPY_DEST); a
refused create is made as before. Off by default.

Tests: the matching and the state widening (cast_list), and a GPU test of
the route itself in a child process with the debug layer on: one texture
written as R32_UINT through a UAV and read through an R9G9B9E5 SRV,
committed and reserved (tiles mapped on a second queue), every texel
compared with a CPU decode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preserve the title's resource states, honor zero-mip full-chain views, and bind its cast list to the allocation being created. Exercise repeated reads and writes in the 2D route test.

Checked: xcl-dev#3340 review 6143106973; xcl-dev#3491 follow-up 7331505470.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


/// 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)> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/xcl/src/hle/d3d12x/cast_list.rs Outdated
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 });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

};
// (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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

KDenKC and others added 2 commits December 1, 2026 22:35
Limit cast-list writer selection to the currently placed compatible resource, retain live writers by address, and refresh pair-page upload caps as placements change.
With XCL_CAST_LIST=1 a sampled texture at a written texture's address has
its views made on the current live writer there (view_on_writer), so it
is read through that writer: on the console a barrier on the reader is
one on that memory. Its transitions went to its own PC texture, so a
writer the title left in a write state was sampled in it when the title
moved only the reader.

A reader is noted with the writer its views were last made on; when that
writer is released the reader's barriers are its own again until its
views are made on another live writer. Per recording the state each
writer was left in is kept per subresource, in the title's states, from
the writer's own transitions; a recording that has not moved a writer
finds it where the recordings closed before it left it (in the order
they were closed). A reader's read-only transition becomes the writer's
move of the same subresource(s): from a write state to the read state
the reader asks for, from a read state lacking it to both; a writer
already in it needs nothing. Not known (never moved, a split's first
half, all of it asked for while its subresources differ): nothing is
added. Each case is counted in a log line. A reader's move into or out
of a write state stays on the reader. A split's first half carries the
whole move.

Tests: a_barrier_on_a_cast_list_reader_moves_its_writer and
a_barrier_on_a_reader_of_a_released_writer_stays_on_the_reader (the
title's barrier on the reader through resource_barrier_x),
a_readers_read_moves_are_its_owners (per subresource, a split, a
recording that finds an earlier one's state),
a_readers_owner_follows_release_and_a_new_view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@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

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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

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 Runtime: CPU check at start, bounded reads in the exception logger, t… #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 Runtime: CPU check at start, bounded reads in the exception logger, t… #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 D3D12.X: XCL_PAIR_PAGES=1 caps a texture in a live one's memory to its pages #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 D3D12.X: XCL_PAIR_PAGES=1 caps a texture in a live one's memory to its pages #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.

@KDenKC
KDenKC marked this pull request as draft December 2, 2026 06:03
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants