D3D12.X: fix XG optimal_mode overflow, BCn UAV bits_per_pixel, and get_texel_offset bounds #1480

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

@⁠b3IKK on GitHub · 2026-11-24 16:46 UTC · original
b3IKK:xg/swizzle-and-texel-offset-bounds → main · +41 −5 · 1 files · 1 commits · open

Fixes three bugs in crates/xcl/src/hle/xg.rs:

  • optimal_mode() multiplied bits_per_pixel * width * height as u64 without saturating, overflowing u64 on large widths (aborting across extern "system" fn XGSuggestSwizzleMode in debug or wrapping into the <= 0x8_0000 4KB_S_X threshold in release).
  • XGSuggestSwizzleMode's fallback path computed 8u64 << e instead of dividing by side * side for block-compressed formats (16× too large for BCn, selecting 64KB_R_X instead of 4KB_S_X for a 128×128 BC7 UAV), and checked only d[0] == 2 instead of the full u32 Dimension field.
  • get_texel_offset() checked mip and slice but not x / y against the mip's element dimensions, causing out-of-bounds x (such as u64::MAX on a tail mip with non-zero origin) to overflow and abort (STATUS_STACK_BUFFER_OVERRUN) across extern "system" fn.

This uses saturating_mul in optimal_mode(), divides by side * side and reads the full u32 Dimension in XGSuggestSwizzleMode(), and bounds-checks x < m.width && y < m.height in get_texel_offset().

What is in it

  • crates/xcl/src/hle/xg.rs: fix optimal_mode, XGSuggestSwizzleMode, and get_texel_offset; add unit tests optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav and get_texel_offset_rejects_out_of_bounds_xy (both verified failing/aborting 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): 772 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 hle::xg::tests: 5 passed, 0 failed (both new tests failed/aborted before the fix)

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: 47e5ef07a33420099a17ff4bec0c240228ac2412
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1651 (PresentX 1651)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14601 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 hle/xg.rs, wrote the fixes and unit tests, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 16:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1480) `b3IKK:xg/swizzle-and-texel-offset-bounds` → `main` · +41 −5 · 1 files · 1 commits · open Fixes three bugs in `crates/xcl/src/hle/xg.rs`: - `optimal_mode()` multiplied `bits_per_pixel * width * height as u64` without saturating, overflowing `u64` on large widths (aborting across `extern "system" fn XGSuggestSwizzleMode` in debug or wrapping into the `<= 0x8_0000` `4KB_S_X` threshold in release). - `XGSuggestSwizzleMode`'s fallback path computed `8u64 << e` instead of dividing by `side * side` for block-compressed formats (16× too large for BCn, selecting `64KB_R_X` instead of `4KB_S_X` for a 128×128 BC7 UAV), and checked only `d[0] == 2` instead of the full `u32` `Dimension` field. - `get_texel_offset()` checked `mip` and `slice` but not `x` / `y` against the mip's element dimensions, causing out-of-bounds `x` (such as `u64::MAX` on a tail mip with non-zero origin) to overflow and abort (`STATUS_STACK_BUFFER_OVERRUN`) across `extern "system" fn`. This uses `saturating_mul` in `optimal_mode()`, divides by `side * side` and reads the full `u32` `Dimension` in `XGSuggestSwizzleMode()`, and bounds-checks `x < m.width && y < m.height` in `get_texel_offset()`. **What is in it** - `crates/xcl/src/hle/xg.rs`: fix `optimal_mode`, `XGSuggestSwizzleMode`, and `get_texel_offset`; add unit tests `optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav` and `get_texel_offset_rejects_out_of_bounds_xy` (both verified failing/aborting 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`): 772 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 hle::xg::tests`: 5 passed, 0 failed (both new tests failed/aborted before the fix) **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: 47e5ef07a33420099a17ff4bec0c240228ac2412 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1651 (PresentX 1651) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14601 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 `hle/xg.rs`, wrote the fixes and unit tests, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
Three bugs in hle/xg.rs:
- optimal_mode() multiplied `bits_per_pixel * width * height as u64`
  without saturating, overflowing u64 on large widths (aborting across
  extern "system" fn XGSuggestSwizzleMode in debug or wrapping into the
  4KB_S_X threshold in release).
- XGSuggestSwizzleMode's fallback path computed `8u64 << e` instead of
  dividing by `side * side` for block-compressed formats (16x too large
  for BCn), and tested only `d[0] == 2` instead of the full u32
  Dimension field.
- get_texel_offset() checked `mip` and `slice` but not `x` / `y` against
  the mip's dimensions, allowing out-of-bounds `x` (e.g. u64::MAX on a
  tail mip with non-zero origin) to overflow and abort across FFI.

