Skip to content

op_reach: which unmeasured translator rules the 1.0.2.1 shaders reach (census + docs/isa_coverage.md) - #6735

Open
abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:op-reach
Open

abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:op-reach

Conversation

@abilliontokens

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6414 (comment) (corpus reach of the translator rules marked "not measured" / "not run on the shader corpus")

Depends on: none. It adds one tool and one test, and appends a section to docs/isa_coverage.md. No docs/design.md row is edited, so it does not overlap #4137 / #4147 (which pin some of these rows to gfx1100 measurements) or the EGEN-ISA-TABLES-DOC claim's edits higher up in isa_coverage.md.

What and why

Many rows of the translator contract in docs/design.md say part of a rule is not measured on hardware, and two say it was not run on the shader corpus (v_cvt_pknorm_*_f16, v_cmp_class_f16/f64). Whether the game reaches such a rule decides whether the gap matters for 1.0.2.1. This PR measures that:

  • tools/op_reach.py (new, stdlib) counts, over a folder of .s listings, the shaders and instructions using each instruction. It merges the _e32/_e64/_sdwa/_dpp encodings (the suffixes base_op() strips) and counts only the program up to a listing's last s_endpgm. Data words LLVM decoded after it are left out and reported as a separate total: on 1.0.2.1 that is where all 4 s_cmov_b32 are. --index adds a per-stage count, --json writes the rows. An OP name no listing uses prints 0.
  • tests/test_op_reach.py (new, 7 tests on hand-written listings): encoding merge, one shader counted once, comments ignored, data after the last s_endpgm dropped, the per-stage counts, the CLI JSON output, and exit codes 2 (missing folder) and 1 (no listing).
  • docs/isa_coverage.md: a section listing which of those rows the game reaches and which no 1.0.2.1 shader uses. Measured counts only. Where a row's unmeasured part is narrower than its instruction (a modifier, an operand range), the table says the count is the instruction's.

Measured (1.0.2.1, 26,503 listings: 12,101 PS, 9,282 MS, 2,689 CS, 2,236 VS, 195 GS)

0 shaders use: buffer_load_{u,s}byte/{u,s}short, the 8/16-bit global_store/d16 global_load forms, v_rcp/rsq/sqrt_f64, ds_cmpst_f32/_rtn, global/buffer_atomic_fcmpswap, ds_add_f32/_rtn, the six extra image_atomic_*, s_cmov_b32 (in program code), s_cmovk_i32, s_cmov_b64, s_pack_*, v_mul_hi_*24, v_lshrrev_b64/v_ashrrev_i64, v_(m)qsad_pk_u16_u8, v_div_fixup_f16/f64, the f16/f64 frexp/ldexp, all four v_cvt_pknorm_*, v_cmp(x)_class_f16/f64, the bitwise buffer_atomic_*_x2, v_dot2c_i32_i16, v_dot8c_i32_i4, v_log_f16.

Reached: v_interp_p1ll_f16/p2_f16 4,776 PS; v_interp_mov_f32 3,673 PS; v_cvt_f16_f32 6,306; v_fma_mix_f32 9,620, mixlo 6,155, mixhi 842; v_exp_f16 3 CS, v_cos_f16 1 CS; v_cndmask_b32 22,553; image_get_resinfo 407, image_get_lod 653; image_bvh(64)_intersect_ray 40 / 24 CS; s_bfe_u32 15,398, s_bfe_i32 2,847. The full numbers are in the doc.

Not covered: the embedded programs (52 BVH-builder FSSM, 29 FidelityFX) and later game builds; the doc says so.

Tested

Commit 32f09b1a8 on origin/main 1cc6e3c12. This is a census plus docs, with no translator change, so there is no translate/spirv-val before-and-after.

$ python -I tests/test_op_reach.py
Ran 7 tests
OK

$ for t in tests/test_docs_*.py tests/test_isa_coverage.py tests/test_ci_registration.py; do python -I $t; done
OK (each; test_isa_coverage skips its 4 real-XML tests without LEONIDA_RDNA2_ISA_XML)

$ python -I tools/op_reach.py <work>/shaders/dxbc/disasm --index <work>/shaders/dxbc/index.json <the 79 names in the doc>
26503 listings {'cs': 2689, 'gs': 195, 'ms': 9282, 'ps': 12101, 'vs': 2236}, 2035 decoded instructions after the last s_endpgm left out

The corpus run took about 2 minutes, CPU only, on Windows 11 (10.0.26200) with Python 3.12.10. No GPU or driver involved.

AI-assisted: yes (omp orchestrator).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule; this measures the corpus reach of existing rows.)

tools/op_reach.py counts, over a disassembled corpus, the shaders and
instructions using each instruction, merging the _e32/_e64/_sdwa/_dpp
encodings and counting only the program up to a listing's last s_endpgm
(decoded data words after it are reported separately). tests/test_op_reach.py
checks it on hand-written listings.

docs/isa_coverage.md lists, for the docs/design.md rows whose rule is partly
not measured on hardware (or 'not run on the shader corpus'), which
instructions no 1.0.2.1 shader uses (v_cvt_pknorm_*, v_cmp_class_f16/f64,
v_div_fixup_f16/f64, f16/f64 frexp/ldexp, f64 rcp/rsq/sqrt, ds_add_f32,
the fcmpswap family, s_cmov/s_pack, the x2 bitwise buffer atomics, the extra
image atomics, v_dot2c/v_dot8c, sub-dword buffer/global forms) and how many
use the others (16-bit interpolation 4,776 PS, v_fma_mix* 9,620, ...).
@Proudnoob4

Copy link
Copy Markdown
Contributor

