Repository navigation
xshader: lower masked and quad byte SADs - #286
Merged
Merged
Conversation
Add v_msad_u8 to the 32-bit integer forms and v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8 in a new quad_sad module. Window k of the S0 pair is bits [8k+31:8k]; each window's SAD against S1 goes into the matching 16- or 32-bit accumulator field of S2. Every result word is computed before any is written, so a destination may overlap S0 or S2. Plain VGPR operands without clamp, op_sel or negation, compute only. The live-in analysis knows the extra source words and wider results. Native RDNA2 execution (tools/native_rdna2/check_sad.py) settled what the ISA text leaves open: the masked forms skip a byte whose S1 byte is zero, the 16-bit fields wrap without clamp, and MODE changes nothing. 81,920 comparisons, no mismatches. tools/check_byte_sad_gpu.py runs the translated shaders on a D3D12 GPU against the same model, with dynamic operands and overlapping destinations: 384 inputs, 6,528 results, zero mismatches. Masking on S0 or a 17-bit field fails it. It joins the translator's GPU checks, and the sad-mad64 negative control now uses a clamped v_msad_u8, which stays refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the four masked and quad byte SAD forms that the translator refused:
v_msad_u8,v_qsad_pk_u16_u8,v_mqsad_pk_u16_u8andv_mqsad_u32_u8.v_msad_u8joins the other SADs inint32.rs. The quad forms get their own module,quad_sad.rs. Window k of the S0 pair is bits [8k+31:8k], each window is compared with S1, and the result goes into the matching accumulator field of S2: 16 bits for the_pkforms, 32 bits forv_mqsad_u32_u8. The translator computes every result word before it writes any, so a destination may overlap S0 or S2. As with the existing SADs, the forms accept plain VGPR operands without clamp, op_sel or negation, in compute shaders only. The register analysis knows about the extra source words and the wider results.Semantics from native execution
The ISA documentation is unclear on two points.
tools/native_rdna2/check_sad.pysettles them by running the instructions natively on an RX 6950 XT, through the HSA runtime:_pkforms wrap. A saturating model fails.MODE does not change any result: MODE 0 and 0x3ff give identical results. 16,384 inputs per kernel, 81,920 comparisons, no mismatches.
GPU control
tools/check_byte_sad_gpu.pyruns the translated shaders on a D3D12 GPU against the same model. It uses dynamic VGPR operands and includes destinations that overlap the accumulator and the S0 pair. Result on the RX 6950 XT: 384 inputs and 6,528 results, all correct.Baseline: the previous translator refuses the program.
Negative controls: masking on S0 instead of S1 fails 12 of 12 dispatches, and so does a 17-bit field instead of a 16-bit one.
Translator checks:
byte-sadis now part oftools/check_translator_gpu.py. Thesad-mad64control hadv_msad_u8as a negative control (it must be refused). It now usesv_msad_u8 ... clamp, which stays refused.python tuxbox.py checkon the RX 6950 XT: Lanes, the D3D12 regression controls and all translator checks pass. (On the first runsad-mad64failed on that old negative control; after the change,sad-mad64andbyte-sadpass.) There is no run on an NVIDIA card yet.Coverage of single decodable ALU instructions goes from 498 to 502 translated.
Evidence:
evidence/native-rdna2-byte-sad.json,evidence/byte-sad-control.json.AI-assisted.