Shader: decode the packed typed-buffer formats #25

Manually merged
github merged 1 commit from gh-pr/25/head into gh-pr/25/base 2026-11-26 03:47:00 +00:00
Owner

@⁠artor410 on GitHub · 2026-11-23 23:18 UTC · original
artor410:packed-buffer-formats → main · +117 −26 · 1 files · 1 commits · merged 2026-11-24 07:46 UTC

Summary

Typed buffer loads (tbuffer_load_format_*) in the 10_11_11, 11_11_10 and 10_10_10_2 families (GFX10 unified formats 30-49) were refused, so any shader using them failed translation. This fills in their channel layouts and decodes the unsigned small floats.

 buffer_format(30..=36)  // 10_11_11
-  None
+  [11, 11, 10]           // R11G11B10, channels from bit 0
 buffer_format(37..=43)  // 11_11_10
-  None
+  [10, 11, 11]
 buffer_format(44..=49)  // 10_10_10_2
-  None
+  [2, 10, 10, 10]        // mirror of 2_10_10_10

 format_load, Numeric::Float
-  legacyF16ToF32(field)
+  legacyF16ToF32(field << half_shift(w))   // 4 for 11-bit, 5 for 10-bit, 0 for 16-bit

An unsigned 11/10-bit float is a half's exponent (5 bits, bias 15) plus the top of its mantissa without the sign, so shifting it into half position widens exactly, denormals, infinities and NaNs included. The other numerics (unorm, snorm, scaled, int) go through the existing generic per-width code.

Sources, cited in the code: format numbers from LLVM's UfmtGFX10 (SIDefines.h; the GFX10 buffer table has no 5_9_9_9), channel order from Mesa's ac_formats.c (R11G11B10_FLOAT is 10_11_11; 10_10_10_2 has its 2-bit channel in the low bits).

Evidence

  • Before: buffer_format(36) (and 30-49) returned None, so the load failed translation with "a buffer format".
    After: new unit tests in emit::lower::tests:
    • packed_buffer_formats_by_number: the ids map to the layouts and numerics above.
    • small_floats_widen_as_halves: spec values through the shift: 11-bit 0x001 = 2^-20, 0x03F = largest denormal, 0x3C0 = 1.0, 0x7BF = 65024, 0x7C0 = inf, 0x7C1 = NaN; the same for 10-bit; 16-bit unchanged.

cargo test -p victory-shader passes (59). cargo clippy adds no warnings and cargo xtask policy is clean.

Not covered: I can't run diff_tests (no console compiler here), so the emitted DXIL is untested on a GPU and against the game. The snorm -1 clamp on the 2-bit channel is the existing generic code and isn't tested here either. A typed loads diff case with R11G11B10_FLOAT and the 10_10_10_2 formats would cover both.

Merge Danger

Door: two-way

Blast Radius: small

Only shaders that used to fail translation on these formats change. The 16-bit float path keeps a shift of 0.

🤖 Generated with Claude Code

**@⁠artor410** on GitHub · 2026-11-23 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/25) `artor410:packed-buffer-formats` → `main` · +117 −26 · 1 files · 1 commits · merged 2026-11-24 07:46 UTC ## Summary Typed buffer loads (`tbuffer_load_format_*`) in the 10_11_11, 11_11_10 and 10_10_10_2 families (GFX10 unified formats 30-49) were refused, so any shader using them failed translation. This fills in their channel layouts and decodes the unsigned small floats. ```diff buffer_format(30..=36) // 10_11_11 - None + [11, 11, 10] // R11G11B10, channels from bit 0 buffer_format(37..=43) // 11_11_10 - None + [10, 11, 11] buffer_format(44..=49) // 10_10_10_2 - None + [2, 10, 10, 10] // mirror of 2_10_10_10 format_load, Numeric::Float - legacyF16ToF32(field) + legacyF16ToF32(field << half_shift(w)) // 4 for 11-bit, 5 for 10-bit, 0 for 16-bit ``` An unsigned 11/10-bit float is a half's exponent (5 bits, bias 15) plus the top of its mantissa without the sign, so shifting it into half position widens exactly, denormals, infinities and NaNs included. The other numerics (unorm, snorm, scaled, int) go through the existing generic per-width code. Sources, cited in the code: format numbers from LLVM's `UfmtGFX10` (`SIDefines.h`; the GFX10 buffer table has no 5_9_9_9), channel order from Mesa's `ac_formats.c` (R11G11B10_FLOAT is 10_11_11; 10_10_10_2 has its 2-bit channel in the low bits). ## Evidence - **Before:** `buffer_format(36)` (and 30-49) returned `None`, so the load failed translation with "a buffer format". **After:** new unit tests in `emit::lower::tests`: - `packed_buffer_formats_by_number`: the ids map to the layouts and numerics above. - `small_floats_widen_as_halves`: spec values through the shift: 11-bit `0x001` = 2^-20, `0x03F` = largest denormal, `0x3C0` = 1.0, `0x7BF` = 65024, `0x7C0` = inf, `0x7C1` = NaN; the same for 10-bit; 16-bit unchanged. `cargo test -p victory-shader` passes (59). `cargo clippy` adds no warnings and `cargo xtask policy` is clean. Not covered: I can't run `diff_tests` (no console compiler here), so the emitted DXIL is untested on a GPU and against the game. The snorm -1 clamp on the 2-bit channel is the existing generic code and isn't tested here either. A `typed loads` diff case with R11G11B10_FLOAT and the 10_10_10_2 formats would cover both. ## Merge Danger **Door:** two-way **Blast Radius:** small Only shaders that used to fail translation on these formats change. The 16-bit float path keeps a shift of 0. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Typed buffer loads in the 10_11_11, 11_11_10 and 10_10_10_2 families
(GFX10 unified formats 30-49) were refused, failing the shader. Fill in
their channel layouts and decode the unsigned 11- and 10-bit floats by
shifting them into half position for legacyF16ToF32, which is exact for
denormals, infinities and NaNs. Format numbers from LLVM's UfmtGFX10,
channel order from Mesa's ac_formats.c.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:57 +00:00
github manually merged commit 9fe73ba977 into gh-pr/25/base 2026-11-26 03:47:00 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:07 UTC · original

Tested f1485bc stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test --workspace: 157 passed, 0 failed, 3 ignored; the merge with #39 is clean.
  • No test file appears in the diff, so this run shows the packed typed-buffer paths do not disturb the existing shader tests rather than covering the new formats themselves; a synthetic decode case would pin them.
  • Review note: the diff against main also carries a 133-line change in crates/victory-loader/src/threads.rs that does not look related to the typed-buffer work — worth confirming it is intended in this PR.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/25#issuecomment-7117723589) Tested `f1485bc` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test --workspace`: **157 passed, 0 failed, 3 ignored**; the merge with #39 is clean. - No test file appears in the diff, so this run shows the packed typed-buffer paths do not disturb the existing shader tests rather than covering the new formats themselves; a synthetic decode case would pin them. - Review note: the diff against `main` also carries a 133-line change in `crates/victory-loader/src/threads.rs` that does not look related to the typed-buffer work — worth confirming it is intended in this PR. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:48 UTC · original

checked: PR head f1485bc (merge-base 8c26061), Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1 (from rust-toolchain.toml), throwaway worktree, no game files used.

Ran (shader crate only):

  • cargo test -j4 -p victory-shader: 53 passed, 0 failed (includes the new packed_buffer_formats_by_number, small_floats_widen_as_halves and the edited buffer_formats_by_number).
  • cargo clippy -j4 -p victory-shader --tests: no new warnings. One constant_color is never used dead-code warning in emit/mod.rs tests, which this PR does not touch.
  • Fail-before check: I put origin/main's lower.rs back (without half_shift) and added only the new packed_buffer_formats_by_number test. It fails: buffer_format(30) returns None, expected Some(([11, 11, 10], Unorm)). small_floats_widen_as_halves cannot be run against the old code because it calls the new half_shift.

Cross-checks of the claims:

  • Format numbers: I fetched LLVM's SIDefines.h (UfmtGFX10) and counted the enum. 10_11_11 starts at 30 (FLOAT is 36), 11_11_10 at 37 (FLOAT 43), 10_10_10_2 at 44, 2_10_10_10 at 50, 32_32_32_32_FLOAT is 77. This matches the table in the PR.
  • Channel order: Mesa ac_formats.c maps PIPE_FORMAT_R11G11B10_FLOAT to the 10_11_11 format and picks 2_10_10_10 for channel sizes (10,10,10,2) and 10_10_10_2 for (2,10,10,10), listed from channel 0. That agrees with the widths [11,11,10] and [2,10,10,10] listed from the lowest bits.
  • Small floats: shifting an 11-bit (5-bit exponent, 6-bit mantissa) value left by 4 and a 10-bit value left by 5 gives a half with the same exponent and the mantissa in the top bits, no sign. I worked through denormals, infinity and NaN by hand and they widen exactly. The test values agree.

