Shaders: decode 16-bit integer inline float constants as f32 bits #1295
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!1295
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1295"
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?
@WALID1618Y on GitHub · 2026-11-24 17:13 UTC · original
WALID1618Y:fix/half-int-inline-constants→main· +99 −10 · 2 files · 1 commits · openIn
crates/victory-shader/src/emit/lower.rs,half_srcunconditionally decoded GFX10 inline float constants (240..=248) viaf16_operandfor all non-packed 16-bit instructions. On RDNA2 (GFX10), inline float constants use FP16 bit patterns only for 16-bit floating-point operands; 16-bit integer instructions (u16/i16/b16, includingv_add_nc_u16,v_cvt_f16_u16/i16, andv_cmp_*_u16/i16) interpret those encodings as 32-bit FP32 bit patterns and select the low or high 16-bit half viaop_sel(the non-packed counterpart to #637 forpacked_src, per LLVM's GFX10 encoding table).Change
float: boolparameter toLower::half_src, mirroringLower::packed_srcfrom #637:float = true(f16_operand) for FP16 sources:half_fsrc,cvt_norm16, andv_cmp_class_f16.float = false(operand) for 16-bit integer sources:v_cvt_f16_u16/v_cvt_f16_i16, 16-bit integer VALU ops (v_add_nc_u16,v_sub_nc_u16,v_mul_lo_u16, shifts, min/max), andv_cmp_*_u16/v_cmp_*_i16.half_int_ops_decode_inline_float_constants_as_f32_bitsincrates/victory-shader/src/emit/valu_tests.rs.op_selmain(ffe310e)v_add_nc_u16(+ 0)248(1/(2π)),op_sel:[0,0]0x000031180x0000f983v_add_nc_u16(+ 0)248(1/(2π)),op_sel:[1,0]0x000000000x00003e22v_add_nc_u16(+ 5)242(1.0),op_sel:[0,0]0x00003c050x00000005v_add_nc_u16(+ 5)242(1.0),op_sel:[1,0]0x000000050x00003f85v_cvt_f16_u16242(1.0),op_sel:[0]0x000073800x00000000v_cmp_eq_u16(== 0xf983/== 0x3118)248(1/(2π))0/11/0v_add_f16(control,+ 0)248(1/(2π)),op_sel:[0,0]0x000031180x00003118Verification
1.98.1,dxil.dllvalidation enabled (VICTORY_DXIL), NVIDIA GeForce RTX 3050 (driver32.0.16.2124) + Microsoft WARP (10.0.26100.9818). Synthetic tests only; I did not run the game.main(ffe310e), the new test fails on hardware withv_add_nc_u16 low half of inline 248: got 0x00003118, want 0x0000f983.cargo test -p victory-shader --locked(withdxil.dll): 121 passed, 0 failed, 1 ignored (4 differential tests skip without the console compiler)cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo xtask policy:154 files okNote: open PR #926 also edits
half_src(to ignoreop_selon 16-bit compares); if merged first, rebasing is a one-line signature merge.AI-assisted; all builds, DXIL validations, and GPU dispatches were executed locally.
@geiyiliyabumo on GitHub · 2026-11-24 17:25 UTC · original
Independent verification of \
6cf80f2\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:Code audit looks solid: splitting \half_src(inst, k, float)\ matches \packed_src\ so 16-bit integer ops read raw f32 bits of inline float constants \240..=248\ while 16-bit float ops preserve f16 bits (including \_cvt_f16_u16/\_cvt_f16_i16\ and \cmp*_u16/i16).
AI-assisted; synthetic tests only, no game files.
@adamdotpy on GitHub · 2026-11-24 17:31 UTC · original
Reviewed at head
6cf80f2(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The claim is right and the change is complete at every call site. On RDNA2, a non-packed 16-bit integer VOP3 op reads the selected half of the inline constant's f32 bit pattern, while 16-bit float ops (and packed VOP3P ops via
packed_src) read f16 bits. The mechanics confirm it:f16_operand(lower.rs:1245) maps constants 240..=248 to f16 words in the low half (0x3118 for 1/(2π) etc.), whileoperandmaps them throughcrate::resource::inlineto the f32 bits (0x3E22F983 for 1/(2π)).half_srcnow takes afloat: booland picks between the two; I audited all 7 call sites on the head:truefor the f16 operand paths (4351, 4693, 5277) andfalsefor the integer-source paths (4559v_cvt_f16_u16/i16— source is an integer even though the dst is f16, correct; 4632/4633 the 16-bit int ALU arm; 5394/5395 the u16/i16 compare arm). No caller was missed.2. Red/green proven here. The PR's
valu_tests.rsagainst main'slower.rsfails (half_int_ops_decode_inline_float_constants_as_f32_bits: 0 passed / 1 failed — old behavior reads 0x3118 where the f32 low half 0xF983 is expected); on6cf80f2it passes on the GPU. So the branch changes exactly the integer-operand constant decode and leaves the float one alone.3. Hardware evidence on this machine.
cargo test -p victory-shader --lib half_int_opsruns the new test throughrun_caseson the GPU: 6 cases pass — low/high half of inline 248 and 242 throughv_add_nc_u16(f32 halves), thev_add_f16control keeping f16 bits (0x3118),v_cvt_f16_u16reading the f32 low half of 1.0 as 0, and av_cmp_eq_u16_e64against inline 248 matching 0xF983 but not 0x3118. Fullcargo test -p victory-shader --lib: 121 passed / 0 failed / 1 ignored.4. Checks:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds;rustfmt --edition 2024 --checkon both changed files shows only the same 3 pre-existinglower.rshunks main has (shifted +8 lines) — the PR adds no new fmt diffs,valu_tests.rsfully clean.5. Behavior note, not a defect: this changes what previously-translating shaders compute when a 16-bit integer op consumes an inline float constant — before, they silently used the f16 bits. That is precisely the bug being fixed (the f16 and f32 halves disagree, e.g. 0x3118 vs 0xF983), and the packed-op path is untouched, so VOP3P shaders are unaffected.
Nothing found that would block this.
@Marvisak on GitHub · 2026-11-25 01:21 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.