HLE: XGSuggestSwizzleMode TEXTURE_1D branch never reached by any test #868

Closed
opened 2026-11-26 04:14:05 +00:00 by github-bot · 4 comments
Owner

@⁠kss306 on GitHub · 2026-11-24 13:00 UTC · original

suggestions_follow_the_use in crates/victory-hle/src/modules/xg.rs tests three of the four branches of XGSuggestSwizzleMode but never exercises the TEXTURE_1D branch, which is the first check in the helper.

Implementation evidence

xg.rs, fn suggested(), line 58:

fn suggested(desc: &ResourceDesc) -> Swizzle {
    if desc.dimension == TEXTURE_1D {   // TEXTURE_1D = 2
        Swizzle::LINEAR                 // → output 0x100 (SWIZZLED | LINEAR)
    } else if desc.flags & ALLOW_DEPTH_STENCIL != 0 {
        Swizzle::SW_64KB_Z_X            // → 0x118
    } else if desc.flags & ALLOW_RENDER_TARGET != 0 {
        Swizzle::SW_64KB_R_X            // → 0x11b
    } else {
        Swizzle::SW_4KB_S               // → 0x105
    }
}

XGSuggestSwizzleMode returns SWIZZLED | suggested(desc).0. For a 1D texture this is 0x100 | 0 = 0x100.

Missing test

fn suggestions_follow_the_use() (line 657) constructs its descriptor with desc(256, 256, 1, 98, 0) which always sets dimension: 3 (TEXTURE_2D). The test then varies flags to reach the depth-stencil and render-target branches and the else-branch, but never changes dimension to TEXTURE_1D (= 2).

The three covered branches produce 0x118, 0x11b, and 0x105. The TEXTURE_1D branch producing 0x100 is never asserted.

Why it matters

According to the D3D12 / Xbox GDK specification, 1D textures must use row-major (linear) layout — there is no tiled 1D swizzle mode. If the branch were accidentally removed or its condition changed to something else (e.g., TEXTURE_3D), no test would catch the regression, and titles that query XGSuggestSwizzleMode for a 1D texture would receive a wrong swizzle mode.

Suggested fix

Add a single assertion to suggestions_follow_the_use:

// TEXTURE_1D → LINEAR (the only swizzle valid for 1D textures).
let mut d1d = desc(256, 1, 1, 10, 0); // R16_FLOAT, 1D dimensions
d1d.dimension = TEXTURE_1D;
XGSuggestSwizzleMode(&d1d, 0, &mut out);
assert_eq!(out, 0x100); // SWIZZLED | LINEAR

cargo test -p victory-hle — the new assertion passes, all existing assertions still pass. No GPU or game data needed.

AI-assisted: found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.

**@⁠kss306** on GitHub · 2026-11-24 13:00 UTC · [original](https://github.com/Marvisak/VIctory/issues/868) `suggestions_follow_the_use` in `crates/victory-hle/src/modules/xg.rs` tests three of the four branches of `XGSuggestSwizzleMode` but never exercises the `TEXTURE_1D` branch, which is the first check in the helper. ## Implementation evidence `xg.rs`, `fn suggested()`, line 58: ```rust fn suggested(desc: &ResourceDesc) -> Swizzle { if desc.dimension == TEXTURE_1D { // TEXTURE_1D = 2 Swizzle::LINEAR // → output 0x100 (SWIZZLED | LINEAR) } else if desc.flags & ALLOW_DEPTH_STENCIL != 0 { Swizzle::SW_64KB_Z_X // → 0x118 } else if desc.flags & ALLOW_RENDER_TARGET != 0 { Swizzle::SW_64KB_R_X // → 0x11b } else { Swizzle::SW_4KB_S // → 0x105 } } ``` `XGSuggestSwizzleMode` returns `SWIZZLED | suggested(desc).0`. For a 1D texture this is `0x100 | 0 = 0x100`. ## Missing test `fn suggestions_follow_the_use()` (line 657) constructs its descriptor with `desc(256, 256, 1, 98, 0)` which always sets `dimension: 3` (TEXTURE_2D). The test then varies `flags` to reach the depth-stencil and render-target branches and the else-branch, but never changes `dimension` to `TEXTURE_1D (= 2)`. The three covered branches produce `0x118`, `0x11b`, and `0x105`. The `TEXTURE_1D` branch producing `0x100` is never asserted. ## Why it matters According to the D3D12 / Xbox GDK specification, 1D textures must use row-major (linear) layout — there is no tiled 1D swizzle mode. If the branch were accidentally removed or its condition changed to something else (e.g., `TEXTURE_3D`), no test would catch the regression, and titles that query `XGSuggestSwizzleMode` for a 1D texture would receive a wrong swizzle mode. ## Suggested fix Add a single assertion to `suggestions_follow_the_use`: ```rust // TEXTURE_1D → LINEAR (the only swizzle valid for 1D textures). let mut d1d = desc(256, 1, 1, 10, 0); // R16_FLOAT, 1D dimensions d1d.dimension = TEXTURE_1D; XGSuggestSwizzleMode(&d1d, 0, &mut out); assert_eq!(out, 0x100); // SWIZZLED | LINEAR ``` `cargo test -p victory-hle` — the new assertion passes, all existing assertions still pass. No GPU or game data needed. **AI-assisted:** found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:05 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 13:06 UTC · original

Melissa added a regression on ffe310e that passes the output of XGSuggestSwizzleMode into XGCreateTextureComputer. For a 256-texel 1D R16_FLOAT texture, the selector returned 0x100 both with and without ALLOW_RENDER_TARGET. In each case the resulting address computer placed texels 3 and 255 at byte offsets 6 and 510, as expected for two bytes per texel.

All five XG tests passed under Wine. This verifies that VIctory's selector and address computer agree; an independent console layout measurement remains open. Test-only commit

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 13:06 UTC · [original](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132360627) Melissa added a regression on ffe310e that passes the output of XGSuggestSwizzleMode into XGCreateTextureComputer. For a 256-texel 1D R16_FLOAT texture, the selector returned 0x100 both with and without ALLOW_RENDER_TARGET. In each case the resulting address computer placed texels 3 and 255 at byte offsets 6 and 510, as expected for two bytes per texel. All five XG tests passed under Wine. This verifies that VIctory's selector and address computer agree; an independent console layout measurement remains open. [Test-only commit](https://github.com/MichaelSmithAI/VIctory/commit/4e2a5abb78cf215cd46a2285dbff522ee2e79126)
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 13:30 UTC · original

Claiming this issue.

Technical Analysis

In crates/victory-hle/src/modules/xg.rs:
suggested(desc: &ResourceDesc) -> Swizzle checks:
ust if desc.dimension == TEXTURE_1D { Swizzle::LINEAR } else if desc.flags & ALLOW_DEPTH_STENCIL != 0 { ...
XGSuggestSwizzleMode returns SWIZZLED | suggested(desc).0. For 1D textures (desc.dimension == TEXTURE_1D == 2), the specification mandates row-major linear swizzle (

**@⁠pushkarreddyy** on GitHub · 2026-11-24 13:30 UTC · [original](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132934581) Claiming this issue. ### Technical Analysis In crates/victory-hle/src/modules/xg.rs: suggested(desc: &ResourceDesc) -> Swizzle checks: ` ust if desc.dimension == TEXTURE_1D { Swizzle::LINEAR } else if desc.flags & ALLOW_DEPTH_STENCIL != 0 { ... ` XGSuggestSwizzleMode returns SWIZZLED | suggested(desc).0. For 1D textures (desc.dimension == TEXTURE_1D == 2), the specification mandates row-major linear swizzle (
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 13:31 UTC · original · edited 2026-11-24 14:22 UTC

Verified Implementation Ready on Fork

The regression test coverage for XGSuggestSwizzleMode TEXTURE_1D is implemented and available on my fork:

Compare: https://github.com/Marvisak/VIctory/compare/main...pushkarreddyy:VIctory:test/hle-swizzle-1d-coverage

Verification

  • Exercises XGSuggestSwizzleMode on TEXTURE_1D across default, ALLOW_RENDER_TARGET, and ALLOW_DEPTH_STENCIL configurations, guaranteeing that 1D textures always resolve to linear swizzle (
**@⁠pushkarreddyy** on GitHub · 2026-11-24 13:31 UTC · [original](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132964664) · edited 2026-11-24 14:22 UTC ### Verified Implementation Ready on Fork The regression test coverage for XGSuggestSwizzleMode TEXTURE_1D is implemented and available on my fork: - **Branch:** [ est/hle-swizzle-1d-coverage](https://github.com/pushkarreddyy/VIctory/tree/test/hle-swizzle-1d-coverage) - **Commit:** [78e2d19](https://github.com/pushkarreddyy/VIctory/commit/78e2d19) based on main (ffe310e) Compare: https://github.com/Marvisak/VIctory/compare/main...pushkarreddyy:VIctory:test/hle-swizzle-1d-coverage #### Verification - Exercises XGSuggestSwizzleMode on TEXTURE_1D across default, ALLOW_RENDER_TARGET, and ALLOW_DEPTH_STENCIL configurations, guaranteeing that 1D textures always resolve to linear swizzle (
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 14:37 UTC · original

Pull request is now open for review: #975.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 14:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7134683745) Pull request is now open for review: #975.
This discussion has been locked. Commenting is limited to contributors.
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#868
No description provided.