Skip to content

D3D12.X: download block-compressed texture mip tails - #3550

Open
BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:d3d12x/download-small-bc-mips
Open

BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:d3d12x/download-small-bc-mips

Conversation

@BBareth

@BBareth BBareth commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

A GPU-written title texture is copied back into the title's memory through a download plan. For a block-compressed texture the plan was refused for the smallest mips: D3D12 returns a 4×4 footprint for the 2×2 and 1×1 mips of a BC3 texture, and the single-footprint query kept an unaligned base offset (0x555780 after mip 6 of a 2048×2048 chain on an RTX 5070 Ti) where the check expected the next 512-byte boundary. Both ended in driver footprint differs from the exact subresource, and reverse layout compared against the logical mip size as well. This change aligns each query base and uses whole-block extents for the copy and the reverse layout. Part of #505.

The base alignment is not specific to block compression: it applies to every format, so an uncompressed multi-mip chain whose previous mip ends off a 512-byte boundary, which main also refuses, is downloaded as well. A refused plan is not dropped on main: it is prepared again at every submit and refused again.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: the download layout rounds each query base up to the placement alignment and validates, copies and reverse-tiles with dimensions rounded to whole format blocks.
  • Test gpu_download_publishes_every_bc3_mip (GPU): uploads a pattern to all 12 mips of a 2048×2048 BC3 texture, downloads it through the plan and compares the tiled buffer byte for byte.
  • Test gpu_download_publishes_every_rgba8_mip (GPU): the same for all 8 mips of a 128×128 RGBA8 texture, whose small mips end off a 512-byte boundary too. It fails with the base alignment taken out (driver footprint differs from the exact subresource).
  • Test download_layout_accepts_full_bc_blocks_for_small_mips (no GPU): the 4×4 footprints, byte counts and offsets of the two smallest mips, and an unrounded footprint is still refused.
  • README.md: the Textures row names block-compressed mip tails.

Tested

  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; debug suite, release smoke.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 443ad63 (on main ff0c364): 2892 passed, 0 failed, 51 ignored.
  • SKIPPED on this adapter: 28: 22 no wave64; 2 no heap windows; 2 no d3d12SDKLayers.dll; 1 no D3D12 debug layer; 1 cannot disable the driver cache (no Developer Mode).
  • Download plans counted in GTA 6 (Xbox 1.0.2.1) with a local counter in prepare_downloads (not in this PR), main 493dbd3 against 493dbd3 merged with this PR, two 120 s runs each after a warm-up: on main no plan was accepted and at least 512 and 256 were refused (all block-compressed, formats 77 and 78, the same textures prepared again at every submit, from about 100 s); with this PR one plan was accepted (a 12-mip format 78 texture) and none refused. No plan for another format was prepared in any of the four runs. Frames shown: main 3093 and 3047, with this PR 3142 and 3061; no device removal or crash.
  • Both new tests failed before the change with driver footprint differs from the exact subresource (on the earlier base 9dfbe3e) and pass with it; the GPU test ran on the RTX 5070 Ti, not skipped.

Regression run

xcl-smoke v1
commit: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3087 (PresentX 3087)
presents per 2 s (last 3): 49 46 47
device removals: 0
crashes: 0
peak commit: 30932 MB
xcl-smoke v1
commit: 443ad6381509f78a63bffadf049c151e39c8cedd
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3068 (PresentX 3068)
presents per 2 s (last 3): 54 41 6
device removals: 0
crashes: 0
peak commit: 31617 MB

Each run follows one warm-up run of the same build; the A button is pressed once at 70 s.

Not tested

  • The content of the block-compressed download accepted in the retail runs above was not compared; only the GPU test checks bytes.
  • An uncompressed multi-mip download in a retail title: the retail runs prepared none (the GPU test covers RGBA8). The world, later than 120 s, was not counted.
  • AMD and Intel GPUs: the footprints were only observed on the RTX 5070 Ti.
  • Block-compressed formats other than BC3, and metadata-plane downloads.

