Shaders: fix 16-bit VALU SDWA placement/sext and inline float constants #1285
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!1285
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1285"
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?
@hamdog0203 on GitHub · 2026-11-24 17:08 UTC · original
hamdog0203:fix/valu16-sdwa-inline-const→main· +216 −33 · 2 files · 2 commits · openFixes three related 16-bit VALU / SDWA lowering bugs in
crates/victory-shader/src/emit/lower.rs:UNUSED_SEXTinwrite_half()write_half()rejected bytedst_sel(0..=3) and ignoreddst_unused == 1(UNUSED_SEXT), zero-extending even negative 16-bit results instead of sign-extending them across the upper bits.dst_sel0..=5(BYTE_0..BYTE_3,WORD_0,WORD_1) anddst_unused0..=2(UNUSED_PAD,UNUSED_SEXT,UNUSED_PRESERVE) directly toplace_bits(), matching 32-bit SDWA writes.sexton 16-bit integer sources inhalf_src_typed()half_src()rejected bytesrc_sel(0..=3) and ignoredsd.sext.src_sel0..=5throughselect_bits(x, sel, sext)(applyingsd.sextfor 16-bit integer ops, masked to 16 bits as the operand width).240..=248) using f32 bit patterns for 16-bit integer instructions (half_int_src())v_add_nc_u16,v_cvt_f16_i16,v_cmp_*_u16/i16, etc.) read the low/high halves of the 32-bit float constant rather than the f16 encoding (matching howpacked_src(..., float)already distinguishesv_pk_*_f16fromv_pk_*_i16/u16).half_int_src()for the 16-bit integer call sites while keepinghalf_src()for f16 instructions.Verification
crates/victory-shader/src/emit/valu_tests.rs:sdwa_16bit_dst_word0_sext_and_byte_placementsdwa_16bit_src_byte_select_and_sextint16_inline_float_constants_use_f32_bitsdxil.dll, NVIDIA GeForce RTX 4060, and WARP (cargo test --workspace --locked: 345 passed, 0 failed, 6 ignored; all 3 new tests fail on unpatchedmainffe310e).cargo clippy --workspace --all-targets --locked -- -D warningsand--all-featuresboth pass cleanly.cargo xtask policypassed (2 files ok, no game files/assets).@geiyiliyabumo on GitHub · 2026-11-24 17:30 UTC · original
Independent verification of \
e34f8c3\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:Code audit looks clean: delegating SDWA \dst_sel\ (\␀..=5) / \dst_unused\ (\␀..=2) through \place_bits\ / \write_placed\ and gating SDWA \sext\ on !float\ fixes byte/word SDWA handling alongside the 16-bit integer inline constant fix (note: overlaps #1295 on \half_src, while this PR additionally covers SDWA).
AI-assisted; synthetic tests only, no game files.
@fuzeofficlal on GitHub · 2026-11-24 17:30 UTC · original
Reviewed
write_half/half_src_typedand verified the 16-bit SDWAWORD_0 + UNUSED_SEXT(v_cvt_i16_f16_sdwa,v_cvt_norm_i16_f16_sdwa,v_add_f16_sdwa) +WORD_0/WORD_1/DWORDPAD/SEXT/PRESERVEmatrix on NVIDIA GeForce RTX 5090, D3D12 WARP, anddxil.dll(reference test suite infuzeofficlal/VIctory@b6c916b).One small guard worth tightening in
Lower::write_half:(6, _)currently accepts the reserveddst_unused == 3encoding whendst_sel == 6(DWORD), whereasplace_bits(and(0..=5, 0..=2)) rejectsdst_unused == 3. Narrowing that arm to(6, 0..=2)keeps reserveddst_unused == 3consistently rejected across alldst_selvalues.@muhammed-aksoy on GitHub · 2026-11-24 17:54 UTC · original
I tested
e34f8c3together with #1291 (94dbc0a) onffe310e. Windowscargo test --locked -p victory-shader -- --test-threads=1passed 124 tests with zero failures and one ignored at local merge6d40e1b, with the Windows SDK DXIL validator configured. Git reports a separate overlap with #1314 inemit/valu_tests.rs. AI-assisted.@adamdotpy on GitHub · 2026-11-24 18:05 UTC · original
Reviewed at head
e34f8c3(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The SDWA rework is correct.
half_srcis split intohalf_src(f16 ops) /half_int_src(16-bit int ops) overhalf_src_typed(inst, k, float). Source side: with SDWA present,src_sel0..=3 selects a byte (select_bitsshift-left/shift-right extract), 4..=5 a word, 6 the low word;sd.sextbitksign-extends via AShr, only for integer ops (!float) — matching GFX10, where SDWA takes precedence over opsel. Without SDWA, opsel bitkpicks the high word as before. Destination side:write_halfnow routes SDWA throughplace_bits(byte/word placement withdst_unused0 = pad zeros, 1 = sign-extend, 2 = preserve old bits viawrite_placedreading the old register value) and accepts all(0..=5, 0..=2)combos plus(6, _)= low word; opsel bit 3 remains the non-SDWA path. I read both helpers and the bit math is right in each mode.2. Inline float constants: same rule as #1295 (independently): 16-bit integer ops read the f32 bit pattern of constants 240..=248 (
operand), f16 ops read f16 bits (f16_operand). Note for whoever merges: this overlaps #1295 — both changehalf_srcand add a near-identical test (int16_inline_float_constants_use_f32_bitshere vshalf_int_ops_decode_inline_float_constants_as_f32_bitsthere); the second to merge will conflict on those lines. Behavior is identical, so either can land first.3. Hardware evidence on this machine. The new GPU tests pass:
sdwa_16bit_dst_word0_sext_and_byte_placement(dst WORD_0 with SEXT of 0xBC00 → 0xFFFF_BC00 preserved-high case 0x0000_3C00, byte1-preserve 0xAABB_CCDD → 0xAABB_42DD, byte1-sext 0xC900 → 0xFFFF_F600),sdwa_16bit_src_byte_select_and_sext(BYTE_1 select with/without sext throughv_cvt_f16_i16andv_cmp_lt_i16), and the inline-constant test (0xF983 low half of 248). Ran here: the sdwa-filtered tests 2 passed, fullcargo test -p victory-shader --lib123 passed / 0 failed / 1 ignored (21 s, GPU tests included).4. Checks:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds;rustfmt --edition 2024 --checkon both files shows only the 3 pre-existinglower.rshunks main has (shifted) — no new fmt diffs.5. Behavior notes, not defects: SDWA byte/word selects on 16-bit ops and SEXT were previously refused (
"a byte select on a 16-bit operation"/ restricted dst combos), so this strictly widens translation; and like #1295, int-op inline constants now use f32 bits where they previously used f16 — the intended fix.Nothing found that would block this.
@hamdog0203 on GitHub · 2026-11-24 18:28 UTC · original
Thank you all for the thorough independent verification across RDNA4, RTX 5090, WARP, and
dxil.dll(@geiyiliyabumo, @fuzeofficlal, @muhammed-aksoy, @adamdotpy)!Good catch on
(6, _)inLower::write_half, @fuzeofficlal — pushedac1a6e2narrowing it to(6, 0..=2)so reserveddst_unused == 3is rejected consistently across alldst_selvalues, along with a regression check insdwa_16bit_dst_word0_sext_and_byte_placement(victory-shader: 123 passed, 0 failed, 1 ignored; bothclippyprofiles andxtask policyclean).@adamdotpy on GitHub · 2026-11-24 19:04 UTC · original
Verified the new head
ac1a6e2here (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). The reserved-combo tightening is right:write_halfnow accepts(dst_sel 6, dst_unused 0..=2)and rejects(6, 3)— per the SDWA encoding,dst_unused=3is reserved withdst_sel=DWORD, and refusing it beats silently treating it as pad. The newdword_padGPU case (0xC500 → 0x0000_FFFB) and the reserved-reject case both pass on the GPU. Fullcargo test -p victory-shader --lib123 passed / 0 failed / 1 ignored, clippy--all-targets --all-features --locked -D warningsclean, release build ok, andrustfmt --checknow shows only main's 3 pre-existinglower.rshunks. One merge note: thetry_build_valu_cssplit here also exists in #1261 — whichever lands second will conflict on that helper; trivial to resolve.@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,crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 00:04 UTC · original
I prepared efe7a63 on main
63bcca4. It keepsac1a6e2as first parent, so both original hamdog0203 commits and their author are intact. The conflict resolution keeps main'slow16_srchandling when an SDWA selection fits in the known half, plus the typed test-builder errors and all main tests.The same three existing fixtures run on both revisions with the typed error assertion. On main, WORD_0 sign extension returns
0x0000bc00, the byte-source conversion is refused, and the 16-bit integer inline operand returns0x3118. Onefe7a63, all three pass, including0xffffbc00for the sign extension and0xf983for the integer operand. The reserved DWORD selection control also passes. The overlapping inline-constant case is the one in #1295.App-local WARP SM 6.6 with DXIL validation: 38 VALU tests pass, 34 semantics tests pass (1 ignored), 33 lowerer tests pass, and the existing partial interpolation-half test passes. Strict shader Clippy in both configurations and the asset policy pass.
lower.rsis 521,544 bytes. The offered commit merges cleanly with63bcca4.The branch
andrewpozdnakov7-jpg:codex2/merge-1285-current-mainis available to bring into this PR. If the conflict resolution is folded into another commit, please retain Git authorship orCo-authored-by: andrewpozdnakov7-jpg <[email protected]>.@rminzao on GitHub · 2026-11-26 02:18 UTC · original
Tested
ac1a6e2merged onto currentmain(63bcca4). It no longer merges cleanly. The conflicts are small, and the resolution I tested is below. Synthetic tests only, no game files.Results with the merge
main'slower.rswith the PR's testscargo test -p victory-shader --libon Intel: 308 tests, 294 passed, 11 failed, 3 ignored. The 11 failures are the same set that fails onmainon this machine (BVH, FMad 1-ULP, and the wave-32 pipelines this 16-lane GPU refuses).cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean.cargo xtask policyis clean.lower.rsis 521,563 bytes, under the limit.Conflict 1:
half_src_typed.mainadded thelow16cache, whichhalf_srcreads when op_sel and SDWA select nothing. That cache holds only the low word, so it can't feed an SDWA byte or word select or an op_sel high half. I kept it only for unselected reads, for both the float and the integer path:Conflict 2:
valu_tests.rs.try_build_valu_csonmainnow returnscrate::ShaderError, notString, so I keptmain's helper. The dst_unused=3 test then needslet err = format!("{err:?}");before itserr.contains("SDWA destination"). The other two hunks are tests both sides added next to each other, so I kept both.The change itself looks right to me:
place_bits, the same path the 32-bit SDWA writes use.dst_unused3 is refused for everydst_sel.sextis applied only to integer sources.SIInstrInfo::isInlineConstant(bug 46302); I didn't check the source again. Neither WARP nor NVIDIA can confirm what the console does here, so an RDNA2 run ofint16_inline_float_constants_use_f32_bitswould settle it.One nit: the new comment
// v_cmp_lt_i16_sdwa vcc, sext(v1), v2 src0_sel:BYTE_1 src1_sel:WORD_0; v_cndmask_b32 v0, 0, 1, vccis 103 columns.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.