Review notes (all minor):

  • small_floats_widen_as_halves checks the shift amount against a small Rust model of a half. It does not exercise the emitted shl plus legacyF16ToF32 IR, and no test lowers a typed buffer load with one of the newly accepted formats. A tiny compute program using format 36 or 49, translated through emit, would cover the decode path itself.
  • The 2-bit Snorm/Sint channel goes through the existing generic path (max 1, sign-extended from bit 1, clamped to -1); that reads correctly to me, but nothing tests it.
  • Conflicts: GitHub currently shows this PR as conflicting. Against origin/main 9aef3d9 the only conflict is the use super::{...} line of the lower.rs test module (main's new tests import Parts, lower etc.); the resolution is the union of the imports. A trial merge also conflicts in lower.rs with #127, #116 and #110 (I did not inspect those hunks) and is clean with #48, #54, #69, #73, #101, #126.

Not verified: any Windows or GPU runtime, DXIL validation of the emitted shader, or real titles. Only the unit tests and the cross-checks above were run.

**@⁠tedin7** on GitHub · 2026-11-24 00:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/25#issuecomment-7118445389) checked: PR head `f1485bc` (merge-base `8c26061`), Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1 (from rust-toolchain.toml), throwaway worktree, no game files used. Ran (shader crate only): - `cargo test -j4 -p victory-shader`: 53 passed, 0 failed (includes the new `packed_buffer_formats_by_number`, `small_floats_widen_as_halves` and the edited `buffer_formats_by_number`). - `cargo clippy -j4 -p victory-shader --tests`: no new warnings. One `constant_color is never used` dead-code warning in `emit/mod.rs` tests, which this PR does not touch. - Fail-before check: I put `origin/main`'s `lower.rs` back (without `half_shift`) and added only the new `packed_buffer_formats_by_number` test. It fails: `buffer_format(30)` returns `None`, expected `Some(([11, 11, 10], Unorm))`. `small_floats_widen_as_halves` cannot be run against the old code because it calls the new `half_shift`. Cross-checks of the claims: - Format numbers: I fetched LLVM's `SIDefines.h` (`UfmtGFX10`) and counted the enum. 10_11_11 starts at 30 (FLOAT is 36), 11_11_10 at 37 (FLOAT 43), 10_10_10_2 at 44, 2_10_10_10 at 50, 32_32_32_32_FLOAT is 77. This matches the table in the PR. - Channel order: Mesa `ac_formats.c` maps `PIPE_FORMAT_R11G11B10_FLOAT` to the 10_11_11 format and picks 2_10_10_10 for channel sizes (10,10,10,2) and 10_10_10_2 for (2,10,10,10), listed from channel 0. That agrees with the widths `[11,11,10]` and `[2,10,10,10]` listed from the lowest bits. - Small floats: shifting an 11-bit (5-bit exponent, 6-bit mantissa) value left by 4 and a 10-bit value left by 5 gives a half with the same exponent and the mantissa in the top bits, no sign. I worked through denormals, infinity and NaN by hand and they widen exactly. The test values agree. Review notes (all minor): - `small_floats_widen_as_halves` checks the shift amount against a small Rust model of a half. It does not exercise the emitted `shl` plus `legacyF16ToF32` IR, and no test lowers a typed buffer load with one of the newly accepted formats. A tiny compute program using format 36 or 49, translated through `emit`, would cover the decode path itself. - The 2-bit Snorm/Sint channel goes through the existing generic path (max 1, sign-extended from bit 1, clamped to -1); that reads correctly to me, but nothing tests it. - Conflicts: GitHub currently shows this PR as conflicting. Against `origin/main` `9aef3d9` the only conflict is the `use super::{...}` line of the `lower.rs` test module (main's new tests import `Parts`, `lower` etc.); the resolution is the union of the imports. A trial merge also conflicts in `lower.rs` with #127, #116 and #110 (I did not inspect those hunks) and is clean with #48, #54, #69, #73, #101, #126. Not verified: any Windows or GPU runtime, DXIL validation of the emitted shader, or real titles. Only the unit tests and the cross-checks above were run.
Author
Owner

@⁠artor410 on GitHub · 2026-11-24 02:03 UTC · original

Thanks @⁠DaviTostes and @⁠tedin7! Rebased onto the latest main; the PR now touches only crates/victory-shader/src/emit/lower.rs and the stray loader diff is gone.

**@⁠artor410** on GitHub · 2026-11-24 02:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/25#issuecomment-7119718183) Thanks @⁠DaviTostes and @⁠tedin7! Rebased onto the latest main; the PR now touches only crates/victory-shader/src/emit/lower.rs and the stray loader diff is gone.
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/Marvisak--VIctory!25
No description provided.