D3D12.X: clear alignment and check overflow on GetResourceAllocationInfo(2) error #1360

Open
b3IKK wants to merge 1 commit from upstream-pr/1370 into main
b3IKK commented 2026-11-24 15:19:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T15:19:42Z.


In device_x::allocation_of (shared by get_resource_allocation_info_x and get_resource_allocation_info2_x), a descriptor that failed after the first one (s == u64::MAX or a == 0) returned (u64::MAX, align) with the previous descriptor's alignment, instead of D3D12's error sentinel { SizeInBytes: UINT64_MAX, Alignment: 0 }. The alignment and accumulation steps (size.next_multiple_of(a), offset + s, and the final size.next_multiple_of(align)) also used unchecked arithmetic, panicking in debug and wrapping in release on overflow.

This returns (u64::MAX, 0) on a descriptor error and uses checked_next_multiple_of / checked_add throughout, treating an overflow (or landing exactly on u64::MAX) as (u64::MAX, 0).

What is in it

  • crates/xcl/src/hle/d3d12x/device_x.rs: the error return and checked arithmetic in allocation_of; the failure-case expectation of allocation_info_of_several_is_padded_to_the_largest_alignment becomes (u64::MAX, 0), and the new test allocation_of_clears_alignment_on_error_and_overflow covers the error after a valid descriptor, the sum overflow, the alignment rounding overflow and the final padding overflow.

Since the last push: rebased onto main 06c9f55; the conflict was in the test module (a UAV-format test main had added 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 -- allocation_of and -- uav_format_promotion: 2 passed, 0 failed
  • allocation_of_clears_alignment_on_error_and_overflow with the error return put back to (u64::MAX, align): 0 passed, 1 failed — left: (18446744073709551615, 65536), right: (18446744073709551615, 0)

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 (9238a8d, clean tree, no local changes):

xcl-smoke v1
commit: 9238a8dfc9e1aa174327d8707047efd689b763ff
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1644 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16305 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 makes GetResourceAllocationInfo fail after a valid descriptor (the test drives allocation_of directly)
  • the overflow paths on a machine where usize/u64 arithmetic could differ (none expected; the code is u64 throughout)
  • 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 error return, ran the suite and the scripts/smoke.ps1 pair.
<!-- greyfinch-sync:ivall/xcl:issue:5474999752 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1370). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T15:19:42Z. --- In `device_x::allocation_of` (shared by `get_resource_allocation_info_x` and `get_resource_allocation_info2_x`), a descriptor that failed after the first one (`s == u64::MAX` or `a == 0`) returned `(u64::MAX, align)` with the previous descriptor's alignment, instead of D3D12's error sentinel `{ SizeInBytes: UINT64_MAX, Alignment: 0 }`. The alignment and accumulation steps (`size.next_multiple_of(a)`, `offset + s`, and the final `size.next_multiple_of(align)`) also used unchecked arithmetic, panicking in debug and wrapping in release on overflow. This returns `(u64::MAX, 0)` on a descriptor error and uses `checked_next_multiple_of` / `checked_add` throughout, treating an overflow (or landing exactly on `u64::MAX`) as `(u64::MAX, 0)`. **What is in it** - `crates/xcl/src/hle/d3d12x/device_x.rs`: the error return and checked arithmetic in `allocation_of`; the failure-case expectation of `allocation_info_of_several_is_padded_to_the_largest_alignment` becomes `(u64::MAX, 0)`, and the new test `allocation_of_clears_alignment_on_error_and_overflow` covers the error after a valid descriptor, the sum overflow, the alignment rounding overflow and the final padding overflow. **Since the last push**: rebased onto `main` `06c9f55`; the conflict was in the test module (a UAV-format test `main` had added 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 -- allocation_of` and `-- uav_format_promotion`: 2 passed, 0 failed - `allocation_of_clears_alignment_on_error_and_overflow` with the error return put back to `(u64::MAX, align)`: 0 passed, 1 failed — `left: (18446744073709551615, 65536), right: (18446744073709551615, 0)` **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 (`9238a8d`, clean tree, no local changes): ``` xcl-smoke v1 commit: 9238a8dfc9e1aa174327d8707047efd689b763ff gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1644 (PresentX 1645) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16305 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 makes `GetResourceAllocationInfo` fail after a valid descriptor (the test drives `allocation_of` directly) - the overflow paths on a machine where `usize`/`u64` arithmetic could differ (none expected; the code is `u64` throughout) - 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 error return, ran the suite and the `scripts/smoke.ps1` pair.
futurepro62 commented 2026-11-24 16:07:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:26:32Z.


Full-suite run, since this PR has no test report yet. Tested exact head 52b928d (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: get_resource_allocation_info_resets_alignment_on_error_and_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.
<!-- greyfinch-sync:ivall/xcl:comment:7136032382 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1370#issuecomment-7136032382). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:26:32Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `52b928d` (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: `get_resource_allocation_info_resets_alignment_on_error_and_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.
DavidM1911 commented 2026-11-24 17:06:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:33:32Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (b7aa9f3) in crates/xcl/src/hle/d3d12x/device_x.rs — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7137853946 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1370#issuecomment-7137853946). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:33:32Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** (`b7aa9f3`) in `crates/xcl/src/hle/d3d12x/device_x.rs` — needs a rebase before it can be tested.
b3IKK commented 2026-11-25 16:12:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-25T15:43:53Z.


Rebased onto main 06c9f55; the conflict was a UAV-format test main had added at the same place, and both are kept. Head 9238a8d: 1266 passed, 0 failed, 46 ignored. With the error return put back to (u64::MAX, align) the new test fails (left: (2^64-1, 65536), right: (2^64-1, 0)); the smoke pair in the description is 426a5a7 / this head. AI use: OpenCode, Claude Fable 5.2.

<!-- greyfinch-sync:ivall/xcl:comment:7167280075 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1370#issuecomment-7167280075). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-25T15:43:53Z. --- Rebased onto `main` `06c9f55`; the conflict was a UAV-format test `main` had added at the same place, and both are kept. Head `9238a8d`: 1266 passed, 0 failed, 46 ignored. With the error return put back to `(u64::MAX, align)` the new test fails (`left: (2^64-1, 65536), right: (2^64-1, 0)`); the smoke pair in the description is `426a5a7` / this head. AI use: OpenCode, Claude Fable 5.2.
DavidM1911 commented 2026-11-26 01:05:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:26:38Z.


Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7178762026 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1370#issuecomment-7178762026). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T00:26:38Z. --- Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
github-actions[bot] commented 2026-11-30 08:40:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:40:22Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7273198987 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1370#issuecomment-7273198987). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:40:22Z. --- 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.
Foniass commented 2026-12-01 05:32:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:32:31Z.


Triage (#1607) – head 9238a8d

No open or merged PR makes the same change. Main's allocation_of in device_x.rs still returns (u64::MAX, align) on an error and uses unchecked next_multiple_of and +.
No problems found in the diff. The branch conflicts with main and needs a rebase.
Recommendation: keep open.

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

<!-- greyfinch-sync:ivall/xcl:comment:7301879252 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1370#issuecomment-7301879252). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:32:31Z. --- **Triage (#1607)** – head 9238a8d No open or merged PR makes the same change. Main's `allocation_of` in `device_x.rs` still returns `(u64::MAX, align)` on an error and uses unchecked `next_multiple_of` and `+`. No problems found in the diff. The branch conflicts with main and needs a rebase. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1370:upstream-pr/1370'
git switch 'upstream-pr/1370'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1370'
git switch 'upstream-pr/1370'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1370'
git switch 'upstream-pr/1370'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1370'
git switch 'main'
git merge --squash 'upstream-pr/1370'
git switch 'main'
git merge --ff-only 'upstream-pr/1370'
git switch 'main'
git merge 'upstream-pr/1370'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1360
No description provided.