Tested 32f09b1a on Windows 10 22H2, Python 3.13.0, CPU only, with my own 1.0.2.1 listings: pass.

python -I tools/op_reach.py <work>/shaders/dxbc/disasm --index <work>/shaders/dxbc/index.json --json <out> over all instructions exits 0 in 85 s and reports 26503 listings {'cs': 2689, 'gs': 195, 'ms': 9282, 'ps': 12101, 'vs': 2236}.

  • All 79 names in the new section match. The 63 instructions in the first table have 0 shaders here too. The 16 reached rows match exactly in shaders, instructions and stage split, e.g. v_cvt_f16_f32 6,306 (44,496): 4,490 MS, 926 CS, 580 PS, 310 VS, and image_get_resinfo 407 (1,148): 381 PS, 26 CS.
  • s_cmov_b32: 0 listings in program code and 4 after the last s_endpgm, as written.
  • One number differs. I get 2,041 decoded instructions after the last s_endpgm (in 71 listings), against 2,035 in the PR body and the doc. My own scan of the listings gives the same 2,041. These are data words: the most common are 884 v_mac_f32_e32, 689 v_madmk_f32, 100 s_subvector_loop_end and 92 v_illegal. So the total depends on how the listings were made, the LLVM version or the disassembler's code range. Mine come from make_game.py's shaders stage at bb2e1842 with llvm-mc 23.1.4 (MSYS2). No count in the two tables depends on it, but the doc could name the LLVM version next to 2,035, or say "about 2,000".
  • Tests: tests/test_op_reach.py 7 OK; tests/test_isa_coverage.py 22 OK (4 skipped, no ISA XML); tests/test_ci_registration.py and the 11 tests/test_docs_*.py pass.

AI-assisted (Claude Code). Counts only.

@wasonidas

Copy link
Copy Markdown

CPU-only review of 32f09b1a866176946f2fd777e13c082077a8f480 on 1cc6e3c1. Seven stock test_op_reach.py tests and five independent synthetic controls passed. Suffix normalization, last-s_endpgm truncation, and per-listing/per-instruction counts behaved as described.

One documentation scope issue: the table currently labels that count p10 / p20, but the 3,673 listings / 6,926 occurrences count is for the opcode as a whole. The SHADER-177 contract records that all 6,926 used p0. Please label the whole-opcode count and give p10/p20 as zero per that measurement, or place those operands in the zero-reach table. The tool's syntactic counts alone do not distinguish the operands.

Synthetic inputs only. AI-assisted.

@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 32f09b1 on my own Xbox 1.0.2.1 copy (all 108 files match game/xbox-1.0.2.1.json by size). Listings came from make_game.py --stages shaders of main 1cc6e3c1 (shader_disasm.py --mcpu gfx1013, llvm-mc 23.1.6). Windows 11 Home 26200, Python 3.13, CPU only: pass, with one difference noted below.

python -I tools/op_reach.py <work>/shaders/dxbc/disasm --index <work>/shaders/dxbc/index.json --json <scratch> (all ops, about 40 s):

  • Listings: 26,503 (cs 2,689, gs 195, ms 9,282, ps 12,101, vs 2,236), the same as the PR.
  • Every "Reached" count in the description matches, shaders and stages: v_cndmask_b32 22,553, s_bfe_u32 15,398, v_fma_mix_f32 9,620, v_cvt_f16_f32 6,306, v_fma_mixlo_f16 6,155, v_interp_p1ll_f16/p2_f16 4,776 PS, v_interp_mov_f32 3,673 PS, s_bfe_i32 2,847, v_fma_mixhi_f16 842, image_get_lod 653, image_get_resinfo 407, image_bvh_intersect_ray 40 CS, image_bvh64_intersect_ray 24 CS, v_exp_f16 3 CS, v_cos_f16 1 CS.
  • I checked 38 of the "0 shaders" names one by one (the byte/short buffer loads, f64 rcp/rsq/sqrt, ds_cmpst/ds_add_f32, the fcmpswaps, the s_cmov*, s_pack_*, v_mul_hi_*24, the 64-bit shifts, (m)qsad, div_fixup_f16/f64, the f16/f64 ldexp, cvt_pknorm, the f16/f64 class compares, dot2c_i32_i16/dot8c_i32_i4, v_log_f16): all 0 here too.
  • One difference: my run reports 0 decoded instructions after the last s_endpgm, where the PR has 2,035 (and all 4 s_cmov_b32 there). My listings come from current main's disassembly with llvm-mc 23.1.6, so it looks like that disassembly no longer decodes the trailing words. It changes no count above. You may want to say in the doc which disassembly the 2,035 comes from.

Counts only, nothing from the package leaves my machine. AI-assisted (Claude Code).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary
Adds tools/op_reach.py, which counts shaders and instructions per opcode across .s listings while merging encoding suffixes and dropping data after the last s_endpgm, plus tests/test_op_reach.py and a measured section in docs/isa_coverage.md.

Why merge
Answers which contract rows marked unmeasured are actually reached by the 1.0.2.1 corpus, replacing guesswork with counts over 26,503 listings. Self-contained census tool and docs update with seven tests.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary
Adds tools/op_reach.py, which counts shaders and instructions per opcode across .s listings while merging encoding suffixes and dropping data after the last s_endpgm, plus tests/test_op_reach.py and a measured section in docs/isa_coverage.md.

Why merge
Answers which contract rows marked unmeasured are actually reached by the 1.0.2.1 corpus, replacing guesswork with counts over 26,503 listings. Self-contained census tool and docs update with seven tests.

Verdict: Approve

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 32f09b1 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_op_reach.py - all exit 0.

AI-assisted (Claude Code).

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