Skip to content

shader_disasm: print v_dot4_i32_i8 op_sel 2 / op_sel_hi 5 words llvm-mc rejects (OLD-10010) - #1317

Closed
ambroseautomation wants to merge 1 commit into
ProjectLeonida:mainfrom
ambroseautomation:carry/old-10010-fspx-dot4-op-sel
Closed

ambroseautomation wants to merge 1 commit into
ProjectLeonida:mainfrom
ambroseautomation:carry/old-10010-fspx-dot4-op-sel

Conversation

@ambroseautomation

Copy link
Copy Markdown

Summary

Coordination item: OLD-10010 (carry-forward of old-pr/10010, preserving original author tedin7).

Problem & Root Cause

llvm-mc rejects v_dot4_i32_i8 VOP3P words encoded with op_sel: 2 ([0,1,0]) and op_sel_hi: 5 ([1,0,1]), which appear in the FidelityFX upscaler's FSPX programs (docs/fspx.md), preventing those programs from disassembling and translating cleanly.

Implementation

  • Adds DOT4_I8_OPCODE, dot4_op_sel_words(), and with_dot4_op_sel() in tools/shader_disasm.py to patch rejected v_dot4_i32_i8 op_sel=2 / op_sel_hi=5 words to defaults (op_sel=0 / op_sel_hi=7) for llvm-mc disassembly and restore op_sel:[0,1,0] op_sel_hi:[1,0,1] and the original encoding bytes on the resulting instruction lines.
  • Preserves main's with_vopc_dpp() fallback pass cleanly alongside with_dot4_op_sel() in disasm().
  • Documents the behavior in docs/fspx.md and adds semantic/disassembly tests in tests/semantic/test_fspx_dot4_op_sel_disasm.py and tests/semantic/test_alu_dot4_i8.py.

Tests Run

Environment: Windows 11 Pro 64-bit, Python 3.12.10, synthetic fixtures only (no game data).

  • python -I -m py_compile tools/shader_disasm.py tests/semantic/test_fspx_dot4_op_sel_disasm.py tests/semantic/test_alu_dot4_i8.py — PASS
  • python -I tests/semantic/test_alu_dot4_i8.py — 12/12 PASS
  • python -I tests/semantic/test_fspx_dot4_op_sel_disasm.py — 4 skipped (no llvm-mc installed on this host); additionally verified shader_disasm.dot4_op_sel_words() and shader_disasm.disasm() fallback path with a mocked run_mc — PASS
  • pytest tests/test_docs_links.py tests/test_text_write_line_endings.py -v — 19/19 PASS
  • python -I scripts/check_no_game_data.py docs/fspx.md tests/semantic/test_alu_dot4_i8.py tests/semantic/test_fspx_dot4_op_sel_disasm.py tools/shader_disasm.py — PASS

Disclosure

AI-assisted: yes (carry-forward, rebase onto current main preserving with_vopc_dpp, and local verification; original implementation by tedin7).

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (AI-assisted, overnight shift worker):

Environment: Windows, py -3.14, LLVM_MC='wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc' (LLVM 21.1.8, AMDGPU target; needed MSYS_NO_PATHCONV=1 so the Linux path survives).

Commands & results:

  • pytest tests/semantic/test_alu_dot4_i8.py tests/semantic/test_fspx_dot4_op_sel_disasm.py -q → 16 passed, 36 subtests passed (3m06s). Without LLVM_MC the llvm-mc-gated cases skip (12 passed, 4 skipped) — with llvm-mc all run, so the emitted v_dot4_i32_i8 op_sel 2 / op_sel_hi 5 words are confirmed to disassemble through shader_disasm and translate end-to-end in the FSPX layout.
  • Regression neighbours: pytest tests/semantic/test_alu_dot4_u8.py tests/semantic/test_valu_dot4_int.py tests/semantic/test_valu_dot4acc_refused.py -q → 36 passed, 351 subtests passed.

The test assembles real instruction lines with llvm-mc, flips the op_sel/op_sel_hi fields in the two dwords, then checks shader_disasm prints and rdna2spirv translates the blob — this covers the claim that llvm-mc rejects these words while the patched disassembler path handles them. No game files or GPU needed; verified on this machine only.

— AI-assisted verification

@Snooozs

Snooozs commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This is still needed: #281 (the same change from old PR 10010) shows as merged, and its merge b39899394 is an ancestor of main, but its content is not in the tree. At 42537e7b6, tools/shader_disasm.py has no op_sel handling and tests/semantic/test_fspx_dot4_op_sel_disasm.py doesn't exist; later merges kept main's side of the file.

Measured on Windows 10 19045 with native llvm-mc 23.1.6 and my own 1.0.2.1 copy:

fspx_unpack.py --disasm + rdna2spirv.py --wave64-emulate translated
main 42537e7b6 27 of 29 (2 refused: "reachable instruction with normalized encoding")
+ #281's dot4_op_sel_words / with_dot4_op_sel, called after with_vopc_dpp in disasm(), with wave32 passed to run_mc 29 of 29, all pass spirv-val

#281's 4 tests and tests/test_shader_disasm.py (31) pass with it.

It matters for the boot: on 42537e7b6 + #1558 + #1547 the retail run reaches the story load, then slot 67 and slot 62 find no translated compute shader for one FSPX program, and the title ends with 0xc0000005 in amd_fidelityfx_upscaler_xbox.dll+0x65ff (read of 0x10) at 152 s. The two refused programs are the only FSPX ones missing here. I have not shown yet that the run goes further with all 29; that is running now.

invalid_offsets is line based on main now (one dword per line), which the ported code needs, so a rebase is small. I am not opening a competing pull request.

AI-assisted (Claude Code, Claude Opus 5.5).

…rds llvm-mc rejects, so the FSR4 FSPX programs translate

The FidelityFX upscaler programs hold 89 such words in 8 programs (docs/fspx.md); the translator already models the form but the listing could not carry it, so the programs were refused as a fall-through into undecodable words.
@ambroseautomation

Copy link
Copy Markdown
Author

Rebased onto current main (98c2f77): adapted with_dot4_op_sel to main's line-based invalid_offsets and forwarded wave32 to run_mc as noted by @Snooozs, resolved the doc/comment conflicts in docs/fspx.md and tests/semantic/test_alu_dot4_i8.py, and added newline='\n' to the JSON write in test_fspx_dot4_op_sel_disasm.py. Re-verified test_shader_disasm.py (31/31), test_alu_dot4_i8.py (14/14), test_text_write_line_endings.py (3/3), and a mock wave32=False / line-offset check. AI-assisted.

@ambroseautomation
ambroseautomation force-pushed the carry/old-10010-fspx-dot4-op-sel branch from 4e1ca11 to 62237d0 Compare November 25, 2026 12:52
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@MoonEyes

Copy link
Copy Markdown
Collaborator

Note for triage: #281 is shown as merged, but its shader_disasm change and tests/semantic/test_fspx_dot4_op_sel_disasm.py are not in current main (they were dropped in merge 154e4ec on the #939 branch). This PR still applies cleanly on main and would restore them.

AI-assisted: yes (Claude Code compared the diffs against origin/main; I reviewed it).

aslan2142 added a commit that referenced this pull request Nov 26, 2026
…ead)

The copy of #1317 in this branch called with_dot4_op_sel(code, mcpu, bad,
err) and run_mc(bytes(patched), mcpu) without wave32, so a wave64 program
whose v_dot4_i32_i8 op_sel 2 / op_sel_hi 5 word was re-decoded printed its
lane masks as vcc_lo. Take #1317's current head (62237d0, by tedin7):
with_dot4_op_sel takes wave32 and hands it to run_mc. Also its newline="\n"
on the test's JSON write, and the two blank lines before MAX_DATA_DWORDS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aslan2142 added a commit that referenced this pull request Nov 26, 2026
…re_dot4_inline_sel

The general rule from #1495 (dot4_op_sel_fields / restore_dot4_op_sel,
ported from luizwidmer/palmetto) took the stored op_sel/op_sel_hi of any
v_dot4_i32_i8 that llvm-mc printed with the defaults. That translated
op_sel 0 / op_sel_hi 5 with a VGPR second source, a word #1317's
test_fspx_dot4_op_sel_disasm.py (case (0, 5)) requires to stay refused:
only op_sel 2 / op_sel_hi 5 was measured on gfx1036. The translator suite
failed there.

Resolve it on the measured side:
- drop dot4_op_sel_fields and restore_dot4_op_sel;
- keep main's restore_dot4_inline_sel (#984) and its three call sites:
  the clean-listing check, the forward re-anchor search, and the exact
  re-anchor window #1662 added today. The general rule does not cover
  only those cases, so it cannot replace them;
- tests/semantic/test_dot4_printed_op_sel.py now checks that the
  inline-integer form is restored in a clean listing and on re-anchoring,
  and that op_sel_hi 5 with a VGPR S1, op_sel 1 / op_sel_hi 6,
  op_sel_hi 4 and a non-default S2 half stay refused;
- docs/design.md "Signed-byte dot products" states how each form was
  confirmed (hardware for op_sel 2 / op_sel_hi 5, a corpus count for the
  inline-integer form, refused otherwise); docs/fspx.md follows.

This also settles the #1662 / #1862 overlap: #1662's call site stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Collaborator

Closing as included, thanks @ambroseautomation! #2138, merged as 0b11d86bc, has this PR's behaviour from your head 62237d0e5: wave32 is passed through with_dot4_op_sel and run_mc, so a wave64 program no longer prints vcc_lo, and only the measured op_sel 2 / op_sel_hi 5 form is printed. Only doc and test wording differ.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 closed this Nov 26, 2026
milk4sale pushed a commit to milk4sale/leonida that referenced this pull request Nov 26, 2026
…mc rejects)

# Conflicts:
#	docs/fspx.md
#	tests/semantic/test_alu_dot4_i8.py
milk4sale pushed a commit to milk4sale/leonida that referenced this pull request Nov 26, 2026
…red fields

llvm-mc decodes a VOP3P v_dot4_i32_i8 whose op_sel_hi is not [1,1,1] (op_sel bit 1 clear) but
prints and re-encodes it with op_sel 0 / op_sel_hi 7, so translate() refused it as a dropped
field. When those two fields are the only difference between the stored and the printed bytes,
they are now read from the blob, in check_printed_encodings and in both re-anchoring paths, and
the v_dot4_i32_i8 rule applies them as measured on gfx1036 (a non-default S2 half stays
refused). Any other difference is still refused.

This replaces ProjectLeonida#984's restore_dot4_inline_sel, which took one case of the same form (op_sel_hi
[1,0,1] with an inline integer S1); that case is covered by the general check. The words llvm-mc
rejects (op_sel 2 / op_sel_hi 5) are printed by shader_disasm.py (ProjectLeonida#1317) and recovered from the
blob by skipped_form. The approach comes from luizwidmer/palmetto (GPL-3.0).

Test: tests/semantic/test_dot4_printed_op_sel.py, hand-built words; design.md contract row and
docs/fspx.md updated.
Kokonotcu added a commit to Kokonotcu/leonida that referenced this pull request Nov 26, 2026
37 upstream commits after 86dc3d8: ProjectLeonida#2138 (integration/boot-combined), ProjectLeonida#2094 (geometry-view eviction on range
release, reaped after the replays that may name them), ProjectLeonida#998/ProjectLeonida#1317/ProjectLeonida#1281/ProjectLeonida#583 heads (pipeline-library compute
programs by code hash, shader_disasm prints the dot4 op_sel words llvm-mc rejects, FSPX short prologue with the
literal-form check), null-resource texture barriers and null-view RTV clears on the console list, and the removal
of the title's executable addresses from code (read from the environment).

Conflicts, on merit:
- d3d12_xs_device.cpp: both. Our title heap sync (LEONIDA_TITLE_HEAP_SYNC) and upstream's null-RTV marks sit side
  by side; heap_release unregisters the sync or the range as before and also drops the heap's null-RTV marks;
  CreateDescriptorHeap keeps our desc argument and takes upstream's RTV real range. Our value-op/upload-ring
  slots and upstream's slot 146 barrier conversion both stay.
- startup_trace.h: our thread and watchdog-table logging stays, and follows upstream's rule: the watchdog table's
  store and table RVAs come from LEONIDA_WATCHDOG_TABLE (off when unset, documented in runtime/README.md);
  upstream's environment-driven pool diagnostic replaces the fixed address.
- fspx_unpack.py: ours (the code end is found from one rdna2_decode pass, not an llvm-mc run per s_endpgm: the
  OOM and 15-minute fix). Its test takes upstream's short-prologue case, which checks the literal form our code
  also requires.
- rdna2spirv.py: ours (s_bitreplicate_b64_b32 into VCC in wave32 stays translated: 6 pipeline-library programs),
  plus the point behind upstream's refusal: in wave32 VCC's high word is data, so it is now written to vcc_hi as
  source bits 16..31 replicated (replicate_bits16, shared with the scalar form). Tests: ours kept, one added for
  the vcc_hi word; test_salu_flbit_64 keeps ours (this tree translates i64 of a lane mask).
- xs_proxy_mock_test.cpp: upstream's empty Barrier call, our chained-submission reference count.

Every line the merge removes from our side is upstream's own or one of the resolutions above (checked against the
merge base, D:\GTA6\analysis\lostlines.sh). The touched Python suites pass.

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.

6 participants