Shader: decode the packed typed-buffer formats #25
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!25
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/25/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCSummary
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.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'sac_formats.c(R11G11B10_FLOAT is 10_11_11; 10_10_10_2 has its 2-bit channel in the low bits).Evidence
buffer_format(36)(and 30-49) returnedNone, 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-bit0x001= 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-shaderpasses (59).cargo clippyadds no warnings andcargo xtask policyis 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. Atyped loadsdiff 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 on GitHub · 2026-11-24 00:07 UTC · original
Tested
f1485bcstacked 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.mainalso carries a 133-line change incrates/victory-loader/src/threads.rsthat does not look related to the typed-buffer work — worth confirming it is intended in this PR.AI-assisted (DeepSeek V4.1 Flash coding agent).
@tedin7 on GitHub · 2026-11-24 00:48 UTC · original
checked: PR head
f1485bc(merge-base8c26061), 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 newpacked_buffer_formats_by_number,small_floats_widen_as_halvesand the editedbuffer_formats_by_number).cargo clippy -j4 -p victory-shader --tests: no new warnings. Oneconstant_color is never useddead-code warning inemit/mod.rstests, which this PR does not touch.origin/main'slower.rsback (withouthalf_shift) and added only the newpacked_buffer_formats_by_numbertest. It fails:buffer_format(30)returnsNone, expectedSome(([11, 11, 10], Unorm)).small_floats_widen_as_halvescannot be run against the old code because it calls the newhalf_shift.Cross-checks of the claims:
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.ac_formats.cmapsPIPE_FORMAT_R11G11B10_FLOATto 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.Review notes (all minor):
small_floats_widen_as_halveschecks the shift amount against a small Rust model of a half. It does not exercise the emittedshlpluslegacyF16ToF32IR, 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 throughemit, would cover the decode path itself.origin/main9aef3d9the only conflict is theuse super::{...}line of thelower.rstest module (main's new tests importParts,loweretc.); the resolution is the union of the imports. A trial merge also conflicts inlower.rswith #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.
@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.