Skip to content

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
DexNom:mainfrom
murillojndem:fix/v-dot4-i32-i8
Open

murillojndem wants to merge 1 commit into
DexNom:mainfrom
murillojndem:fix/v-dot4-i32-i8

Conversation

@murillojndem

Copy link
Copy Markdown

The decoder knows VOP2 v_dot4c_i32_i8 (0x0d) and VOP3P v_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_dir is called only there), and fidelityfx.rs then 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_i8 is the four signed byte products of src0 and src1 plus src2, wrapping: LLVM's llvm.amdgcn.sdot4, which V_DOT4_I32_I8 selects, and Mesa's sdot_4x8_iadd. It is lowered with DXIL's Dot4AddI8Packed.
  • With clamp, the whole sum saturates to i32's range: Mesa's sdot_4x8_iadd_sat computes it in 64 bits and clamps, and Mesa's ACO selects that opcode as v_dot4_i32_i8 with clamp on GFX10. The lowering adds the products' sum, which cannot overflow, to the accumulator and saturates on signed overflow.
  • op_sel and op_sel_hi on src0 and src1 pick their 16-bit halves, as for the other packed integer instructions (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 with v_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_i8 adds the same dot product to its destination. GFX10 has it as VOP2 and DPP only (LLVM's VOP2Instructions.td).
  • Refused by name: neg_lo or neg_hi on v_dot4_i32_i8 ("a negated dot product"), and SDWA, the VOP3 form or VOP3 modifiers on v_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_i8 are 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; and v_dot4c_i32_i8 with 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:

Limits:

  • The tests check the translation on host GPUs. The op_sel reading rests on the gfx10.3 and gfx11 measurement and on ACO, not on a console. An inline float constant is read as its f32 bits, this tree's rule for packed integer instructions; no measurement covers a float constant on dot4.
  • v_dot4c_i32_i8 with DPP goes through the generic DPP path; there is no DPP test.
  • The other dot instructions the decoder knows (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.
  • Whether an RDNA1 driver still zero-extends a constant multiplicand was not checked (no RDNA1 card here).
  • The Mesa sources cited were read from a GitHub copy of recent Mesa (lfdevs/mesa-for-android-container), as Mesa's GitLab did not answer scripted requests. The two NIR definitions are the same in the Mesa 25.0.7 copy in OpenBSD's xenocara; ACO's PkU16 operand 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant