Skip to content

D3D12.X: XCL_PAIR_PAGES=1 caps a texture in a live one's memory to its pages - #3281

Open
Pipodi wants to merge 2 commits into
xcl-dev:mainfrom
Pipodi:pair-pages-cap
Open

Pipodi wants to merge 2 commits into
xcl-dev:mainfrom
Pipodi:pair-pages-cap

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

A compute pass of a retail title reads R9G9B9E5 views placed at the same address as R32_UINT 1280x720 textures. XG (xg_xs.dll of GDK 261000, measured) sizes the view at 0x3c0000 (layout 2) or 0x398000 (layout 0), against the texture's 0x384000. The title places its next texture at +0x384000, which supersedes the view and unmaps its tiles, so the view reads zero.

With XCL_PAIR_PAGES=1, a sampled texture placed in the memory of a texture the GPU writes is capped to the writer's pages, and title_textures keeps the capped extent, so the neighbour no longer supersedes the view. Only a partner that is current (mapped, held by the title, not superseded in the placement registry), that the GPU writes and whose console size is known caps (the size CreatePlacedResourceX passes: XG's, or for a 3-D texture XG cannot lay out the bytes of its texels, from #2753's console_bytes); only sampled textures are capped, never a texture the GPU writes. The switch is off by default, and with it off the code paths are the same as on main.

Related: #3094 (XCL_ALIAS_COPY) fixes the same defect by copying. The two are alternatives: with both on, the copy is redundant.

What is in it

  • 69b8c95c D3D12.X: XCL_PAIR_PAGES=1 caps a texture in a live one's memory to its pages: Target::pair, pair_partners, pair_bytes and the cap in place_on_pages (crates/xcl/src/hle/d3d12x/vram.rs); placements::current (placements.rs), asked after the PAGES lock is dropped, so the Registry-then-PAGES lock order holds; tests for a writer made second, sampled after sampled, a writer of unknown size, a superseded writer before and after the deferred unmap, and a GPU test through place_on_pages.
  • 223b5658 D3D12.X: XCL_PAIR_PAGES=1 caps the title_textures range of a capped view: the entry of a capped sampled texture keeps the capped extent (title_textures.rs, vram::pair_capped_bytes), and the written-page test, the pages a partial upload compares and the fingerprint use it; every upload of a capped view, its first whole one too, stops at its cap (vram::pair_capped_tiles, texture_upload::Item::own_tiles, owned_parts in texture_upload.rs), with each array slice's own packed mips; register_gpu_owned keeps no cap; a GPU-written capped view is read back only up to its cap (publish_download), and a capped view whose tiles vram cannot give uploads nothing.
  • Review fixes, squashed into the two commits: pair_pages() reads the environment once (OnceLock); a test-only override with a drop guard turns the switch on; pair_capped_bytes returns a size only for a texture a pair actually capped (Target::capped); only a view of the current writer's texels pairs with it (placements::current_view); the upload clip above (review finding 1).

Size: +1058 −44 against main, of which about 260 lines are runtime code and the rest GPU and unit tests. The upload clip and the per-slice packed mips are the fix for review finding 1 (the capped view was still watched and uploaded at its full size, which wrote over the writer's texels), so they stay in this PR: without them its pairing overwrites the writer's tiles.

This revision: rebased onto main 5eaadb54; the place_on_pages calls #3553 added in tests now pass pair: false (in the first commit).

Tested

  • NVIDIA GeForce RTX 4090, driver 621.40, i9-13900K, Windows 11 Pro 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09), debug build for the suite, release builds for the smoke runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on this head 223b5658 (main 5eaadb54): 2990 passed, 0 failed, 52 ignored, 25 SKIPPED.
  • SKIPPED (25): no wave64 (22), no heap windows (2), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Developer Mode is required) (1).
  • Tests that fail without the fix, on earlier heads of this PR (32f43dbf, b0192a85, c9d3abea): with the old partner rule put back, gpu_a_written_texture_made_second_is_not_capped fails; with the registry not asked, a_superseded_written_texture_is_not_a_partner fails; with the writer exclusion removed, a_sampled_texture_caps_nothing_and_a_written_one_is_not_capped fails; with the capped filter taken out of pair_capped_bytes, its assert for the written texture fails. On f32c1894: with own_tiles_of disabled in upload_all, gpu_a_capped_views_first_upload_leaves_the_tiles_past_its_cap fails (30720 texels past the cap overwritten); with slice 0's packed-mip start used for every slice, or the packed-level check left out, gpu_a_capped_arrays_first_upload_stops_at_its_cap_in_a_later_slice fails. GPU tests checked on WARP.
  • On 223b5658: with the read-back not stopped at the cap, gpu_a_capped_views_download_ends_at_its_cap fails; with a capped entry without tiles uploading whole, a_capped_view_without_its_tiles_owns_none fails. The GPU tests read each texture back through the one that wrote it, after an aliasing barrier, and the 1280x720 test also reads the view's tiles through the R32_UINT texture. Packed mips of two descriptions are not compared: their layouts are not guaranteed to match on PC, and an earlier version of the array test that did so failed intermittently. On GitHub's no-GPU runner the array test skips (CreateReservedResource refuses the 2-slice 9-mip reserved array).
  • Stress: 22 of 24 runs of the whole lib suite (--test-threads=4 --nocapture) passed; 2 runs aborted the test binary outside these tests (one in the early gpu::dxil tests), not checked on main.
  • A retail title with XCL_PAIR_PAGES=1, not repeated on this head (see Not tested):
    • On an older local tree with the same mechanism: all 14 dispatches of the compute program read non-zero data on both views, against 0 before.
    • On an earlier head plus PR 2 (stacked on this one) and local press diagnostics: both views are capped, 0 of 2 are superseded, against 2 of 2 with the switch off.

