XG: report tail mips with OffsetBytes zero #1659

Closed
github-bot wants to merge 1 commit from github-bot/gh-1659 into main AGit
Owner

@⁠Shad0wrend on GitHub · 2026-11-28 23:07 UTC · original
Shad0wrend:xg/mip-tail-offset → main · +11 −5 · 1 files · 1 commits · closed without merging

What

The GDK's XG_MIPLEVEL_LAYOUT says a mip-tail level reports OffsetBytes == 0; its position inside the tail is then given by MipTailOffsetElementsX/Y/Z. XGSuggestSwizzleMode's layout was instead reporting t.offset, a byte offset inside the tail block, in OffsetBytes, and only filled the element position for 3D textures. A title following the documented contract would mislocate packed tail mips.

  • All tail mips now report OffsetBytes == 0 and fill the element position (x bits 0-10, y bits 11-21) whether the texture is 2D or 3D.
  • Non-tail mips keep their byte offsets.

Validation

  • cargo test --release --locked -p victory -p victory-gpu -p victory-hle — green (29 + 2 + 550 + 199 + 1 tests, 0 failures). layout_and_copies_through_the_object now checks OffsetBytes == 0 and compares tail_position with the element position from victory-formats; all xg tests pass.
  • cargo clippy --release -p victory-hle --all-targets --locked -- -D warnings with pre-existing upstream lints allowed — clean.
  • cargo run --release --quiet -p xtask -- policy --staged — 1 file ok.

No game paths, logs or binaries are included.

**@⁠Shad0wrend** on GitHub · 2026-11-28 23:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1659) `Shad0wrend:xg/mip-tail-offset` → `main` · +11 −5 · 1 files · 1 commits · closed without merging ## What The GDK's `XG_MIPLEVEL_LAYOUT` says a mip-tail level reports `OffsetBytes == 0`; its position inside the tail is then given by `MipTailOffsetElementsX/Y/Z`. `XGSuggestSwizzleMode`'s layout was instead reporting `t.offset`, a byte offset *inside* the tail block, in `OffsetBytes`, and only filled the element position for 3D textures. A title following the documented contract would mislocate packed tail mips. - All tail mips now report `OffsetBytes == 0` and fill the element position (`x` bits 0-10, `y` bits 11-21) whether the texture is 2D or 3D. - Non-tail mips keep their byte offsets. ## Validation - `cargo test --release --locked -p victory -p victory-gpu -p victory-hle` — green (29 + 2 + 550 + 199 + 1 tests, 0 failures). `layout_and_copies_through_the_object` now checks `OffsetBytes == 0` and compares `tail_position` with the element position from `victory-formats`; all xg tests pass. - `cargo clippy --release -p victory-hle --all-targets --locked -- -D warnings` with pre-existing upstream lints allowed — clean. - `cargo run --release --quiet -p xtask -- policy --staged` — 1 file ok. No game paths, logs or binaries are included.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:08:13 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-28 23:28 UTC · original

Checked on Windows 11, Rust 1.98.1 (pinned), applied on current main (d4b5d51); cherry-picks cleanly. Clippy reports nothing in xg.rs (it stops at the two victory-shader errors already on main, #1517), the xg tests pass including the updated layout_and_copies_through_the_object, and cargo test -p victory-hle --lib gives 199 passed, 0 failed.

I can't check the GDK header here, so I looked at whether the two ways of locating a tail mip agree in this layer.

  • In victory-formats, the tail block is the first block of each slice ("Standard mips from the smallest up, after the tail block"), so a tail mip's Mip::offset is 0 and t.offset is also its byte offset from the start of the slice. main's 2D OffsetBytes = t.offset therefore pointed at the right bytes; what main got wrong for 2D is leaving MipTailOffsetElementsX/Y at 0, so a title that follows the header (OffsetBytes 0, position from the element fields) would put every 2D tail mip at element (0, 0). This PR fills those in, which is the part that fixes something.
  • To check that the new element position names the same bytes, a throwaway test (not part of this PR) walked 2D textures in SW_64KB_S, _D, _S_X, _D_X and _R_X, at 1–16 bytes per element and seven sizes from 4×4 to 2048×512 and 1×4096, with full mip chains: 1135 tail mips, every one with its tail block at slice offset 0. For the 454 that Layout::offset can address, offset(mip, 0, 0, 0) (which shifts by t.x, t.y) equals t.offset in every case, with no mismatches. The other 681 get an error from offset(), so they're unchecked.

So for 2D, OffsetBytes = 0 plus the element position describes the same place main described with the byte offset alone. Whether OffsetBytes should be 0 for a tail mip is the header's call, which I can't confirm from here.

**@⁠babuakhil** on GitHub · 2026-11-28 23:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1659#issuecomment-7247454030) Checked on Windows 11, Rust 1.98.1 (pinned), applied on current `main` (`d4b5d51`); cherry-picks cleanly. Clippy reports nothing in `xg.rs` (it stops at the two `victory-shader` errors already on `main`, #1517), the xg tests pass including the updated `layout_and_copies_through_the_object`, and `cargo test -p victory-hle --lib` gives 199 passed, 0 failed. I can't check the GDK header here, so I looked at whether the two ways of locating a tail mip agree in this layer. - In `victory-formats`, the tail block is the first block of each slice ("Standard mips from the smallest up, after the tail block"), so a tail mip's `Mip::offset` is 0 and `t.offset` is also its byte offset from the start of the slice. `main`'s 2D `OffsetBytes = t.offset` therefore pointed at the right bytes; what `main` got wrong for 2D is leaving `MipTailOffsetElementsX/Y` at 0, so a title that follows the header (`OffsetBytes` 0, position from the element fields) would put every 2D tail mip at element (0, 0). This PR fills those in, which is the part that fixes something. - To check that the new element position names the same bytes, a throwaway test (not part of this PR) walked 2D textures in `SW_64KB_S`, `_D`, `_S_X`, `_D_X` and `_R_X`, at 1–16 bytes per element and seven sizes from 4×4 to 2048×512 and 1×4096, with full mip chains: 1135 tail mips, every one with its tail block at slice offset 0. For the 454 that `Layout::offset` can address, `offset(mip, 0, 0, 0)` (which shifts by `t.x`, `t.y`) equals `t.offset` in every case, with no mismatches. The other 681 get an error from `offset()`, so they're unchecked. So for 2D, `OffsetBytes = 0` plus the element position describes the same place `main` described with the byte offset alone. Whether `OffsetBytes` should be 0 for a tail mip is the header's call, which I can't confirm from here.
github-bot force-pushed github-bot/gh-1659 from 38fe2dc65f to 0301d2c731 2026-11-29 00:39:34 +00:00 Compare
github-bot closed this pull request 2026-11-29 01:40:30 +00:00
Author
Owner

@⁠Shad0wrend on GitHub · 2026-11-29 01:39 UTC · original

Closing per maintainer request; not pursuing these changes.

**@⁠Shad0wrend** on GitHub · 2026-11-29 01:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1659#issuecomment-7248932357) Closing per maintainer request; not pursuing these changes.

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/trustno1-coder--VIctory-NVIDIA!1659
No description provided.