D3D12.X: guard mip shift overflow and zero dimensions in tiling::Chain and image_chain #1509

Open
github-bot wants to merge 1 commit from github-bot/gh-1509 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 17:09 UTC · original
b3IKK:gpu/tiling-mip-shift-and-zero-dims → main · +53 −3 · 1 files · 1 commits · open

tiling::Chain shifted the mip dimensions and the depth by the level index unconditionally: a chain with more than 32 levels (mips > 32) hit a shift overflow (a panic in debug, a wrong value in release), and Chain::new_3d with a zero width or height produced levels[0] of 0, so slice_bytes no longer matched the level it describes.

image_chain did not reject a zero width/height or a max_mip of 32 or more at all; it computed a chain for them.

This clamps every dimension to at least 1, uses checked shifts (a shift past 32 gives 1), and makes image_chain return None for a zero dimension or max_mip >= 32.

What is in it

  • crates/xcl/src/gpu/tiling.rs: the max(1) clamps and checked_shr in Chain::new / new_3d; the image_chain guard; test chain_and_image_chain_handle_large_mips_and_zero_dimensions (33 levels of a 16×16 image, a zero-size 3D chain, and image_chain with max_mip = u32::MAX, 32, a zero width and a zero height).

Since the last push: rebased onto main 06c9f55 (the commit was then re-created with the same tree so GitHub refreshed the PR's head); the only conflict was a test module where main had added layout_cache_shares_tables_and_isolates_base_xor at the same place, and both are kept.

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): 1266 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib -- gpu::tiling: all pass, including the new test
  • the new test with the image_chain guard removed: 0 passed, 1 failed — a shift-overflow panic at tiling.rs:497

Regression run

main (426a5a7, clean tree, no local changes):

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

PR (a0178fc, clean tree, no local changes):

xcl-smoke v1
commit: a0178fce33f76bb767a461a04f12867e4c4f1f05
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: 15759 MB

(The main block is 426a5a7, an ancestor of the current main 06c9f55, from the same machine and data folder.)

Not tested

  • a title that asks for more than 32 mips or a zero-sized image (the test builds both directly)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto 06c9f55, kept both tests at the conflict, re-verified that the new test fails without the guard, ran the suite and the scripts/smoke.ps1 pair.
