shader: lower clamped integer, carry-out, MAD/SAD, and f16 pack VALU ops #516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/516"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T23:42:39Z.
Summary
CLAMPsemantics across VALU operations routed throughLower::write_i,valu16, andpacked16that previously failed as"integer output modifiers"or"modifiers on a 16-bit/packed integer operation"(while leaving non-clamped emission unchanged and keepingomod != 0and bitwise/shiftclamprefused):v_add_nc_i32andv_sub_nc_i32(sadd.sat.i32/ssub.sat.i32withclamp, wrapping withoutclamp),v_cvt_pk_u16_u32,v_cvt_pk_i16_i32, andv_mad_i32_i16.v_add_co_u32,v_sub_co_u32,v_subrev_co_u32,v_add_co_ci_u32,v_sub_co_ci_u32, andv_subrev_co_ci_u32withclamp(saturatingvdstat0xffffffffor0while keeping the un-clamped carry/borrow mask insdst).v_mul_{u32_u24,i32_i24},v_mad_{u32_u24,i32_i24,u32_u16,i32_i16},v_mad_{u64_u32,i64_i32}, andv_sad_{u8,hi_u8,u16,u32}/v_msad_u8withclamp.v_cvt_f16_f32(opsel == 0, matchingvalu16),v_cvt_pkrtz_f16_f32([0.0, 1.0]float clamp before RTZ conversion), andv_cvt_pknorm_{u16,i16}_f32/v_cvt_norm_{u16,i16}_f16withclamp.v_add_nc_u16,v_sub_nc_u16,v_subrev_nc_u16,v_mul_lo_u16, andv_pk_{add,sub,mad}_{u16,i16}/v_pk_mul_lo_u16withclamp.Verification
victory_shader::emit::lower::testsandvictory_shader::emit::valu_testsvictory_gpu::native::tests::addr_tests::clamped_integer_carry_mad_sad_and_half_packs_saturate_on_the_gpu(16 boundary/saturation cases on Metal)cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtaskcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policyCloses #515
Refs #4, #258
cc @Olima34
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:48:33Z.
Thanks @Sheffy007! Integer output modifiers are one of the refusal classes we see most often in world shaders, so this is welcome. Keeping
omod != 0and bitwise/shiftclamprefused rather than guessing reads right to us.Heads-up: main moved an hour ago to
86cefd22(the maintainer merged the preview branch: page-crossing reads, mesh rules, the compute heap-index rule, LOD clamp and bias). We'll sweep #516 on that main over our two boot corpora (4,921 and 4,129 containers) and on the 21,600-container world corpus, then post newly translated / regressions / changed outputs per stage here, the same way as on #464. We'll also flag any overlap with your #448, #464 and #512 where they touch the same lowering.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T01:55:18Z.
Thanks for this PR! Here is the corpus sweep I promised, with no game run.
Corpus sweep (
examples/sweep+tools/corpus/compare.sh), measured on maina6a58361. That main translates shaders the same way as226645f9.497baed6.65a04a4bonly changes test context; the shader-side diff is the same, and main's newer victory-shader commits sincea6a58361only add tests.The same holds at the earlier head
4dccd5ab, which still had thev_cvt_pk_u16_u32part: 0 / 0 / 0 on all three sets.No shader in these sets is refused first for "integer output modifiers" or "modifiers on a 16-bit/packed integer operation" on current main. So this is a no-regression check rather than a coverage measurement. Shaders whose first refusal is something else may still carry these ops further in.
Overlap with #448, #464 and #512: #516 merges cleanly with each of them, and with all three together, on
a6a58361. Since #516 changes no output in these sets, its gains cannot overlap theirs.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.