Regression run

The same retail title for 60 s on both sides, scripts/smoke.ps1 on clean trees, release builds, XCL_PREPARE=0 and XCL_PRESS_AT=15.00:A,32.80:A,33.90:A,34.80:RIGHT,35.67:A,37.00:A,38.27:A,39.50:DOWN,45.01:DOWN,45.40:A,47.14:A,47.54:DOWN,48.08:A,48.74:DOWN,49.14:A on both sides, RTX 4090 (driver 621.40).

main (5eaadb54):

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1609 (PresentX 1609)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 18303 MB

This PR's head (223b5658):

xcl-smoke v1
commit: 223b5658593a98f57113e356c2d4b3750533f5b8
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1605 (PresentX 1605)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19701 MB

The PR's run got 99.8 % of main's frames and 107.6 % of its peak commit.

Not tested

  • A title run with XCL_PAIR_PAGES=1 on this head; the title numbers above are from earlier heads.
  • The per-slice packed-mip start was checked on WARP, not on NVIDIA or AMD hardware tiling.
  • The per-dispatch result on a main-based tree: the full cinematic did not finish there (the title's frame loop stopped during start-up in most runs, with the switch on, off, and on plain main).
  • XCL_PAIR_PAGES=1 in the 60 s smoke run.
  • AMD, Intel and other GPUs, and other titles.
  • A 3-D texture as a partner: since D3D12.X: a 3-D texture XG cannot size is taken at its texels' bytes #2753, a GPU-written 3-D texture that XG cannot lay out has its texels' bytes as its size and can be paired; no such pairing was seen in the title or tested.
  • A capped sampled texture that the title also writes on the GPU with a copy is still read back by its whole layout (publish_download); not seen in the title.

AI use

  • Claude Code: Claude Opus 5.5 (main session) diagnosed the defect, analysed the review, checked it against the GDK and wrote this description; Claude Fable 5.2 wrote the fix and its tests; Claude Sonnet 5.5 subagents ran the builds, the tests and the title runs. For the rebase onto main 493dbd3d, Claude Sonnet 5.5 agents rebased the commits, fixed the comment and ran the suite, the mutation checks and the smoke runs; a Claude Opus 5.5 reviewer checked the result.
  • The review fixes on 223b5658 (the upload clip, the read-back cap, the CI skip and the test reads): Claude Code, Claude Opus 5.5 (main session) orchestrated them and updated this description; Claude Opus 5.5 subagents made the fixes and the tests, diagnosed an intermittent test failure and reviewed the result; Claude Sonnet 5.5 subagents ran the suite and the smoke pair.

@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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@CharlyRien

Copy link
Copy Markdown
Contributor

Test report for #3281 (XCL_PAIR_PAGES=1) on the retail title: it fixes a half-black window we could not explain otherwise.

Stack. main 0fe06eb + 41 commits of ours (BM2T, 04f2744a), which include:

On top of that: #3281 cherry-picked (1917a18, dc899d5; one conflict in vram.rs against our own place_pages early returns, resolved by keeping them and passing pair_pages() to place_on_pages), plus a one-line fix of a test Entry initializer that lacked the new cap field.

RTX 3090, Windows 11, XCL_PREPARE=0 with a warm translated cache.

Env: XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_ALIAS_COPY=1 XCL_PLACE_RETIRE=0 XCL_DEPTH_UAV_TWIN=1 XCL_TWO_PASS_MB=2048 XCL_VIEW_REACH_MB=36 XCL_OUTSIDE_VIEW_USE=1 XCL_DRED=1, plus XCL_PAIR_PAGES=1 for the runs with it.

The defect. At an early pose (a character in front of a window), one diagonal half of the window turns black or dark red a few seconds after the pose is reached, and stays that way. The diagonal runs corner to corner of the glass.

What draws it (pixel history at one texel of the dark half, two frames; a local tool, XCL_PIXEL_HISTORY / XCL_SKIP_PS, that I will open as a PR). The texel is lit up to the depth of field. Then the DoF composite, an indirect draw (VS_TileGridDefaultPass / PS_CompositeIndirectDrawBlend, blend SRC_ALPHA / INV_SRC_ALPHA), sets it to exactly RGB 0.

A/B. Share of dark texels (summed RGB < 90) in the window's dark half, head-centred pose, world + ~100..200 s:

run XCL_PAIR_PAGES XCL_ALIAS_COPY dark half
4 runs without #3281 – 1 57–83 % (stays dark to the end)
with #3281, run 1 1 1 0 % (w+105..150)
with #3281, run 2 1 1 0–2 % (w+72..199)
with #3281, run 3 1 0 0 % to w+148; 10–19 % after, from a closer framing (the character fills more of the box), window clear by eye

By eye, in all three runs the outside is visible through the whole window, with the DoF composite active.

Caveat: 2 of 7 runs without the fix were clean for a while (from about w+135), so the window is not dark in every run without #3281. With it, it was clean in 3 of 3 runs. The third run shows that the alias copy is not needed for this window.

Side effect, not checked. The cap is not limited to the 1280×720 pairs. With XCL_PLACE_RETIRE=0 (old targets stay mapped), "pair pages:" reached "256 so far" by world + 30 s, so between 256 and 511 textures were capped. The log prints counts 1, 2 and powers of two only. The logged ones include:

  • 1-tile textures (0x10000 → 0x3c00, 0xf00, 0x3000);
  • a 240-tile texture (0xf00000 → 0xe10000);
  • 22-tile and 2-tile textures.

We did not check what those textures show past their cap (private tiles instead of the shared pages), nor how it behaves with XCL_PLACE_RETIRE at its default.

Not covered: other GPUs; a faint line of bright specks still follows the same diagonal in some frames; other scenes.

AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

@Elytes

Elytes commented Nov 30, 2026

Copy link
Copy Markdown

merge-check
base: d52ff48
head: dc899d5
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> lib 2739 passed, 1 failed, 31 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, also failing on the base alone (base lib 2733 passed / 1 failed; the +6 are this PR's tests, all passing). 2 of 8 merge lib runs were cut short by a pre-existing race in the uma_driver tests (they re-reserve their window without a lock; exit 0x7C10003); 5 alternating base/merge runs were all clean, so it is not tied to this PR.
review: no blocking finding after reading the whole diff and the comments. With the switch off the paths are main's (no cap, owned_extent = the given size). For CharlyRien's side-effect question: with XCL_PAIR_PAGES=1 and XCL_PLACE_RETIRE at its default, this title's first 60 s already capped 16-31 textures, not only the 1280x720 pairs (logged: 60 tiles 0x3c0000 -> 0x384000, 15 tiles 0xf0000 -> 0xe1000, 1 tile 0x10000 -> 0x1000); I did not check what those show.
performance: retail title, 60 s, XCL_PREPARE=0, same scripted A press (XCL_PRESS_A_AT=22), base and merge alternated twice: frames 1335 / 1301 vs 1298 / 1313 (99.0 %), peak commit 26662 / 27858 vs 27404 / 28307 MB (102.2 %), 0 device removals, 0 crashes. With XCL_PAIR_PAGES=1: 1265 frames, 27550 MB, 0 device removals, 0 crashes.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1 / Claude Code (Claude Opus 5.5) ran the merge, build, suite, smoke runs and log comparison, and reviewed the diff and comments.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: dc899d5
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2891 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The 6 new tests passed, the two GPU ones ran on this card. With the cap in place_on_pages turned off (if false && pair) in the merged tree, cargo test -p xcl --lib hle::d3d12x::vram::tests::gpu_ -- --test-threads=1 fails gpu_a_sampled_pairs_last_tiles_are_not_the_next_textures and gpu_register_takes_the_cap_from_the_pair, so both test the change.
review: whole diff read (+357/-17, vram.rs, title_textures.rs, device_x.rs, placements.rs). "Caps" means: with XCL_PAIR_PAGES=1, a texture placed at the address of a mapped texture with the same tile count gets pages only for the smallest console size among them (pair_bytes), and title_textures keeps that smaller extent (Entry::extent), so the next texture the title places after it does not supersede and unmap it. With the switch unset (the default) place_on_pages gets pair = false, pair_capped_bytes returns None, every extent() is tex.size() and owned_extent returns the given bytes, so the paths are the same as on main. When the live partner is freed first, the capped one keeps its capped size, and a later texture at that address is capped to it too (forgetting_the_first_texture_keeps_the_seconds_tail_tiles); an unmapped (superseded) one is not taken as a partner. The two layouts do not put a texel at the same offset; the PR says so and does not try to. Three notes, none a blocker. (1) The cap is not limited to the 1280x720 pair: in our world run below it capped at least 256 textures by 136 s, among them 15-tile (0xf0000 -> 0xe1000), 22-tile and 1-tile (0x10000 -> 0x1000, 0xb000 -> 0x3000) ones; I did not check what those show past the cap. (2) gpu_register_takes_the_cap_from_the_pair sets XCL_PAIR_PAGES for the whole process while it runs; it holds the vram and title_textures test locks, but another test that places a texture without those locks would see the switch on. (3) pair_pages() reads the environment at every placement and registration. #3282 is stacked on this PR (it contains the same pair_bytes/owned_extent code), and #3094 (XCL_ALIAS_COPY) is an alternative fix for the same view.
performance: scripts/smoke.ps1, 60 s of a retail title, release, switch off, after one warm-up run of the base: 1662 frames and 18117 MB peak commit against 1649 frames and 17417 MB on the base (warm-up: 1609, 17266 MB). No device removal, no crash. World runs, one each, so an indication only: the same 330 s plan with scripted presses, 16 UMA windows and the RAM guard, warm cache, base as it is and the merge with XCL_PAIR_PAGES=1. Base: world from about 90 s, the guard ended it at about 150 s (free RAM under 1 GB), no device removal; its only world frame saved (frame 1640, 98 s) is black (0 % lit). Merge: world from about 104 s, ran the full 330 s without the guard (min free RAM 2.67 GB, peak commit 41.1 GB against 39.3 GB), no device removal. Runs on this PC sit close to the guard limit and base runs today have passed it by chance, so I would not read a memory gain into that. Frames 1640 (172 s, 89 % lit) and 1700 (274 s, 52 % lit) show the lit interior. The frames come from different moments, so they cannot show whether the half-black window is gone: in frame 1700 a large part of the window is still dark, and I cannot tell from one frame whether that is the defect or the scene.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests, smoke and world runs, reviewed the diff against the merged source and wrote this)

  • Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Source-level correctness concern on head dc899d5f. pair_bytes chooses the smallest size among any mapped texture at the same address with the same tile count. It does not check whether the partner is a GPU writer or still the current logical placement. A GPU-owned target placed after a smaller sampled texture can therefore inherit that smaller cap; register_gpu_owned stores it, while publish_download still processes the full texture layout. Separately, the placement registry can mark a target superseded before deferred unmapping changes the page table’s mapped flag, so a later sampled texture may select a stale partner during that interval.

Please derive the cap only from a compatible, current GPU-writable partner with an exact known console size; do not apply an inherited cap to GPU-write targets or treat an estimated lower-bound size as exact. Add deterministic coverage for writer-created-second and for a superseded target before/after deferred unmap, while retaining the existing writer-first case. The two lifecycle paths use a Registry-then-PAGES lock order, which pairing must preserve.

This is a source trace; I did not reproduce it on a GPU or title. The exact reverse-order readback and stale-target schedules remain untested. AI use: OpenAI Codex (GPT-6.2 Sol) traced the source; GPT-6.2 Astra checked the deferred-unmap and lock-order path.

@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed ready-to-merge Has 2 independent safe merge-checks on current head (#3041) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: b0192a8

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head b0192a8

Base of a stack: #3282 is stacked on it, and #3340 and #3491 carry its two commits (rebased) underneath their own, so the shared lines are the stack, not duplicates. #3094 (XCL_ALIAS_COPY) is an alternative fix for the same R32_UINT/R9G9B9E5 pair (by copying), as the description says.
No problems found in the diff. The pair cap only applies to sampled textures over a current, GPU-written partner of known size. placements::current is asked after PAGES is released, which keeps the lock order. With the switch off, nothing changes.
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

merge-check
base: 493dbd3
head: b0192a8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 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 (+516/-18). With XCL_PAIR_PAGES unset nothing changes in behaviour: a few fields, one gpu_owned() call per placement, and one environment read per placement and per register. The run below has a second smoke with XCL_PAIR_PAGES=1 on this head, which no earlier check had. Findings, switch on only: (1) The pairing rule is a guess. Any sampled texture at the same address and with the same PC tile count as a live GPU-written texture of known size gets capped (vram.rs ~2300). Most textures under 64 KiB are one tile, so small ones can pair by chance. Nobody has counted caps on this head; the 256+ reported earlier were under the older rule. With XCL_PLACE_RETIRE=0 old writers stay current and keep capping. (2) A capped texture's tail is no longer watched for title writes (title_textures.rs ~587, touched_by ~248). src_pieces cover only the capped range, so a CPU write only in [cap, size) triggers no re-upload, although an upload still reads the whole size (~2150, ~2166). (3) pair_pages() (~2290) reads the environment on every call, where the module's other switches use a OnceLock. It's per call so the test can toggle it. (4) The test sets the variable for the whole test process (~5016-5021), so parallel tests that place or register textures see it, and a failing assert at ~5017 leaves it on. #3282 tests the same rule through place_with(.., pair=true) instead. Fine: only sampled textures are capped, only against a GPU-written partner of known size, and register_gpu_owned keeps no cap. The registry is asked whether the partner is still current after PAGES is released, so the lock order holds. The capped texture shares the writer's pages and tail tiles exactly, nothing is remapped on a live resource, and the two placement ranges match, so neither supersedes the other. Earlier merge-checks are on older heads, and one was written with a model CONTRIBUTING excludes. #3282 is stacked on it, #3340 carries an older copy, and #3094 is an alternative fix for the same aliasing.
performance: 60 s smoke of a retail title, main 493dbd3 vs this merge (b0192a8): 1670 -> 1671 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 18325 MB, 0 device removals, 0 crashes. A second 60 s run of the same merge with XCL_PAIR_PAGES=1: 1677 frames shown (last presents per 2 s: 60 60 60), peak commit 17514 MB, 0 device removals, 0 crashes; the log shows the cap applied (60-tile textures owning 0x384000 of 0x3c0000 bytes, 4+ times in the first 9 s).
verdict: safe to merge (off by default; switching the test to place_with(.., pair=true), as #3282 does, would remove the process-wide set_var)
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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: b0192a8
merge: clean (the head sits on this base; merge 0e611d42)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same machine, same commit: 2900 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache).
review: recheck after the rebase; my check of ddd5c6ca no longer counts. git range-diff of the two PR commits against the ones I read then shows no code change: only the comment on Target::pair and the first commit's message differ (they now say that console_bytes is what CreatePlacedResourceX passes, which since #2753 is the bytes of the texels for a 3-D texture XG cannot lay out). No blocking finding. As before: off by default; without XCL_PAIR_PAGES=1, pair_pages() is false, Target::pair is None, pair_capped_bytes returns None and Entry::extent() is the texture's whole size, so the call sites compute what they did before. Two notes, neither blocking, both only with the switch on: (1) pair_capped_bytes returns the target's console_bytes for any placed texture, not only a capped one, and register takes it as a cap whenever it is below XG's size; with #2753 a 3-D texture now has such a size, and the author states that no such pairing was seen or tested. (2) the switch is read from the environment on every placement and every register. Size: +516/-18, over the ~400-line target, most of it tests. Not done: a game run with the switch on.
performance: default path, 120 s smoke of a retail title (GTA 6), one run each after a warm-up, A pressed at 70 s: base 493dbd3 3087 frames shown, peak commit 30932 MB; this merge 3007 frames (97 %), peak commit 31706 MB (103 %); 0 device removals and 0 crashes in both. With the switch on: not measured.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 compared the two heads, ran the build, the suite and the smoke runs and wrote this check.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@github-actions github-actions Bot removed the ready-to-merge Has 2 independent safe merge-checks on current head (#3041) label Dec 1, 2026
@Pipodi

Pipodi commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@Foniass (merge check on b0192a8)

Thanks for the check. Each point against the code, on the new head c9d3abea:

  1. Pairing rule (pair_partners): agreed, it is a heuristic (same address, same tile count, a live GPU-written texture of known size). It stays behind XCL_PAIR_PAGES=1, off by default. No change.
  2. A capped texture's tail is not watched: by design; I only added a sentence to the comment on Entry::cap. Past the cap the memory is the next texture's on the console (the written texture's allocation ends there), so the view's range and its source links stop at the cap. That is what keeps the neighbour's placement from superseding the view (the zeros the second commit fixes). A tail write is still seen when it falls in a 1 MiB source piece the capped range touches (link_src works in 1 MiB pieces, and the dirty test of the upload selection uses the whole size); only a tail that reaches a further piece is missed, and those rows have no memory of their own on the console.
  3. pair_pages() read the environment on every call: fixed, cached in a OnceLock like the module's other switches.
  4. The test set XCL_PAIR_PAGES for the whole test process: fixed. It now uses a test-only override (PAIR_PAGES_FOR_TEST, the LEVEL_PAGES_FOR_TEST pattern, under VRAM_TEST_LOCK) with a drop guard, so a failing assert leaves it off. No test touches the environment.

Suite on c9d3abea (RTX 4090, driver 621.40, i9-13900K, Windows 11, debug): cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 2910 passed, 0 failed, 51 ignored, 25 SKIPPED (no wave64 and the usual adapter skips).

Written with Claude Code (Claude Opus 5.5; the code check and the fixes by a Claude Fable 5.2 subagent).


@BBareth (notes on b0192a8)

  1. pair_capped_bytes returned the placed size of any texture, capped or not: right. On this head the two sizes could not differ for a texture register accepts (console_bytes in device_x.rs is XG's size whenever XG lays the texture out; the texel-bytes fallback is taken only when Texture::new fails, and register fails there too), but nothing enforced it. Fixed in c9d3abea: the Target records that a pair capped it, and pair_capped_bytes returns a size only then. The test now asserts None for the written texture and for a sampled texture placed alone with less than XG's size; with the filter taken out the test fails (Some(3686400) for the written texture, run on this head).
  2. The switch was read from the environment on every placement and register: fixed, cached in a OnceLock.

Written with Claude Code (Claude Opus 5.5; the code check and the fixes by a Claude Fable 5.2 subagent).

@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 c9d3abea: 4 finding(s). 3 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/title_textures.rs:2152: The Entry::cap doc says the CPU-write watch ends at the cap, but the dirty test, the upload/fingerprint sizes, written_pages and texture_upload::Written still use the full e.tex.size(). With XCL_PAIR_PAGES=1, the view is capped at 0x384000 and the neighbour starts at va+0x384000. A CPU write to the neighbour's first 0x3c000 bytes lands in the same 1 MiB src piece, touched_by returns the view, and the whole view is uploaded again. The neighbour's bytes go into the view's tail tiles, the extra pages (va, 57..59) it shares with the GPU-written R32_UINT texture, which overwrites that writer's texels.


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.

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

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 partner snapshot is taken under one PAGES lock, placements::current is checked with the lock dropped, and PAGES is locked again to insert, so the cap can be decided on stale state. If thread A has inserted the writer into PAGES.targets but not yet reached placements::placed, a concurrent placement of the sampled view sees current(writer) == false and stays uncapped at 60 pages, and it gets superseded and unmapped again, which is the bug this fixes. The other way round, a writer released between the snapshot and the re-lock still caps the view, and the cap is kept for good.

if writer {
return Vec::new();
}
targets.iter().filter(|(_, t)| t.mapped && t.va == va && t.total == total).filter_map(|(&res, t)| Some((res, t.pair?))).collect()

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 cap depends on placement order: only a writer that's already mapped and current when the sampled texture is placed can cap it. If the title creates the R9G9B9E5 view before the R32_UINT UAV at the same va, or recreates the view while the writer's registry entry is briefly not current, the view keeps 0x3c0000 / 60 pages, gets superseded by the texture at +0x384000, and the compute pass reads zeros even with XCL_PAIR_PAGES=1.

return Vec::new();
}
targets.iter().filter(|(_, t)| t.mapped && t.va == va && t.total == total).filter_map(|(&res, t)| Some((res, t.pair?))).collect()
}

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 pairing test (same va, same PC tile count, a current GPU writer of known size) can also match an unrelated sampled texture placed over a UAV the title still holds. That texture gets capped to the UAV's size, its last tiles go to shared extra pages, and title_textures stops linking src past the cap, so CPU writes to its tail never trigger an upload.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head c9d3abe, since b0192a8, diff read, not a merge-check):

  • Triage (keep open, no problems; part of a stack with D3D12.X: XCL_PAIR_PAGES=1 puts a GPU-owned texture on pages at an address its layout allows #3282, D3D12.X: XCL_CAST_LIST=1 shares one texture between R32_UINT and R9G9B9E5 #3340 carrying its commits, D3D12.X: a sampled texture in the memory of a written one of another format is copied from it (XCL_ALIAS_COPY=1) #3094 the copy-based alternative): still right. The new changes (Target::capped, the test override) keep the lock order and the default path as they were.
  • The pairing rule is a guess: still open. A sampled texture is still capped by any current, mapped, GPU-written texture of known size at the same address with the same PC tile count (vram.rs ~2314-2318), and there is no count of caps and no XCL_PAIR_PAGES=1 run on this head; the switch is still off by default.
  • A capped texture's tail is not watched for title writes: partly fixed. The comment on Entry::cap (title_textures.rs ~101-105) now says the memory past the cap belongs to the next texture, but the dirty check and the upload still use the whole tex.size() (~2152, ~2168), so an upload started by a CPU write before the cap still reads the bytes past it.
  • pair_pages() read the environment on every call: fixed (OnceLock, with PAIR_PAGES_FOR_TEST for tests, vram.rs ~2295-2306).
  • The test set XCL_PAIR_PAGES for the whole test process: fixed. gpu_register_takes_the_cap_from_the_pair sets a test-only atomic under VRAM_TEST_LOCK and title_textures' TEST_LOCK, cleared by a drop guard (vram.rs ~5036-5042).

New:

  • Stale duplicate block in the description. After the first xcl-smoke pair, a stray **Not tested**): heading repeats the retail-title bullets and a second Regression run for 493dbd3d / b0192a85 before the real Not tested, so it is unclear which run and head each statement is about.

Fine: pair_capped_bytes now returns a size only for a texture a pair actually capped (Target::capped, vram.rs ~713, ~2459), so a sampled texture placed with less than XG's size is no longer taken as capped, and the GPU test checks both cases; title_textures uses the capped extent consistently in insert, remove, the restore of shadowed textures and recheck_gpu_view_sources.

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

@Pipodi

Pipodi commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review of c9d3abea. Pushed f32c1894 (commits 1a38d2c6 + f32c1894, on main 493dbd3d); each fix is squashed into the commit it belongs to.
Suite: cargo test --workspace --no-fail-fast -- --test-threads=4 on 9cd6c839 (includes f32c1894) (gpuq log 20261201-231222-57a8): 2918 passed, 0 failed, 51 ignored, 25 SKIPPED (22 no wave64, 2 no heap windows, 1 driver cache needs Developer Mode).


1. title_textures.rs:2152 (outside the diff): the cap is not used by the dirty test, uploads and fingerprints

Confirmed, thank you. With XCL_PAIR_PAGES=1 a write to the neighbour's first 0x3c000 bytes was in a
1 MiB source piece of the view, the dirty test went by tex.size(), and the whole view went up again,
the neighbour's bytes into its tail tiles. It cannot happen with the switch off: Entry::cap is only
set from vram::pair_capped_bytes.

Fixed in f32c1894: the dirty test (Entry::written_in), the written pages of a partial upload
(dirty_on) and the fingerprints of an unwatched view (seed_stream_recheck,
recheck_streamed_unwatched_at) now go by Entry::extent(). Tests:
capped_placed_view_is_not_superseded_by_its_neighbour (a write to the neighbour's first page no
longer names the view's own memory) and a_capped_views_fingerprint_ends_at_its_cap (a write past the cap, in the end slice of a whole-size
fingerprint, queues the view when the baseline or the recheck fingerprints the whole size).

The view's uploads now end at its cap too. Its tiles past the cap are not its own pages: they are
the extra pages keyed (va, 57..59) (owned_pages at vram.rs:2250, called from place_on_pages at
vram.rs:2503; bind_range at vram.rs:2145 and vram.rs:2183) it shares with the writer, whose
last PC tiles they are, so a whole upload of the view wrote the neighbour's bytes over the writer's
texels there. gpu_written did not keep the view from that: register makes its entry with
pending: true, gpu_written: false (title_textures.rs:616-617), texture_needs_upload
(title_textures.rs:1203) sends a pending entry before it looks at gpu_written, and gpu_written
is set only on the entry of the resource a submitted list writes (title_textures.rs:990), the
writer's. Fixed in f32c1894: every upload of a capped view, its first whole one and later ones,
carries the tiles it owns (texture_upload::Item::own_tiles, from vram::pair_capped_tiles at
vram.rs:719 through own_tiles_of at title_textures.rs:2956, set in upload_all at
title_textures.rs:2899), and plan_item clips each piece to them (texture_upload.rs:476 and
493, owned_parts at texture_upload.rs:550). 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:
slice s's start at D3D12_PACKED_MIP_INFO's (slice 0's) plus s times the tiles of a slice
(texture_upload.rs:563), and a level from NumStandardMips on is taken as packed
(texture_upload.rs:566), as WARP gives the packed subresources of slice 1 slice 0's start and no
tiles rather than D3D12_PACKED_TILE. With the switch off no entry has a cap and own_tiles is None.
Tests, both through upload_all: gpu_a_capped_views_first_upload_leaves_the_tiles_past_its_cap
places the pair on pages, registers the view and checks that its first upload leaves the writer's
texels in tiles 57..59; it fails with the clip off or with no own_tiles from upload_all (30720
texels overwritten). gpu_a_capped_arrays_first_upload_stops_at_its_cap_in_a_later_slice caps a
2-slice 256x256 array with 9 mips one tile into slice 1; it fails with slice 0's packed start for
every slice, or with no own_tiles from upload_all (slice 1's packed mips get the view's bytes).

2. vram.rs:2441: the partner snapshot and placements::current are not under one lock

Right, there is a window. If the written texture is in PAGES.targets but not yet in the registry
(between the insert and placements::placed) when its view is placed on another thread, the view is
not capped: it is then placed as it is with the switch off. The other way round, a writer released in
the window still caps the view. Off by default; with the switch off nothing is paired.

Not changed in this PR: closing it needs one lock order across the snapshot and the insert (the
registry's lock is the outer one, placements::unmap_if_superseded), or registering the writer before
it goes into PAGES.targets. I would rather do that as its own change if the pairing stays.

3. vram.rs:2318: the cap depends on placement order

Right: only a writer already placed and current caps a view (pair_partners), and a writer gets no
partners. A view placed before its writer keeps its full size, as with the switch off. In the title
run the cap fired, so there the writer was placed before its view; that this holds every time is
not shown. Capping a view after the fact means re-binding its pages when the
writer arrives, which is a larger change; not in this PR.

4. vram.rs:2319: the pairing can match an unrelated sampled texture

Partly right. The pairing asked only for the same address and PC tile count, so a texture of another
shape over a UAV the title still holds could be capped. Fixed in 1a38d2c6: it now also has to be a
view of the writer's texels (placements::current_view, the Desc::same_texels rule placements
already uses for aliases: same size, levels and texel size). Test:
only_a_view_of_a_current_targets_texels_pairs_with_it, and the GPU test places a 720x1280 texture with
as many tiles over the written one and checks it keeps its size. A texture of the same shape and texel
size at the address of a UAV the title holds is still taken for its alias: by its description it is
one. Off by default.


AI use: Claude Code with Claude Opus 5.5 (checked each point against the code, ran the tests, wrote
these replies).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head f32c189, since c9d3abe, diff read, not a merge-check):

New: none.

Fine: owned_parts clips whole and partial uploads to the view's own tiles, sends a slice's packed mips only when the view owns all of them, and computes the packed start per array slice; the two new GPU tests check that the written texels past the cap survive the view's first upload for a 2-D texture and a 2-slice array, under the same test locks and override as before.

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

@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 f32c1894: 4 finding(s).

Re-review after the new commits. Still present from my earlier review: the cap still depends on the writer being placed first (vram.rs ~2326), and the snapshot / re-lock race in pairing (vram.rs ~2455). The new findings below aren't in the earlier review. 2 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/title_textures.rs:4027: publish_download reads a GPU-written sampled texture back into title memory over its whole XG layout, which for a capped view runs past the cap into the neighbour. With XCL_PAIR_PAGES=1, the R9G9B9E5 view at va is capped to 0x384000 and the next texture starts at va+0x384000. After the title copies into the view (line 990 sets gpu_written), the download uses layout().size() = 0x3c0000, reverse-lays out PC tiles 57..59 (the writer's shared pages), and write_changed_pages writes them over va+0x384000..va+0x3c0000. The neighbour's first 0x3c000 bytes are silently corrupted. The cap: None comment in register_gpu_owned assumes this can't happen.

crates/xcl/src/hle/d3d12x/title_textures.rs:2893: A clipped whole upload of a capped view still calls all_sent over the full tex.size(), so the tiles past the cap are recorded as sent even though own_tiles skipped them. Once the writer is released, the view is the only user of extra pages (va, 57..59). Those tiles never get the view's texels, because they're never re-sent and dirty_on/written_in ignore writes past the cap, so the bottom rows sample stale writer data.


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 tiles a capped view (`extent` below its size) owns (`vram::pair_capped_tiles`): each of its
/// uploads, its first whole one too, stops before the tiles past them, the pages of the texture the
/// title placed after it. None: all of its tiles.
fn own_tiles_of(res: &ID3D12Resource, extent: usize, tex: &xg::Texture) -> Option<u32> {

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.

own_tiles_of silently falls back to a full upload when pair_capped_tiles returns None (Target not found, or owned_pages None), while Entry.cap stays set. The whole view, tiles 57..59 included, then goes up over the writer's texels, which is the overwrite the cap is meant to prevent. The cap is now tracked in three places (Entry.cap, Target.capped/console_bytes, a fresh PAGES lookup per upload), and they can disagree.

least
});
place_on_pages(dev, this, va, desc, state, clear, console_bytes, false, lazy, riid, ppv)
place_on_pages(dev, this, va, desc, state, clear, console_bytes, false, lazy, pair_pages(), riid, ppv)

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.

place_pages passes pair_pages() without the known gate that place uses (pair_pages() && known). A sampled texture with console_bytes=None gets least_texture_bytes (only a lower bound) as its size, can be paired with a smaller writer and get Target.capped=true, and register then turns that guessed cap into Entry.cap.

@Pipodi

Pipodi commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. Pushed b02b2c34 (commits 1a38d2c6 + b02b2c34, on main 493dbd3d); each fix is squashed into the commit it belongs to.
Suite on the #3282 stack head ea91c5f4, which contains this commit (local GPU through gpuq, debug): cargo test --workspace -- --test-threads=4: 2920 passed, 0 failed, 51 ignored; 25 SKIPPED (no wave64 x22, no heap windows x2, driver cache needs Developer Mode).

Also in b02b2c34, from CI (not from this review): the new array test unwrapped
CreateReservedResource for a 2-slice 256x256 array with 9 mips, which GitHub's runner refuses with
E_INVALIDARG (it already skips placed_title_textures_share_vram_and_preserve_pixels for a reserved
cube with mips). It now skips with "this adapter makes no reserved texture of this shape". The other
8 CI failures were TEST_LOCK.lock().unwrap() in other tests seeing the lock this test poisoned when
it panicked; reproduced locally by simulating the refusal (the test then SKIPs and nothing is
poisoned).

A limit, found while hardening that test: on PC, two different descriptions on the same tiles are
not guaranteed the same layout for their packed mips (64KB_UNDEFINED_SWIZZLE). The array test read
the view's packed mips through the R32_UINT texture and failed about 2 times in 30 runs. It now reads
each texture's packed mips back through the description that wrote them, after an aliasing barrier.
The single-mip 1280x720 test still reads the view's own tiles through the R32_UINT texture too (both
32 bpp, standard tiles), which is the case the title relies on. In the title, the pair is a single-mip
1280x720 one, so pairing does not rely on the packed-mip layout. A paired texture with
packed mips could read differently through its partner, though, and that case is not covered.


