GPU: preserve sub-64 KiB alignments and check bounds in allocation_info #1396

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

@⁠fuzeofficlal on GitHub · 2026-11-24 17:43 UTC · original
fuzeofficlal:fix/resource-allocation-info-alignment-782 → main · +133 −1 · 1 files · 1 commits · open

Fixes #782.

Summary

  • Initialize total.alignment to 1 instead of KIB_64 in place() so 4 KiB (SW_4KB_S) and 256-byte linear texture layouts retain their alignments in GetResourceAllocationInfo and GetResourceAllocationInfo2 (and count == 0 returns { size: 0, alignment: 1 }).
  • Round fallback footprint() sizes up to their computed alignment rather than KIB_64 so 4 MiB-aligned fallback resources never return size < alignment.
  • Guard u64 offset/size arithmetic with checked_next_multiple_of + checked_add, reject null descriptor pointers when count > 0, fill remaining AllocationInfo1 entries with error sentinels on failure, and write out via out.write(total) when non-null without creating references to uninitialized return slots.

Verification

  • Added resource::tests::allocation_info_preserves_sub_64k_alignments_and_bounds covering 4 KiB BC7 textures, 256-byte linear textures, mixed batches, 4 MiB fallback alignment, null/empty calls, and u64 overflow boundaries, verified against native ID3D12Device::GetResourceAllocationInfo on NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, and D3D12 WARP.
  • cargo test -p victory-gpu, cargo clippy --workspace --all-features, and cargo xtask policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1396) `fuzeofficlal:fix/resource-allocation-info-alignment-782` → `main` · +133 −1 · 1 files · 1 commits · open Fixes #782. ### Summary - Initialize `total.alignment` to `1` instead of `KIB_64` in `place()` so 4 KiB (`SW_4KB_S`) and 256-byte linear texture layouts retain their alignments in `GetResourceAllocationInfo` and `GetResourceAllocationInfo2` (and `count == 0` returns `{ size: 0, alignment: 1 }`). - Round fallback `footprint()` sizes up to their computed `alignment` rather than `KIB_64` so 4 MiB-aligned fallback resources never return `size < alignment`. - Guard `u64` offset/size arithmetic with `checked_next_multiple_of` + `checked_add`, reject null descriptor pointers when `count > 0`, fill remaining `AllocationInfo1` entries with error sentinels on failure, and write `out` via `out.write(total)` when non-null without creating references to uninitialized return slots. ### Verification - Added `resource::tests::allocation_info_preserves_sub_64k_alignments_and_bounds` covering 4 KiB BC7 textures, 256-byte linear textures, mixed batches, 4 MiB fallback alignment, null/empty calls, and `u64` overflow boundaries, verified against native `ID3D12Device::GetResourceAllocationInfo` on **NVIDIA GeForce RTX 5090**, **AMD Radeon(TM) Graphics**, and **D3D12 WARP**. - `cargo test -p victory-gpu`, `cargo clippy --workspace --all-features`, and `cargo xtask policy`: passed.
Start place()'s running total alignment at 1 instead of 64 KiB so
sub-64 KiB console texture layouts (4 KiB and 256-byte) preserve their
alignments across GetResourceAllocationInfo and
GetResourceAllocationInfo2.

Closes #782
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:22 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 17:51 UTC · original

Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. main@ffe310e baseline on this box: 342 passed, 0 failed, 6 ignored.

cargo test --workspace
343 passed; 0 failed; 6 ignored   (exit 0)

One more than the baseline; preserving sub-64 KiB alignments and checking bounds is exercised and green.

Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran cargo test --workspace, reverted it.

**@⁠dcastell1** on GitHub · 2026-11-24 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1396#issuecomment-7139801367) Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. `main@ffe310e` baseline on this box: **342 passed, 0 failed, 6 ignored**. ``` cargo test --workspace 343 passed; 0 failed; 6 ignored (exit 0) ``` One more than the baseline; preserving sub-64 KiB alignments and checking bounds is exercised and green. Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran `cargo test --workspace`, reverted it.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:25 UTC · original · edited 2026-11-26 00:25 UTC

Automated triage for the maintainers.

Merge candidate. The PR is now reduced to what the second look asked for. place() in crates/victory-gpu/src/resource.rs starts the running total at alignment 1 instead of 64 KiB, so GetResourceAllocationInfo / GetResourceAllocationInfo2 report the 4 KiB or 256-byte alignment that footprint gives each resource (#782). The new test allocation_info_preserves_sub_64k_alignments checks the 4KB_S BC7 total (0x56000, 0x1000) through both 0xc8 and 0x360 against each[0], the 256-byte linear texture, and the offsets and maximum alignment of a mixed batch.

On your reply: confirmed. The footprint() rounding change, the null, overflow and sentinel guards, and test sections 3 to 6 are all gone, and the diff is one hunk plus the test. It merges cleanly with current main.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1396#issuecomment-7149527759) · edited 2026-11-26 00:25 UTC <!-- victory-triage v1 head=08fb746f03093b3936fa75dbfce6851c8a37799d verdict=merge-candidate at=2026-11-26T00:25:32Z --> Automated triage for the maintainers. **Merge candidate.** The PR is now reduced to what the second look asked for. `place()` in `crates/victory-gpu/src/resource.rs` starts the running total at alignment 1 instead of 64 KiB, so `GetResourceAllocationInfo` / `GetResourceAllocationInfo2` report the 4 KiB or 256-byte alignment that `footprint` gives each resource (#782). The new test `allocation_info_preserves_sub_64k_alignments` checks the 4KB_S BC7 total `(0x56000, 0x1000)` through both 0xc8 and 0x360 against `each[0]`, the 256-byte linear texture, and the offsets and maximum alignment of a mixed batch. On your reply: confirmed. The `footprint()` rounding change, the null, overflow and sentinel guards, and test sections 3 to 6 are all gone, and the diff is one hunk plus the test. It merges cleanly with current `main`. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:01 UTC · original

Automated triage for the maintainers, second look (a review against main, with the PR built and tested).

The core change is right and matters: the running total's alignment should start at 1, so that a batch of 4 KiB-aligned textures reports 4 KiB, which is what the title asks for and checks. This can be merged once it is reduced to that. Please keep the place() change in crates/victory-gpu/src/resource.rs (alignment: 1 for the running total) and the first two cases of the new test (the 4KB_S BC7 total of (0x56000, 0x1000) through 0xc8 and 0x360 equal to each[0], and the mixed batch offsets). Please drop the footprint() fallback rounding change, the null and overflow guards and the sentinel back-fill in allocation_info, allocation_info2 and place, and test sections 3 to 6 (including the host-adapter enumeration): the title passes neither null pointers nor sizes near 2^64, and nothing shows that the rounding change is needed.

Push the change and it will be reviewed again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1396#issuecomment-7175845335) Automated triage for the maintainers, second look (a review against `main`, with the PR built and tested). The core change is right and matters: the running total's alignment should start at 1, so that a batch of 4 KiB-aligned textures reports 4 KiB, which is what the title asks for and checks. This can be merged once it is reduced to that. Please keep the `place()` change in `crates/victory-gpu/src/resource.rs` (`alignment: 1` for the running total) and the first two cases of the new test (the 4KB_S BC7 total of `(0x56000, 0x1000)` through 0xc8 and 0x360 equal to `each[0]`, and the mixed batch offsets). Please drop the `footprint()` fallback rounding change, the null and overflow guards and the sentinel back-fill in `allocation_info`, `allocation_info2` and `place`, and test sections 3 to 6 (including the host-adapter enumeration): the title passes neither null pointers nor sizes near 2^64, and nothing shows that the rounding change is needed. Push the change and it will be reviewed again. Thank you for the contribution.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:38 UTC · original

Reduced and rebased onto main (f3578e3) in 08fb746 per second-look feedback:

  • Kept only the place() change (alignment: 1 for the running total) and the first two test sections (4KB_S BC7 (0x56000, 0x1000) through 0xc8/0x360 matching each[0], linear 256-byte texture, and mixed batch offsets/max alignment).
  • Dropped the footprint() fallback rounding change, null/overflow/sentinel guards in allocation_info/allocation_info2/place, and test sections 3–6 (including host-adapter enumeration).
  • Re-verified resource::tests (18/18 passed), cargo clippy -p victory-gpu --all-targets (default & --features diagnostics, 0 warnings), and cargo xtask policy (190 files ok).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1396#issuecomment-7176603102) Reduced and rebased onto `main` (`f3578e3`) in `08fb746` per second-look feedback: - Kept only the `place()` change (`alignment: 1` for the running total) and the first two test sections (4KB_S BC7 `(0x56000, 0x1000)` through `0xc8`/`0x360` matching `each[0]`, linear 256-byte texture, and mixed batch offsets/max alignment). - Dropped the `footprint()` fallback rounding change, null/overflow/sentinel guards in `allocation_info`/`allocation_info2`/`place`, and test sections 3–6 (including host-adapter enumeration). - Re-verified `resource::tests` (18/18 passed), `cargo clippy -p victory-gpu --all-targets` (default & `--features diagnostics`, 0 warnings), and `cargo xtask policy` (190 files ok).
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/1396/head:github-bot/gh-1396'
git switch 'github-bot/gh-1396'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1396'
git switch 'github-bot/gh-1396'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1396'
git switch 'github-bot/gh-1396'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1396'
git switch 'main'
git merge --squash 'github-bot/gh-1396'
git switch 'main'
git merge --ff-only 'github-bot/gh-1396'
git switch 'main'
git merge 'github-bot/gh-1396'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1396
No description provided.