**@⁠b3IKK** on GitHub · 2026-11-24 17:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509) `b3IKK:gpu/tiling-mip-shift-and-zero-dims` → `main` · +53 −3 · 1 files · 1 commits · open `tiling::Chain` shifted the mip dimensions and the depth by the level index unconditionally: a chain with more than 32 levels (`mips > 32`) hit a shift overflow (a panic in debug, a wrong value in release), and `Chain::new_3d` with a zero width or height produced `levels[0]` of 0, so `slice_bytes` no longer matched the level it describes. `image_chain` did not reject a zero width/height or a `max_mip` of 32 or more at all; it computed a chain for them. This clamps every dimension to at least 1, uses checked shifts (a shift past 32 gives 1), and makes `image_chain` return `None` for a zero dimension or `max_mip >= 32`. **What is in it** - `crates/xcl/src/gpu/tiling.rs`: the `max(1)` clamps and `checked_shr` in `Chain::new` / `new_3d`; the `image_chain` guard; test `chain_and_image_chain_handle_large_mips_and_zero_dimensions` (33 levels of a 16×16 image, a zero-size 3D chain, and `image_chain` with `max_mip = u32::MAX`, `32`, a zero width and a zero height). **Since the last push**: rebased onto `main` `06c9f55` (the commit was then re-created with the same tree so GitHub refreshed the PR's head); the only conflict was a test module where `main` had added `layout_cache_shares_tables_and_isolates_base_xor` at the same place, and both are kept. **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`): **1266 passed, 0 failed, 46 ignored** (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib -- gpu::tiling`: all pass, including the new test - the new test with the `image_chain` guard removed: 0 passed, 1 failed — a shift-overflow panic at `tiling.rs:497` **Regression run** main (`426a5a7`, clean tree, no local changes): ``` xcl-smoke v1 commit: 426a5a745db4d5e4b037449ede0b70cb342f5192 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15158 MB ``` PR (`a0178fc`, clean tree, no local changes): ``` xcl-smoke v1 commit: a0178fce33f76bb767a461a04f12867e4c4f1f05 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: 15759 MB ``` (The main block is `426a5a7`, an ancestor of the current `main` `06c9f55`, from the same machine and data folder.) **Not tested** - a title that asks for more than 32 mips or a zero-sized image (the test builds both directly) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: rebased onto `06c9f55`, kept both tests at the conflict, re-verified that the new test fails without the guard, ran the suite and the `scripts/smoke.ps1` pair.
In gpu/tiling.rs:
- Chain::new_3d shifted `width >> i`, `height >> i`, `depth >> i`, and
  `1 << i` without checking `i >= 32` / `i >= 64`, panicking in debug or
  wrapping back to full-size mip levels in release when `mips > 32`.
- Passing `width == 0` or `height == 0` left `w0 == 0` and
  `slice_bytes == 0` while `levels[0].width == 1`.
- image_chain() computed `t.max_mip + 1` without validating `t.width`,
  `t.height`, or `t.max_mip < 32` (overflowing on `t.max_mip == u32::MAX`).

Clamp width/height/depth/side to `.max(1)` and use checked_shr /
checked_shl in Chain::new_3d, and reject `width == 0 || height == 0 ||
max_mip >= 32` in image_chain().

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:55 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509#issuecomment-7141302867) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠Belox17 on GitHub · 2026-11-24 20:02 UTC · original

Test report for 175ed9c6 on NVIDIA (RTX 3060 Ti): passes, and the test fails without the fix

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head 175ed9c6 as is (base b7aa9f3), clean tree.
  • The new test (chain_and_image_chain_handle_large_mips_and_zero_dimensions) with cargo test -p xcl --lib <name>: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 771 passed, 0 failed, 41 ignored; its base b7aa9f3 on the same machine: 770 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Merged into current main c160d86e (clean merge): 859 passed, 0 failed, 42 ignored; main alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.
  • With the non-test hunks of gpu/tiling.rs reverted (test kept), the test panics with attempt to shift right with overflow at tiling.rs:282.

Not tested

  • AMD / native wave64 hardware; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.

**@⁠Belox17** on GitHub · 2026-11-24 20:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509#issuecomment-7142968766) **Test report for `175ed9c6` on NVIDIA (RTX 3060 Ti): passes, and the test fails without the fix** **Tested** - NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head `175ed9c6` as is (base `b7aa9f3`), clean tree. - The new test (`chain_and_image_chain_handle_large_mips_and_zero_dimensions`) with `cargo test -p xcl --lib <name>`: 1 passed. - `cargo test --workspace -- --test-threads=4` on the head: **771 passed, 0 failed, 41 ignored**; its base `b7aa9f3` on the same machine: 770 passed, 0 failed, 41 ignored. SKIPPED on both: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64). - Merged into current `main` `c160d86e` (clean merge): **859 passed, 0 failed, 42 ignored**; `main` alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above. - With the non-test hunks of `gpu/tiling.rs` reverted (test kept), the test panics with `attempt to shift right with overflow` at `tiling.rs:282`. **Not tested** - AMD / native wave64 hardware; any retail title (no smoke run). **AI use:** Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:20 UTC · original

Empirical test report (175ed9c6)

PR #1509 was tested at commit 175ed9c6060b4424a25f856a423808844ee030cd from a clean checkout.

Hardware / environment

  • Windows x64, build 26200. AMD x64 CPU (family 23, model 113, stepping 0).
  • rustc 1.100.0 (0ef1bc386 2026-11-09), host x86_64-pc-windows-msvc. dxc.exe --version reported dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47).
  • Unoptimized Cargo test profile with debug info and incremental compilation disabled. The focused test ran with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1. Both commands ran outside Invoke-ArcTest.ps1 without acquiring the Arc GPU mutex.

Commands and results

  • cargo test --workspace --no-run exited 0 and built the workspace test binaries. The build emitted a Rust deprecation warning for AtomicU32::fetch_update in XGameRuntime.
  • cargo test -p xcl --lib gpu::tiling::tests::chain_and_image_chain_handle_large_mips_and_zero_dimensions -- --exact --nocapture exited 0. The log recorded 1 passed, 0 failed, 0 ignored, 0 skipped, and 743 filtered out.