title_textures.rs:4027: publish_download writes a capped view's whole layout back

Confirmed, thank you. Any registered texture a submitted list writes gets gpu_writers
(publish_submission_effects, title_textures.rs:984-990) and is read back, and publish_download
wrote its whole XG layout into the title's memory, past the cap into the next texture. Only with
XCL_PAIR_PAGES=1: Entry::cap is set from nothing else.

Fixed in b02b2c34: the write-back stops at Entry::extent() (title_textures.rs:4042). Test
gpu_a_capped_views_download_ends_at_its_cap (title_textures.rs:6510): a texture registered with
a cap at half its size, written by the GPU and downloaded; the memory past the cap keeps its bytes.
It fails with the whole layout written back ("the memory past its cap keeps its bytes").

title_textures.rs:2893: a clipped whole upload still records all of the view as sent

Not changed. The hashes all_sent records for the pages past the cap are never compared: the pages a
partial upload compares come from dirty_on(..., d.extent) (title_textures.rs:163) and the dirty
test from Entry::written_in (title_textures.rs:156), both cut at the cap. So recording them changes
nothing. That the view's tiles past the cap never get the view's texels is the cap itself: on the
console those bytes are the next texture's, and on the PC those tiles are the written texture's pages.
After the written texture is released they keep its last texels instead of the neighbour's bytes;
both are bytes the view does not own.

