D3D12.X: opt-in staged GPU compute detiling for swizzled 2D textures #3651
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3651"
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-12-02T03:46:07Z.
Adds an opt-in (
XCL_GPU_DETILE=1, default off) staged GPU compute detiling path intexture_upload::submit()usingcs_5_0shaders (compiled viaD3DCompile, no runtime DXC required) and the GF(2) offset tables fromgpu::tilingacross 1-, 2-, 4-, 8-, and 16-byte elements (R8,R16,RG8,RGBA8,BC1,BC7).When enabled, 2D swizzled non-tail pieces at or above
XCL_GPU_DETILE_MIN_BYTES(default 256 KiB) copy raw tiled blocks into the upload buffer and recordknownpage hashes on the CPU before detiling into a pooled DEFAULT-heap UAV scratch buffer ahead ofCopyTextureRegion. This preserves CPU detiling's source-read timing and unchanged-page deduplication. The default stays off until end-to-end GPU-time benefits are measured on heavy streaming workloads; the direct-UMA read path is split out for a separate follow-up PR.Total diff vs
main: 5 files changed,+781 / -34(+595 / -33runtime,+186 / -1unit/GPU tests).What is in it
crates/xcl/src/gpu/tiling.rs(+7):Layout::gpu_detile_tablesexposing the existingox,oy,hx,hyGF(2) tables and fixed XOR bits.crates/xcl/src/hle/d3d12x/gpu_detile.rs(+429,mod gpu_detileinmod.rs):XCL_GPU_DETILE=1(default off) andXCL_GPU_DETILE_MIN_BYTES(default256 KiB).cs_5_0compute shaders (1, 2, 4, 8, 16B elements),TablePacklayout deduplication, andeligible()filter (2D swizzled non-tail pieces meeting the size threshold).xcl-gpu-detile-init): both device-independentD3DCompile+D3D12SerializeRootSignature(cached inOnceLock) and per-queueCreateRootSignature+ 5×CreateComputePipelineStaterun off the submitting thread; uploads fall back cleanly to CPU detiling until ready.Slotis owned directly bytitle_textures::QueueUploadsand dropped ontitle_textures::forget_queue, with no global device cache and noID3D12Device::Releasehook (real.rsuntouched).Slot::pollstate transitions, env parsing, table deduplication, andeligible()filtering.crates/xcl/src/hle/d3d12x/texture_upload.rs(+338 / -29) andcrates/xcl/src/hle/d3d12x/title_textures.rs(+6 / -5):Work::RawBlocksstaging, pooled DEFAULT-heap UAV detile scratch buffer (ensure_detile_buf), UAV barrier andCOMMON/COPY_SOURCEtransitions, andJob::in_flight_bytes()accounted againstIN_FLIGHT_BYTES/IN_FLIGHT_MAX.take()ranks pooled jobs by smallest fitting upload buffer first (pool_rank), tie-breaking on detile scratch fit, so small GPU batches do not grab the largest pooled upload buffer.take_ranks_upload_size_before_scratch_fitandgpu_detile_matches_xg_for_all_element_sizes_and_64k_modes(R8, R16, RG8, RGBA8, BC1, BC7 × all four 64 KiB modes, whole textures, array slices, partial dirty-tile updates,knownpage hashing,in_flight_bytes()accounting, andSlot::FailedCPU fallback).Tested
32.0.16.1074), AMD Ryzen 9 9950X 16-Core, Windows 11 x64,rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.cargo build --release -p xcl: ok (39 pre-existingxcllib warnings, 0 new vsmain, 0 in changed code)..\scripts\test.ps1(with DXC 1.9.2609): 3010 passed, 0 failed, 52 ignored; 24SKIPPED(22no wave64, 2no heap windows; 0 DXC skips; all 6 newgpu_detileandtexture_uploadtests passed).cargo test -p xcl --lib gpu_detile -- --test-threads=1,cargo test -p xcl --lib texture_upload::tests -- --test-threads=1, andXCL_ADAPTER=warpcargo test -p xcl --lib texture_upload::tests::gpu_detile -- --test-threads=1): all passed, 0 skipped.Regression run
main:
PR (default,
XCL_GPU_DETILEunset):PR (opt-in,
XCL_GPU_DETILE=1):XCL_GPU_DETILEunset) vsmain:1696vs1698frames shown (99.9%),60 60 60vs60 61 60last presents per 2 s,0device removals,0crashes,17246vs15798MB peak commit (109.2%); GPU detiling stays inactive.XCL_GPU_DETILE=1) vsmain:1697vs1698frames shown (99.9%),60 61 60vs60 61 60last presents per 2 s,0device removals,0crashes,17256vs15798MB peak commit (109.2%,+10 MBvs default off).texture upload: GPU compute detiling active (min_bytes=262144)logged at 5.2 s with 0 Present stalls and 0 errors.Not tested
XCL_GPU_DETILEon by default).AI use
origin/main(817eb1fc9), stripped the direct-UMA path out for a separate follow-up PR, defaultedXCL_GPU_DETILEoff, movedGpuDetileownership into per-queueQueueUploads(removing the global cache andreal.rshook), moved bothD3DCompileand D3D12 PSO creation onto a background init thread, fixedtake()pool ranking with a unit test, and ran the release build, DXC 1.9 test suite, WARP test, and paired 60 s smokes.Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:41:59Z.
Diff review (head
d2a7bdba3, read-only code review — not a#3041merge-check):The GF(2) compute-detiling math (
gpu_detile_tablesox/oy/hx/hy/oz/hz, partial dirty-rectpitch/cols/span, mip-tail offsets, and thecs_5_0hlsl_packed/hlsl_directshaders) checks out cleanly againsttiling.rs::offset_z. Two lifetime/concurrency hazards should be resolved before enabling this by default:[HIGH] Device leak and ABA pointer-reuse UB in
gpu_detile::of(dev)(crates/xcl/src/hle/d3d12x/gpu_detile.rs:333-358):MADE: Mutex<Vec<(usize, Option<Arc<GpuDetile>>)>>caches up to 8(dev.as_raw() as usize, GpuDetile)entries permanently with no cleanup hook on device destruction. EachGpuDetileowns anID3D12RootSignatureand 5ID3D12PipelineStateobjects, pinning up to 8ID3D12Deviceinstances alive until process exit; worse, if a device is destroyed/evicted and a newID3D12Deviceis allocated at the same raw address (ABA),of(dev)returns PSOs/RS created on the dead device. Wiring aforget_device(dev: usize)cleanup hook on device release (matching other D3D12.X caches) closes both the leak and ABA hazard.[HIGH] Async direct-UMA read race when
XCL_GPU_DETILE_DIRECT=1(currently default ON) (crates/xcl/src/hle/d3d12x/gpu_detile.rs:193-199,crates/xcl/src/hle/d3d12x/texture_upload.rs:1048-1115,crates/xcl/src/hle/d3d12x/title_textures.rs:2658-2889):Previously,
texture_upload::submitsynchronously copied and detiled texels from the title's UMA memory into the staging upload buffer before returning. Withdirect_vaenabled by default,stage_with_gpu_detileperforms zero CPU copy for committed coherent UMA textures and submits an asynchronous computeDispatch(including on XCL's separateOWN_UPLOADSqueue) that reads live UMA memory directly, returning while theDispatchis still queued/in-flight. Any CPU-thread overwrite or buffer reuse of that coherent UMA memory before the upload fence completes will tear/corrupt the uploaded texture. Either defaultingXCL_GPU_DETILE_DIRECToff (until CPU-write synchronization is guaranteed) or fencing/copying mutable staging sources avoids silent texture corruption.[Scope] Diff size (
+1123/-19) & default-ON cross-GPU coverage:Since the PR is >800 lines and turns both
XCL_GPU_DETILEandXCL_GPU_DETILE_DIRECTon by default across all vendors while tested only on NVIDIA + WARP so far, splitting direct-UMA reading into a small follow-up PR (after verifying packed GPU detile across NVIDIA + AMD/Wine) would reduce risk and keep each PR under the 800-line guideline.AI use: Antigravity (Gemini 4 Neon) audited the full diff against
mainand drafted this review.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:46:13Z.
Review (head
d2a7bdba, diff read, not a merge-check):title_textures.rs ~2689addsf.bytesto the queue's in-flight bytes, andJob.bytesis only the UPLOAD buffer. On the GPU path that buffer holds the tables plus any copied raw blocks, so a batch of direct pieces is aboutBUFFER_MIN(1 MiB) (texture_upload.rs ~1067,take(dev, plan.upload_bytes)). Each job also holds a DEFAULT-heapdetile_bufthe size of the batch's linear texels (ensure_detile_buf ~879). SoIN_FLIGHT_BYTES/IN_FLIGHT_MAXno longer limit what is in flight: up to about 2048 jobs, each with its own VRAM scratch.take()picks a pooled job by upload size only, and the pool keeps 64 MiB of scratch. A large batch therefore makes a new committed DEFAULT buffer on the submitting thread. The smoke block reports commit, not VRAM.directclosures tostage_with_gpu_detile, sogpu_detile::direct_va(uma_device()check,in_committed_window,uma_va_ofonto the real window buffers) never runs with a positive result. The "device guard" assertion (texture_upload.rs ~1774,direct_va(&dev, bc7_src, ..) == None) cannot fail:bc7_srcis aVirtualAllocoutside every UMA window, soin_committed_windoworexisting()returns None before the device is compared.Hashes::forget ~633). A later write is still uploaded, but every write-watch hit on those pages now re-uploads with no hash comparison. That is a cost the throughput table cannot show: the table measures CPU staging cycles only, not the GPU time of the up to 118 dispatches.gpu_detile_tablesplus thegpu_detilemodule and its tests, not called yet; staged GPU detiling insubmit(); direct UMA reads; and thebenches/formats.rsdetile_blocksbench. The bench measures the CPUdetile_blockspath and is unrelated to the GPU change.Fine: the swizzle math matches
Layout::offset_z/detile_blocks(sameox/oy/hx/hy, sliceoz^hz^base_xor, power-of-two masks enforced ineligible). Direct reads stay insidespan((rows-1)*pitch+colsblocks, block stride matchingblock_at), and committed, non-shadowed windows are required. The scratch barriers (COMMON→UAV→COPY_SOURCE→COMMON) are right. Every failure (no PSO, no scratch, size overflow) falls back to the CPU path. Both switches are on by default. Merges cleanly with #3653 / #3662 / #3665: their new trailing view windows are not committed windows, so textures there keep the copy path.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-02T10:46:14Z.
merge-check
base:
1c8b551475head:
d2a7bdba3bmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2915 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 by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3651#issuecomment-7339902907 and its findings stand. Most serious: the VRAM scratch for detiling isn't counted in the in-flight cap, and the real direct path has no test.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (d2a7bdba): 1652 -> 1426 frames shown (86 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 18099 MB, 0 device removals, 0 crashes. This run is lower than most today: the PC was in use at the time (a browser and Discord running), and main's own runs on this machine today ranged from 1370 to 1652 frames, so the difference isn't clearly from this PR.verdict: not yet: the VRAM scratch for detiling isn't counted in the in-flight cap, and the real direct path has no test (see the review)
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-02T14:57:02Z.
Rebased onto
origin/main(5eaadb54c) and updated to5d0b81e4aaddressing all points from @Decodere and @Foniass:gpu_detile::of(@Decodere #1): Wiredgpu_detile::take_device/forget_deviceintoID3D12Device::Release(real::dev_releaseviarelease_taking_firstinoverrides(Kind::Device)) so cached root signatures and PSOs are evicted beforeIUnknown::Releasecan free or reuse the device address. Covered bygpu_detile::tests::forget_device_evicts_cached_entryandreal::heap_release_order_tests::device_release_evicts_gpu_detile_before_address_reuse.Job.bytesprivate and addedJob::in_flight_bytes()(bytes + detile_bytes), used bytitle_textures.rs(submit_on/reclaim) soIN_FLIGHT_BYTES/IN_FLIGHT_MAXbound both UPLOAD staging and DEFAULT detile scratch. Updatedtake(dev, bytes, detile_bytes)to prefer pooled jobs whosedetile_bufalready fitsdetile_bytes(or jobs without adetile_bufwhendetile_bytes == 0).XCL_GPU_DETILE_DIRECTdefaulted OFF & read-timing/hash-forget semantics documented (@Decodere #2, @Foniass #3):XCL_GPU_DETILE_DIRECTnow requires explicit=1opt-in; default (XCL_GPU_DETILE=1,XCL_GPU_DETILE_DIRECT=0) uses staged packed GPU detiling, copying raw blocks and hashing pages at submit so source-read timing andknown-page deduplication match CPU detiling. The PR description andgpu_detile.rsdoc comments state the live-read timing andHashes::forgetre-upload tradeoff of opt-inXCL_GPU_DETILE_DIRECT=1.gpu_detile::direct_vaand productionsubmit()(@Foniass #2): Replaced theVirtualAllocassertion with isolated subprocess testgpu_detile_direct_va_uses_real_uma_window_and_rejects_other_device(XCL_GPU_DETILE_DIRECT=1), which opens a real committed coherent UMA window viareal::open_uma_for_test, asserts positivedirect_va(&dev, src, len) == Some(uma_va_of(src)), asserts wrong-device rejection on that exact committed UMA address, checks alignment/OOB rejection, and executes productiontexture_upload::submit()over a 9-mip BC7 chain (incl. mip tail) withDISPATCHESdelta == 9,in_flight_bytes() == bytes + detile_bytes, and bit-exact readback.crates/xcl/benches/formats.rschange and added a size justification to the PR description (~560 lines runtime + ~740 lines tests, with direct UMA opt-in).Re-verified on RTX 5070 Ti + WARP (
cargo build --release -p xcl: 39 lib warnings, 0 new;scripts/test.ps1with DXC 1.9: 2983 passed / 0 failed / 52 ignored / 24SKIPPED[22no wave64, 2no heap windows]; clean 60 s smoke vs5eaadb54c: 1657 vs 1698 frames,61 61 60presents/2s, 0 removals, 0 crashes, 17593 vs 15798 MB commit).AI use: Antigravity (Gemini 4 Neon) implemented these review fixes, ran the tests and smoke, and drafted this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T18:01:56Z.
merge-check
base:
5eaadb54c1head:
5d0b81e4a9merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2983 passed, 0 failed, 52 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: follow-up on
5d0b81e4(reworked and rebased fromd2a7bdba, my last review's head). Now one commit of +1298/-26 in 6 files; thebenches/formats.rshunk is gone. Reading straight from the UMA window is now opt-in (XCL_GPU_DETILE_DIRECT=1); the default path copies the raw tiled blocks into the upload buffer (hashing them on the CPU), then detiles them on the GPU for pieces of at least 256 KiB. A pooled DEFAULT-heap scratch buffer is counted throughJob::in_flight_bytes(),ID3D12Device::Releasegets a hook to evict the per-device pipeline cache, and a child-process test coversdirect_vaandsubmit()on a real committed window. Earlier findings: (1) scratch missing from the in-flight cap: fixed (title_textures.rs~2620 / ~2705 add and subtractin_flight_bytes()); a large batch still creates a committed DEFAULT buffer on the submitting thread (ensure_detile_buf,texture_upload.rs~886). (2) the direct path untested: fixed (gpu_detile_direct_va_uses_real_uma_window_and_rejects_other_device, ~1735). (3) source-read timing not stated: fixed for the default path. (4) size: partly fixed; the bench is dropped and there's a size note, but it says only that the parts were kept together, its "~560 lines of runtime code" is about 785 by count, and the opt-in direct path (direct_va*,uma_device,open_uma_for_test,Hashes::forget, thedirectbranches, two GPU tests) is still a separable second PR. New: (a) GPU detiling is on by default for every title with no measured benefit: the throughput harness prints CPU cycles only, the dispatches' GPU time isn't measured, and the PR's own smoke shows 97.6 % frames and peak commit 15798 -> 17593 MB (111.4 %), unexplained; the default path also needs a DEFAULT scratch buffer the size of the linear data on top of the upload buffer. (b) Thedev_releasehook (real.rs~4835) runs on every device Release and evicts only whenrelease_taking_firstsees the last reference, which device children likely never allow on a real device; the ABA protection is shown only on a fake refcounted object (~15409). (c) The first eligible upload compiles fivecs_5_0shaders withD3DCompileinsideown_workon the submitting thread (gpu_detile.rs~366), a one-time stall on the title's thread. (d)take()withdetile_bytes > 0(texture_upload.rs~926) ranks by scratch fit before upload size, so a small GPU batch can take the largest pooled upload buffer. Fine: the swizzle math matchesoffset_z/detile_blocks;RawBlocksreads the same block runs asWork::Blocksand notes their pages the same way; the scratch barriers are right; every failure falls back to the CPU path; the default path is checked bit-exact for R8 / R16 / RG8 / RGBA8 / BC1 / BC7 in the four 64 KiB modes.performance: 60 s smoke of a retail title, main
5eaadb54vs this merge (5d0b81e4): 1422 -> 1675 frames shown (117 %; last presents per 2 s: 60 60 61), peak commit 17184 -> 16410 MB, 0 device removals, 0 crashes.verdict: not yet: GPU detiling is now on by default for every title with no measured benefit (its own smoke shows 97.6 % frames and +1.8 GB peak commit), bundled with the separable opt-in direct-UMA path in a 1298-line PR (see the review)
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-02T18:26:44Z.
Review: COMMENTED
Review of
5d0b81e4: 1 finding(s) (1 medium), most severe first.crates/xcl/src/hle/d3d12x/real.rs:4837: Not certain about this one, because it depends on D3D12 device children holding a reference on their device: the newdev_releasehook probably never evicts the gpu_detile cache for a real device. (inline)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-02T18:26:45Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 4837Medium: Not certain about this one, because it depends on D3D12 device children holding a reference on their device: the new
dev_releasehook probably never evicts the gpu_detile cache for a real device. The cached root signature and five PSOs are device children, so while the entry exists the device refcount never drops to the value the AddRef probe looks for. After one large GPU-detiled upload, the title's final Release leaves the device, its PSOs and the MADE slot alive for the life of the process (up to 8 devices before FIFO eviction). If children don't hold that reference, the opposite problem appears:release_taking_firstdrops the taken PSOs inafteronly after the final Release has already freed the device. The unit test uses a fake object with no child references, so it can't tell the two apart. Evicting from an explicit device-teardown point, or holding the cache by weak/private-data association, would avoid both.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:26:46Z.
@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-02T18:41:13Z.
Thanks @Foniass and @bmjask for the thorough reviews — reworked and rebased onto
origin/main(817eb1fc9) as72a12a04f(+781 / -34across 5 files:+595 / -33runtime,+186 / -1tests):direct_va*,uma_device,open_uma_for_test,Hashes::forget, direct branches and direct GPU tests) for a separate follow-up PR so this PR covers staged GPU compute detiling only and stays cleanly scoped.XCL_GPU_DETILEOFF (opt-inXCL_GPU_DETILE=1) until end-to-end GPU-time vs CPU-time gains are measured on heavy streaming workloads.@Foniass(b) &@bmjaskreal.rs:4837): removed the globalMADEcache and thedev_releasehook completely (crates/xcl/src/hle/d3d12x/real.rsis untouched vsmain). Each upload queue now owns itsgpu_detile::Slotdirectly insidetitle_textures::QueueUploadsand drops it intitle_textures::forget_queue.@Foniass(c)): moved both device-independentD3DCompile+D3D12SerializeRootSignatureand per-queueCreateRootSignature+ 5×CreateComputePipelineStateonto background threadxcl-gpu-detile-init, falling back transparently to CPU detiling until ready (slot_poll_is_non_blocking_until_background_init_finishes). (TestingXCL_GPU_DETILE=1during the initial smoke caught thatCreateComputePipelineStatealone contended with startup background PSO compiles for 12.3 s when left on the submitting thread; moving PSO creation off-thread too eliminated the stall completely.)take()pool ranking (@Foniass(d)):pool_ranknow ranks pooled jobs by smallest fitting upload buffer first and tie-breaks on detile scratch fit, with unit testtake_ranks_upload_size_before_scratch_fit.Verification on
72a12a04f(RTX 5070 Ti, driver32.0.16.1074, Ryzen 9 9950X, Windows 11 x64,rustc 1.99.0, DXC 1.9.2609):cargo build --release -p xcl: ok (39 pre-existing warnings, 0 new)..\scripts\test.ps1: 3010 passed, 0 failed, 52 ignored; 24SKIPPED(22 no wave64, 2 no heap windows; 0 DXC skips), plus targeted WARPgpu_detile_matches_xg_for_all_element_sizes_and_64k_modespass.title: ea3b5e4d,main5eaadb54c:1698frames,15798 MBpeak commit):XCL_GPU_DETILEunset):1696frames (99.9%),60 60 60,0removals,0crashes,17246 MBpeak commit.XCL_GPU_DETILE=1):1697frames (99.9%),60 61 60,0removals,0crashes,17256 MBpeak commit (GPU compute detiling activeat 5.2 s, 0 Present stalls).Ready for re-check. (Update authored with Antigravity, Gemini 4 Neon.)
Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-03T01:09:41Z.
merge-check claim
head:
72a12a04f7Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-03T01:16:55Z.
merge-check
base:
078358a058head:
72a12a04f7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3012 passed, 0 failed, 52 ignored (44 test binaries); SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none. All 6 tests the PR adds ran and passed, gpu_detile_matches_xg_for_all_element_sizes_and_64k_modes on the RTX 4070 SUPER (not skipped). git diff --check clean; 39 compiler warnings, the same as main.
title run: not run
review: (1) Off by default, and the default path is unchanged: with XCL_GPU_DETILE unset, submit() passes no minimum, so no GPU plan is made and the Slot never starts its init thread. take() ranks by upload size alone when no pooled job has scratch (pool_rank reduces to (bytes, false, 0)), in_flight_bytes() equals bytes, and give_back's scratch trim does nothing. (2) With XCL_GPU_DETILE=1: when no pooled scratch fits, the batch's DEFAULT scratch buffer is created on the submitting thread (ensure_detile_buf, texture_upload.rs ~631); Foniass's earlier point, still the case. The benefit is unmeasured (the PR keeps it off for that reason), and no run with it on is reported here. (3) The bit-for-bit GPU test ran here on NVIDIA only; no AMD run here (the PR is gpu:both). (4) Open #3747 (same author) conflicts with this PR in texture_upload.rs and title_textures.rs (git merge-tree); whichever lands second has to adapt. Checked and fine: the compute shaders use the same GF(2) tables as Layout::offset_z (Layout::gpu_detile_tables, tiling.rs:254). The GPU test compares against xg's CPU detile bit for bit for 1/2/4/8/16-byte elements in four 64 KiB modes, including partial rectangles, array slices, page hashing and the CPU fallback. The 1- and 2-byte forms pack 4/E elements per dword and stay inside the 256-byte-aligned row pitch. eligible() keeps 3D textures, mip tails, non-power-of-two layouts and pieces over 4 GiB on the CPU. RawBlocks reads through the same read() and note() as the CPU path, so source-read timing and page hashing don't change. The scratch buffer goes COMMON -> UAV for the dispatches, UAV -> COPY_SOURCE before the copies and back to COMMON after, and it counts against the in-flight cap. D3DCompile and PSO creation run on the xcl-gpu-detile-init thread, and uploads stay on the CPU path until it's ready. The Slot belongs to its upload queue and is dropped in forget_queue; real.rs is untouched. Duplicates: I searched open and merged PRs for GPU detile, compute detile, detiling compute shader, XCL_GPU_DETILE, gpu_detile, detile on the GPU, swizzled textures GPU and untile compute, and checked #1607's groups (none lists 3651). No open PR makes the same change. Closed #1513 (not merged) took the same approach (GPU detile into a scratch UAV, also behind XCL_GPU_DETILE).
performance: Default: no cost (reasoned: the feature is off and the default path is unchanged, review (1)). With XCL_GPU_DETILE=1 (not measured): a DEFAULT scratch buffer the size of the batch's linear data on top of the upload buffer, at most 64 MiB of it kept pooled (DETILE_FREE_BYTES), counted against the in-flight cap.
verdict: safe to merge: off by default with the default path unchanged, no blocking finding, and the suite passes, the bit-for-bit GPU test included. Its benefit when switched on is still unmeasured.
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T10:55:14Z.
merge-check
base:
16c2fd082ahead:
72a12a04f7merge: clean
build: ok
tests: 3018 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 1 medium, 3 nits (below)
performance: 60 s smoke run: 1683 → 1652 frames (98 % of main), peak commit 18505 → 18585 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 232 s there, 0 device removals, 0 crashes, 2.8 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Adds opt-in (XCL_GPU_DETILE=1) staged GPU compute detiling: raw tiled blocks are copied and hashed on the CPU, then detiled by cs_5_0 shaders into a pooled DEFAULT scratch buffer before CopyTextureRegion. The rework fixes my last merge-check's points: it is off by default, the direct-UMA path is split out, init runs off-thread, the pipelines belong to each queue, and the pool ranking is fixed. With the switch unset the default path is unchanged. Nothing blocks.
Medium
Nit
Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.