Skip to content

Direct RDNA2 decoder: recognize SDWA inline scalar constants - #2811

Draft
kacper-serewis wants to merge 21 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/sdwa-inline-2038
Draft

kacper-serewis wants to merge 21 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/sdwa-inline-2038

Conversation

@kacper-serewis

@kacper-serewis kacper-serewis commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

BUILD-807. Original claim and continuation.

Depends on: #2038
Depends on: #2786

#2038 at 998128ec supplies the SDWA implementation. This branch integrates #2786 at 2e594cf1, which includes #2038, and main at aa2988cc. The contribution specific to #2811 is a synthetic regression checking all 90 inline constants across five VOP1, VOP2 and VOPC source positions. #2323 adds direct-backend consumers and is a tracker merge-order predecessor, not a prerequisite for this test. Tracker order is #2038 → #2323 → #2786 → #2811.

On Windows, 13 synthetic decoder tests and 19 shader-disassembly tests passed. Four independent LLVM 21.1.8 gfx1013 assemblies matched the decoded operands for positive and negative integers, floating-point 1.0, an SGPR, and VGPRs including v242. LLVM rejected a non-inline immediate for v_mov_b32_sdwa as expected.

The optional LLVM fixture parity test still fails on ps_sdwa_f16_const.asm. LLVM renders the 8-byte inline v_cvt_f16_u16_sdwa as a 12-byte literal encoding. Existing parity finding.

AI-assisted. CPU only, with no game archives, GPU or driver used.

…negatives as decimal

Addresses review feedback on PR ItsNotRexed#2038 (@borislisandro):
- Sign-extend SOPP branch simm16 offsets with _s16(simm16) so backward branches decode
  as negative integers (e.g. -4, -20) matching shader_ir/llvm-mc 21/22 instead of 0xfffc.
- Format negative immediates (< 0) as decimal rather than broken '0x-...' hex.
- Clarify module docstring (shader_ir-compatible .s text) and update unit tests
  (normalizing SOPP branch immediates mod 16-bit for LLVM 18 vs 21/22 parity).
@Marukooh

Copy link
Copy Markdown
Contributor

Independent CPU check of 80b46f6b on CachyOS Linux, Python 3.14, LLVM MC 23.1.5. All 9 direct decoder tests and 14 shader-disassembly tests passed. This includes the optional LLVM parity test, which completed without the LLVM 21.1.8 mismatch reported in the PR. With the new SDWA regression run against the parent decoder 4da88513, all 450 subcases errored because the operand had no immediate value. The head passes all 450. AI-assisted, synthetic fixtures only.

@padhossein

Copy link
Copy Markdown
Contributor

Independent SDWA scalar-bit differential (80b46f6b). I tested both settings of the scalar-selector bit across all 90 constant-coded index bytes and the five source positions in VOP1/VOP2/VOPC. On the stack base, 450/450 vector controls matched and 0/450 scalar inline selections matched. This head matched 450/450 in both sets, so the non-scalar branch still selects the same VGPR even when its numeric byte also denotes a scalar constant. The LLVM-enabled suite was 22 passed with the separately documented, existing SDWA literal-length mismatch in ps_sdwa_f16_const (LLVM 21.1.8).

AI-assisted (Codex).

@dac0129

dac0129 commented Nov 22, 2026

Copy link
Copy Markdown

Hardware & Test Verification: PASS on GPU (Dual-GPU Tested)

AI-assisted review. Validated branch shader/sdwa-inline-2038 on Windows 11 Build 26200 across:

  • NVIDIA GeForce RTX 4080 (Driver 617.42 / Vulkan 1.4.351)
  • AMD Radeon(TM) Graphics (Raphael RDNA2 iGPU, Driver 26.11.2 / Vulkan 1.4.315)
  • LLVM-MC: 21.1.8

GPU Results:

  • python -I scripts/run_gpu_tests.py --filter sdwa:
    • ps_sdwa: PASS (4096/4096 pixels exact on both RTX 4080 and AMD RDNA2 iGPU).
    • ps_sdwa_f16_const: PASS (4096/4096 pixels exact on both RTX 4080 and AMD RDNA2 iGPU).

LLVM Parity Confirmation:

Confirmed that test_parity_with_llvm_mc_on_shader_fixtures fails solely at ps_sdwa_f16_const.asm on the encoding length of v_cvt_f16_u16_sdwa (f9a00a7ef2148500 vs LLVM appending 003c0000 literal bytes during -disassemble), exactly as noted in the PR description. On real hardware through Vulkan, the shader compiles and executes bit-for-bit identical to the reference output.

Zero game data used.

@Kam471

Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed at head 80b46f6b (draft). The new decode is correct against LLVM's VOP_SDWA9e: w1[7:0]=src0, w1[23]=src0_sgpr, w1[31]=src1_sgpr, w1[18:16]=src0_sel, w1[26:24]=src1_sel, with SIDefines.h ranges 128-208 for int and 240-248 for float. test_rdna2_decode.py 8 pass / 1 skip, test_shader_disasm.py 14/14, test_rdna2spirv_decode.py 23/23, 450/450 subcases. No game data or absolute paths.

This is correctly blocked, not wrong: the decoder is absent from main (open #2038), the PR is a draft, and LLVM parity was skipped (llvm-mc absent), leaving sreg_242 and the v_cvt_f16_u16_sdwa discrepancy unverified. Ready once #2038 lands, the branch is rebased, and the LLVM parity check runs.

@kacper-serewis

Copy link
Copy Markdown
Contributor Author

Clarifying the LLVM gate in the latest review: this remains draft pending #2038. The LLVM-enabled checks in the earlier comments did run: Marukooh reports the parity test passing with LLVM 23.1.5; padhossein and dac0129 independently reproduced only the documented ps_sdwa_f16_const encoding-length discrepancy on LLVM 21.1.8, and dac0129 ran both SDWA pixel fixtures on NVIDIA and native RDNA2 Vulkan. Those reports do not resolve cross-version LLVM parity generally, so that limitation stays explicit. We will rebase and rerun after #2038 lands. AI-assisted coordination.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD-807. Depends on: #2786. Depends on: #2038. AI-assisted integration at 3b47b72. Relative to #2786, only the 450-case SDWA inline-constant regression test remains. All 38 CPU tests passed without skips, including LLVM 21.1.8 fixture parity. No GPU or archive was used.

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.

6 participants