D3D12.X: disable lazy level pages when a sampled texture aliases a live GPU page #3188
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3188"
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-28T17:05:33Z.
Port of
amd-devdece6dd9(part 1, by @raylitebull) tonvidia-dev.Under
XCL_TEXTURE_LEVEL_PAGES=1,vram::place_pagessetslazy = truefor every sampled 2D single-slice texture (D3D12_RESOURCE_FLAG_NONE), deferring tile mapping untilmap_levels_with_texelssees non-zero CPU texels at the placement VA. When a sampled texture is placed at the same 64 KiB-aligned VA as a live GPU-owned texture (render target, depth buffer, or UAV), CPU memory at that VA is all zeros, so its tiles are never mapped and shaders read zeros. Mapping eagerly whenPages::pagesalready holds a live page atcanonical_va(va)reuses the existing shared pages at zero extra VRAM cost.This is separate from #3116 (which issues a NULL-range
UpdateTileMappingsand fence wait on lazy placement to avoid page faults) and #3094 (XCL_ALIAS_COPY=1, which copies across different formats).What is in it
crates/xcl/src/hle/d3d12x/vram.rs: addhas_live_pageandshould_use_lazy_levels, and disable lazy level pages inplace_pageswhenva % PAGE == 0andPages::pagesalready containscanonical_va(va).vram::tests::should_use_lazy_levels_skips_gpu_aliased_sampled_textures.vram::tests::gpu_sampled_texture_aliasing_live_gpu_target_maps_eagerly_with_level_pages: places anR8G8B8A8_UNORMrender target at a 64 KiB-aligned VA, clears it on the GPU, places a sampledR8G8B8A8_UNORMtexture at the same VA withLEVEL_PAGES_FOR_TEST = true, and asserts!has_lazy_levels(srv)and that reading back the sampled view returns the cleared texels[64, 128, 192, 255].Tested
cargo test --release -p xcl --lib -- should_use_lazy_levels gpu_sampled_texture_aliasing --nocapture: 2 passed, 0 failed.Not tested
Regression run
150 s each, same title (
ea3b5e4d), same GPU (NVIDIA GeForce RTX 5070 Ti), release build, warm DXIL cache (XCL_DIRECT_DXIL=all,XCL_HEAP_WINDOWS=1,XCL_DRED=1).main(b49be183):nvidia-devbase (54225f58):This PR's head (
ae348ff5):AI use
Antigravity (Gemini 4 Neon) ported the change, wrote the GPU test, ran the tests and smoke run, and drafted this description.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T17:30:53Z.
At
ae348ff5a6cfaf857455742e6ba345937e8aac85on RTX 5070 12 GB, driver 616.92, the sampled texture reused all four pages when the producer covered it completely. With a smaller producer at the same start address, it reused one page and acquired three more.The sampled texture was 256×256 RGBA8 (four 64 KiB tiles). In each fresh process I GPU-cleared a live RGBA8 render target, waited for the queue, then placed the sampled texture with level pages enabled. I compared the pool/tile identities and XCL's per-device allocated texture-page counter before and after the sampled placement.
For these aligned resources, a live first page triggered eager placement of the entire sampled texture. A live second page alone did not. The 192 KiB is the increase in XCL's allocated texture-page accounting for the three previously absent pages; DXGI residency and heap capacity were not measured. Four focused tests passed, zero skipped. Retail title behavior was outside this test.
AI use: OpenAI Codex (GPT-6) prepared the test-only fixture, ran the four native controls and wrote the report.
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-28T18:20:59Z.
Ran the aliased lazy-level-page tests at
ae348ff5on an NVIDIA Blackwell desktop part; the GPU test ran here, with no SKIPPED line.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib should_use_lazy_levels_skips_gpu_aliased_sampled_textures -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_sampled_texture_aliasing_live_gpu_target_maps_eagerly_with_level_pages -- --test-threads=1: 1 passed, 0 failed, 0 ignored.What this adds
Both tests pass: a sampled texture whose VA aliases a live GPU target skips lazy level pages, and the readback sees the target's cleared texels. The thread already has an RTX 5070 12 GB report; this adds a Blackwell 5070 Ti datapoint. These are synthetic tests, not a title launch.
Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T20:31:41Z.
Source review of head
74ef846. Three focused points before treating the GPU fixture as merge evidence:has_live_pagetests membership inPages::pages, butbind_rangepopulates that map for ordinary sampled uploads as well. A live one-tile sampled texture at VA A followed by a four-tile sampled texture at A therefore selects eager placement, allocates the three missing tiles (192 KiB), and loses per-level reclamation without any GPU-owned producer. The current partial-overlap report covers a GPU target, not this sampled-only control. The eager decision needs producer ownership, not just page presence; please add that control and a released-producer case.The GPU fixture clears the producer in
RENDER_TARGETand creates the reserved sampled alias inCOPY_SOURCE. Its fence orders commands, but does not make those states compatible for per-tile data inheritance. Microsoft's D3D12 rule requires these reserved textures to be inCOMMONfor that inheritance, with an aliasing barrier between uses. Transition the producer toCOMMONafter the clear, create the alias inCOMMON, issue the aliasing barrier, then transition/promote the alias for readback.The fixture's
tier2(&dev)guard checksResourceHeapTier, whilePages::newrequiresTiledResourcesTier >= 2. Check both capabilities before asserting a live page, so a heap-tier-2/tiled-tier-1 adapter skips this fixture correctly.Update — RTX 3080 Ti reproduction of point 1. I extended the existing GPU fixture with an unaliased sampled control, then placed a one-tile sampled texture at another VA and a four-tile sampled texture at the same VA. The control remained lazy. On the unchanged head
74ef846, the sampled-only overlap became eager and allocated 196,608 additional page bytes.cargo test --offline --locked -j 4 -p xcl --lib gpu_sampled_texture_aliasing_live_gpu_target_maps_eagerly_with_level_pages -- --test-threads=1: 0 passed, 1 failed, 0 ignored, zero skips (Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC). The original GPU-target readback and unaliased control completed before this assertion. This is a test-only regression; no production fix or title behavior was tested.Test-only regression diff on
74ef846For a production fix, count GPU-owned references on each physical
OwnorExtrapage key alongside total users. After resource tiling is known, check the keys the sampled binding would acquire under the samePAGESlock that commits the placement, stopping at the first producer. Keep the count through a deferred unmap; decrement when its NULL mapping completes or the last producer releases, and restore it on a fresh remap. A sampled user can keep a page resident without a producer. This avoids sampled/idle false positives and a check-to-bind race without scanning every target. Add controls for last-producer release with a sampled user remaining, two overlapping producers, a later-page overlap, and producer bind/release during sampled creation. This ownership design is source-reviewed, not implemented or tested here. Points 2 and 3 above remain source review only. The description's smoke block still namesae348ff5, so the current74ef846head also needs its required clean-head block. AI use: Codex (GPT-6.2 Astra) traced the pinned code and ownership lifecycle; Codex (GPT-6.2 Sol) checked the execution paths, ran the synthetic RTX regression, and wrote this review.Imported from ivall/xcl. Originally posted by throny on 2026-11-28T21:08:01Z.
merge-check claim
head:
74ef846124Imported from ivall/xcl. Originally posted by throny on 2026-11-28T21:36:51Z.
merge-check
base:
beeb81behead:
74ef846124merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2596 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at
beeb81be(main after the merge of nvidia-dev): 2594 passed, 0 failed, 49 ignored.review: the tests pass, but the points of the earlier review in the thread are unanswered and hold in the source. (1) The alias test only asks whether the first page at the texture's address exists in the page table. That table also holds the pages of other sampled textures and idle pages kept for a short time, so a sampled texture placed where another sampled texture was also loses its lazy levels; and a target that begins one page later (or an address that is not page-aligned) is not seen, so that case still reads zeros. (2) When it triggers, every level of the texture gets pages; only the tiles shared with the target cost nothing, so "zero extra video memory" in the description does not hold in general. (3) The check takes the pages lock on every placement even when level pages are off (the default); asking the switch first would avoid that. Also open: the GPU fixture relies on data surviving a state change that D3D12 does not promise, checks the heap tier where it means the tiled-resources tier, and prints SKIPPED itself instead of using skip_test. The smoke blocks in the description are for an earlier head, so the description check is red. No conflict with #3179 or #3192 (another file).
performance: default runs pay one extra lock per placement; with level pages on, more memory for each texture it triggers on. No translator source.
verdict: not yet: narrow the alias test to live targets (and to the texture's whole range), and refresh the smoke blocks.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T12:08:49Z.
Re-ran the aliased lazy-level-page tests at
74ef8461after the head moved fromae348ff5; this is a new response in the same thread, not an edit of my earlier report: https://github.com/xcl-dev/xcl/pull/3188#issuecomment-7243722612System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib should_use_lazy_levels_skips_gpu_aliased_sampled_textures -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_sampled_texture_aliasing_live_gpu_target_maps_eagerly_with_level_pages -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The GPU test ran here, with no SKIPPED line.What this adds
Both tests still pass at the new head: a sampled texture whose VA aliases a live GPU target skips lazy level pages and reads back the target's cleared texels. This adds the new head and driver 32.0.16.2140 as dimensions; I did not run a title.
Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by ettehn on 2026-11-30T07:31:26Z.
I prototyped the producer-ownership approach from the review above on main
d52ff48c. The current74ef8461also conflicts invram.rsagainst that base.The candidate counts mapped GPU owners by exact
OwnandExtrakeys. After tiling, the sampled placement usesowned_pagesand the actual PC tile count to query only the keys it would bind. The ordered index supports range lookups inside the existing placement lock. A deferred unmap keeps the producer entries through the title-queue wait and drops them when the NULL mapping is submitted. Cancelling that unmap transfers the same owners back.Windows Release CPU tests on the local candidate passed 6/6, including later and unaligned overlap, exact extra-tile keys, the last of two producer releases, and the existing level-ownership controls. A positive overlap still maps the entire texture, including non-shared tiles.
Native GPU follow-up. Windows Release on an RTX 5070 Ti Laptop (621.24). The combined synthetic run passed 7/7 with zero skips. Two 128×128 RGBA8 reserved textures shared one physical page. With the producer transitioned to
COMMON, an aliasing barrier and a fenced copy, all 16,384 pixels matched the GPU clear. After releasing the producer’s mapping, a sampled-only placement stayed lazy. A separate control verified that a 256×256 sampled texture reused the existing physical tile when the only GPU producer began on its second page. The latter control checked mapping metadata. Streaming cost remains unmeasured. D3D12 aliasing and data inheritanceOpenAI Codex (GPT-6.2 Sol) assisted with implementation and Windows verification.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:21:22Z.
Review (head
c8faf777, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):has_live_page(vram.rs~2972-2975) only asks whetherPages::pagesholds the address, and that map also holds pages of sampled textures and idle pages with no users, kept for 2 s (release_tiles,IDLE). So a streamed texture placed again at the same address maps all its levels eagerly, undoing level pages for exactly the textures the feature saves memory on. Checking that the page has users and that a GPU-written target owns it would fix that.place_pagescall even with level pages off (~2999); testinglevel_pages()first would avoid the extra lock and lookups.XCL_TEXTURE_LEVEL_PAGES=1, so it never reached this code, and it ran onae348ff5(on top of nvidia-dev) rather than this head, which is whyPR descriptionfails. The full suite wasn't run.println!("SKIPPED...")(~5687) instead ofskip_test, and fails rather than skips if the target falls back to an arena.Fine: the diagnosis matches main (lazy levels only get pages from non-zero CPU texels,
map_levels_with_texels_in), the GPU test fails without the change and holdsVRAM_TEST_LOCKand resetsLEVEL_PAGES_FOR_TEST, and with level pages off placement behaves as before.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T16:48:27Z.
Test report (not a merge-check:
PR descriptionred)base:
b2b1f109d2head:
c8faf77790merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 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: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3188#issuecomment-7301684158, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
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 Kalmarv on 2026-12-02T19:38:03Z.
Closing: conflicts in
vram.rsand review showed the alias check undoes lazy level pages for sampled textures; not worth rebasing.Pull request closed