Native host: R8G8_UINT and R8G8_SNORM were mapped to each other's formats #39

Merged
ShadyUnderLight merged 3 commits from upstream-pr/39 into main 2026-11-26 11:17:36 +00:00
ShadyUnderLight commented 2026-11-26 10:56:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ShadyUnderLight on 2026-11-26T10:56:50Z.


Summary

Corrects the host mapping of the three R8G8 DXGI formats. 4a4d844 collapsed DXGI 49 and 50 onto Rg8Unorm, and mapped DXGI 51 to Rg8Uint.

Problem

DXGI defines these as three distinct formats:

DXGI Format Host before Host after
49 R8G8_UNORM Rg8Unorm Rg8Unorm
50 R8G8_UINT Rg8Unorm Rg8Uint
51 R8G8_SNORM Rg8Uint Rg8Snorm

A uint view sampled through an RG8Unorm texture returns normalized floats instead of integers; a snorm view sampled through an RG8Uint texture returns raw integers instead of [-1, 1]. DXGI 50 also missed is_integer()'s no-blend rule for integer render targets.

Fix

  • Map 49, 50 and 51 separately in descriptors::format.
  • Add Format::Rg8Snorm with its (1, 2) block size and its Metal mapping MTLPixelFormat::RG8Snorm. It is a normalized format, so it stays out of is_integer().
  • Correct the format table in docs/native-host.md.

Tests

r8g8_formats_keep_their_numeric_kind covers all three formats and the integer/normalized distinction.

On main the Rg8Snorm variant does not exist yet, so the test does not compile (E0599). With that one line lifted out, it fails on the mapping:

panicked at crates/victory-gpu/src/native/descriptors.rs:257:9:
assertion `left == right` failed
  left: Some(Rg8Unorm)
 right: Some(Rg8Uint)

A temporary probe on main printed 49 -> Rg8Unorm, 50 -> Rg8Unorm, 51 -> Rg8Uint is_integer=true. The probe was deleted and is not part of this PR. The new test passes here, and host_formats_have_the_title_formats_element_size (which walks 49, 50 and 51) still passes.

Verification

Run on the native arm64 host, plus the Windows target CI uses:

cargo test -p victory-gpu r8g8_formats_keep_their_numeric_kind   ok, 1 passed
cargo test -p victory-gpu                                        ok, 145 passed, 1 ignored
cargo test -p victory-metal                                      ok, all suites
cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
                                                                 clean
cargo xtask policy                                               363 files ok

Native-only lint (not part of CI) still reports two pre-existing unnecessary_cast lints in crates/victory-metal/src/present.rs:126 and :144. They reproduce on unmodified main and this PR does not touch that file.

Risk

Low. DXGI 49 keeps its existing mapping; 50 and 51 now keep their numeric kind. No shader translation, pipeline state or draw-path code changes. Format 50 now takes the existing integer-target path, so integer render targets of that format no longer blend.

Notes

Found while auditing a 75 s native run; the title uses format 50 (64x64) and format 51 (1024x1024). No claim is made about visual output or frame rate.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625127364 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/39). Originally posted by [ShadyUnderLight](https://github.com/ShadyUnderLight) on 2026-11-26T10:56:50Z. --- ## Summary Corrects the host mapping of the three R8G8 DXGI formats. [`4a4d844`](https://github.com/LakshanSivakumar/Native-Victory-macOS/commit/4a4d844) collapsed DXGI 49 and 50 onto `Rg8Unorm`, and mapped DXGI 51 to `Rg8Uint`. ## Problem DXGI defines these as three distinct formats: | DXGI | Format | Host before | Host after | | --- | --- | --- | --- | | 49 | `R8G8_UNORM` | `Rg8Unorm` | `Rg8Unorm` | | 50 | `R8G8_UINT` | `Rg8Unorm` | `Rg8Uint` | | 51 | `R8G8_SNORM` | `Rg8Uint` | `Rg8Snorm` | A uint view sampled through an `RG8Unorm` texture returns normalized floats instead of integers; a snorm view sampled through an `RG8Uint` texture returns raw integers instead of [-1, 1]. DXGI 50 also missed `is_integer()`'s no-blend rule for integer render targets. ## Fix - Map 49, 50 and 51 separately in `descriptors::format`. - Add `Format::Rg8Snorm` with its `(1, 2)` block size and its Metal mapping `MTLPixelFormat::RG8Snorm`. It is a normalized format, so it stays out of `is_integer()`. - Correct the format table in `docs/native-host.md`. ## Tests `r8g8_formats_keep_their_numeric_kind` covers all three formats and the integer/normalized distinction. On main the `Rg8Snorm` variant does not exist yet, so the test does not compile (`E0599`). With that one line lifted out, it fails on the mapping: ```text panicked at crates/victory-gpu/src/native/descriptors.rs:257:9: assertion `left == right` failed left: Some(Rg8Unorm) right: Some(Rg8Uint) ``` A temporary probe on main printed `49 -> Rg8Unorm`, `50 -> Rg8Unorm`, `51 -> Rg8Uint is_integer=true`. The probe was deleted and is not part of this PR. The new test passes here, and `host_formats_have_the_title_formats_element_size` (which walks 49, 50 and 51) still passes. ## Verification Run on the native arm64 host, plus the Windows target CI uses: ```text cargo test -p victory-gpu r8g8_formats_keep_their_numeric_kind ok, 1 passed cargo test -p victory-gpu ok, 145 passed, 1 ignored cargo test -p victory-metal ok, all suites cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings clean cargo xtask policy 363 files ok ``` Native-only lint (not part of CI) still reports two pre-existing `unnecessary_cast` lints in `crates/victory-metal/src/present.rs:126` and `:144`. They reproduce on unmodified `main` and this PR does not touch that file. ## Risk Low. DXGI 49 keeps its existing mapping; 50 and 51 now keep their numeric kind. No shader translation, pipeline state or draw-path code changes. Format 50 now takes the existing integer-target path, so integer render targets of that format no longer blend. ## Notes Found while auditing a 75 s native run; the title uses format 50 (64x64) and format 51 (1024x1024). No claim is made about visual output or frame rate.
LakshanSivakumar commented 2026-11-26 11:07:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:07:14Z.

Review: APPROVED


Correct, thanks. 50/51 were swapped in our own 4a4d844, and the doc table now matches DXGI too. Tested merged with current main: gpu/hle/victory tests, Windows clippy and policy pass.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073049711 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/39#pullrequestreview-6073049711). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:07:14Z. **Review:** APPROVED --- Correct, thanks. 50/51 were swapped in our own 4a4d844, and the doc table now matches DXGI too. Tested merged with current main: gpu/hle/victory tests, Windows clippy and policy pass.
Sign in to join this conversation.
No reviewers
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
LakshanSivakumar/Native-Victory-macOS!39
No description provided.