Skip to content

Shader: decode the packed typed-buffer formats - #25

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
artor410:packed-buffer-formats
Nov 24, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
artor410:packed-buffer-formats

Conversation

@artor410

Copy link
Copy Markdown
Contributor

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

@DaviTostes

Copy link
Copy Markdown

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 Build: make workspace tests run on Linux #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).

@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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):

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.

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 <noreply@anthropic.com>
@artor410
artor410 force-pushed the packed-buffer-formats branch from f1485bc to 9fe73ba Compare November 24, 2026 02:03
@artor410

Copy link
Copy Markdown
Contributor Author

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.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
… into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ghost ghost mentioned this pull request Nov 24, 2026
@Marvisak
Marvisak merged commit 1f858b0 into Marvisak:main Nov 24, 2026
Xeltax referenced this pull request in Xeltax/VIcky Nov 24, 2026
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Shader: decode the packed typed-buffer formats
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
Shader: decode the packed typed-buffer formats
H4itz pushed a commit to H4itz/victory that referenced this pull request Nov 26, 2026
…binds again is not named, queried and kept again (one lookup by address instead of two QueryInterface calls, three locks and a name search per switch)

Read line by line before merging.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants