Shaders: read inline floats as f32 bits in 16-bit integer ops #1668
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!1668
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1668"
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?
@Calvix2k on GitHub · 2026-11-24 20:36 UTC · original
Calvix2k:codex/shader-inline-16bit-021→main· +34 −4 · 2 files · 1 commits · openAddresses
VIC-BT-021from audit #1242.Summary
half_srcdecoded the inline float constants (240..=248) as packed f16 patterns for every 16-bit operation. Hardware only does that when the source type is F16: a 16-bit integer operation sees the 32-bit value, so1.0is0x3F800000, its low half is 0 and its high half0x3F80.half_int_src(the 32-bit view) next tohalf_src(the f16 view), sharing the op_sel/SDWA half selection.v_cvt_f16_u16/v_cvt_f16_i16, the 16-bit arithmetic/shift/min/max ops, and theu16/i16compares through it.half_fsrc,v_cvt_norm_*_f16,v_cmp_class_f16) keep the f16 decoding.Test
New hardware test
integer_16bit_ops_read_inline_floats_as_f32_bits:v_add_nc_u16 v0, 1.0, v1withv1 = 5gives 5 (low half 0), not the old0x3C05.op_selselecting the high half it gives 16261 (5 + 0x3F80), not 5.Verified on a Radeon RX 7800 XT (Agility SDK 1.616 runtime for SM 6.6): before the change the same test fails with
15365(0x3C05).Validation
cargo test -p victory-shader --locked -- --test-threads=1 --skip emit::valu_tests --skip emit::waterfall_tests— passed (102 tests).cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings— passed.cargo xtask policy— passed (154 files).@adamdotpy on GitHub · 2026-11-24 20:56 UTC · original
Reviewed head d027c4f locally (isolated worktree, fresh CARGO_TARGET_DIR, this machine's GPU really dispatches).
What it does:
half_srcis split intohalf_src_bits(.., f16)with two wrappers — float 16-bit ops keepf16_operand(inline constants packed as f16), while 16-bit integer ops (v_cvt_f16_u16/i16and theu16/i16VOP3 bin-op arm) now go through plainoperand, i.e. the inline float is read as its raw 32-bit value and the op takes the low or high half: inline1.0is0x3F800000→ low half 0, high half (op_sel)0x3F80, not the f16-packed0x3C00.Verified locally:
cargo test -p victory-shader --lib integer_16bit_ops_read_inline_floats_as_f32_bits -- --nocapture— passes in 7.4s on the real GPU backend (no skip), both cases:5 + low16(1.0) == 5and5 + high16(1.0) == 16261cargo test -p victory-shader --lib --locked— 121 passed / 0 failed / 1 ignoredcargo clippy -p victory-shader --all-targets --all-features --locked— cleancargo build --release -p victory --locked— oklower.rshas 2 new hunks vs main (at 4638 and 5398 — exactly the two edited tuple bindings; the 3 pre-existing hunks near 7113 are untouched),valu_tests.rsclean. Cosmetic only; CI has no fmt job.Findings, ranked:
half_srcchokepoint, so the three PRs compose semantically. Expect textual conflicts inlower.rs's 16-bit arms with #1285/#1295/#1300 — same behavior, either order fine.rustfmtpass on the branch, not blocking.LGTM.
@Calvix2k on GitHub · 2026-11-24 22:17 UTC · original
Rebased onto
70564ae. The lowering now keeps upstream'slow16_srcvalue path and only changes the fallback: f16 operations usef16_operand, integer operations use the 32-bitoperand. The call sites were already split intohalf_src/half_int_src. Test-module conflict resolved by keeping upstream's new helpers and this PR's regression.cargo check -p victory-shader --testspasses; the hardware test was verified on the RX 7800 XT before the rebase.@Marvisak on GitHub · 2026-11-25 03:32 UTC · original · edited 2026-11-25 22:17 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main(conflict incrates/victory-shader/src/emit/valu_tests.rs). It will be reviewed again once it is rebased.From the earlier needs-work note, still open: a source (ISA section, LLVM commit rationale, or the title's own shaders) for the op_sel high-half reading of inline floats in 16-bit integer ops, or limit the PR to the low-half case.
Generated by Claude Code
@Calvix2k on GitHub · 2026-11-25 08:38 UTC · original
I looked for the source the triage asks for and found a note that points the other way, so I would rather ask than cite it as support:
AMDGPUOperandSyntax, "Floating-point inline constants cannot be used with 16-bit integer operands").AMDGPUAsmParser.cpphas the truncation rule: "When floating-point immediate is used as operand of type i16, the 32-bit representation of the constant truncated to the 16 LSBs should be used."That last point supports the packed path (
packed_src) this change follows, but for the non-packed 16-bit integer ops the documented hardware rule is "low 16 bits of the 32-bit literal", not "the f32 bits as an integer". Those differ:1.0fis0x3F800000; its low half is 0, while as an i32 it is 1065353216.If the measured behaviour on the console really is the f32 bits (as the title's constants would suggest), the place to say so is a hardware row like the ones in the AnyPS5 debt page, not the assembler documentation — and I do not have one. Can you point me at the measurement or the ISA section you had in mind? With that I will put it in the PR and the change is ready; without it I would rather keep the old reading than switch to one that contradicts LLVM's documented encoding.
@Calvix2k on GitHub · 2026-11-25 10:15 UTC · original
Hardware run on an RX 7800 XT (RDNA3), Windows 10 19045 with SM 6.6 via the Agility runtime for the test binaries (#486):
victory-shaderlib suite 248 passed, 0 failed, 3 ignored, including the 16-bit integer ops and inline-constant cases this PR adds. The lowering runs on the card here.33101a2f32to305c296c9c@catminou4 on GitHub · 2026-11-24 21:42 UTC · original · approved these changes
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.16-bit integer ops now read inline floats as f32 bits (half_int_src/half_src_bits): integer_16bit_ops_read_inline_floats_as_f32_bits pins the reinterpretation.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.