D3D12.X: fix XG optimal_mode overflow, BCn UAV bits_per_pixel, and get_texel_offset bounds #1470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1480"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T16:46:22Z.
Fixes three bugs in
crates/xcl/src/hle/xg.rs:optimal_mode()multipliedbits_per_pixel * width * height as u64without saturating, overflowingu64on large widths (aborting acrossextern "system" fn XGSuggestSwizzleModein debug or wrapping into the<= 0x8_00004KB_S_Xthreshold in release).XGSuggestSwizzleMode's fallback path computed8u64 << einstead of dividing byside * sidefor block-compressed formats (16× too large for BCn, selecting64KB_R_Xinstead of4KB_S_Xfor a 128×128 BC7 UAV), and checked onlyd[0] == 2instead of the fullu32Dimensionfield.get_texel_offset()checkedmipandslicebut notx/yagainst the mip's element dimensions, causing out-of-boundsx(such asu64::MAXon a tail mip with non-zero origin) to overflow and abort (STATUS_STACK_BUFFER_OVERRUN) acrossextern "system" fn.This uses
saturating_mulinoptimal_mode(), divides byside * sideand reads the fullu32DimensioninXGSuggestSwizzleMode(), and bounds-checksx < m.width && y < m.heightinget_texel_offset().What is in it
crates/xcl/src/hle/xg.rs: fixoptimal_mode,XGSuggestSwizzleMode, andget_texel_offset; add unit testsoptimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uavandget_texel_offset_rejects_out_of_bounds_xy(both verified failing/aborting before the fix).Tested
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: 2no 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:
PR:
Not tested
AI use
hle/xg.rs, wrote the fixes and unit tests, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:59:59Z.
Full-suite run, since this PR has no test report yet. Tested exact head
47e5ef0(on its baseb7aa9f3).Tested
cargo build --workspace, thenXCL_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.optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav,get_texel_offset_rejects_out_of_bounds_xy.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:21Z.
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 unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:26:25Z.
Empirical test report (
47e5ef07)Hardware / environment
rustc 1.100.0 (0ef1bc386 2026-11-09), hostx86_64-pc-windows-msvc. DXC reporteddxcompiler.dll: 1.9(5512-01b62ad4)(1.9.2609.5) - 1.9.2609.5 (01b62ad47).47e5ef07a33420099a17ff4bec0c240228ac2412. The unoptimized Cargo test profile ran with incremental compilation and debug symbols disabled. Both commands ran outsideInvoke-ArcTest.ps1and did not acquire the Arc GPU mutex.Commands and results
cargo test --workspace --no-runexited 0. Cargo compiled the workspace test executables.With
XCL_ADAPTER=NONE_CPU_ONLYandRUST_TEST_NOCAPTURE=1, ran: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
SKIPPEDlines.Observed behavior
optimal_modereturned mode 27 for a UAV whose nominal bit count exceedsu64::MAX. The two-sample 128 × 128 BC7 UAV descriptor took theXGSuggestSwizzleModefallback and returnedS_OKwith4KB_S_X(0x115).get_texel_offsetreturned zero forx = u64::MAXon 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.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.logand published.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T20:18:11Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:54:06Z.
Triage (#1607) – head
47e5ef0No open or merged PR makes these changes to
hle/xg.rs.optimal_modeproduct now saturates instead of overflowing.XGSuggestSwizzleModefallback divides block bits byside*side, so BCn gets bits per pixel (BC7: 128/16 = 8).get_texel_offsetbounds-checks x/y against the level's element width/height, which matches the unitselement_offsetuses.The change of the 1D check from
d[0]to the full u32 is not in the title but is harmless. Whether real XG picks 4KB_S_X for small BCn UAVs is not shown here.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T09:38:52Z.
merge-check claim
head:
47e5ef07a3Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T09:59:58Z.
merge-check
base:
493dbd3dd0head:
47e5ef07a3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same machine, same commit: 2900 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). Both new tests ran and passed:
optimal_mode_and_suggest_swizzle_handle_overflow_and_bcn_uav,get_texel_offset_rejects_out_of_bounds_xy.review: no blocking finding; one file (+41/-5), every line read. Four small fixes in
xg.rs: (1)optimal_modemultiplies with saturation instead of overflowing; (2)XGSuggestSwizzleModereads the dimension as the 32-bit field it is, not its first byte; (3) its fallback computes bits per pixel for block-compressed formats per pixel, not per block (BC7: 8, not 128), which changes the suggested mode for small BCn UAV textures on that fallback path only (MSAA, 3-D render targets); (4)get_texel_offsetreturns 0 for x / y outside the level instead of indexing past it; x and y are compared with the level size in elements, the unitelement_offsettakes. The PR bundles four fixes, each small and in one function family. Not tested here: a retail title that reaches the fallback or passes out-of-range coordinates.performance: none: a few comparisons.
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.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T10:12:49Z.
merge-check claim
head:
47e5ef07a3Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T10:19:27Z.
merge-check
base:
493dbd3dd0head:
47e5ef07a3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 1 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T21:42:37Z.
merge-check
base:
5ad98adbc3head:
47e5ef07a3merge: clean (merge commit 5bb0b24f7dee2e9dfd5bbac1d85b4a2fe4ca60a0;
git diff --checkclean)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored; SKIPPED: 24 (22 no wave64, 2 no heap windows); failing: none
title run: Newer Retail Game, release build of this merge, Series S settings (
XCL_DEVICE_TYPE=lockhart,XCL_COHERENT_MB=512,XCL_UMA_WINDOWS=16,XCL_SPARSE_LAZY=1), scripted A presses, 240 s planned: into the world at 82 s, 42 s there with 58 frames presented, no crash, no device removal; then our RAM guard stopped it (free RAM under 1 GB on this 32 GB PC, as in main's second run).review: none. Note:
get_texel_offsetnow returns 0 for x at or past the mip width (or y past the height), where a padded coordinate used to get an offset.performance: none. World frame rate not compared: on this 32 GB PC the runs of main and of the PRs end 30 to 150 s into the world (RAM guard or time limit).
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26300 / Claude Code with Claude Opus 5.5
Same settings on main
5ad98adb, two runs: into the world at 94 s with 145 s there and no frame presented (ran to the 240 s limit); into the world at 80 s with 59 s there and 90 frames, then stopped by our RAM guard (free RAM under 1 GB). "In the world" here means the first 2 s window of the activity log with 5,000+ draws and dispatches.AI use: Claude Code (Claude Opus 5.5) ran the build, tests and title runs and wrote this; a Claude Sonnet subagent read the diff and I checked its points.
~Tiago
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.