Use saturating_mul in optimal_mode(), divide by `side * side` and read
the full u32 Dimension in XGSuggestSwizzleMode(), and bounds-check
`x < m.width && y < m.height` in get_texel_offset().

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

@⁠futurepro62 on GitHub · 2026-11-24 16:59 UTC · original · edited 2026-11-24 17:07 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 47e5ef0 (on its base b7aa9f3).

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: 772 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: optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav, get_texel_offset_rejects_out_of_bounds_xy.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 772 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.
**@⁠futurepro62** on GitHub · 2026-11-24 16:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1480#issuecomment-7138531127) · edited 2026-11-24 17:07 UTC Full-suite run, since this PR has no test report yet. Tested exact head `47e5ef0` (on its base `b7aa9f3`). **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`: **772 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: `optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav`, `get_texel_offset_rejects_out_of_bounds_xy`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **772 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.
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/1480#issuecomment-7141293449) 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

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

Empirical test report (47e5ef07)

Hardware / environment

  • Windows x64 build 26200 on AMD Family 23 Model 113 Stepping 0 with 12 logical processors.
  • rustc 1.100.0 (0ef1bc386 2026-11-09), host x86_64-pc-windows-msvc. DXC reported dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47).
  • Clean detached checkout at 47e5ef07a33420099a17ff4bec0c240228ac2412. The unoptimized Cargo test profile ran with incremental compilation and debug symbols disabled. Both commands ran outside Invoke-ArcTest.ps1 and did not acquire the Arc GPU mutex.

Commands and results

  • cargo test --workspace --no-run exited 0. Cargo compiled the workspace test executables.

  • With XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1, ran:

    cargo test -p xcl --lib -- --nocapture --exact hle::xg::tests::optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav hle::xg::tests::get_texel_offset_rejects_out_of_bounds_xy
    

    Exit 0. 2 passed, 0 failed, 0 ignored, 0 skipped, 743 filtered out. Counts came from the focused log's case-sensitive test result and SKIPPED lines.

Observed behavior

  • optimal_mode returned mode 27 for a UAV whose nominal bit count exceeds u64::MAX. The two-sample 128 × 128 BC7 UAV descriptor took the XGSuggestSwizzleMode fallback and returned S_OK with 4KB_S_X (0x115).
  • get_texel_offset returned zero for x = u64::MAX on mip 5 and for each coordinate at the mip-0 extent of 64. The test also confirmed that the bit offset was cleared for the mip-5 call.
  • Both tests use synthetic descriptors and CPU tiling calculations. Neither creates a D3D12 device or submits GPU work.

Not tested

The full GPU workspace suite and game smoke runs were omitted. The changed 32-bit Dimension check has no dedicated assertion in the two focused tests.

AI use

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

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1480#issuecomment-7153773067) ### Empirical test report (47e5ef07) **Hardware / environment** - Windows x64 build 26200 on AMD Family 23 Model 113 Stepping 0 with 12 logical processors. - `rustc 1.100.0 (0ef1bc386 2026-11-09)`, host `x86_64-pc-windows-msvc`. DXC reported `dxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47)`. - Clean detached checkout at `47e5ef07a33420099a17ff4bec0c240228ac2412`. The unoptimized Cargo test profile ran with incremental compilation and debug symbols disabled. Both commands ran outside `Invoke-ArcTest.ps1` and did not acquire the Arc GPU mutex. **Commands and results** - `cargo test --workspace --no-run` exited 0. Cargo compiled the workspace test executables. - With `XCL_ADAPTER=NONE_CPU_ONLY` and `RUST_TEST_NOCAPTURE=1`, ran: ```powershell cargo test -p xcl --lib -- --nocapture --exact hle::xg::tests::optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav hle::xg::tests::get_texel_offset_rejects_out_of_bounds_xy ``` Exit 0. 2 passed, 0 failed, 0 ignored, 0 skipped, 743 filtered out. Counts came from the focused log's case-sensitive test result and `SKIPPED` lines. **Observed behavior** - `optimal_mode` returned mode 27 for a UAV whose nominal bit count exceeds `u64::MAX`. The two-sample 128 × 128 BC7 UAV descriptor took the `XGSuggestSwizzleMode` fallback and returned `S_OK` with `4KB_S_X` (`0x115`). - `get_texel_offset` returned zero for `x = u64::MAX` on mip 5 and for each coordinate at the mip-0 extent of 64. The test also confirmed that the bit offset was cleared for the mip-5 call. - Both tests use synthetic descriptors and CPU tiling calculations. Neither creates a D3D12 device or submits GPU work. **Not tested** The full GPU workspace suite and game smoke runs were omitted. The changed 32-bit Dimension check has no dedicated assertion in the two focused tests. **AI use** Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1480-focused.log` and published.
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/1480/head:github-bot/gh-1480'
git switch 'github-bot/gh-1480'

Merge

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