AI use

  • Codex (GPT-6.2-Sol): found the footprint mismatch, wrote the fix and the two tests.
  • Claude Code, Claude Fable 5.2: briefed and reviewed that work, rebased the branch, wrote the RGBA8 test after review, ran the suite, the regression runs and the download counts above and wrote this description.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 30, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows GPU check of #3550 head 3b4a7a4 against its exact main parent 86e86fc.

I ran the same synthetic 60×20 BC1, six-mip test in isolated source trees. It uploads distinct tight bytes to each mip, checks every native GPU readback row, and compares the published tiled allocation against an independently CPU-tiled expected buffer. The unmodified parent fails while planning mip 1 (driver footprint differs from the exact subresource); the PR head passes all six mip footprints, all 888 payload bytes, and the complete 4,104-byte published allocation, including untouched padding. Mip 1 is a 32×12 driver footprint at offset 1,536.

Windows 11 build 26300; RTX 3080 Ti, NVIDIA driver 621.40; Rust 1.99.1 MSVC. With XCL_REQUIRE_GPU=1, both trees ran cargo test --offline --locked -j 3 -p xcl --lib hle::d3d12x::title_textures::tests::gpu_download_publishes_every_nonsquare_bc1_mip -- --exact --nocapture --test-threads=1 (separate target directories). Parent: 0 passed, 1 failed, 0 ignored, 0 GPU skips. PR head: 1 passed, 0 failed, 0 ignored, 0 GPU skips. This is focused evidence for the non-square BC1 mip path; I did not run the full workspace suite or a title smoke, so it is not a merge check.

