Skip to content

D3D12.X: process 2D texture tiling in contiguous block runs - #2820

Open
KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-tiling-block-runs
Open

KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-tiling-block-runs

Conversation

@KOLESNiii

Copy link
Copy Markdown

Part of #1833. This is T1 from the extraction plan in #2787. It takes b81ac2eb from #2778 (bmjask), unchanged. That commit adapts raylitebull's 032c661a block-slab algorithm.

CPU texture tiling and detiling in gpu/tiling.rs went through swizzled 2D textures one element at a time and worked out each element's block position again. For each GFX10 layout, this caches the longest horizontal run that is provably contiguous, works on one 4 KiB / 64 KiB block at a time, and copies whole runs in one go. It keeps the element-by-element bounds checks for a truncated source. Low base-swizzle bits make the runs shorter. Thick 3D single-slice helpers keep their existing path. The persistent detile workers (6dd9d53f) are not included.

What is in it

  • D3D12.X: process 2D texture tiling in contiguous block runs (crates/xcl/src/gpu/tiling.rs), cherry-picked with -x from b81ac2eb. Its two new tests compare tiled and detiled output with the element-by-element path, including base XOR.

Tested

  • NVIDIA GeForce RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, rustc 1.100.0, debug tests and a release smoke run
  • cargo test --workspace -- --test-threads=4 on 065f31bb: 1437 passed, 0 failed, 47 ignored
  • 25 SKIPPED on this adapter: 24 recompiler GPU tests with no wave64 (or the wave32 per-lane form refused), and heap_window_out_of_memory_falls_back_to_the_switch_form with no heap windows
  • Byte parity and timing: retrope13 measured this commit on main b49be183 (RTX 4060 Laptop, i5-14500HX, release) in #2787. Output checksums were identical in all 8 cases. 1920×1080 R8 mode 5 detile went from 18.75 to 0.59 ms. 2048×2048 RGBA8 mode 10 detile went from 40.14 to 5.48 ms. 2048×2048 BC7 detile went from 2.84 to 1.11 ms. I did not repeat that benchmark.

Regression run

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1480 (PresentX 1480)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17754 MB

This PR:

xcl-smoke v1
commit: 065f31bbcd08b891af2b144d045feecd4a04fcd7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1414 (PresentX 1414)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17752 MB

Not tested

  • How much this changes world-load time on the retail title. The 60 s smoke run is a regression check only, and I did not measure the time spent detiling during it.
  • AMD and Intel GPUs. The 47 ignored tests.

AI use

  • Claude Code (Claude Opus 5.5) chose this item from Plan for extracting focused PRs from #2778 #2787, cherry-picked it, ran the tests and smoke runs, and wrote this description. The source commit's own message names the tools that wrote it (Codex, Antigravity).

🤖 Generated with Claude Code

The existing row-factorized detiler still visited swizzled textures one element at a time and recalculated block placement for every element. Large CPU-written textures therefore consumed milliseconds on the submit path even after persistent detile workers.

Adapt raylitebull's 032c661 block-slab algorithm: cache the largest provably contiguous horizontal run for each immutable GFX10 layout, keep one 4 KiB/64 KiB block hot at a time, bulk-copy complete runs, and retain element-wise bounds checks for a truncated source. Low-bit base swizzles shorten runs safely; thick 3D single-slice helpers retain their former path.

On this AMD EPYC 7R13 Linux host, an isolated release benchmark against 032c661's parent reduced 1920x1080 R8 mode-5 detile from 8.8-10.3 ms to 0.76-0.87 ms and tile from 28-31 ms to 0.64-0.78 ms. A 2048x2048 RGBA8 mode-10 detile fell from 28-31 ms to 9.7-11.8 ms and tile from 59-67 ms to 5.8-6.9 ms.

All 17 isolated pure tiling tests passed. The Windows GNU library/test cross-check passed with the existing warnings; Windows MSVC, GPU, and smoke tests were unavailable.

Source algorithm: 032c661 by raylitebull, assisted by Antigravity (Gemini 4 Neon High).

Assisted-by: Codex (GPT-5.6-sol)
(cherry picked from commit b81ac2e)
@KOLESNiii
KOLESNiii marked this pull request as ready for review November 26, 2026 14:32
@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the texture-tiling tests at 065f31b:

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.

XCL_ADAPTER=nvidia cargo test -p xcl --lib gpu::tiling -- --test-threads=1 --nocapture
17 passed; 0 failed; 0 ignored; 1321 filtered out      (exit 0)

All 17 pass, including the two new parity tests (tile_level_matches_element_by_element_and_exploits_contiguous_runs, low_base_xor_bits_bound_runs_without_changing_bytes). This is CPU-side tiling; the adapter is not involved in the comparison.

What this adds: the author ran the suite on an RTX 2070 SUPER and the benchmark on an RTX 4060 Laptop (in a separate issue). This host verifies the cherry-pick on a Blackwell machine; I did not repeat the timing benchmark.

Not tested: the full workspace suite, a paired 60 s smoke run, the release timing numbers, AMD and Intel GPUs, native wave64, 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.

@SzczepanGrela

Copy link
Copy Markdown

Paired Wine release measurements on Ryzen 7 7700, plus RX 9070 upload/readback checks.

Tested

  • Head 065f31bbcd08b891af2b144d045feecd4a04fcd7 against main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • Production sources unchanged on both revisions. Both receive identical local test-only fixtures for CPU parity/timing and GPU upload/readback. Removing those appended fixtures reconstructs the pinned source hashes.

CPU conversion

Original gpu::tiling::tests:: module: head 17 passed, main 15 passed, with both --test-threads=1 and 4. No failures or ignored tests.

The local timing fixture uses Chain::detile_level and Chain::tile_level, level 0 / slice 0, with PipeConfig { pipes_log2: 0, pkrs_log2: 0 }. Detile includes its output allocation; tile writes into a preallocated destination. Reference bytes are generated outside the timer through per-element offsets. Output equality is checked outside each timed interval.

Three fresh processes per revision, alternating main/head order, two warmups and five measured iterations per workload/process. Each cell below is median milliseconds [minimum, maximum] across 15 samples. Builds and the workflow's GPU checks finished before timing; no cargo/rustc processes were active at the start of that phase. CPU affinity and unrelated system activity were not controlled.

Workload Main detile Head detile Main tile Head tile
1920x1080 R8, mode 5 4.8372 [4.7129, 5.6251] 0.9120 [0.8939, 0.9299] 12.2125 [12.1012, 12.5152] 0.5307 [0.5256, 0.5496]
2048x2048 RGBA8, mode 10 19.4781 [18.4783, 20.0147] 6.1628 [5.8727, 6.6437] 26.9693 [26.4260, 27.3807] 4.8796 [4.7140, 5.0973]
512x512 16-byte blocks, mode 10 1.4251 [1.4034, 1.5321] 0.9520 [0.9463, 0.9948] 1.6924 [1.6532, 1.7747] 0.5567 [0.5466, 0.5788]
1023x577 RGBA8, mode 21, base XOR 12 2.4258 [2.3383, 2.9226] 2.2508 [2.2370, 2.2857] 3.5789 [3.4832, 3.6383] 1.6923 [1.6859, 1.7219]
1920x1080 RGBA8, linear mode 0 0.8345 [0.7412, 0.9867] 0.7685 [0.7391, 0.8898] 12.4296 [12.2486, 12.5983] 0.2700 [0.2508, 0.3446]

The 16-byte block case is opaque CPU block conversion, equivalent in dimensions to 2048x2048 BC7; it does not decode BC7. Linear and tiled byte hashes match between revisions for all five workloads. These are warmed CPU conversion measurements under Wine, with no inference about title loading or FPS.

RX 9070 correctness

The local fixture compares full tiled buffers with per-element Layout::offset references, detiles those references, uploads the resulting 8x8 R32_UINT textures and reads all 64 texels through a native wave64 IMAGE_LOAD kernel.

  • Modes: 0, 1, 2, 5, 6, 9, 10, 17, 18, 21, 22, 24, 25, 26, 27.
  • Base XOR: 0, 4, 12 and half the layout's block size. Same zero-valued pipe/packer configuration as above.
  • HLSL and direct DXIL, three fresh serial processes per backend/revision: 60 cases/process, 720 cases total.
  • Both revisions pass. All 46,080 raw GPU texel values match independently computed expectations; each case's tiled hash matches across revisions, backends and repetitions. No runtime capability skips or ignored tests.

All 22 top-level process summaries, raw readbacks, timing samples, source inventories and executable hashes were independently checked. Build: cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. Run the Wine libtest binary with gpu::tiling::tests::, or either exact local selector gpu::tiling::workflow_tiling_cpu_wine_measurement / gpu::recomp::tests::gpu_tiling_conversion_upload_reads_all_texels, using --nocapture --test-threads=1. GPU processes use XCL_REQUIRE_GPU=wave64, explicit RX 9070 selection and XCL_DIRECT_DXIL=0 / 1; inherited XCL_* flags are cleared before the explicit settings and XCL_NETWORK=0.

Not tested

Retail inputs, scripts/smoke.ps1, the full suite, native Windows, other GPUs, GPU BC7 decoding, other pipe/packer configurations, GPU mip/array/thick-3D variants, cold-cache performance, world-load time or FPS. The offset reference is software parity, not a native console tiling oracle.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, created the local synthetic fixtures, ran the paired checks, independently verified the evidence and drafted this report. Publication authorized by the account owner.

@Gevroska

Copy link
Copy Markdown

I measured warm CPU texture preparation on Windows 11 25H2 with a Ryzen 7 5700X. I used two optimized local builds with the same instrumentation and fixture. The only code difference between them was tiling.rs, taken from the PR’s parent and head 065f31bb respectively.

I timed the full preparation call for eight synthetic textures spanning 24 mip levels, with both 4 KiB and 64 KiB swizzles. Across six paired rounds with alternating run order, every run produced byte-identical output. Median wall times were:

Workers Parent tiling code PR tiling code
1 7.441 ms 2.948 ms
4 2.722 ms 1.309 ms

Two independent repeat rounds also favored the PR at both worker counts. These timings cover warm CPU preparation only. GPU upload and title loading were outside the measurement.

I also checked truncated input directly on parent b49be183 and head 065f31bb. Across 48 cutoff comparisons per revision, a four-byte texel with only three source bytes available decoded to zero. Including the fourth byte restored the exact source texel. Both revisions matched the scalar reference, including cuts inside a later physical block.

I used Codex GPT-6.2 Sol for the fixtures and measurements, and a separate GPT-6.2 Sol agent for independent verification. Codex GPT-6.2 Astra wrote this comment.

I reviewed and approved this comment before posting.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Intel i5-11400F / Windows 11 release verification of PR #2820 at 065f31bbcd08b891af2b144d045feecd4a04fcd7 (parent & merge-base origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0, default flags, no input)

Targeted release unit tests (065f31bb)

  • cargo test --release -p xcl --lib tile_level_matches_element_by_element_and_exploits_contiguous_runs -- --nocapture: 1 passed, 0 failed, 0 ignored (0.29 s, 0 SKIPPED).
  • cargo test --release -p xcl --lib low_base_xor_bits_bound_runs_without_changing_bytes -- --nocapture: 1 passed, 0 failed, 0 ignored (0.01 s, 0 SKIPPED).
  • cargo test --release -p xcl --lib gpu::tiling:: (3 consecutive parallel passes): 17 passed, 0 failed, 0 ignored on all 3 passes (1.02 s / 1.00 s / 1.01 s, 0 SKIPPED).

Paired 60 s RTX 4060 smoke (b49be183 vs 065f31bb)

Both runs held steady 60/2 s pacing with 0 device removals and 0 crashes (065f31bb xcl.log: 6,176 MB peak / 6,116 MB end local VRAM, 4,651 MB end non-local VRAM, 19,339 translated draws / 1,024 dispatches with 0 skipped, 8,192 title-texture upload-skip milestones reached cleanly).

Base origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2820 head (065f31bb):

xcl-smoke v1
commit: 065f31bbcd08b891af2b144d045feecd4a04fcd7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1564 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13994 MB

Limits of coverage

  • Full workspace test suite was not re-run (only the 2 new tests individually, 3 passes of gpu::tiling::, release build, and paired 60 s retail smokes).
  • No standalone CPU microbenchmark of texture-preparation time was run separately on this host; visual inspection of interactive in-world textures beyond the 60 s no-input smoke was not performed.
  • Single Intel i5-11400F / NVIDIA RTX 4060 (8 GB) native Windows 11 host; no AMD, Intel GPU, or Wine/Linux run.

AI use

Ran the targeted release unit tests, release build, and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts, timings, memory figures, and smoke blocks were extracted directly from cargo test, xcl.log, and scripts/smoke.ps1 outputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants