Skip to content

startup: refuse a modifier for handlers that do not model one - #1778

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/modifier-free
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/modifier-free

Conversation

@triggered02

@triggered02 triggered02 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1771. The systematic fix for the class that produced five separate review findings (set_vf op_sel, op_v_cndmask_b32 clamp/mul:2, compare() modifiers, the handlers here, and the interpolation source modifiers found while reviewing this PR).

Problem

Several handlers take the modifier list and never read it, so a modifier their encoding can carry was dropped from the emitted HLSL:

v_mov_b32_e64 v1, v2 clamp               -> v1 = v2;            (clamp dropped)
v_cvt_pkrtz_f16_f32_e64 v1, v2, v3 op_sel:[0,0,1]
                                         -> v1 = f32tof16(F(v2)) | (f32tof16(F(v3)) << 16);   (op_sel dropped)
v_interp_mov_f32_e64 v1, p10, attr0.x clamp
                                         -> v1 = i.fparam0.x;  (clamp dropped)

The interpolations also carry modifiers inside the operand text, which no modifier-list guard can see: v_interp_p1_f32_e64 v1, |v2|, attr0.x silently interpolated the unmodified source because the handler never reads that operand.

Fix

A module-level set names the handlers whose encoding can carry a modifier but whose lowering does not model it, and the dispatch refuses the modifier before the handler runs:

MODIFIER_FREE_HANDLERS = frozenset((
    'op_v_mov_b32', 'op_v_cvt_pkrtz_f16_f32',
    'op_v_interp_p1_f32', 'op_v_interp_p2_f32', 'op_v_interp_mov_f32',
))
...
if handler:
    if mods and handler.__name__ in MODIFIER_FREE_HANDLERS:
        raise Unsupported('%s with %s' % (base, mods))
    return handler(ops, mods)

The two p1/p2 handlers additionally refuse an abs/neg printed on their data-source operand, since that one arrives as operand text rather than as a modifier list.

Scalar-ALU handlers are deliberately absent: their encoding has no modifier field, so nothing can reach them with one; adding them would be noise that cannot be exercised. The test asserts none is in the set.

Test

startup_gfx2hlsl_modifier_free builds VOP1/VOP2/VOP3A encodings from the checked-in decoder's layout, decodes them, then translates. For the interpolations it uses their real operand profile (attr in w1[5:0], channel w1[7:6], data source w1[16:9], abs at w0[9], neg at w1[30]) — an earlier revision of this PR used the generic [V2, 0] layout, which is invalid for those forms and only exercised decoder refusal.

Seventeen checks: the declared set, plain forms translating, each modifier refused per handler, abs/neg on the interpolation data source refused, the attribute channel read from the operand, and no scalar handler in the set.

dev:     12/12 startup_gfx2hlsl* + startup_translator passed
release: startup_gfx2hlsl_modifier_free Passed 0.14 s

Fail-first: removing the dispatch guard fails a clamp on the flat interpolation is refused; dropping a handler from the set fails a mul:2 on the move is refused; removing the p1/p2 source check fails an absolutely-modified p2 source is refused.

What this does not establish

  • That the hardware ignores these modifier bits; the safe side is to refuse, and that is what this does rather than claiming they are no-ops.
  • Anything about executable-backed tests: the dev tree here has no built binaries, so only the Python-level ctests were run.

AI-assisted (Claude Code).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T18:33:12.783740Z f8b962f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8b962f935

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/startup/gfx2hlsl.py Resolved
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Review on R0Y00#1778 (P2): the p1/p2 interpolations have their own VOP3 operand profile (data source in w1[16:9], abs at w0[9], neg at w1[30]), and the decoder prints those modifiers inside the operand text rather than as a modifier list, so the dispatch guard does not see them. The handlers never read that operand (the value comes from the interpolator), so |v2| or -v2 on it was silently ignored. Both handlers now refuse a modified data source. The test's previous p1/p2 checks used the generic [V2, 0] layout, which is invalid for these forms and only exercised decoder refusal; they are replaced with real encodings that translate plain forms and refuse abs/neg, plus a clamp through the modifier list.
@triggered02

Copy link
Copy Markdown
Contributor Author

Fixed in 00479dc9. You are right on both counts, and the second one matters more than the first.

The finding: the p1/p2 forms have their own VOP3 operand profile — data source in w1[16:9], abs at w0[9], neg at w1[30] — and the decoder prints those modifiers inside the operand text (|v2|, -v2) rather than as a modifier list, so the dispatch guard passes and the handlers, which never read that operand, silently produced the unmodified interpolation:

v_interp_p1_f32_e64 v1, |v2|, attr0.x  -> attrs {0: {'linear'}}, no line   (modifier dropped)
v_interp_p2_f32_e64 v1, |v2|, attr0.x  -> v1 = U(i.param0.x);              (modifier dropped)

Both handlers now refuse a modified data source (interpolation source modifier |v2|).

My fixture was the worse mistake: the earlier p1/p2 checks used the generic [V2, 0] layout, which is invalid for these forms, so they only proved the decoder rejects a malformed word — exactly the "hand-written assembly that never exercises the path" trap. The test now builds the real profile (attr in w1[5:0], channel w1[7:6], source w1[16:9]) and checks:

a plain p1 interpolation translates
a plain p2 interpolation translates        -> v1 = U(i.param0.x);
the attribute channel is read from the operand -> v1 = U(i.param1.y);
an absolutely-modified p1 source is refused
a negated p1 source is refused
an absolutely-modified p2 source is refused
a clamp on the p1 interpolation is refused   (that one arrives through mods)

17 checks pass, dev startup_gfx2hlsl* + startup_translator 12/12, and fail-first removing the refusal fails at an absolutely-modified p2 source is refused.

Thanks for catching the invalid fixture — a passing test built on a word the assembler would never emit is worse than no test, and this is the second time that shape has hidden a gap in my work.

AI-assisted (Claude Code).

@tedin7 tedin7 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.

Reviewed at f8b962f93504146bd48466fca293906b9f7a5618.

No P1/P2 defects found in local verification. MODIFIER_FREE_HANDLERS (op_v_mov_b32, op_v_cvt_pkrtz_f16_f32, op_v_interp_p1_f32, op_v_interp_p2_f32, op_v_interp_mov_f32) covers the vector/interpolation handlers in tools/startup/gfx2hlsl.py that accept mods without reading it, and Stage.one rejects non-empty mods with Unsupported before dispatch while leaving scalar-ALU handlers (whose encodings carry no modifier field) unaffected.

Local Verification

  • Linux checks:
    • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1778 --dir /tmp/rev-sm2-rexb/1778 --json (git_diff_check, docs_links_check, bidi_controls_check, py_compile: all ok)
    • /root/.local/share/x2w-rev-venv/bin/python -B /tmp/rev-sm2-rexb/1778/tests/startup_gfx2hlsl_modifier_free_check.py: PASS
    • All tests/startup_gfx2hlsl*_check.py scripts (9/9): PASS
  • Win2025 Debug (--preset dev) & Release /O2 (--preset release):
    • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1778 --regex '^(startup_gfx2hlsl_modifier_free|startup_gfx2hlsl_bit_alu_controls|startup_gfx2hlsl_cndmask_neg|startup_gfx2hlsl_operand_count|startup_gfx2hlsl_sdwa|startup_gfx2hlsl_sdwa_cvt|startup_gfx2hlsl_smem_offset|startup_gfx2hlsl_vcvt_omod|startup_translator)$' --py-checks tests/startup_gfx2hlsl_modifier_free_check.py
    • Debug (--preset dev): 9/9 passed (0.84s), Windows Python check ok (0.15s)
    • Release /O2 (--preset release): 9/9 passed (0.82s)
  • Mutation test:
    • Commented out 'op_v_mov_b32' in MODIFIER_FREE_HANDLERS in tools/startup/gfx2hlsl.py and ran /root/.local/share/x2w-rev-venv/bin/python -B /tmp/rev-sm2-rexb/1778/tests/startup_gfx2hlsl_modifier_free_check.py: FAIL (rc=1 on the declared modifier-free handlers are exactly these five, a clamp on the move is refused, a mul:2 on the move is refused), then restored with git checkout -- ..

AI-assisted; commands listed were executed locally.

@roansystemlabs

Copy link
Copy Markdown
Contributor

Small note on the fixture: encode_vop3a(VOP3A_INTERP_MOV, 1, [0, 0]) sets src1 = 0, which the decoder prints as p10, not p0, so the "plain flat interpolation" control pins the P10 selector as accepted. p0 is src1 = 2. The selector itself being ignored is a separate gap; I've opened #1890 for it so this PR can stay about modifiers.

AI-assisted.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Ran it; the guard, the list and the self-check all fail when broken

At the PR head, device-free:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_modifier_free_check.py
no scalar handler is declared modifier-free: ok
PASS      exit 0

Three mutations to tools/startup/gfx2hlsl.py, each reverted:

mutation result
op_v_mov_b32 removed from MODIFIER_FREE_HANDLERS caught
if mods and handler.__name__ in MODIFIER_FREE_HANDLERS: → if False: caught
a SALU handler (op_s_mov_b32) added to the set caught

The third is the one I would not have expected a fixture to catch: the set is a hand-maintained list, and a later contributor
dropping a SALU name into it would be silently wrong (SALU encodings carry no modifier field, so the refusal could never fire
for a real instruction). The check derives the SALU handler names and refuses to see them in the set, which turns a
list-maintenance mistake into a failure.

Why this shape is right for the class

#1771 was one bug in five places (set_vf op_sel, op_v_cndmask_b32 clamp/mul, compare() modifiers, these handlers,
and the interpolation modifiers). A per-handler guard would have to be remembered each time; the single
if mods and handler.__name__ in MODIFIER_FREE_HANDLERS at the dispatch point makes the default "refuse unless the handler
opts in", and the fixture fails if the list and the handlers disagree.

One consequence worth stating in the description: a handler that does model a modifier must not be in the set, so adding
support for clamp on v_mov_b32 later means removing the name. That is the intended workflow, but nothing forces the two
edits to happen together beyond this check.

Scope

Three files (gfx2hlsl.py +19/-0, one new check, CMakeLists.txt +3), no draw mode, no hardware. The docs/experiments.md
row follows the same shape as its neighbours.

Verdict

Reviewed. Every part of the mechanism is pinned by a mutation, including the list's self-consistency. No objections.

Notes

  • AI-assisted review.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 could you rebase this branch onto current main and force-push?

GitHub reports head 00479dc9 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (cf97bee1):

  • CMakeLists.txt
  • tools/startup/gfx2hlsl.py

Commands run locally:

git fetch origin main pull/1778/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1778 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and force-pushed.

  • #1821 (src_scc): merged main in, resolved the CMakeLists.txt registration conflict keeping both sides, head is 5dc597c1. startup_gfx2hlsl_src_scc and startup_translator pass.
  • #1778 (modifier-free): head 7a72fab0. Merging main surfaced a real behaviour change — v_interp_mov_f32 now decodes the parameter selector as p10, p20, p0 and refuses p10/p20 because they need per-vertex attribute values. My test used the old p0 encoding, which now decodes as p10, so it failed. Fixed the fixture (src1 = 2 for p0) and added checks that p10 and p20 are refused rather than read as p0. startup_gfx2hlsl_modifier_free and startup_translator pass.
  • #1722 (1D sampling): head b96eb6b7; the only conflict was an older docs/experiments.md paragraph you had since rewritten, so I kept main's version of it and dropped my wording-only change there. startup_gfx2hlsl_image_1d, startup_image_sample_l and startup_translator pass.

Two of the five I closed rather than rebased, because their content is already on main or duplicated:

AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 could you rebase this branch onto current main and force-push?

GitHub reports head 7a72fab0 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (214ed093):

  • CMakeLists.txt
  • docs/experiments.md
  • tools/startup/gfx2hlsl.py

Commands run locally:

git fetch origin main pull/1778/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1778 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 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.

Review of head 7a72fab0fe42780f7a4c3f063582c880610e9a2d.

Summary: The change is correct in intent. The modifier refusal for v_mov_b32, v_cvt_pkrtz_f16_f32 and the interpolation handlers is sound, and the new test kills my mutations. One existing test now fails, so this is not mergeable as is.

