shader: lower s_pack_ll/lh/hh_b32_b16 #89
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/89"
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 uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:22:43Z.
What is broken
The scalar packs decode, but a program using one fails to translate with
s_pack_ll_b32_b16 is not supported(or the matching name):s_pack_ll_b32_b16s_pack_lh_b32_b16s_pack_hh_b32_b16Compilers use them to build packed 16-bit constants and operands for the
v_pk_*instructions.How I found them: I translated, through the CPU harness of #62, a one-instruction program for every SOP1 and SOP2 opcode the decoder names, with the result in
s12. The scout coverage run useds10, which overlaps the program's UAV descriptor ins[8:11], so it reported nearly every scalar op as "a descriptor changed after loading". Withs12, 50 scalar opcodes turn out to be refused, and these three are among them.Semantics
AMD's RDNA2 ISA (§12.1, opcodes 50–52):
s_pack_ll_b32_b16:D = {S1[15:0], S0[15:0]}s_pack_lh_b32_b16:D = {S1[31:16], S0[15:0]}s_pack_hh_b32_b16:D = {S1[31:16], S0[31:16]}They write no SCC. The IR's
writes_sccalready leaves them out.The change (
emit/lower.rs, insop)Each source's named half is masked or shifted into place, and the two are ORed.
Tests
emit::lower::tests::scalar_packs_translate(every host): all three decode, and a program that moves the result tov0and stores it translates. Without thelower.rschange it fails:s_pack_ll_b32_b16 [990c0100, 7e00020c]: GFX10 code at 0x24: s_pack_ll_b32_b16 is not supported.valu_tests::scalar_packs_take_the_halves_their_names_say(Windows/GPU): two hand-computed cases per opcode.lli. I compared against a Rust reference on 60 scrambled pairs per opcode, also with src0 an inline constant (−1) and a 32-bit literal. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:26:11Z.
I can take native Windows GPU validation at exact head
eb43d9711a91abdec336479bd6dd448b02ec25a2. I will run both existing regressions, add focused fixed-expectation halfword, SCC-preservation and inline/literal controls where coverage is missing, and verify a targeted negative control followed by fresh restored-source runs. RTX 4060 Laptop and WARP runs will use the SDK validator. Exact counts, skipped cases and remaining native AMD/game scope will accompany the small patch. AI-assisted with Codex.Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:54:14Z.
Windows acceptance and a small regression test
Tested PR #89 at
eb43d9711a91abdec336479bd6dd448b02ec25a2, based on2b33e081ed7831f49610b747a508fb56d3cb3aa9.The existing scalar-pack translation and GPU tests pass. The attached test also passes and adds SCC retention, contrasting halfwords, and constant-source coverage for all three scalar packs. This is an AI-assisted contribution with local Windows execution and independent review of the fixed expected values.
Environment and actual execution
VICTORY_STRICT_TESTS=1was enabled, with an explicit Windows SDKVICTORY_DXILpath. Each final exact invocation ran one test and reported one pass, zero failures and zero ignored tests. No selected test was skipped.dxil.dllwas version 1.8.2502.11 from SDK 10.0.26100.0. Its SHA256 was77e039c905030a641e53658a008b74e90635a5ea9b6b79eabd0f2003bdfca59a.cargo test --release --locked -p victory-shader --lib --no-run, completing in 1m10s. The two GPU exacts and the translation exact were then rerun against that final executable.Added coverage
scalar_packs_preserve_scc_with_register_and_constant_sourcesuses fixed expected values for SOP2 0x32/0x33/0x34. The selected halves follow AMD's RDNA2 SOP2 opcodes 50–52. AMD RDNA2 ISA12345678/9ABCDEF0, andFFFF0000/0000FFFF. The distinctive pair gives LLDEF05678, LH9ABC5678, and HH9ABC1234.s_add_u32 s14, s3, 1. The test separately reads the pack result and SCC throughs_cselect_b32 s15, 1, 0.-1and a real 32-bit literal89ABCDEF, with source112345678, under both incoming SCC values. The expected constant results are fixed in the test.v_cmp_lgdocumentation, unchanged, from the scalar-pack test tov_cmp_lg_is_false_for_nan.Negative control and final checks
A temporary IR mutation incorrectly classified the
packmnemonic stem as an SCC writer. The original GPU test still passed on hardware and WARP. The new test failed on hardware for LL, reading s15 with input[ffffffff, ffffffff, 0, 0], returning SCC 1 where the preserved value was 0. Cargo exited 101 as expected. The mutation was removed, andir.rsandlower.rswere restored byte-for-byte before the final compilation and successful exact reruns.scalar_packs_translatepassed.scalar_packs_take_the_halves_their_names_saypassed on hardware and WARP.scalar_packs_preserve_scc_with_register_and_constant_sourcespassed on hardware and WARP.cargo clippy --release --locked -p victory-shader --all-targets -- -D warningspassed.cargo run --release --locked -p xtask -- policypassed with 195 files checked.rustfmt --checkandgit diff --checkpassed.Scope and preparation notes
The selected exact tests contain no skipped or ignored cases. The other 244 library tests filtered out by each final exact invocation were outside this targeted run. Native AMD execution, game/visual acceptance, other platforms, the full workspace suite, all source combinations and destination/source aliasing were not exercised.
An initial preparation guard incorrectly expected two existing container-hash assertions. The pinned source has two validator-load sites and one VALU hash assertion. The guard stopped before any source write or dependent test. It was corrected before the recorded acceptance runs, and that preparation attempt is excluded from the results.
Final
valu_tests.rsSHA256 ise6c076bb6f1468c6e16e517a0ae30aba2ca4aab8231380b0a47171aa9a56e4ea. The patch SHA256 isf1e906166755e1df6082f92c081797e3c8b54012303bc22e7937a7349f2ca47d. Final test-executable SHA256 is2f056bf72815b72f3befcf801b40ae62ca582a9916d5504e7e5b0c0414149a5c. Onlycrates/victory-shader/src/emit/valu_tests.rsdiffers from the pinned head.Reproduction
Set
VICTORY_STRICT_TESTS=1andVICTORY_DXILto the installed SDK x64dxil.dll. After applying the patch, run the following from the repository root.Applicable regression-test patch
Pull request closed