Observed behavior

  • The regression test exercises CPU layout arithmetic with a linear layout and in-memory image descriptors. A 33-level chain retained all 33 levels, produced a 1-by-1 mip at index 32, and had a positive slice size. A chain built with zero width and height produced a 1-by-1 base level and a slice size of at least four bytes.
  • image_chain returned None for max_mip values of 32 and u32::MAX, and for descriptors with zero width or zero height.

Not tested

The full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1509-focused.log and published.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509#issuecomment-7153676405) ### Empirical test report (175ed9c6) PR #1509 was tested at commit `175ed9c6060b4424a25f856a423808844ee030cd` from a clean checkout. **Hardware / environment** - Windows x64, build 26200. AMD x64 CPU (family 23, model 113, stepping 0). - `rustc 1.100.0 (0ef1bc386 2026-11-09)`, host `x86_64-pc-windows-msvc`. `dxc.exe --version` reported `dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47)`. - Unoptimized Cargo test profile with debug info and incremental compilation disabled. The focused test ran with `XCL_ADAPTER=NONE_CPU_ONLY` and `RUST_TEST_NOCAPTURE=1`. Both commands ran outside `Invoke-ArcTest.ps1` without acquiring the Arc GPU mutex. **Commands and results** - `cargo test --workspace --no-run` exited 0 and built the workspace test binaries. The build emitted a Rust deprecation warning for `AtomicU32::fetch_update` in XGameRuntime. - `cargo test -p xcl --lib gpu::tiling::tests::chain_and_image_chain_handle_large_mips_and_zero_dimensions -- --exact --nocapture` exited 0. The log recorded 1 passed, 0 failed, 0 ignored, 0 skipped, and 743 filtered out. **Observed behavior** - The regression test exercises CPU layout arithmetic with a linear layout and in-memory image descriptors. A 33-level chain retained all 33 levels, produced a 1-by-1 mip at index 32, and had a positive slice size. A chain built with zero width and height produced a 1-by-1 base level and a slice size of at least four bytes. - `image_chain` returned `None` for `max_mip` values of 32 and `u32::MAX`, and for descriptors with zero width or zero height. **Not tested** The full GPU workspace suite and game smoke runs were omitted. **AI use** Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1509-focused.log` and published.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-25 16:04 UTC · original

Rebased onto main 06c9f55; the only conflict was layout_cache_shares_tables_and_isolates_base_xor, which main had added at the same place, and both tests are kept. The commit was then re-created with the same tree to refresh the PR head (GitHub kept the previous head after the first force-push). Current head a0178fc: suite 1266 passed, 0 failed, 46 ignored; the new test fails with the image_chain guard removed (shift-overflow panic at tiling.rs:497); smoke 1641 frames, 0 crashes, 0 removals. The JJAutoCompare report above is for the old 175ed9c; the smoke pair in the description now names this head.

AI use: OpenCode, Claude Fable 5.2 rebased it, re-created the commit, ran the suite and the smoke run and wrote this.

**@⁠b3IKK** on GitHub · 2026-11-25 16:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509#issuecomment-7167565546) Rebased onto ``main`` ``06c9f55``; the only conflict was ``layout_cache_shares_tables_and_isolates_base_xor``, which ``main`` had added at the same place, and both tests are kept. The commit was then re-created with the same tree to refresh the PR head (GitHub kept the previous head after the first force-push). Current head ``a0178fc``: suite 1266 passed, 0 failed, 46 ignored; the new test fails with the ``image_chain`` guard removed (shift-overflow panic at ``tiling.rs:497``); smoke 1641 frames, 0 crashes, 0 removals. The JJAutoCompare report above is for the old ``175ed9c``; the smoke pair in the description now names this head. AI use: OpenCode, Claude Fable 5.2 rebased it, re-created the commit, ran the suite and the smoke run and wrote this.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:40 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 05:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1509#issuecomment-7183700903) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1509/head:github-bot/gh-1509'
git switch 'github-bot/gh-1509'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1509'
git switch 'github-bot/gh-1509'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1509'
git switch 'github-bot/gh-1509'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1509'
git switch 'main'
git merge --squash 'github-bot/gh-1509'
git switch 'main'
git merge --ff-only 'github-bot/gh-1509'
git switch 'main'
git merge 'github-bot/gh-1509'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.