P1: existing test regresses

  • tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:111: modified move overwrite refused: MISMATCH "v_mov_b32 with ['clamp']". The case v_mov_b32_e32 v7, s2 clamp is still refused, but now by the dispatch guard (tools/startup/gfx2hlsl.py:691) before the readfirstlane code runs. The test expects the readfirstlane refusal text, so it reports 1 failure.
  • This test passes on origin/main (0 failed). The PR registers a new CTest but does not update this one.
  • Fix: add 'modified move overwrite': "v_mov_b32 with ['clamp']" to the EARLIER map (next to the existing op_sel overwrite entry, just after the REFUSED list). If the case was meant to reach the readfirstlane path, use a modifier that is not refused earlier.

P2: none.

Nits

  • tools/startup/gfx2hlsl.py:308-315: MODIFIER_FREE_HANDLERS is followed directly by def smem_mods with no blank lines, and the two blank lines before class Stage (line 340) were removed. This breaks PEP8 spacing (E302/E305).

Checked and fine

  • The guard sits before handler(ops, mods), so it covers every handler in the set. handler.__name__ matches the declared names.
  • The p1/p2 abs/neg refusal on ops[1] is needed because the decoder prints it inside the operand, not as a mod.
  • Title is neutral. No clean-room problems seen. No CI checks are reported for the branch.

Commands run locally (worktree at the head SHA)

  • python3 -B tests/startup_gfx2hlsl_modifier_free_check.py -> PASS
  • all tests/startup_gfx2hlsl_*_check.py (31 files) -> 1 FAIL: startup_gfx2hlsl_readfirstlane_uniform_check.py (passes on origin/main)
  • python3 tests/docs_links_check.py -> ok (18 files, 395 links)
  • python3 tests/bidi_controls_check.py -> ok
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: removed op_v_cvt_pkrtz_f16_f32 from the set -> new test fails (MISMATCH)
  • Mutation 2: disabled the dispatch guard -> new test fails (6 MISMATCH)
  • Mutation 3: disabled the p1/p2 source-modifier check -> new test fails (3 MISMATCH)
  • Windows WARP run: not needed. The change only adds refusals in Python and emits no new HLSL.

AI-assisted; commands listed were executed locally.

@triggered02
triggered02 force-pushed the startup/modifier-free branch from 7a72fab to 3af8ad7 Compare November 25, 2026 16:18
@triggered02

Copy link
Copy Markdown
Contributor Author

Re-created on origin/main (7092683a) as a single clean commit and addressed both items from your review on 7a72fab0:

  1. Fixed P1 (tests/startup_gfx2hlsl_readfirstlane_uniform_check.py): added 'modified move overwrite': "v_mov_b32 with ['clamp']" to EARLIER next to 'op_sel overwrite', since the dispatch guard now refuses v_mov_b32 with clamp before the readfirstlane uniform check runs.
  2. Fixed PEP8 spacing nit (tools/startup/gfx2hlsl.py): two blank lines around MODIFIER_FREE_HANDLERS and before class Stage:.

Measured checks

  • tests/startup_gfx2hlsl_modifier_free_check.py: 20/20 checks ok, PASS.
  • tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: 0 failed.
  • All 62 tests/startup_gfx2hlsl_*_check.py scripts + tests/startup_translator_check.py: 62/62 + startup_translator passed.
  • tests/docs_links_check.py (464 links), tests/bidi_controls_check.py (1,724 files), git diff --check origin/main: clean.
  • Fail-first mutations (removing op_v_cvt_pkrtz_f16_f32 from MODIFIER_FREE_HANDLERS, disabling the dispatch guard, and disabling the op_v_interp_p1_f32/op_v_interp_p2_f32 operand-modifier check) all fail startup_gfx2hlsl_modifier_free_check.py (exit 1).

Not established

  • Only Python translator checks and startup_translator ran on this head (no C++ changes; no Windows CTest executable run on this worktree).

AI-assisted (Gemini).

@triggered02
triggered02 force-pushed the startup/modifier-free branch from 3af8ad7 to 72603d6 Compare November 25, 2026 20:03

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

I integrated current main in 664d9996. The merged readfirstlane check keeps the new modified-move refusal and the existing lane-mask, VCC and EXEC refusals. The modifier, uniformity, recompute and handler-arity checks passed locally, and the documentation check verified 510 links.

@R0Y00
R0Y00 merged commit 7287979 into R0Y00:main Nov 26, 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.

startup: handlers that take modifiers and silently drop them (scan of gfx2hlsl dispatch)

5 participants