Repository navigation
Shaders: lower v_dot4_i32_i8 and v_dot4c_i32_i8 (restores upstream 0b35b7f's dot4, with clamp) - #219
Open
murillojndem wants to merge 1 commit into
Open
murillojndem wants to merge 1 commit into
murillojndem wants to merge 1 commit into
Conversation
The decoder knew both, but lowering stopped at them, so programs using them (upstream names the console upscaler's) were not translated. v_dot4_i32_i8 is the four signed byte products of src0 and src1 plus src2, wrapping (LLVM's llvm.amdgcn.sdot4, Mesa's sdot_4x8_iadd), lowered with DXIL's Dot4AddI8Packed. With clamp the whole sum saturates to i32 (Mesa's sdot_4x8_iadd_sat, which ACO selects as this instruction with clamp). op_sel and op_sel_hi pick the halves of src0 and src1, and src2's are ignored, as measured on gfx10.3 and gfx11 hardware (LLVM's pull request 100485) and as Mesa's ACO takes these sources. v_dot4c_i32_i8 adds the dot product to its destination. neg on v_dot4_i32_i8, and SDWA or the VOP3 form of v_dot4c_i32_i8 (GFX10 has neither), are refused by name. Tests: dot4_sums_signed_byte_products_and_the_accumulator (16 forms on 8 run-time inputs, against a 64-bit reference) and dot4_forms_not_lowered_are_named. Both fail on main; both pass with this change on WARP and on an RX 7900 XT. Restores the dot4 part of Marvisak/VIctory 0b35b7f, which 570a941 removed, with clamp lowered instead of refused. Co-authored-by: Marvis <marvis@noreply.invalid> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The decoder knows VOP2
v_dot4c_i32_i8(0x0d) and VOP3Pv_dot4_i32_i8(0x16), but lowering stopped at them (Unsupported { what: "v_dot4_i32_i8" }), so a program using them was not translated. Marvisak/VIctory@0b35b7f describes them as instructions the console upscaler's programs need. Outside the FSR 4K mode this tree does not load the host's FidelityFX provider (use_host_diris called only there), andfidelityfx.rsthen lets the title's own FidelityFX DLLs run, whose GPU programs go through this translator. Whether the title upscales in those modes, and how many of its programs use these instructions, was not checked here.Semantics:
v_dot4_i32_i8is the four signed byte products of src0 and src1 plus src2, wrapping: LLVM'sllvm.amdgcn.sdot4, whichV_DOT4_I32_I8selects, and Mesa'ssdot_4x8_iadd. It is lowered with DXIL's Dot4AddI8Packed.sdot_4x8_iadd_satcomputes it in 64 bits and clamps, and Mesa's ACO selects that opcode asv_dot4_i32_i8with clamp on GFX10. The lowering adds the products' sum, which cannot overflow, to the accumulator and saturates on signed overflow.packed_src), and src2's are ignored. LLVM only emits the default selects, and its assembler has rejected other selects since its commit d57230c72e; in the review of that change (LLVM's pull request 100485), an AMD reviewer wrote that dot4 and dot8 have no op_sel. In the same review, DadSchoorse reported the behavior lowered here from experiments on gfx10.3 and gfx11 hardware withv_dot4_u32_u8, as a formula and four examples; one of the examples, as written, gives 3 under the formula where 6 is reported. Mesa's ACO takes the two sources as packed 16-bit halves (PkU16) and folds constants into them with half selects. Upstream lowered them the same way; its test of the title's upscaler dot products describes a constant folded in as an inline 2.0 with op_sel set and op_sel_hi clear for it, that is 0x4000.v_dot4c_i32_i8adds the same dot product to its destination. GFX10 has it as VOP2 and DPP only (LLVM'sVOP2Instructions.td).v_dot4_i32_i8("a negated dot product"), and SDWA, the VOP3 form or VOP3 modifiers onv_dot4c_i32_i8("modifiers on v_dot4c_i32_i8").This restores the dot4 part of Marvisak/VIctory@0b35b7f (by Marvis). That commit is in this repository's history: 570a941 ("Publish DexNom Runtime Radeon sources with upstream credits and build instructions") removed these lowerings, with no note on why. If that was deliberate for the Radeon runtime, this PR is not wanted. It differs from upstream's in three points: clamp is lowered (upstream refused it); SDWA and the VOP3 form of
v_dot4c_i32_i8are refused (upstream lowered them through its generic source and result handling); and the tests are written for this tree's harness, since upstream's used a container builder this tree does not have.Tests:
emit::valu_tests::dot4_sums_signed_byte_products_and_the_accumulator: 16 forms on 8 inputs against a 64-bit reference. The forms are the plain one; an inline 2.0 with its halves swapped; src0's halves swapped; one half of a source used twice (each way); selects on src2; a literal multiplicand with negative bytes, whole and with its halves swapped; an inline -16 with its halves swapped; an inline -1 accumulator; SGPR multiplicands; clamp, alone and with src0's halves swapped; andv_dot4c_i32_i8with a VGPR, an SGPR and a literal src0. The inputs cross i32's top and bottom, use the byte ends, and two of them have different halves in every operand. The operands from registers are root constants, known only at run time: Marvisak/VIctory@49761f9 found that an RX 5700's driver zero-extends the bytes of a dot4 multiplicand it sees as a constant, and the literal forms check that on this card.emit::lower::tests::dot4_forms_not_lowered_are_named: the plain forms lower; neg_lo, neg_hi, SDWA and the VOP3 form stop with the names above.Results on
4ad8692:mainwith the new tests: both fail at their first case withUnsupported { offset: 36, what: "v_dot4_i32_i8" }.0x800000b0for0x7ffffeb0); applying the selects to src2 too (at the src2 form,0xfff07c04for0x7ffffbf5); dropping the saturation (at clamp,0x8000fbf4for0x7fffffff); droppingv_dot4c_i32_i8's accumulator (at its first form).recttests fail PSV0 validation with the SDK 10.0.22621dxil.dll, and threevalu_testsfail pipeline creation on WARP only. On the RX 7900 XT it gives 239 passed, 2 failed (therecttests), 4 ignored.cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean with and without--all-features,cargo xtask policypasses, and rustfmt reports nothing new. The change merges without conflicts with each of my open PRs (Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #204 to Shaders: float inline constants in 64-bit operands are doubles #206, Shaders: a first interpolation half no second half completes is P0 + i P10 (it drew zero or was refused) #208, Shaders: dword 0 of root constants is an offset, not an address base (port of upstream #2154) #209, Shaders: lanes that skip a compare's region read 0 of its lane mask (port of upstream 4a3166e) #211, Shaders: lower v_sad_*, v_msad_u8, v_mul_hi_*_24 and s_quadmask (ports of upstream 5d6889e, 344704e, c3a04e2) #213 to Shaders: normalized buffer codes load as the float nearest their quotient (port of upstream da82e44, restores 645391b) #218).Limits:
v_dot4c_i32_i8with DPP goes through the generic DPP path; there is no DPP test.v_dot2_f32_f16,v_dot2_i32_i16,v_dot2_u32_u16,v_dot2c_f32_f16,v_dot4_u32_u8,v_dot8_u32_u4) are still not lowered.PkU16operand types are not in that older copy.Claude (Anthropic) restored the lowerings, wrote the tests, and ran the WARP and hardware checks.
Generated with Claude Code