Skip to content

D3D12.X: force MipLevels=1 and skip mip arithmetic for MSAA descriptors in image_d3d12 - #1339

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:gpu/desc-msaa-mips
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:gpu/desc-msaa-mips

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

valid_image_shape returns early for D2Msaa and D2MsaaArray without validating max_mip or last_level (which encodes log2(samples) for MSAA). image_d3d12 then unconditionally computed t.max_mip + 1 and t.last_level.saturating_sub(t.base_level) + 1, overflowing on u32::MAX and setting MipLevels > 1 for 1x MSAA textures (last_level == 0, samples == 1).

This sets mips = 1 and levels = 1 directly whenever t.ty is D2Msaa or D2MsaaArray.

What is in it

  • crates/xcl/src/gpu/desc.rs: force MipLevels = 1 and skip max_mip + 1 / last_level mip-level arithmetic for D2Msaa / D2MsaaArray in image_d3d12; add unit test msaa_resources_always_have_one_mip_and_never_overflow (verified failing before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib msaa_resources_always_have_one_mip_and_never_overflow: 1 passed, 0 failed (failed before the fix with MipLevels == 16)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: ad9c154d7734be7d78d8ea00a2cbe455f9246077
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1641 (PresentX 1641)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14595 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited desc.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.

…rs in image_d3d12

valid_image_shape returns early for D2Msaa and D2MsaaArray without
validating max_mip or last_level (which encodes log2(samples) for MSAA).
image_d3d12 then unconditionally computed `t.max_mip + 1` and
`t.last_level.saturating_sub(t.base_level) + 1`, overflowing on u32::MAX
and setting MipLevels > 1 for 1x MSAA textures (last_level == 0,
samples == 1).

Set mips = 1 and levels = 1 directly whenever the image type is D2Msaa
or D2MsaaArray, with a unit test.

Assisted-by: OpenCode (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 708 passed, 0 failed, 21 ignored.

Thanks!

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head ad9c154 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: msaa_resources_always_have_one_mip_and_never_overflow.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…v#1305-xcl-dev#1379

Integrate 22 open upstream PRs targeting world rendering, shader correctness, DirectStorage terrain loads, and crash/memory stability:
- xcl-dev#1321 (xcl-dev#1307): fall back to pc blocks when structured CFG HLSL grows oversized (eliminates the 148 MB HLSL / 1 GB/s commit explosion from b8b1f49 so XCL_PSO_PRELOAD=1 stays flat at ~5.4 GiB)
- xcl-dev#549, xcl-dev#1312: DirectStorage late page-array queue hold (fixes 0x89240009 terrain read failures) and 0-byte memory-source requests
- xcl-dev#1365 (xcl-dev#1361): GFX10.30 scratch SADDR 0x7F addresses the immediate offset alone instead of adding v0
- xcl-dev#1368: translated compute PSOs use NodeMask 0
- xcl-dev#1371 (xcl-dev#105): deduplicate packed ISG1 vertex input struct fields
- xcl-dev#1375 (xcl-dev#1360): ES s_setpc_b64 ends block before gs_start
- xcl-dev#1350, xcl-dev#1351, xcl-dev#1352, xcl-dev#1353, xcl-dev#1349: VS layer/viewport outputs, PS sample index/fixed-point position & SV_Coverage, depth+UAV initial states, console SetPredication
- xcl-dev#1305, xcl-dev#1306, xcl-dev#1314, xcl-dev#1319, xcl-dev#1322, xcl-dev#1334, xcl-dev#1339, xcl-dev#1355, xcl-dev#1357, xcl-dev#1379: console_list UMA hold on Release, v_cmp_class_f32 bitwise abs/neg, late_release vram queue wait, root arg clamping, empty BVH / NaN rays, NULL IASetIndexBuffer clearing, MSAA MipLevels=1, VFS lazy-page commits, coherent VirtualFree validation, cpu_writes PAGE_GUARD & stale fence wakeups
- README.md: document the integrated PRs, XCL_PSO_PRELOAD=1, and 16 GiB cap

Verified on RX 9060 XT / GE-Proton11-14: release build clean, targeted unit tests pass (75 passed, 0 failed), and 80 s run with XCL_PSO_PRELOAD=1 and XCL_MEM_LIMIT=12G stays flat at 5340-5413 MB with 512+ pipelines preloaded (1385 frames, exit 0x0).

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…v#1305-xcl-dev#1379

Integrate 22 open upstream PRs targeting world rendering, shader correctness, DirectStorage terrain loads, and crash/memory stability:
- xcl-dev#1321 (xcl-dev#1307): fall back to pc blocks when structured CFG HLSL grows oversized (eliminates the 148 MB HLSL / 1 GB/s commit explosion from b8b1f49 so XCL_PSO_PRELOAD=1 stays flat at ~5.4 GiB)
- xcl-dev#549, xcl-dev#1312: DirectStorage late page-array queue hold (fixes 0x89240009 terrain read failures) and 0-byte memory-source requests
- xcl-dev#1365 (xcl-dev#1361): GFX10.30 scratch SADDR 0x7F addresses the immediate offset alone instead of adding v0
- xcl-dev#1368: translated compute PSOs use NodeMask 0
- xcl-dev#1371 (xcl-dev#105): deduplicate packed ISG1 vertex input struct fields
- xcl-dev#1375 (xcl-dev#1360): ES s_setpc_b64 ends block before gs_start
- xcl-dev#1350, xcl-dev#1351, xcl-dev#1352, xcl-dev#1353, xcl-dev#1349: VS layer/viewport outputs, PS sample index/fixed-point position & SV_Coverage, depth+UAV initial states, console SetPredication
- xcl-dev#1305, xcl-dev#1306, xcl-dev#1314, xcl-dev#1319, xcl-dev#1322, xcl-dev#1334, xcl-dev#1339, xcl-dev#1355, xcl-dev#1357, xcl-dev#1379: console_list UMA hold on Release, v_cmp_class_f32 bitwise abs/neg, late_release vram queue wait, root arg clamping, empty BVH / NaN rays, NULL IASetIndexBuffer clearing, MSAA MipLevels=1, VFS lazy-page commits, coherent VirtualFree validation, cpu_writes PAGE_GUARD & stale fence wakeups
- README.md: document the integrated PRs, XCL_PSO_PRELOAD=1, and 16 GiB cap

Verified on RX 9060 XT / GE-Proton11-14: release build clean, targeted unit tests pass (75 passed, 0 failed), and 80 s run with XCL_PSO_PRELOAD=1 and XCL_MEM_LIMIT=12G stays flat at 5340-5413 MB with 512+ pipelines preloaded (1385 frames, exit 0x0).

Assisted-by: Antigravity (Google DeepMind)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows test on ad9c154. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 752 passed, 0 failed, 41 ignored. The pass count includes two wave64 runtime skips.

With the D3D12 debug layer enabled, cargo test --offline --locked -j 4 -p xcl --lib local_msaa_descriptors_create_native_resources -- --nocapture --test-threads=1 passed 1 of 1 without skips in a scratch fixture. Both 1× cases created native resources with one mip, and a regular 2D control kept three mips. Both 4× cases, with max_mip = u32::MAX, created one-mip native resources and valid shader-resource views after the fixture added ALLOW_RENDER_TARGET. Passing the unmodified 4× resource descriptors directly produced E_INVALIDARG and debug message 599, which requires a render-target or depth-stencil flag for multisampled resources. All five successful resource and view cases emitted zero debug messages. This was synthetic descriptor and resource creation coverage.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.

@github-actions

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 28, 2026
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: ad9c154

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@BBareth

BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: ad9c154
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. The new test gpu::desc::tests::msaa_resources_always_have_one_mip_and_never_overflow passed, as did the existing desc tests. Note: the base failure above is in the MSAA tests too, and this PR does not change it (it fails the same way with and without the PR).
review: no blocking finding; one file, every hunk read. For D2Msaa / D2MsaaArray images image_d3d12 now sets the mip count to 1 from the image type and no longer from samples > 1, and the view's level count to 1. Two cases change: an MSAA-typed image with one sample (last_level 0) got max_mip + 1 mip levels before and gets 1 now; and max_mip + 1 / the level arithmetic are no longer evaluated for MSAA images, where last_level holds the sample count, so max_mip = u32::MAX no longer overflows (a panic in debug builds). Non-MSAA images take the same path as before. Not tested by me: a title that binds a one-sample MSAA-typed image.
performance: none.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@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 Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: ad9c154
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The new test gpu::desc::tests::msaa_resources_always_have_one_mip_and_never_overflow ran and passed. With the two lines put back to main (mips = t.max_mip + 1 and MipLevels: if samples > 1 { 1 } else { mips }), it fails at desc.rs:597 (left 16, right 1); file restored after.
review: one file, whole diff read. What this adds to the first check: no path a title reaches today runs the changed lines for an MSAA image. In production image_d3d12 is called only from texture::create (texture.rs:142), which first calls subresources and so placement, and placement returns an error for D2Msaa / D2MsaaArray (texture.rs:61-63, "not yet (MSAA)"). The other callers are tests (real.rs:10456, real.rs:10492, recomp/tests.rs:5565). The overflow case also needs max_mip or last_level near u32::MAX, but image() decodes both from 4-bit fields (desc.rs:68-69), so only a hand-built Image reaches it. The change is still correct and consistent: levels is not used by the MSAA view arms (desc.rs:279-283), and a one-sample MSAA image now gets one mip. A note for whoever enables MSAA upload later: tiling::image_chain still builds max_mip + 1 levels (tiling.rs:927), so a one-sample MSAA image with max_mip > 0 would give more subresources than MipLevels and fail validate_subresource_count (texture.rs:185); today placement stops it first. Overlap: #540 adds D3D12 tests of image_d3d12 that include D2Msaa; I did not check whether its expectations match the new mip count.
performance: scripts/smoke.ps1, 60 s of a retail title, release, after one warm-up run of the base: 1667 frames and 17425 MB peak commit against 1659 frames and 17322 MB on the base (warm-up: 1689, 17197 MB). No device removal, no crash. The changed path is not reached, so this only shows no regression elsewhere.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this)

  • Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head ad9c154

No open or merged PR makes this change. On main, image_d3d12 still computes t.max_mip + 1 and last_level - base_level + 1 for MSAA images. valid_image_shape returns early for MSAA without bounding max_mip, so a large max_mip overflows, and a 1-sample MSAA image gets MipLevels = max_mip + 1. The new test exercises both cases. No problems found in the diff.
Recommendation: keep open.

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

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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041) stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants