Repository navigation
D3D12.X: remember committed source regions instead of asking Windows per submit - #3575
raylitebull wants to merge 1 commit into
Conversation
|
Review (head eab0ffb, diff read, not a merge-check; draft):
Fine: the lock is never held across a Windows call or around other locks, the replay of the 64 latest clears is right (a query that can't be replayed is dropped), holes are never cached (so commits and lazy commits need no hook), paired CPU views are covered, and memory is bounded. #2772, #1191 and #2544 edit the same kernelx hooks. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
eab0ffb to
15ae499
Compare
|
@Foniass thanks, the gaps were real, and most of them are on
AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead. |
|
Re-review (head 15ae499; the diff from eab0ffb read). Most of my review is addressed:
Still open:
Fine: AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
15ae499 to
9fd0f30
Compare
|
@Foniass thanks for the re-review. In 9fd0f30:
AI use: written by Capy (Claude Opus 5.5) and posted on raylitebull's behalf, with their go-ahead. |
|
Follow-up (head 9fd0f30; the diff from 15ae499 read). The open points from my re-review are addressed:
One detail: Still open, as before: no measurement on main and no smoke pair. The test run already queued for this PR will cover this head. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
Test report (not a merge-check: draft, AI-written and posted by Foniass without a human check of each point. |
…per submit holes_now asked Windows about every CPU-view tile a submit touched (K32QueryWorkingSetEx, then VirtualQuery for pages outside the working set) while holding the sparse lock, and shader::readable and read_committed_into walked VirtualQuery for title memory outside the coherent window. SourceRegions keeps the spans found committed and accessible. Only accessible spans are kept, so a commit needs no invalidation. Whatever takes pages away clears their span before Windows does it (no reader trusts it meanwhile) and after (nothing a query found in between stays): kernelx's VirtualFree, VirtualFreeEx, a VirtualProtect or a commit that leaves pages unreadable, physical pages given up (release_at, give_back_homes) and blocks FreeTitlePhysicalPages releases, GPU-view reservations, and sparse's own decommit, release and free paths. A free of size 0 clears the whole reservation, as long as XCL knows it (sparse and view windows, graphics reservations) or VirtualQuery finds it; nothing for a block of a committed window; and the whole cache only when the length is unknown. A query that raced a clear replays the latest 256 clears before inserting, or drops its result when it cannot. XCL_SOURCE_HOLES_CACHE=0 turns the cache off. Each unit test has a cache of its own, on only in the tests that turn it on, so tests that free memory without XCL's hooks leave nothing behind for others. Measured on amd-dev (3a3a8e9, RX 9070 XT, 5+ minutes in a retail title's world): asking Windows which pages are committed went from 1.513 ms avg / 10.233 ms max to 0.002 / 0.009 ms, the sparse lock per submit from 1.637 / 10.414 ms to 0.149 / 0.767 ms. Not measured on main. Ported from amd-dev 3a3a8e9, with the read_committed_into fast path from 4d6d4a7. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
9fd0f30 to
3e04ddb
Compare
Every submit asked Windows about each CPU-view tile it touched while holding the sparse lock: first
K32QueryWorkingSetEx, thenVirtualQueryfor the pages outside the working set.shader::readableandread_committed_intoalso walkedVirtualQueryfor title memory outside the coherent window. This PR keeps the spans found committed and accessible. Whatever takes pages away clears their span both before Windows does it and after. Onamd-dev(3a3a8e9c, RX 9070 XT, 5+ minutes in a retail title's world), asking Windows which pages are committed went from 1.513 ms avg / 10.233 ms max to 0.002 / 0.009 ms, and the sparse lock per submit from 1.637 / 10.414 ms to 0.149 / 0.767 ms.What is in it
sparse.rs:SourceRegions(sorted, coalesced spans plus a log of the latest 256 invalidations, so a query that raced one replays it or drops its result).holes_nowgoes throughsource_holes_cached, andknown_readable/cache_readable_regionserveshader::readable. Sparse's own decommit and release paths invalidate.XCL_SOURCE_HOLES_CACHE=0turns the cache off.sparse::freeclears after its decommit too. Each unit test has a cache of its own (tests::SOURCE_REGIONS), on only where a test turns it on (tests::REGION_CACHE), so tests that free memory with plainVirtualFreeleave nothing behind for others.kernelx.rs:VirtualFreeandVirtualAllocbecome wrappers (virtual_free/virtual_allochold the old bodies).VirtualFreeclears the span before and after every path (placeholders, sparse windows, GPU views, the general one). A free of size 0 clears the whole reservation (whole_len): its length comes from XCL's own records (sparse and view windows, graphics reservations) or fromVirtualQuery. A block of a committed window clears nothing, and the whole cache is cleared only when the length is unknown.VirtualAllocclears it around a commit that leaves pages unreadable. The same before-and-after clearing coversVirtualFreeExof the process's own memory, non-writableVirtualProtect(Ex),release_atandgive_back_homes(physical pages given up), the home blockFreeTitlePhysicalPagesreleases, and GPU-view reservations (mirrors::reserved). The clear after a call happens only when the call succeeded, so the title'sGetLastErroris untouched.gpu/shader.rs:readableanswers from the cache first, and records the regions it finds in UMA windows and graphics reservations.title_textures.rs:read_committed_intocopies at once when the range is known readable (from4d6d4a77).amd-dev: thealiashook (mainhas nokernelx::alias) and theXCL_LOOK_STATS=2timing lines.source_holes_cached_reuses_regions_and_invalidates_only_freed_ranges, andthe_title_s_frees_and_protections_leave_the_region_cache, which goes through kernelx'sVirtualFree(a decommit, then the release of a reservation with holes in it, while another allocation stays cached),VirtualProtectandVirtualAlloc.Tested
cargo check --workspace --all-targets --target x86_64-pc-windows-gnu: no errors, no new warnings.x86_64-pc-windows-gnuand run under Wine 9.0 (no GPU) with--test-threads=4, next to the same filters onmainb2b1f109:hle::d3d12x::sparse: 92 passed, 50 failed, 1 ignored (main: 90 / 50 / 1)hle::kernelx: 66 passed, 0 failed, 1 ignored (main: 66 / 0 / 1)gpu::shader: 4 passed, 2 failed (main: 4 / 2)hle::d3d12x::title_textures: 64 passed, 1 failed, 1 ignored (main: 64 / 1 / 1)The failures are the same tests on both, ones that need a D3D12 device or Windows' working-set queries, which Wine lacks.
Build and test (Windows, no GPU)passed on the earlier headseab0ffbaand15ae499c.Regression run
Not run yet: there was no Windows machine or title here.
scripts/smoke.ps1still has to run on a title, built frommainand from this head, soPR checksfails until those two blocks are added.Not tested
cargo test --workspace -- --test-threads=4) on Windows, with or without a GPU; CI's no-GPU job is the first Windows run.main, and any performance onmain: the numbers above are fromamd-dev.main, whose kernelx differs fromamd-dev's (noaliasmodule). The physical-page paths (release_at,FreeTitlePhysicalPages) are not covered by a unit test.whole_len'sVirtualQuerywalk on a title's frees of size 0 of plain memory (not UMA blocks or graphics reservations, which need no query).AI use
amd-devcommit3a3a8e9ctomain, split it into this PR and five others, and wrote the test, the commit message and this description. Theamd-devmeasurements are raylitebull's own runs.