Repository navigation
Conversation
…-protected title pages
…V textures Adds fault-driven GPU -> CPU texture copy-back behind opt-in XCL_COPY_BACK=fault (default off, requires XCL_GUEST_WRITE_GUARD=1 from xcl-dev#3597) to address xcl-dev#2663 for GPU-owned RT/DS/UAV textures without paying eager per-submit download cost. - Tracks GPU-owned placed textures (vram::place: RTV/DSV/UAV binds, clears, UAV barriers, and resource state transitions touching RENDER_TARGET|UNORDERED_ACCESS|DEPTH_WRITE|COPY_DEST|RESOLVE_DEST) alongside kept sampled textures, arming whole committed title pages PAGE_NOACCESS behind a native per-queue fence after submission. - On CPU access violation, waits for the writing submit fence on XCL's upload queue, downloads from tracked post-submit resource states (gpu::texture::download), opens the pages, and re-tiles changed 4 KiB pages into console layout (title_textures::write_subresources). - Skips imported coherent UMA ranges (!uma.shadowed() && uma.in_committed_window) upfront in O(1), avoiding Windows OpenExistingHeapFromAddress VirtualProtect error 87 and ~20 ms VirtualQuery PTE walks. - Coexists deadlock-free with title_textures's eager Copy/Resolve download publisher via copy_back::disarm_overlapping before write_changed_pages, and serializes page-protection against pinned kernel writes via guest_write::while_unpinned. - Adds unit and GPU tests covering kept textures, end-to-end adopted-hook GPU-owned RT clear + state transitions, write_changed_pages coexistence, multi-plane DS skip, coherent UMA skip, and guest_write::while_unpinned.
5 tasks
Contributor
|
Review (head 6950d2e, diff read, not a merge-check):
Not reviewed line by line because of the size. Fine: everything is behind AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds opt-in fault-driven GPU → CPU texture copy-back behind
XCL_COPY_BACK=fault(off by default, requiresXCL_GUEST_WRITE_GUARD=1from stacked PR #3597) to address #2663 for GPU-owned RT/DS/UAV textures without eager per-submit GPU downloads.TL;DR — Before vs After (RX 6650 XT 8 GB,
origin/amd-dev41aa60ce)XCL_COPY_BACKoff)XCL_COPY_BACK=fault)vram::place)copy_back_gpu_owned_rt_and_uav_texture_reads_back_on_cpu_touch)0x5Abytes (#2663)Signal/ onCOPYqueuecopy_back_a_cpu_read_of_a_gpu_written_texture_sees_the_gpu_texels)0x5Abytes+0.01 ms/submit,0failed,0crashes (imported coherent UMA skipped in O(1))6950d2e5, default off vsmaind8bd9a38)main)6950d2e5, opt-in on)=fault)What is in it
crates/xcl/src/hle/d3d12x/copy_back.rs(new):XCL_COPY_BACK=fault(default off; refuses to activate and logs a warning ifXCL_GUEST_WRITE_GUARD=1is not set).register_gpu_owned): tracks single-plane non-MSAAvram::placetextures (reusingxg::Texture::new(&x)indevice_x.rs), their CPU-accessible title VA (mirror_source_of), and per-subresourceD3D12_RESOURCE_STATES.ClearRenderTargetView,OMSetRenderTargets(RTV + DSV),ClearDepthStencilView,ClearUnorderedAccessView*,D3D12_RESOURCE_BARRIER_TYPE_UAV, resource transitions touchingRENDER_TARGET | UNORDERED_ACCESS | DEPTH_WRITE | COPY_DEST | RESOLVE_DEST, andCopy*/Resolve*.after_submit): signals a native per-queue fence (real::native_queue_signal, bypassing titleSignalhooks), skips unsupported (multi-plane / MSAA) and imported coherent UMA ranges (!uma.shadowed() && uma.in_committed_window, where WindowsdxgkrnlrejectsVirtualProtect(..., PAGE_NOACCESS)with error 87 andVirtualQuerywalks ~500k PTEs), registers whole committed pages withguest_write, and marks themPAGE_NOACCESSviaguest_write::while_unpinned.fault): on CPU read/write access violation inside an armed texture, GPU-waits for the writing submit's fence on XCL's upload queue (real::native_queue_wait), downloads all subresources from tracked post-submit states (gpu::texture::download), restoresPAGE_READWRITE, and re-tiles changed 4 KiB pages into console layout (title_textures::write_subresources). Pages always reopen even on failure so the title continues.Copy*/Resolve*downloads:disarm_overlapping(va, len)(takingHANDLER→STATElock order) opens any overlapping armed pages beforetitle_textures::publish_downloadreads title bytes or callswrite_changed_pages, preventing fence deadlocks.submit_cost.rs): logs armed count, faults, MB read back, skip breakdown (uma/unsup/small/overlap/prot), and live GPU-owned VA census every 1024 submits when enabled.crates/xcl/src/gpu/texture.rs: addstexture::download(usingreal::native_queue_executeand retaining objects on failed wait).crates/xcl/src/hle/d3d12x/title_textures.rs: addswrite_subresources,write_writable,download_and_write_after,read_back_after,read_back,copy_back_range,mirror_source_of,disarm_overlappinghook inpublish_download, and 5 unit/GPU tests.crates/xcl/src/hle/kernelx/guest_write.rs: addswhile_unpinned(serialized across protectors without holdingPINSacrossVirtualProtect, withopen_withwait synchronization),meets_guarded_view, and a unit test.crates/xcl/src/hle/d3d12x/{device_x,list_x,real,present,submit_cost,mod}.rs: opt-in hooks gated behindcopy_back::on()(single relaxed atomic load when off) plusforgeton resource release andforget_queueon queue retirement.Tested
32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11,rustc 1.100.0 (0ef1bc386 2026-11-09).cargo test -p xcl --lib -- copy_back read_back written_subresources write_changed_pages download guest_write --test-threads=1(debug): 25 passed, 0 failed, 0 ignored (includes end-to-end adopted-hook GPU RT clear + transition test,write_changed_pagescoexistence viadisarm_overlapping, multi-plane DS skip, imported coherent UMA skip, kept-texture fence-wait test, unmapped/RO page handling, andguest_write::while_unpinned).cargo test -p xcl --test guest_write_probe -- --include-ignored --test-threads=1(debug): 2 passed, 0 failed.6950d2e5(release):1,648frames (60 60 60),18,038 MBpeak commit,exit: 0x0,0device removals,0crashes.XCL_GUEST_WRITE_GUARD=1 XCL_COPY_BACK=fault:1,659frames (60 60 60),18,045 MBpeak commit,exit: 0x0,0device removals,0crashes,0guest write:warnings,0failed read-backs; live census observed919live GPU-owned textures (418/840.9 MBin imported coherent UMA skipped cleanly in O(1),504/3,036.6 MBoutside imported coherent UMA,20multi-plane/MSAA skipped).Regression run
Baseline (
main):PR head (
6950d2e5, default off):PR head (
6950d2e5,XCL_GUEST_WRITE_GUARD=1 XCL_COPY_BACK=fault):Not tested
WriteFile/send) directly from armedPAGE_NOACCESStexture pages (not hooked byguest_write).OpenExistingHeapFromAddress), wheredxgkrnlrejectsVirtualProtect(..., PAGE_NOACCESS)with error 87; these are skipped upfront and logged in the census (handling CPU reads of coherent-UMA RT/UAV targets would require a separate non-fault path or placing GPU-owned textures outside the imported coherent window).AI use
XCL_COPY_BACK=faultprototype (a86dd8fa) for kept sampled textures and unit/GPU test harness; Antigravity (Gemini 4 Neon) extended it with GPU-owned RT/DS/UAV tracking, upfront imported coherent-UMA skip,title_textures::publish_downloadcoexistence (disarm_overlapping), native queue signal/wait integration onamd-dev41aa60ce, end-to-end RT GPU tests, and matched 60 s smoke verification.