Skip to content

shader: use named operand codes in gfx1013_isa.cpp and gfx1013_pixel.cpp - #3916

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
Leyukaka:quality-item2-s6-isa-pixel
Dec 3, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
Leyukaka:quality-item2-s6-isa-pixel

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

src/gfx1013_isa.cpp and src/gfx1013_pixel.cpp still write operand codes as bare numbers: 255 for the literal operand, and 128, 192, 193 and 208 for the inline integer bounds. #3830 added src/gfx1013_registers.h to keep the register code, operand and translator slot meanings apart. #3901, #3905, #3910 and #3913 converted gfx1013_graphics_wqm.inl, gfx1013_sampled_pixel.cpp, gfx1013_vertex_id.cpp and gfx1013_compute_clear.cpp.

Change

This is the sixth slice. Both files are small, so they share one PR with one commit each. No behaviour change.

  • 780298ed8 replaces the nine == 255 comparisons in probe_instruction (src/gfx1013_isa.cpp, +7/-5) with operand::literal. Each one compares an already extracted source field (VOP1/VOP2/VOPC, SOP1, SOPC, SOP2, VOP3/VOP3P) against the code that selects the trailing literal dword. The file is inside namespace x2w::gfx1013, so operand:: needs no qualifier. The VOP3 line is wrapped because it became longer; its operands and evaluation order are unchanged.
  • 947377404 names the literal and the inline integer bounds in the v_mov_b32 source decode of decode_color (src/gfx1013_pixel.cpp, +6/-3): operand::literal, operand::zero..operand::int_pos_last and operand::int_neg_first..operand::int_neg_last. decode_color is a file-static function outside namespace x2w, so the file adds namespace gfx1013 = x2w::gfx1013;.
  • Both files include the header. The constants are constexpr unsigned with the same values as the numbers they replace, so the decoded instruction sizes and the decoded colours are unchanged.
  • Left numeric:
    • the field masks & 255 and & 511. They are bit masks, not operand codes.
    • in gfx1013_isa.cpp, the source codes 233, 234, 249 and 250 on the same line as the first literal comparison. The header has no constants for them, and adding some is out of scope here.
    • in gfx1013_pixel.cpp, the lines that tests/cmake/gfx1013_pixel.cmake uses as mutation anchors: src >= 256 && vgpr[src - 256], dst = src - 128;, dst = 192u - src; and the float table. The test configuration stops if an anchor is no longer found, so these stay as they are.
    • the 240..247 float range. The header's operand::float_last is 248, so it is not a like-for-like replacement.
    • opcodes and the VGPR array size.
  • The ten mutation anchors (string(REPLACE ...), five in tests/cmake/gfx1013_isa.cmake and five in tests/cmake/gfx1013_pixel.cmake) target lines this change does not touch.
  • No build change. gfx1013_registers.h is header-only and already in src.

Validation

Built on Windows with MSVC, head 947377404 on main d2e6a4ed9. The targeted set passed:

  • gfx1013_isa_all and the gfx1013_isa_* cases.
  • gfx1013_pixel_all and the gfx1013_pixel_* cases.
  • The ten mutation controls among them (*_mut, WILL_FAIL) still fail as expected, so the anchors still apply:
    • gfx1013_isa_mtbuf_bit3_mut, gfx1013_isa_mimg_nsa_mut, gfx1013_isa_vop3_fallback_mut, gfx1013_isa_vop2_madmk_mut and gfx1013_isa_flat_segment_mut;
    • gfx1013_pixel_inline_int_mut, gfx1013_pixel_inline_neg_mut, gfx1013_pixel_inline_float_mut, gfx1013_pixel_vgpr_copy_mut and gfx1013_pixel_endpgm_trailing_mut.
  • mesh57_integer_alu, which also compiles gfx1013_isa.cpp.
  • native_translator_corpus_dxil and native_translator_corpus_ir.

Translator corpus: the TSV built from main d2e6a4ed9 and the TSV built from this branch have the same SHA-256, so they are byte-identical.

Each replaced site was also read a second time against the header to confirm the same value and meaning, and that the pixel inline integer ranges are unchanged.

Other open PRs

No open PR edits gfx1013_isa.cpp or gfx1013_pixel.cpp. The gfx1013_direct_*.inl frontends are still edited by many open PRs, so they will follow once that work lands.

Replace the nine 255 comparisons in probe_instruction with
operand::literal from src/gfx1013_registers.h. They test whether a
VOP1/VOP2/VOPC, SOP1, SOPC, SOP2, VOP3 or VOP3P source field selects the
trailing literal dword, which adds one word to the instruction size.
The file is inside namespace x2w::gfx1013, so operand:: needs no
qualifier. The values and types are unchanged, so every decoded size
is identical. Left as they are: the DPP and SDWA selectors 233, 234,
249 and 250 (the header has no names for them), field masks and
opcodes. The five mutation anchors are on other lines.
Name the literal operand (255) and the inline integer bounds (128, 192,
193, 208) in the v_mov_b32 source decode of decode_color with the
constants from src/gfx1013_registers.h. The function is a file-static
outside namespace x2w, so the file aliases x2w::gfx1013. The values and
types are unchanged, so the decoded colour is identical. The lines that
tests/cmake/gfx1013_pixel.cmake uses as mutation anchors stay numeric:
src >= 256 && vgpr[src - 256] with its body, dst = src - 128,
dst = 192u - src and the float table. The 240..247 float range is
also left as is.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The Linux check on 94737740 fails two source-contract checks after the operand codes were renamed:

  • tests/gfx1013_isa_meta_check.py still expects src == 233 || src == 234 || src == 249 || src == 250 || src == 255.
  • tests/gfx1013_pixel_meta_check.py still expects src == 255.

Please update the assertions to recognize the named codes while retaining coverage of their numeric values and the literal-operand decoding paths. Both scripts should pass on the revised head.

Linux check log

The source-contract checks still looked for the numeric spellings that
the register-name slices replaced:

- gfx1013_isa_meta_check.py: the ext_src255 and vop3_literal model
  anchors and two contract needles now use operand::literal, the SOP1,
  SOPC and SOP2 literal checks are pinned too, and the header include is
  required.
- gfx1013_pixel_meta_check.py: the literal_255 model anchor and the
  contract needle now use gfx1013::operand::literal; the named inline
  integer ranges, the include and the namespace alias are pinned.
- gfx1013_compute_clear_meta_check.py: the mbcnt_hi_src model anchor
  uses gfx1013::operand::vgpr_base after R0Y00#3913, and the four renamed
  sites and the include are pinned.

Each script now also reads src/gfx1013_registers.h and checks the
numeric values behind the names it relies on (literal 255; zero 128,
int_pos_last 192, int_neg_first 193, int_neg_last 208; sgpr_count 128,
vgpr_base 256), so the encodings stay covered. The test cases, the
models and the CMake mutation anchors are unchanged.
@Leyukaka

Leyukaka commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you for the review. Fixed in 409fa331, on top of 94737740.

  • tests/gfx1013_isa_meta_check.py and tests/gfx1013_pixel_meta_check.py now expect the named codes in their model anchors and contract lines.
  • The numeric values stay covered: each script parses src/gfx1013_registers.h and asserts the values behind the names it relies on. That is literal = 255 in both, and in the pixel check also zero = 128, int_pos_last = 192, int_neg_first = 193 and int_neg_last = 208.
  • The literal-operand decoding paths are unchanged. The ext_src255, vop3_literal and literal_255 mutations keep their control cases, and the test words still encode 255. The models, test cases and CMake mutation anchors are untouched.
  • tests/gfx1013_compute_clear_meta_check.py is fixed in the same commit. It has been broken on main since shader: use named register codes in gfx1013_compute_clear.cpp #3913: its mbcnt_hi_src anchor still expected the old 256 literal. I should have caught that in shader: use named register codes in gfx1013_compute_clear.cpp #3913, sorry. It now expects gfx1013::operand::vgpr_base and asserts sgpr_count = 128, zero = 128 and vgpr_base = 256 from the header.

Validation

  • gfx1013_compute_clear_meta_check.py passed on Windows: 38 cases, 8/8 mutations killed.
  • The isa and pixel scripts need g++ and were not run locally. The Linux job on this push is the check for them.
  • The sampled_pixel and vertex_id scripts were checked by reading only: their anchors do not refer to the renamed lines, so they should be unaffected.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Re-reviewed 409fa33. The updated checks recognize the named operand codes and assert their exact original values. The decoding branches still exercise literal and inline immediates. In Ubuntu 22.04 with GCC, I ran all three scripts with python3 -B: gfx1013_isa_meta_check.py (81 cases, 13/13 mutations caught), gfx1013_pixel_meta_check.py (136 cases, 13/13), and gfx1013_compute_clear_meta_check.py (38 cases, 8/8). This addresses my Linux CI change request.

@R0Y00
R0Y00 merged commit 7b3212a into R0Y00:main Dec 3, 2026
5 checks passed
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.

2 participants