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

Closed
opened 2026-11-24 13:00:01 +00:00 by kss306 · 4 comments
kss306 commented 2026-11-24 13:00:01 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by kss306 on 2026-11-24T13:00:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6582340877 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/868). Originally posted by [kss306](https://github.com/kss306) on 2026-11-24T13:00:01Z. --- `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.
MichaelSmithAI commented 2026-11-24 14:04:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T13:06:34Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132360627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132360627). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T13:06:34Z. --- 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)
pushkarreddyy commented 2026-11-24 14:04:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T13:30:42Z.


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 (

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132934581 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132934581). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T13:30:42Z. --- 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 commented 2026-11-24 14:04:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T13:31:56Z.


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 (
<!-- greyfinch-sync:Marvisak/VIctory:comment:7132964664 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7132964664). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T13:31:56Z. --- ### 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 (
pushkarreddyy commented 2026-11-24 15:04:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T14:37:38Z.


Pull request is now open for review: #975.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134683745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/868#issuecomment-7134683745). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T14:37:38Z. --- Pull request is now open for review: #975.
Sign in to join this conversation.
No labels
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.

Reference
Marvisak/VIctory#868
No description provided.