title_textures.rs:2956: own_tiles_of falls back to a whole upload

Confirmed as a fail-open path, though I found no way to reach it in a run: Entry::cap comes from
the view's Target (vram::pair_capped_bytes), the Target is removed only when the resource is
released (forget_pages), the Due holds a reference to the resource for the upload, and
pair_pages() does not change during a run. Fixed anyway in b02b2c34: a capped entry whose tiles
vram::pair_capped_tiles does not give owns none, so nothing of it goes up rather than all of it
(title_textures.rs:2957). Test a_capped_view_without_its_tiles_owns_none
(title_textures.rs:6481), which fails with the old fallback.

vram.rs:3093: place_pages passes pair_pages() without the known gate

Not changed. place_pages only gets textures vram::gpu_owned refuses (device_x.rs:1283 and
1298), so it never makes a writer, and a writer is the only thing the gate is for: in place
(vram.rs:3315) it keeps a written texture of unknown size from becoming a partner with a
lower-bound size (Target::pair is set only for a writer). A sampled texture of unknown size gets
least_texture_bytes as its size. pair_bytes caps it only when that lower bound is already larger
than the written texture's known size, and then the cap is the written texture's size, the same cap
a known size would give. When the bound is smaller, it is not capped, as with the switch off.
register does not take a guessed size as the cap: Entry::cap is the written texture's size.

