XG: every tail mip names its position, 3D tail mips are placed by it, element offsets count from the plane #3225

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

@⁠dyshay on GitHub · 2026-11-29 20:48 UTC · original
pr/xg-tail-and-element-offsets → main · +104 −10 · 1 files · 1 commits · closed without merging

Fixes #3224

What it changes

All in crates/victory-hle/src/modules/xg.rs:

  • Every tail mip names its tail_position (x bits 0-10, y bits 11-21), not only thick ones. Before, 2D and thin 3D tail mips left it at 0, which puts all of them at element (0, 0) for a caller that reads it.
  • A 3D tail mip, thick or thin, is placed by that position alone (offset 0, one block per depth slab). Before, thin 3D modes gave tail mips a byte offset as 2D does, so a 3D tail mip could land in the wrong block. 2D tail mips keep t.offset, which already names the right bytes (the tail block is the first block of each slice).
  • element_offset (slot 0x30) counts from the plane's start. For a depth+stencil texture, the stencil plane's elements came back shifted by the whole depth plane. mip_offset (slot 0x28) still includes the plane's offset. The title reads texels of a 128x4 4KB_S texture on the CPU through element_offset (see the comment there); an offset it does not expect makes it read the wrong bytes.
  • Doc comments on element_offset, texel_coordinate and mip_offset now say which start each offset counts from.

No switch: it is a correctness fix, pinned by tests.

How it was tested

  • GPU and profile: RTX 4090, Series X, the house scene, 300 s unattended run each.
  • Before (baseline run without the change): median 37.8 ms, CPU preparing 30.6 ms, GPU 19.0 ms, no device removal, no panics.
  • After: median 39.6 ms, CPU preparing 31.0 ms, GPU 19.0 ms, no device removal, no panics. Same CPU and card time; one run each, so the 1.8 ms median difference is within what a single pair of runs can tell. The p95 was higher in the run with the change (283 ms against 77 ms), in a run that also logged pipelines held back by the memory guard; nothing in this change runs per frame.
  • For shader changes, the wave sizes tested: not a shader change.
  • cargo test passed for the crates it touches: yes, for the XG tests (cargo test -p victory-hle xg): 55 passed, 0 failed, including three new CPU tests (no GPU, no game data):
    • three_d_tail_mips_are_placed_by_position: a 64x64x64 RGBA8 texture, full chain, in SW_4KB_S and SW_64KB_S (thick) and SW_64KB_Z_X and SW_64KB_R_X (thin): every tail mip reports offset 0 and its layout's tail position.
    • two_d_tail_mips_name_their_position: a 256x256 BC7 texture in SW_64KB_D: its 8 tail mips keep their byte offsets and name their positions.
    • element_offsets_count_from_the_plane: a linear D24S8 texture: the stencil plane's first element is at 0 from its plane, further elements step by its pitch, and mip_offset for that plane equals the plane's offset.
  • cargo clippy -p victory-hle --all-targets --locked: nothing in xg.rs. (With -D warnings the build stops first on warnings already on main in victory-loader, victory-shader and victory-gpu, and victory-hle has its existing ones in gameinput.rs and lifecycle.rs.)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1659 (closed; differs as described in #3224: offset 0 only for 3D tail mips, 2D tails keep their offset, plus the new element_offset part), #902 (merged, related: tail mips report the surface's swizzle mode).

Provenance

Ported from dyshay/Janus fb2bd08 (ours).

AI-assisted: written with Claude Code; reviewed and tested as described above.

🤖 Generated with Claude Code

**@⁠dyshay** on GitHub · 2026-11-29 20:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3225) `pr/xg-tail-and-element-offsets` → `main` · +104 −10 · 1 files · 1 commits · closed without merging Fixes #3224 ## What it changes All in `crates/victory-hle/src/modules/xg.rs`: - **Every tail mip names its `tail_position`** (x bits 0-10, y bits 11-21), not only thick ones. Before, 2D and thin 3D tail mips left it at 0, which puts all of them at element (0, 0) for a caller that reads it. - **A 3D tail mip, thick or thin, is placed by that position alone** (offset 0, one block per depth slab). Before, thin 3D modes gave tail mips a byte offset as 2D does, so a 3D tail mip could land in the wrong block. 2D tail mips keep `t.offset`, which already names the right bytes (the tail block is the first block of each slice). - **`element_offset` (slot 0x30) counts from the plane's start.** For a depth+stencil texture, the stencil plane's elements came back shifted by the whole depth plane. `mip_offset` (slot 0x28) still includes the plane's offset. The title reads texels of a 128x4 `4KB_S` texture on the CPU through `element_offset` (see the comment there); an offset it does not expect makes it read the wrong bytes. - Doc comments on `element_offset`, `texel_coordinate` and `mip_offset` now say which start each offset counts from. No switch: it is a correctness fix, pinned by tests. ## How it was tested - GPU and profile: RTX 4090, Series X, the house scene, 300 s unattended run each. - Before (baseline run without the change): median 37.8 ms, CPU preparing 30.6 ms, GPU 19.0 ms, no device removal, no panics. - After: median 39.6 ms, CPU preparing 31.0 ms, GPU 19.0 ms, no device removal, no panics. Same CPU and card time; one run each, so the 1.8 ms median difference is within what a single pair of runs can tell. The p95 was higher in the run with the change (283 ms against 77 ms), in a run that also logged pipelines held back by the memory guard; nothing in this change runs per frame. - For shader changes, the wave sizes tested: not a shader change. - `cargo test` passed for the crates it touches: yes, for the XG tests (`cargo test -p victory-hle xg`): 55 passed, 0 failed, including three new CPU tests (no GPU, no game data): - `three_d_tail_mips_are_placed_by_position`: a 64x64x64 RGBA8 texture, full chain, in `SW_4KB_S` and `SW_64KB_S` (thick) and `SW_64KB_Z_X` and `SW_64KB_R_X` (thin): every tail mip reports offset 0 and its layout's tail position. - `two_d_tail_mips_name_their_position`: a 256x256 BC7 texture in `SW_64KB_D`: its 8 tail mips keep their byte offsets and name their positions. - `element_offsets_count_from_the_plane`: a linear D24S8 texture: the stencil plane's first element is at 0 from its plane, further elements step by its pitch, and `mip_offset` for that plane equals the plane's offset. - `cargo clippy -p victory-hle --all-targets --locked`: nothing in `xg.rs`. (With `-D warnings` the build stops first on warnings already on `main` in `victory-loader`, `victory-shader` and `victory-gpu`, and `victory-hle` has its existing ones in `gameinput.rs` and `lifecycle.rs`.) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1659 (closed; differs as described in #3224: offset 0 only for 3D tail mips, 2D tails keep their offset, plus the new `element_offset` part), #902 (merged, related: tail mips report the surface's swizzle mode). ## Provenance Ported from dyshay/Janus fb2bd08 (ours). AI-assisted: written with Claude Code; reviewed and tested as described above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Every tail mip names its element position in the tail block
  (tail_position), not only thick ones.
- A 3D tail mip, thick or thin, is placed by that position alone
  (offset 0, one block per depth slab). 2D tail mips keep their byte
  offset in the tail block.
- Element offsets (slot 0x30) count from the plane's start: a stencil
  plane's elements no longer include the depth plane before them. Mip
  offsets (slot 0x28) still include the plane's offset.

Three CPU tests pin it: 3D tail mips in thick and thin modes, 2D tail
mips, and a depth+stencil texture's element and mip offsets.

Ported from dyshay/Janus fb2bd08 (ours)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 20:51:48 +00:00
github-bot closed this pull request 2026-12-01 12:37:37 +00:00

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