D3D12.X: restore coexisting committed aliases and re-queue uncovered CPU-backed textures in title_textures::Table::remove #3426
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3426"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T15:30:26Z.
What changed
Table::has_blocking_active_overlapincrates/xcl/src/hle/d3d12x/title_textures.rsmirroringTable::insert's coexistence rule: two committed (!placed) textures covering the exact same[va, end)range coexist as format aliases, while any placed or different-range active overlap blocks reactivation.Table::removeto checkhas_blocking_active_overlapwhen restoring shadowed entries instead ofhas_active_overlap, so all coexisting committed exact-range format aliases reactivate together when a covering texture is released.Table::removeto sete.pending = truewhenever an uncovered entry ise.cpu_backed && !e.gpu_written(not only whene.unmappedwas true), so exact same-range placed aliases whose sharedvram::Pagestiles were overwritten and committed textures whose CPU writes were missed while unlinked fromsrc_piecesre-upload on the next submit.table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pendingcovering coexisting committed aliases, exact-range placed aliases withunmapped == false, and committed/placed layering order.Why
Table::insertallows multiple committed (!placed) textures with the exact same[va, end)range to coexist as format aliases. When a covering texture shadowed those aliases and was later released,Table::removerestored the newest alias first and then rejected every older coexisting alias viahas_active_overlap, leaving them trapped inshadowedand unlinked fromsrc_piecesuntil the newest alias was also released.Table::removecallstexture_upload::forget(&e.known)on every uncovered texture because the covering texture may have overwritten shared video memory, yet only markede.pending = truewhene.unmappedwas true. Exact same-range placed aliases stay mapped (unmapped == false) while sharingvram::Pagestiles, and committed textures never setunmapped, so uncovered CPU-backed textures stayedpending == falsewith stale or overwritten texels.Tested
cargo check --workspace --all-targets(0 errors, 0 new warnings).cargo build --workspaceandcargo build --release -p xcl.table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending(failed before the fix onorigin/main24d21a41, passes after),overlapping_placements_retire_superseded_entries, andgpu_owned_alias_generations_restore_the_previous_address_owner.cargo test --workspace -- --test-threads=4, exit 0, 0 failures across all crates).xcl-smokeon PR head (b243d81c) andmain-ancestor baseline (f0e8fdd5):Not tested
ea3b5e4d.PENDINGaccounting inrecheck_source/mapping_changed(left out of scope to avoid overlapping open PRs#1294/#1733).AI use
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T15:41:34Z.
I ran the restoration through actual upload and fenced GPU readback on an RTX 5070 (616.92), using
b243d81cand the same snapshot with this PR diff reversed.Two committed 64×64 textures (
R8_UNORMandR8_UINT) covered the same CPU source bytes. Both initially read0x31in all 4,096 texels. A larger texture shadowed both. I changed the CPU bytes to0x97, refreshed while the covering texture was still registered, then removed it and refreshed again.0x970/4,096,0/4,0964,096/4,096,4,096/4,096cargo test --locked --offline -p xcl --lib -- --test-threads=1 --nocapture gpu_uncovered_committed_format_aliases_refresh_together table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pendingpassed both tests on the PR without skips. The GPU assertion failed in the matched reversed control. The fixture used the production registration, refresh and forget helpers with synthetic CPU-backed committed resources. Guest release hooks, GPU-written aliases and retail behavior remain untested here.Apply-checked native fixture
AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the fixture and drafted the report.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:55:48Z.
merge-check
base:
d0832e614fhead:
b243d81ceemerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 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 (title_textures.rs, +85/-8). It changes the default path: when a covering texture is released, every uncovered texture that is CPU-backed and not GPU-written is now marked pending and uploaded again in full, not only one whose tiles had been unmapped. Findings: (1) possible overwrite of rendered texels (from reading, not seen on a title). A GPU-owned render target registered with
register_gpu_owned(placed, not CPU-backed) can shadow a placed CPU-backed sampled texture at the exact same range with shared tiles. On main, releasing the target leaves the sampled texture holding what was rendered, as aliasing does on the console. With this PR the texture is re-uploaded from CPU memory over it, unless a download already wrote those texels back. Limiting the re-queue to entries whose tiles were unmapped or that saw CPU writes while shadowed would avoid it. (2) The extra full uploads per uncover aren't measured; the PR's own smoke runs are 89 % of main's frames and +1.7 GB peak commit, one run each. (3) Unmapped, non-CPU-backed, not GPU-written entries are no longer marked pending (on main they were never uploaded, so the pending count leaked). Looks like an improvement but has no test. (4) AI use names no tool or model. Fine:has_blocking_active_overlapfollowsinsert's rule for same-range committed aliases, newest-first restore is consistent for mixed placed and committed entries, no new lock is taken underTEXTURES,pending_resand the pending count move together, and the new test fails on main for both claimed bugs.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (f1635dfe): 1516 -> 1671 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17255 MB, 0 device removals, 0 crashes. This run doesn't show whether the title releases a GPU-owned target over a CPU-backed alias.verdict: not yet: rule out finding (1) (a re-upload from CPU memory over texels a GPU-owned target rendered into a shared-tile alias), e.g. by limiting the re-queue to unmapped or CPU-written entries
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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 439When a GPU-owned placed render target or UAV is released, the exact-range placed sampled texture under it is now marked pending, and its whole upload from stale CPU memory overwrites the shared tiles the GPU rendered into. Sampled placed 20 and GPU-owned RT 21 (
register_gpu_owned: placed=true, cpu_backed=false) share [va,end), and they share tiles the way the console aliases memory. The title renders into 21 and releases it.remove(21)uncovers 20 (unmapped=false),cpu_backed && !gpu_writtensets pending, and the next ExecuteCommandLists uploads 20 whole from title memory, which GPU writes never reach. The rendered texels are replaced with stale bytes. Test case 2 asserts exactly this upload.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 440The same happens for render-target/UAV entries (
target) in general. Entry::target says the GPU can write them other than by copies and XCL doesn't see all of that, sogpu_writtencan stay false after GPU writes. A committed or placed target A that the title renders into, shadowed by cover C, is forced pending withknownforgotten when C is released, and its GPU content is replaced from CPU memory. Before, it was only re-uploaded if the CPU actually wrote its pages. For committed entries (own memory the cover never touched), comparingknownagainst current CPU bytes and uploading only the changed pages would avoid both this and the extra upload cost (the smoke run shows 1510 vs 1695 frames, +1.7 GB peak commit).Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 443PENDING can be counted twice:
mapping_changed()andrecheck_source()already doPENDING.fetch_add(1)on a shadowed entry, andremove()adds +1 again viapending_deltawhen it uncovers that pending entry. The submit decrements only once, so PENDING stays one too high for good, thePENDING == 0fast path is never taken again, and every submit takes the slow selection path. The PR widens this branch without fixing that.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 431Not certain about this one: the uncovered texture now uploads at the next submit, but
remove()doesn't runtexture_upload::inheritfrom the released cover's unfinished sends the wayinsert()does for a placed-over-placed cover. If cover 21 still has an upload queued on another device's XCL queue to the same Pages tiles, 20'sknown.lastdoesn't include it, and 21's late copy can land after 20's upload and corrupt it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.
Review: COMMENTED
Review of
b243d81c: 5 finding(s). 4 are inline. These are on lines outside the diff:crates/xcl/src/hle/d3d12x/title_textures.rs:404: Shadowed entries are only reconsidered when an active cover is released, so the case the PR fixes still happens. With committed A at [0,X), placed P at [0,X) shadowing A, then committed B at [0,X) shadowing P: releasing P (shadowed) returns early here and never reconsiders A. A is a format alias that may coexist with active B, but it stays shadowed, unlinked from src_pieces, and misses CPU writes until B is released.insert()doesn't apply the coexistence rule either.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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:00Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:56Z.
Closing: review flagged stale CPU re-uploads overwriting GPU-rendered shared tiles and double-counted
PENDINGentries.Pull request closed