AI use: Codex (GPT-6.2 Sol) wrote and ran the synthetic GPU test and drafted this report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 3b4a7a4
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2898 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 the whole diff (title_textures.rs +102/-11, README). It changes the default path more widely than the title says: every download query base is now rounded up to 512 bytes for all formats (~4231). On main, any multi-mip download whose previous mip ended off a 512-byte boundary was refused and silently skipped (~3902), uncompressed chains included (e.g. RGBA8 mips under 64 px), so this turns on downloads well beyond BC mip tails; the description should say so. Findings: (1) the PR's own smoke shows 2928 / 2921 frames against main's 3058 / 3073, about 4.5 % lower in both rounds, while other PRs on the same base stayed at 3009-3074; downloads that were refused now running (and the fence held until they're written) is a likely cause, so a count of downloads per frame before and after would settle it. This run is also lower than most on this machine today (see performance). (2) The no-GPU test builds its mock driver layout from the same rule the change adds, so only the BC3 GPU test checks real footprints. Fine: rounding to whole blocks fits xg::element (block sides 1 and 4 only, so BC6 / BC7 are covered), the block-count check is equivalent to the old one, packed mip-tail placement is untouched (tile_level), overflow is checked, and the GPU test uses skip_test.
performance: 60 s smoke of a retail title, main 7d86c5d vs this merge (34f56934): 1663 -> 1448 frames shown (87 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17512 MB, 0 device removals, 0 crashes. This is 87 % of main's frames, lower than most runs of this title on this machine today (typically 1650-1690); together with the PR's own -4.5 % in two rounds it points at a cost, though one run can't separate it from noise.
verdict: not yet: it turns on downloads far beyond BC mip tails (every multi-mip chain main used to skip), and both the PR's smoke runs and this one show fewer frames than main; how many downloads run per frame before and after would show whether that cost is real
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.

@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the check. Both points looked at, head unchanged (3b4a7a4).

Wider than the title: correct, and the description now says so. The base alignment in prepare_texture_download applies to every format, so an uncompressed multi-mip chain that main refuses for the same reason is downloaded too.

Cost: I counted download plans with a local counter in prepare_downloads (not in the PR): main 493dbd3 against 493dbd3 merged with this PR, GTA 6, two 120 s runs each after a warm-up, RTX 5070 Ti.

plans accepted plans refused other formats frames shown
main, run 1 0 at least 512 0 3093
main, run 2 0 at least 256 0 3047
this PR, run 1 1 0 0 3142
this PR, run 2 1 0 0 3061
  • On main a refused plan is not dropped: the same block-compressed textures (formats 77 and 78) are prepared again at every submit and refused again, from about 100 s on. The counter logs at powers of two, so the refused numbers are lower bounds.
  • With this PR the plan is accepted once and the retries stop. No plan for a non-BC format was prepared in any run, so the wider effect is not reached in these 120 s.
  • The frame counts do not show the 4.5 % from my first smokes again. I cannot explain that earlier difference; these four runs are within run-to-run spread.

Not covered: the world after 120 s was not counted, and there is no test of an uncompressed multi-mip download. Both are under Not tested now.

AI use: Claude Code, Claude Fable 5.2 added the local counter, ran the four runs and wrote this reply.

D3D12 returns a 4x4 footprint for the 2x2 and 1x1 BC3 mips. Its
single-footprint query also preserved the unaligned 0x555780 base on
an RTX 5070 Ti. The planner rejected both results, and reverse layout
also expected logical mip dimensions.

Align each query base and use whole-block extents for the copy and
reverse layout. The GPU regression publishes all 12 mips byte for
byte on the RTX 5070 Ti. The title_textures suite reports 67 passed,
0 failed, 1 ignored and no SKIPPED lines.

The base alignment applies to every format: an RGBA8 chain's small mips
were refused the same way, and a second GPU test publishes all 8 mips of
a 128x128 one.

Assisted-by: Codex (GPT-6.2-Sol)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up, head 443ad63: the uncompressed case now has a test.

gpu_download_publishes_every_rgba8_mip uploads a pattern to all 8 mips of a 128×128 RGBA8 texture, downloads it through the plan and compares the published bytes, like the BC3 test (both now share one helper). With the base alignment taken out it fails with driver footprint differs from the exact subresource; with it, it passes on the RTX 5070 Ti. The runtime code is unchanged from 3b4a7a4.

Suite on 443ad63: 2892 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke blocks in the description are rerun on this head.

AI use: Claude Code, Claude Fable 5.2 wrote the test and this comment and ran the tests.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 443ad63

No open or merged PR makes the same change. #3514 (same author) touches texture-download command objects, not the footprint layout.
No problems found in the diff. Rounding to whole blocks keeps side 1 formats unchanged, and aligning the GetCopyableFootprints base matches the 512-byte offsets validate_download_layout expects.
Note: the new GPU test builds ReadyDownload { .. } without the pages field that #3549 adds, so the second of the two to merge must update it. There is also a double blank line before the new tests.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 443ad63

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 443ad63

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 443ad63
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 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: re-check after my "not yet" on 3b4a7a4; the range-diff and the updated description read. Both points are answered. (1) The description and commit message now say the 512-byte base alignment applies to every format, so any multi-mip chain main refused is downloaded. A new GPU test, gpu_download_publishes_every_rgba8_mip, covers an uncompressed chain and fails without the alignment. (2) The frame cost now has a count behind it. The author counted plans in the retail title (local counter, not in the PR): main refused at least 512 / 256 block-compressed plans, re-preparing the same textures at every submit, while this head accepted one and refused none. Frames went 3093 / 3047 -> 3142 / 3061 in two 120 s runs each, so the lower numbers on the first head look like noise rather than download cost. My own smoke below agrees. Still open, both stated in Not tested: the bytes of the accepted retail download weren't compared, and no uncompressed retail download was seen. Fine: the shared helper keeps the BC3 test as it was, and nothing else changed.
performance: 60 s smoke of a retail title, main 493dbd3 vs this merge (d954dc77): 1670 -> 1680 frames shown (100 %; last presents per 2 s: 61 60 60), peak commit 17083 -> 17766 MB, 0 device removals, 0 crashes. In line with the PR's own retail runs (3093 / 3047 -> 3142 / 3061 frames over 120 s); the run is capped at 60 presents per second.
verdict: safe to merge
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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@brainhay5

Copy link
Copy Markdown

merge-check claim withdrawn
Our automated merge-check loop claimed this PR and then stopped before posting a check — two loops were running at once and both are now shut down. No check from us is coming, so this claim is void and the head is free for someone else to take.

AI use: an agent posted this withdrawal.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants