shader: lower v_lerp_u8 #86
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr--gone-20261201!86
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-86"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:14 UTC · original
lcg007xd-c:shader-lerp-u8→main· +85 −0 · 2 files · 1 commits · openWhat is broken
v_lerp_u8(VOP3 0x14D) decodes, but a program using it fails to translate withv_lerp_u8 is not supported. I found it by translating a one-instruction program for every VOP3 opcode the decoder names. It averages packed unsigned bytes, the usual way to blend two RGBA8 values.Semantics
AMD's RDNA2 ISA (§12.12, opcode 333) defines it as an "unsigned 8-bit pixel average on packed unsigned bytes":
D.u[8i+7:8i] = (S0.u[8i+7:8i] + S1.u[8i+7:8i] + S2.u[8i]) >> 1. Bit 0 of each byte of S2 is the rounding bit: set rounds a .5 up, clear truncates it.The change (
emit/lower.rs, ininteger)Per byte: extract both bytes, add them plus the rounding bit, shift right by one, and place the result back. No byte can carry into the next: the most is
(255 + 255 + 1) >> 1 = 255.Tests
emit::lower::tests::byte_average_translates(every host): the encoding decodes to the name, and a program that stores the result translates, with src2 a VGPR or an SGPR. Without thelower.rschange it fails:v_lerp_u8 [d54d0000, 040e0501]: GFX10 code at 0x24: v_lerp_u8 is not supported.valu_tests::v_lerp_u8_averages_bytes_rounding_by_s2(Windows/GPU): exact averages, .5 truncated and rounded up,0xFF+0xFFwith S2 bytes0xFE/0xFF(only bit 0 counts), and mixed bytes.lli. I compared against a Rust reference on 203 inputs (200 scrambled triples plus edges). 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
VOP3 0x14D decoded but failed to translate ("v_lerp_u8 is not supported"). AMD's RDNA2 ISA: each byte of the result is the average of S0's and S1's bytes, rounded up when bit 0 of S2's byte is set: (S0.u8 + S1.u8 + S2.u[8i]) >> 1. Co-Authored-By: Claude Opus 5.5 <[email protected]>@lmouz823-lang on GitHub · 2026-11-28 09:05 UTC · original
I can take native Windows GPU validation at exact head
e1302d7f3e61b6a689b92847211db01dfb8617dd. I will run the existing translation and GPU tests, audit missing source-form or byte-boundary coverage, and provide a focused fixed-expectation regression where justified. Results will include actual RTX 4060 Laptop and WARP execution, SDK validation evidence, a targeted negative control, freshly rebuilt restored-source runs, and explicit skipped/native AMD/game scope. AI-assisted with Codex.@lmouz823-lang on GitHub · 2026-11-28 09:19 UTC · original
Windows validation and rounding-source regression
Windows validation for PR #86 at head
e1302d7f3e61b6a689b92847211db01dfb8617ddis complete. The base is2b33e081ed7831f49610b747a508fb56d3cb3aa9. The original tests and a small additional rounding-source test pass through native Windows execution.Environment and actual execution
VICTORY_STRICT_TESTS=1, withVICTORY_DXILexplicitly naming the SDK 10.0.26100.0 x64dxil.dll, version 1.8.2502.11. Its SHA256 was77e039c905030a641e53658a008b74e90635a5ea9b6b79eabd0f2003bdfca59a.emit::lower::tests::byte_average_translatesemit::valu_tests::v_lerp_u8_averages_bytes_rounding_by_s2emit::valu_tests::v_lerp_u8_reads_scalar_inline_and_literal_rounding_bitsEach final invocation selected exactly one test, and neither GPU run reported a runtime skip. Counts follow the checked test/helper loops, with both adapters confirmed in the raw logs.
Additional coverage
The attached 48-line test exercises S2 from
s3, inline0, inline1, inline-1, and a real literal0x01000100. S0 and S1 remain VGPR inputs. The SGPR value deliberately differs fromv3, so selecting the original vector operand accidentally changes the expected result.The fixed tables check each byte's own rounding bit on odd sums, mixed channel values and maximum byte sums. For example, averaging all-zero with all-one bytes gives
7F7F7F7Ffor inline 0,7F7F7F80for inline 1,80808080for inline -1, and807F807Ffor literal01000100. The four input rows under each of five source forms produce5 × 4 × 2 = 40checked dispatches from 5 modules. The expected words follow RDNA2 VOP3 opcode 333's per-byte unsigned average. AMD RDNA2 ISANegative control and restored-source verification
I temporarily replaced only the literal-S2 value with zero in the
v_lerp_u8lowering arm. The original VGPR-S2 GPU test still passed on both adapters. The added test failed on NVIDIA at its first literal case, input[0, FFFFFFFF, FFFFFFFF, 01000100], with actual7F7F7F7F, expected807F807F, and Cargo exit 101. This failure stopped the remaining literal hardware cases and the literal WARP negative run. The earlier SGPR and inline source loops completed before that deliberate failure.I restored
lower.rsbyte-for-byte, removed diagnostic logging, cleaned only this shader package's release outputs in the isolated build target, and confirmed a real 1m58s compilation of the final source. All three final exact selections above passed after that rebuild.Release Clippy with
--all-targets -- -D warnings, the 195-file asset policy check, new-function rustfmt,git diff --check, forward application against a separate index of this exact head, and reverse application checks passed. Whole-file rustfmt exits 1 on the pinned original and final source. Both have the same 16 pre-existing formatting hunks and identical ordered changed lines, 83 additions and 30 removals.Skipped and unverified scope
The selected final tests had zero ignored or skipped cases. Each final exact invocation filtered out the other 244 library tests. Native AMD execution, actual game/visual acceptance, other platforms and the full shader/workspace suites remain unverified. Other S0/S1 source classes, modifiers, destination/source alias combinations and wave64 were outside this targeted test.
An additional LLVM assembler cross-check was attempted with the installed official LLVM 23.1.6 Windows portable tools. That
llvm-mccould not targetamdgcn-amd-amdhsa, so this check produced no verified assembly encodings. Its failure is excluded from the GPU acceptance counts.Only
crates/victory-shader/src/emit/valu_tests.rsdiffers from the pinned head, with 48 additions. Final source SHA256 is48fa2985abb69124b0ca8120222289f0a578a4bde4412c85629b654b2043a95a. Patch SHA256 isa431e41e53dea44299017046fbb78b99d8081f217968888f6d0fc8cef9137f59.Reproduction
Set
VICTORY_STRICT_TESTS=1andVICTORY_DXILto an installed SDK x64dxil.dll. Apply the attached patch and run from the repository root.AI assistance from Codex covered the audit, test patch, execution and this report. The fixed expected words were also independently checked.
Complete rounding-source regression patch against this head
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.