Still present from the earlier review

The writer-first order (vram.rs ~2326) and the snapshot / re-lock race in pairing (vram.rs ~2455)
are answered in my replies to your earlier review; neither is changed in this PR.


AI use: Claude Code with Claude Opus 5.5 (main session, reviews, fixes), Claude Sonnet 5.5 (runs) and
Claude Fable 5.2 (earlier code).

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head b02b2c3, since f32c189, diff read, not a merge-check):

  • publish_download of a capped view (listed as not tested): handled. A capped view a list writes is now read back into the title's memory only up to its cap (title_textures.rs ~4040-4043, entry.extent().min(size)), and gpu_a_capped_views_download_ends_at_its_cap checks that the memory past the cap keeps its bytes.
  • The pairing rule is a guess (no XCL_PAIR_PAGES=1 title run on this head): unchanged.

New: none. own_tiles_of (~2957) now returns Some(0) for a capped view whose tiles vram no longer gives, so nothing of it goes up rather than all of it over the next texture's pages; a_capped_view_without_its_tiles_owns_none covers it. The GPU tests now read each upload back through the texture that wrote it after an aliasing barrier (alias_to), and the packed-mip test skips adapters that refuse the reserved array instead of panicking. Only b02b2c34 changed; 1a38d2c6 is the same.

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

Pipodi and others added 2 commits December 2, 2026 17:12
…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>
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>
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 223b565, since b02b2c3, diff read, not a merge-check):

  • Earlier points: unchanged; this push is a rebase onto the current main (whose place_on_pages gained an argument, which the PR's test calls now pass). The pairing rule is still unmeasured on a title with XCL_PAIR_PAGES=1.

New: none. #3282 and #3340 carry these commits and will need the same rebase.

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

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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants