Formats texture: add thick-3D mip-tail regression tests matching AMD addrlib #1450

Closed
github-bot wants to merge 2 commits from gh-pr/1450/head into gh-pr/1450/base
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:06 UTC · original
geiyiliyabumo:fix/formats-thick-3d-miptail-depth → main · +86 −0 · 1 files · 2 commits · closed without merging

Summary

Fixes \VIC-BT-014\ (P1, tracked in #1242) in \crates/victory-formats/src/texture.rs:

  • \Layout::new\ computed thick 3D \ ail_max\ / \ ixed[2]\ from block dimensions, but the mip-tail entry predicate only checked width, height, and remaining mip count—allowing deep narrow 3D textures (e.g. \16x16x64, 4 mips, 4 BPP, \Sw64KbS) to enter the 1-block mip tail at mip 0 despite having 64 slices > block depth.
  • Adds the padded mip depth check against \ ixed[2]\ for thick 3D textures so the \16x16x64\ case enters the tail at mip 2 (depth 16), keeping tail rectangles non-overlapping across all 4 KiB and 64 KiB thick block/element combinations.
  • Adds 4 deterministic synthetic unit tests covering non-overlapping addresses and copy round-trips, exact/odd depth boundaries, absent tails, slab offsets/total size, and thin 2D/3D regression checks.

Verification

  • \cargo test -p victory-formats --lib texture: 12 passed, 0 failed
  • \cargo clippy -p victory-formats --all-targets -- -D warnings: clean
  • \cargo xtask policy: 154 files ok

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1450) `geiyiliyabumo:fix/formats-thick-3d-miptail-depth` → `main` · +86 −0 · 1 files · 2 commits · closed without merging ## Summary Fixes \VIC-BT-014\ (P1, tracked in #1242) in \crates/victory-formats/src/texture.rs\: - \Layout::new\ computed thick 3D \ ail_max\ / \ ixed[2]\ from block dimensions, but the mip-tail entry predicate only checked width, height, and remaining mip count—allowing deep narrow 3D textures (e.g. \16x16x64\, 4 mips, 4 BPP, \Sw64KbS\) to enter the 1-block mip tail at mip 0 despite having 64 slices > block depth. - Adds the padded mip depth check against \ ixed[2]\ for thick 3D textures so the \16x16x64\ case enters the tail at mip 2 (depth 16), keeping tail rectangles non-overlapping across all 4 KiB and 64 KiB thick block/element combinations. - Adds 4 deterministic synthetic unit tests covering non-overlapping addresses and copy round-trips, exact/odd depth boundaries, absent tails, slab offsets/total size, and thin 2D/3D regression checks. ## Verification - \cargo test -p victory-formats --lib texture\: 12 passed, 0 failed - \cargo clippy -p victory-formats --all-targets -- -D warnings\: clean - \cargo xtask policy\: 154 files ok *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:32:15 +00:00
github-bot closed this pull request 2026-11-26 04:32:15 +00:00
Author
Owner

@⁠ArnabSaga on GitHub · 2026-11-24 19:06 UTC · original

Independent reference verification — VIC-BT-014

I investigated the proposed thick-3D mip-tail depth condition against an independently compiled AMD addrlib v10.9 reference implementation.

Gfx10Lib::IsInMipTail() checks width, height, and remaining mip count, but does not compare mip depth. Thick-3D depth is handled separately through slab allocation and addressing.

Reference:

github.com/chaotic-cx/mesa-mirror@f8281cfa33/src/amd/addrlib/src/gfx10/gfx10addrlib.h (L529-L541)

Verification results

For the reported 16×16×64, four-mip, four-byte SW_64KB_S descriptor:

Property Executed addrlib Unchanged VIctory Proposed PR behavior
First tail mip 0 0 2
Total allocation (bytes) 262,144 262,144 786,432
Slab-chain size (bytes) 65,536 65,536 196,608

Additional verification:

  • 18,720/18,720 element addresses matched exactly.
  • 33 descriptors were evaluated, including one rejected by both implementations.
  • All 140 mip metadata rows matched.
  • Address uniqueness, allocation bounds, and four-mip tile/detile round-trip checks passed.
  • Debug and release verification passed.
  • Targeted strict Clippy passed.

The proposed predicate changes not only allocation size but also mip offsets, tail coordinates, and XG-visible layout metadata.

Recommendation

Could we retain the existing tail eligibility predicate and update the additional regression tests to use reference-compatible expectations?

I've prepared a reproducible evidence package containing the independent oracle driver, Rust verification harness, exact reference outputs, checksums, and an end-to-end reproduction script. I'm happy to share these for independent verification.

This reference-compatibility concern also applies to the equivalent depth predicate proposed in #1494.

Limitations

I did not execute the PR branch directly or test physical console hardware. The proposed PR values were derived from its diff. Verification used GNU Rust and MinGW; MSVC and full CI parity remain unverified.

**@⁠ArnabSaga** on GitHub · 2026-11-24 19:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1450#issuecomment-7141612455) ## Independent reference verification — VIC-BT-014 I investigated the proposed thick-3D mip-tail depth condition against an independently compiled AMD addrlib v10.9 reference implementation. `Gfx10Lib::IsInMipTail()` checks width, height, and remaining mip count, but does not compare mip depth. Thick-3D depth is handled separately through slab allocation and addressing. **Reference:** https://github.com/chaotic-cx/mesa-mirror/blob/f8281cfa33e2e752d37b0d619ca53111bbe765de/src/amd/addrlib/src/gfx10/gfx10addrlib.h#L529-L541 ### Verification results For the reported 16×16×64, four-mip, four-byte SW_64KB_S descriptor: | Property | Executed addrlib | Unchanged VIctory | Proposed PR behavior | | --- | ---: | ---: | ---: | | First tail mip | 0 | 0 | 2 | | Total allocation (bytes) | 262,144 | 262,144 | 786,432 | | Slab-chain size (bytes) | 65,536 | 65,536 | 196,608 | Additional verification: - 18,720/18,720 element addresses matched exactly. - 33 descriptors were evaluated, including one rejected by both implementations. - All 140 mip metadata rows matched. - Address uniqueness, allocation bounds, and four-mip tile/detile round-trip checks passed. - Debug and release verification passed. - Targeted strict Clippy passed. The proposed predicate changes not only allocation size but also mip offsets, tail coordinates, and XG-visible layout metadata. ### Recommendation Could we retain the existing tail eligibility predicate and update the additional regression tests to use reference-compatible expectations? I've prepared a reproducible evidence package containing the independent oracle driver, Rust verification harness, exact reference outputs, checksums, and an end-to-end reproduction script. I'm happy to share these for independent verification. This reference-compatibility concern also applies to the equivalent depth predicate proposed in #1494. ### Limitations I did not execute the PR branch directly or test physical console hardware. The proposed PR values were derived from its diff. Verification used GNU Rust and MinGW; MSVC and full CI parity remain unverified.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 20:18 UTC · original

Thank you @⁠ArnabSaga for checking \VIC-BT-014\ against a compiled AMD \ddrlib v10.9\ reference!

You're right — \Gfx10Lib::IsInMipTail()\ intentionally checks only padded width, height, and remaining mip count, while thick-3D depth is handled through depth slab chains (\16x16x64\ 4-mip \SW_64KB_S\ starts the mip tail at mip 0 with 4 depth slabs = 262,144 bytes).

Pushed $sha1450\ to:

  • Retain the original \ddrlib-compatible tail-eligibility predicate in \crates/victory-formats/src/texture.rs\ (with a brief note referencing \Gfx10Lib::IsInMipTail()).
  • Update the new tests (\ hick_tail_matches_addrlib_width_height_predicate, \ hick_tail_deep_narrow_3d_matches_addrlib_slabs, \ hin_tails_keep_array_and_volume_layouts, plus the \16x16x64\ 4-mip tile/detile round-trip) to lock in \ddrlib-compatible expectations so deep narrow 3D layouts stay protected against regressions.
  • Re-verified \cargo test -p victory-formats --lib texture\ (12/12 passed), \cargo clippy -p victory-formats --all-targets -- -D warnings, and \cargo xtask policy.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1450#issuecomment-7143347956) Thank you @⁠ArnabSaga for checking \VIC-BT-014\ against a compiled AMD \ddrlib v10.9\ reference! You're right — \Gfx10Lib::IsInMipTail()\ intentionally checks only padded width, height, and remaining mip count, while thick-3D depth is handled through depth slab chains (\16x16x64\ 4-mip \SW_64KB_S\ starts the mip tail at mip 0 with 4 depth slabs = 262,144 bytes). Pushed \$sha1450\ to: - Retain the original \ddrlib\-compatible tail-eligibility predicate in \crates/victory-formats/src/texture.rs\ (with a brief note referencing \Gfx10Lib::IsInMipTail()\). - Update the new tests (\ hick_tail_matches_addrlib_width_height_predicate\, \ hick_tail_deep_narrow_3d_matches_addrlib_slabs\, \ hin_tails_keep_array_and_volume_layouts\, plus the \16x16x64\ 4-mip tile/detile round-trip) to lock in \ddrlib\-compatible expectations so deep narrow 3D layouts stay protected against regressions. - Re-verified \cargo test -p victory-formats --lib texture\ (12/12 passed), \cargo clippy -p victory-formats --all-targets -- -D warnings\, and \cargo xtask policy\. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠fiestorra on GitHub · 2026-11-24 21:06 UTC · original

Measured against addrlib, this change doubles or triples four 3D layouts — including the case it fixes

I took the addrlib reference data that #1549 added (layouts_match_addrlib, 21 descriptions pinned to Mesa src/amd/addrlib at ed09d38, Navi 21 settings), ran it on a tree with this pull request merged, and printed every description that disagrees instead of stopping at the first. Four do, and all four are Tex3d:

description this change says addrlib says
Tex3d 4x4x16, 5 mips, 4 B, SW_4KB_S 16,384, first tail mip 1 8,192, first tail mip 0
Tex3d 1x1x17, 2 mips, 1 B, SW_4KB_S 16,384, first tail mip 1 8,192, first tail mip 0
Tex3d 16x16x64, 4 mips, 4 B, SW_64KB_S 786,432, first tail mip 2 262,144, first tail mip 0
Tex3d 8x8x128, 4 mips, 1 B, SW_64KB_S 786,432, first tail mip 2 262,144, first tail mip 0

The other 17 descriptions, 2D and 1D and the wide 3D ones, still match, so the padded-depth condition only moves the deep narrow volumes — which is exactly the set the change targets.

The third row is the case this pull request describes: 16x16x64, 4 mips, where "the mip-tail entry predicate allowed it to enter the 1-block mip tail at mip 0 despite having 64 slices > block depth", and the change makes it enter at mip 2. addrlib puts the whole chain in the tail at mip 0 and totals 4 × 64 KiB = 262,144 bytes; #1549's other test spells out what that means element by element: each 16-slice slab has its own 64 KiB tail block, mip 0 at +32 KiB, mip 1 at +16 KiB, mip 2 at +4 KiB, mip 3 at +2.5 KiB, with mip 1's 32 slices spanning two slabs. That is a different structure, not a different threshold.

So the overlap problem the change fixes (VIC-BT-014, #1242) is real, but this is not the shape of its fix: at runtime a deep narrow volume would be allotted two to three times the memory addrlib gives it and off-tiled from different offsets, so the bytes the title uploads and the bytes Layout::offset says are the same element stop corresponding.

What I would suggest, since #1549 is tests only and its numbers come from addrlib rather than from our own tests:

  1. keep the overlap check that matters — a tail rectangle may not overlap another — but enforce it inside the slab-and-tail structure addrlib describes, instead of moving the threshold that decides when a mip enters the tail;
  2. the four cases above are your regression set: they should end at addrlib's numbers, and with this change they do not.

Reproduction, on a tree with both pull requests in it (forge/main, where #1450 is c3b045f and #1549 is 78bcd64): replace the assertion in layouts_match_addrlib with a print of (l.size, l.first_tail_mip, h) against expected and run cargo test -p victory-formats --locked layouts_match_addrlib -- --nocapture. Reverting the merge (git revert -m 1 c3b045f) makes all 21 match again.

No game data is involved: layout sizes and offsets only.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 21:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1450#issuecomment-7144484329) **Measured against addrlib, this change doubles or triples four 3D layouts — including the case it fixes** I took the addrlib reference data that #1549 added (`layouts_match_addrlib`, 21 descriptions pinned to Mesa `src/amd/addrlib` at `ed09d38`, Navi 21 settings), ran it on a tree with this pull request merged, and printed every description that disagrees instead of stopping at the first. Four do, and all four are `Tex3d`: | description | this change says | addrlib says | |---|---|---| | `Tex3d 4x4x16`, 5 mips, 4 B, `SW_4KB_S` | **16,384**, first tail mip **1** | 8,192, first tail mip 0 | | `Tex3d 1x1x17`, 2 mips, 1 B, `SW_4KB_S` | **16,384**, first tail mip **1** | 8,192, first tail mip 0 | | `Tex3d 16x16x64`, 4 mips, 4 B, `SW_64KB_S` | **786,432**, first tail mip **2** | 262,144, first tail mip 0 | | `Tex3d 8x8x128`, 4 mips, 1 B, `SW_64KB_S` | **786,432**, first tail mip **2** | 262,144, first tail mip 0 | The other 17 descriptions, 2D and 1D and the wide 3D ones, still match, so the padded-depth condition only moves the deep narrow volumes — which is exactly the set the change targets. The third row is the case this pull request describes: `16x16x64`, 4 mips, where "the mip-tail entry predicate allowed it to enter the 1-block mip tail at mip 0 despite having 64 slices > block depth", and the change makes it enter at mip 2. **addrlib puts the whole chain in the tail at mip 0** and totals 4 × 64 KiB = 262,144 bytes; #1549's other test spells out what that means element by element: each 16-slice slab has its own 64 KiB tail block, mip 0 at +32 KiB, mip 1 at +16 KiB, mip 2 at +4 KiB, mip 3 at +2.5 KiB, with mip 1's 32 slices spanning two slabs. That is a different structure, not a different threshold. So the overlap problem the change fixes (VIC-BT-014, #1242) is real, but this is not the shape of its fix: at runtime a deep narrow volume would be allotted **two to three times** the memory addrlib gives it and off-tiled from different offsets, so the bytes the title uploads and the bytes `Layout::offset` says are the same element stop corresponding. What I would suggest, since #1549 is tests only and its numbers come from addrlib rather than from our own tests: 1. keep the overlap check that matters — a tail rectangle may not overlap another — but enforce it *inside* the slab-and-tail structure addrlib describes, instead of moving the threshold that decides when a mip enters the tail; 2. the four cases above are your regression set: they should end at addrlib's numbers, and with this change they do not. Reproduction, on a tree with both pull requests in it (`forge/main`, where #1450 is `c3b045f` and #1549 is `78bcd64`): replace the assertion in `layouts_match_addrlib` with a print of `(l.size, l.first_tail_mip, h)` against `expected` and run `cargo test -p victory-formats --locked layouts_match_addrlib -- --nocapture`. Reverting the merge (`git revert -m 1 c3b045f`) makes all 21 match again. No game data is involved: layout sizes and offsets only. Written with an AI assistant.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:40 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1549. Despite its description (which says it adds a depth check), the diff only adds a comment and tests that pin main's thick-3D mip-tail behaviour; #1549 covers the same case with addresses taken from AMD's addrlib.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1450#issuecomment-7148756992) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1549. Despite its description (which says it adds a depth check), the diff only adds a comment and tests that pin main's thick-3D mip-tail behaviour; #1549 covers the same case with addresses taken from AMD's addrlib. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1450
No description provided.