D3D12.X: check writability in note_signaled and remove per-frame allocations in WaitFrameEventX #2682
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2692"
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 Decodere on 2026-11-26T06:27:33Z.
What is in it
Hardens
note_signaledagainst non-writable output pointers and removes per-frame heap allocations, unnecessaryArc::clonetraffic, and O(N) ring-buffer shifts on theWaitFrameEventX/mark_flippedhot path incrates/xcl/src/hle/d3d12x/frame.rs.note_signaled: Replacescrate::gpu::shader::readable(out, 4)withwritable(p, len)(viawritable_with_uma(uma, p, len)):gpu::shader::readable'sUma::in_committed_window(p, len)fast path right after the null/zero/oversize/overflow guards and beforeresident_and_writable/VirtualQuery(per @upipibi's review), so a non-resident page inside a 4 GiB committed coherent window (PAGE_READWRITEas a whole) never falls through to a slow kernelVirtualQuerywalk, while cross-window boundary straddles fall through cleanly.K32QueryWorkingSetExfast path (resident_and_writable, up to 16 pages, treating onlyflags & 1 != 0 && protect != 0entries as resident so non-resident orprotect == 0pages fall through cleanly) and falls back toVirtualQuery, requiringMEM_COMMIT, noPAGE_GUARD, and a writable page protection (PAGE_READWRITE,PAGE_WRITECOPY,PAGE_EXECUTE_READWRITE, orPAGE_EXECUTE_WRITECOPY). Read-only, execute-read, guard, no-access, reserved-only, null, and cross-page RW->RO targets are safely skipped without touching pages or triggering guard faults.WaitFrameEventX: Replacesancillary'sVec<HANDLE>with a stack-allocatedAncillaryHandles([HANDLE; 63]+len, implementingDeref<Target = [HANDLE]>andIntoIterator) and replaces the paced wait-handleVec<HANDLE>with a stack[HANDLE; 64]array.Arc::clonefor uncapped mode: Clonesc.kinds[ty as usize].extrainsidewait_frame_event_xonly wheninterval_override() == Some(0), avoiding an unused atomic reference-count increment/decrement on every default paced frame wait.ISSUEDandFLIPPEDfromVec(remove(0)/drain(..n)) toVecDeque(pop_front()/push_back(...)).writable/note_signaled(read-only, resident read-only, RW->RO cross-page straddle,PAGE_GUARDpreservation,PAGE_EXECUTE_READ,PAGE_NOACCESS, reserved-only, and valid write), the committed coherentUma::with_windows(1, 0x2_0000)fast path (non-resident untouched page,PAGE_GUARDshortcut proof, guard rejections, and end-of-window boundary fallthrough),AncillaryHandlesboundary cases (null,0,63,64,u32::MAX, unreadable list), andISSUED/FLIPPEDFIFO eviction order.Part of #103
Tested
b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7): Confirmed unmodifiedgpu::shader::readableaccepted both aPAGE_READONLYtarget (ro_ok=true) and a 4-bytePAGE_READWRITE -> PAGE_READONLYcross-page straddle (straddle_ok=true), whereas post-fixwritablerejects both andnote_signaledskips them safely.cargo clippy --all-targets -- -A clippy::approx_constant->0new warnings incrates/xcl/src/hle/d3d12x/frame.rs.XCL_ADAPTER=warp,XCL_WARP=1):cargo test -p xcl --lib -- hle::d3d12x::frame::tests:: --nocapture->9 passed; 0 failed; 0 ignored(0skipped,0.25seach across all 3 runs).cargo test --release -p xcl --lib -- hle::d3d12x::frame::tests:: --nocapture->9 passed; 0 failed; 0 ignored(0skipped,0.25seach across all 3 runs).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture->37test targets,1439 passed; 0 failed; 47 ignored(29pre-existing host-gatedSKIPPEDnotices:21wave64-only tests on a 32-lane GPU,3per-lane wave32 tests refused by the driver,3D3D12 debug layer tests withoutd3d12SDKLayers.dll,1no heap windows,1cannot disable the driver cache).Regression run
Baseline (exact parent
b49be183):Branch (
HEAD):Not tested
d3d12SDKLayers.dll).K32QueryWorkingSetExreportsprotect == 0(covered structurally by falling through toVirtualQuery).XCL_FRAME_INTERVAL_US=0(uncapped override path).AI use
Implemented, unit-tested, and verified with assistance from Google Antigravity (Gemini 4 Neon); every change and test result was reviewed and executed locally.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-26T06:50:55Z.
Tested on the Linux/Wine lane, full standard env (AMD rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT 20 GB, Arch kernel 7.2.15, Mesa 26.2.5 RADV, wine-11.0 Proton, rustc 1.94.0;
d3d12,d3d12core,dxgi,d3d11,d3d10core=n,boverrides, official DXC kit,VKD3D_CONFIG=ignore_shared_fence, threads=2), head9a547e23, mergeable against mainb49be183:non-gpu suite (
--skip gpu::): 599 passed, 3 failed, 4 ignored, 733 filtered.The failure set is identical to bare main
b49be183measured on the same rig the same day (596 passed, 3 failed): gpu_promoted_uav_clear (our #2490), xma2_source_voice (#2481, vendored-FAudio gate). The third red, the sparse tile video-memory test, is a known batch flake (green solo).Zero delta from this PR; every test it adds passes inside the suite.
Not tested: gpu suite, Windows native.
Correction: an earlier version of this row reported three extra reds; those runs lacked the
d3d12,d3d12core=n,bDLL overrides and hit stub-DLL NOTIMPL artifacts. Re-ran with the standard env, artifacts gone.AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T07:05:50Z.
Test report: passes on NVIDIA. Exact head
9a547e23(its base is currentmainb49be18, so head = merged).Tested
cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the 3 new tests passmainon this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dllnot installed), 1no heap windows, 1pso_measurement_compiles_an_exact_synthetic_record(Developer Mode off)Not tested
WaitFrameEventXpacing on a title.Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by relativespace2K on 2026-11-26T07:18:19Z.
Tested - native Windows AMD RDNA2, PR head
9a547e23onmainb49be183Tool: OpenCode with DeepSeek V4.1 Flash 1017
Windows 11 IoT Enterprise LTSC 26100; release build; DXC 1.9.2602.17.
cargo test --release -p xcl --lib -- hle::d3d12x::frame::tests:: --nocapture:8 passed, 0 failed, 0 ignored, 0 skipped, 1331 filtered out.
XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=1 XCL_RUN_SECONDS=240, no other XCL_* variables; shader and pipelinecaches warm;
mainand the PR run alternately.main1main2 (warm)PR 1 ran second and started with a warmer cache (139 -> 41 DXIL misses); the warm repeat
does not reproduce 3,780 (PR 1,780 vs
main1,849, within run-to-run variance). The onlyconsistent difference is the first frame ~4 s earlier in both PR runs (17.2/16.2 s vs
20.9/20.1 s); n=2, not enough to claim a gain.
Both trees: 40 mesh refusals, 0 failed pipelines, 0 DXIL failures, no crash and no device
removal. The title still stalls on its loading screen (presentation falls to zero around
125 s; 1,780-1,849 frames), so there is no world or FPS comparison in this window.
Not tested: full workspace, NVIDIA, debug build, world/FPS runs.
AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests, read the logs and wrote this comment; the figures and crash lines were checked against the run logs.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T07:23:50Z.
RX 6800M verification at exact PR head
9a547e23ab97a0620384a91c305f5a8ebac3088bagainst current mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7(Windows 11, AMD driver30.0.13002.13003, Rust 1.99.0 MSVC):cargo test --locked -p xcl --lib hle::d3d12x::frame::tests:: -j 1 -- --test-threads=1 --nocapture, withXCL_ADAPTER=6800M: 8 passed, 0 failed, 0 ignored, 1,331 filtered.cargo build --locked --release -p xcl -j 1: passed; head executable SHA-2560A0B772118DD4E4A7DB88D8CE014A70A1146BCCF5F5B48A5C778C62195A7C95C.XCL_FRAME_INTERVAL_US=0,XCL_TRACE_FRAME_EVENTS=1,XCL_ADAPTER=6800M, separate data/DXIL cache directories, and the same locally owned title build (hash2ef5fd64). Both logs explicitly sayXCL_FRAME_INTERVAL_US=0 – uncappedand showWaitFrameEventXcalls plus nonzero frame-event wait counts.b49be1839a547e230x00x0This confirms startup presentation and frame-event activity on this AMD card with the uncapped override. The 12-second samples are too short for a performance conclusion and do not establish world-load behavior or exercise every changed edge case. I did not run the full workspace suite on this head. AI-assisted test report with Codex.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-26T09:41:46Z.
Ran the frame hot-path tests at
9a547e23:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
All eight tests pass, including the three new ones for the writability check (
note_signaled_skips_readonly_guard_and_cross_page_targets), the 63/64-handle boundary (ancillary_stack_handles_boundary_cases) and the FIFO eviction (issued_and_flipped_ring_buffers_evict_oldest_in_order). These are Win32 unit tests, not GPU rendering measurements.What this adds: the author measured on an RTX 4060 (Ada) and WARP; this is a second NVIDIA host (Blackwell, different driver), and the thread already has one more NVIDIA report on an RTX 4080 SUPER.
Not tested: the full workspace suite, a paired 60 s smoke run, the retail title under
XCL_FRAME_INTERVAL_US=0, AMD and Intel GPUs, Wine, release profile, title data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T20:48:36Z.
Source read of
9a547e23, no run.writable(frame.rs:303) drops the coherent-window shortcut thatreadablehas (gpu/shader.rs:215,in_committed_window). If the title'ssignaledpointer is in a committed coherent window and its page is not in the working set,resident_and_writablereturns None andwritablecallsVirtualQuery. Peruma.rs:381-382that walks the whole window, about 40 ms a call on 4 GiB. Before this PR,readablereturned at once for that pointer. The samein_committed_windowcheck before the working-set query (the window is read-write as a whole, kernelx.rs:673) would keepnote_signaledoff that path. I did not trace whether a title'ssignaledpointer actually falls in a committed window, so the cost is the code path, not a measured slowdown.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T21:12:18Z.
Good catch, @upipibi — updated in
4f9c7ff6:writable(p, len)throughwritable_with_uma(uma, p, len)and restoredgpu::shader::readable'sUma::in_committed_window(p, len)fast path right after the null/zero/oversize/overflow guards and beforeresident_and_writable/VirtualQuery, keeping committed coherent UMA windows off the kernelVirtualQuerypath while falling through on cross-window straddles.writable_uses_committed_window_shortcut_and_falls_through_on_boundarycovering untouched non-resident pages inside a localUma::with_windows(1, 0x2_0000)window, aPAGE_GUARDshortcut proof (confirmingSome(&u)short-circuits beforeresident_and_writable/VirtualQuerywithout touching the guard page whileNonerejects), guard checks, and end-of-window straddle fallthrough.cargo clippy --all-targets -- -A clippy::approx_constant(0new warnings inframe.rs), 3x Debug WARP & 3x Release RTX 4060hle::d3d12x::frame::tests::(9/0/0,0skipped), full release workspace (1439/0/47), and paired 60 s smokes vs exact parentb49be183(1618vs1604frames,60 60 60,0rem/crash,14011vs13978 MB).Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:35:46Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:43:44Z.
Triage (#1607) – head
4f9c7ffMain commit
8aba55b("Frame clock: remove paced wait allocations and validate writes", "Adapted from #2692") contains this change inframe.rs:is_writable_protect/resident_and_writable/writable,note_signaledusingwritable,AncillaryHandles, the fixedhsarray inwait_frame_event_x, the scheduled-extra clone only when uncapped, andVecDequeforISSUED/FLIPPED, with tests.The one part main left out is the
writable_with_umashortcut throughUma::in_committed_window. As your own test shows, that shortcut returns true for aPAGE_GUARDpage inside a coherent window. If it is still wanted, it needs its own small PR that says why.Recommendation: close (superseded by main commit
8aba55b).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:58:04Z.
Closing as superseded: this change is already on
main(8aba55ba). main frame.rs has writable() check in note_signaled, AncillaryHandles stack array, VecDeque ISSUED/FLIPPED/ORIGINS and the Arc clone only when uncapped; same changes as the PRTwo independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed