shader: lower v_swap_b32 in gfx2hlsl (Part of #1723) #2005

Closed
tedin7 wants to merge 2 commits from upstream-pr/2012 into main
tedin7 commented 2026-11-24 23:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:04:13Z.


Part of #1723

What this unblocks: Completes 1 graphics pipeline blocked on v_swap_b32 in gfx2hlsl (replaces closed draft #1796, rebased cleanly on origin/main).

Verification:

  • Local swap & filter checks passed after rebase.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593186675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:04:13Z. --- Part of #1723 What this unblocks: Completes 1 graphics pipeline blocked on v_swap_b32 in gfx2hlsl (replaces closed draft #1796, rebased cleanly on origin/main). Verification: - Local swap & filter checks passed after rebase. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 00:04:54 +00:00
ChazY11 commented 2026-11-25 01:01:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:07:37Z.


main already lowers v_swap_b32, and this branch is 114 commits behind

Checked against main at f018831b's content (the tree currently in tools/startup/gfx2hlsl.py):

tools/startup/gfx2hlsl.py:1304  def op_v_swap_b32(self, ops, mods):
tools/startup/gfx2hlsl.py:1318      uniform = (dst in self.uniform_v and self.exec_known, src in self.uniform_v and self.exec_known)
tools/startup/gfx2hlsl.py:1322      self.emit(body if self.exec_known else 'if (exec & 1) ' + body)

That is #1995's implementation, already in main — it arrived with commit f018831b (startup: lower v_swap_b32 in gfx2hlsl), which git log shows on main's history for that file. tests/startup_gfx2hlsl_swap_check.py is on main and green:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_swap_check.py    # exit 0

Your branch:

merge-base with origin/main: 82f0db65 (Merge pull request #1927), 114 commits behind
git diff origin/main -- tests/   ->  36 files changed, 261 insertions(+), 9272 deletions(-)

Those deletions are other people's merged work that your branch predates, not something your patch removes — but a merge today would conflict in CMakeLists.txt and tools/startup/gfx2hlsl.py and would add a second tests/startup_gfx2hlsl_swap_check.py (AA on that path when I merged both branches). So it cannot land as is.

What your version still adds

Two things that the version on main does not have:

# yours
if a != b:
    swap = '{ uint swap_tmp = v%d; v%d = v%d; v%d = swap_tmp; }' % (a, a, b, b)
    self.emit(swap if self.exec_known else 'if (exec & 1) %s' % swap)

v_swap_b32 v5, v5 currently emits { uint t = v5; v5 = v5; v5 = t; } on main — harmless, but dead code in every shader that contains a self-swap. Skipping it is a real (small) improvement, and it is the only part of this PR that is not already upstream.

The other difference goes the other way: main moves the uniformity flag across (uniform = (dst in uniform_v and exec_known, …)), so two uniform registers stay uniform after a swap; your version discards the property for both. That is conservative rather than wrong, but it is a regression against what is on main today.

Suggested shape

A one-handler follow-up on current main that adds only the a != b skip, plus one fixture line asserting that v_swap_b32 v5, v5 emits nothing. That would be reviewable in a minute and would not touch the existing check file.

I am not asking you to do that — just making sure the duplication is visible before someone spends time resolving it.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147043754 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012#issuecomment-7147043754). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:07:37Z. --- ## `main` already lowers `v_swap_b32`, and this branch is 114 commits behind Checked against `main` at `f018831b`'s content (the tree currently in `tools/startup/gfx2hlsl.py`): ```text tools/startup/gfx2hlsl.py:1304 def op_v_swap_b32(self, ops, mods): tools/startup/gfx2hlsl.py:1318 uniform = (dst in self.uniform_v and self.exec_known, src in self.uniform_v and self.exec_known) tools/startup/gfx2hlsl.py:1322 self.emit(body if self.exec_known else 'if (exec & 1) ' + body) ``` That is #1995's implementation, already in `main` — it arrived with commit `f018831b` (`startup: lower v_swap_b32 in gfx2hlsl`), which `git log` shows on `main`'s history for that file. `tests/startup_gfx2hlsl_swap_check.py` is on `main` and green: ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_swap_check.py # exit 0 ``` Your branch: ```text merge-base with origin/main: 82f0db65 (Merge pull request #1927), 114 commits behind git diff origin/main -- tests/ -> 36 files changed, 261 insertions(+), 9272 deletions(-) ``` Those deletions are other people's merged work that your branch predates, not something your patch removes — but a merge today would conflict in `CMakeLists.txt` and `tools/startup/gfx2hlsl.py` and would add a **second** `tests/startup_gfx2hlsl_swap_check.py` (`AA` on that path when I merged both branches). So it cannot land as is. ## What your version still adds Two things that the version on `main` does not have: ```python # yours if a != b: swap = '{ uint swap_tmp = v%d; v%d = v%d; v%d = swap_tmp; }' % (a, a, b, b) self.emit(swap if self.exec_known else 'if (exec & 1) %s' % swap) ``` `v_swap_b32 v5, v5` currently emits `{ uint t = v5; v5 = v5; v5 = t; }` on `main` — harmless, but dead code in every shader that contains a self-swap. Skipping it is a real (small) improvement, and it is the only part of this PR that is not already upstream. The other difference goes the other way: `main` moves the uniformity flag across (`uniform = (dst in uniform_v and exec_known, …)`), so two uniform registers stay uniform after a swap; your version discards the property for both. That is conservative rather than wrong, but it is a regression against what is on `main` today. ## Suggested shape A one-handler follow-up on current `main` that adds only the `a != b` skip, plus one fixture line asserting that `v_swap_b32 v5, v5` emits nothing. That would be reviewable in a minute and would not touch the existing check file. I am not asking you to do that — just making sure the duplication is visible before someone spends time resolving it. ## Notes - AI-assisted review.
chatgpt-codex-connector[bot commented 2026-11-25 01:01:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:04:23Z.


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-24T23:07:52.189498Z 242834c 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146980714 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012#issuecomment-7146980714). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:04:23Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"242834c757b401664f1ded09b364ba04ef5c792a","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:07:52.189498Z">2026-11-24T23:07:52.189498Z</relative-time> | `242834c` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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. </details> </details>
ChazY11 commented 2026-11-25 01:01:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:10:00Z.


Correction: my previous comment was wrong — main does not lower v_swap_b32, and this PR is not a duplicate

I claimed main already contained this handler and that your PR duplicated it. That was wrong, and I apologise for the noise. The check I
should have run, now run three ways against the commit rather than a working tree:

git show origin/main:tools/startup/gfx2hlsl.py | Select-String 'v_swap_b32'     # no match
git grep -l 'op_v_swap_b32' origin/main -- tools/startup/gfx2hlsl.py            # no match
git show origin/main:tests/startup_gfx2hlsl_swap_check.py                       # path does not exist

and, for contrast:

origin/main     contains op_v_swap_b32: False
pr-1995         contains op_v_swap_b32: True
pr-2012         contains op_v_swap_b32: True

origin/main at 66423e45 has 75 op_* methods on Stage and none of them is op_v_swap_b32; tests/startup_gfx2hlsl_swap_check.py is not in
the tree.

What went wrong on my side: I had your branch checked out earlier in the same session to run tests/startup_gfx2hlsl_swap_check.py, and my
later greps read that working tree instead of origin/main. The line numbers I quoted (1304, 1318, 1322) are real — in your branch. The
conclusion I drew from them was not.

What survives from that comment

Two observations were measured on your branch and do not depend on the mistake:

  • v_swap_b32 vA, vA emits { uint swap_tmp = vA; vA = vA; vA = swap_tmp; } with the if a != b: guard removed; your guard is a real
    improvement over emitting the dead block.
  • Your version discards the uniformity flag for both registers rather than moving it across. That is the one thing #1995 does more precisely
    (it sets each register's flag from the other's), and it is worth deciding on rather than leaving to whichever PR lands.

Both PRs touch the same handler and the same file, so whichever lands second needs a rebase — that part stands.

Notes

  • AI-assisted, and self-corrected after re-checking against the commit instead of the working tree.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147089230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012#issuecomment-7147089230). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:10:00Z. --- ## Correction: my previous comment was wrong — `main` does **not** lower `v_swap_b32`, and this PR is not a duplicate I claimed `main` already contained this handler and that your PR duplicated it. That was wrong, and I apologise for the noise. The check I should have run, now run three ways against the **commit** rather than a working tree: ```powershell git show origin/main:tools/startup/gfx2hlsl.py | Select-String 'v_swap_b32' # no match git grep -l 'op_v_swap_b32' origin/main -- tools/startup/gfx2hlsl.py # no match git show origin/main:tests/startup_gfx2hlsl_swap_check.py # path does not exist ``` and, for contrast: ```text origin/main contains op_v_swap_b32: False pr-1995 contains op_v_swap_b32: True pr-2012 contains op_v_swap_b32: True ``` `origin/main` at `66423e45` has 75 `op_*` methods on `Stage` and none of them is `op_v_swap_b32`; `tests/startup_gfx2hlsl_swap_check.py` is not in the tree. **What went wrong on my side**: I had your branch checked out earlier in the same session to run `tests/startup_gfx2hlsl_swap_check.py`, and my later greps read that working tree instead of `origin/main`. The line numbers I quoted (`1304`, `1318`, `1322`) are real — in *your* branch. The conclusion I drew from them was not. ## What survives from that comment Two observations were measured on your branch and do not depend on the mistake: - `v_swap_b32 vA, vA` emits `{ uint swap_tmp = vA; vA = vA; vA = swap_tmp; }` with the `if a != b:` guard removed; your guard is a real improvement over emitting the dead block. - Your version discards the uniformity flag for both registers rather than moving it across. That is the one thing #1995 does more precisely (it sets each register's flag from the other's), and it is worth deciding on rather than leaving to whichever PR lands. Both PRs touch the same handler and the same file, so whichever lands second needs a rebase — that part stands. ## Notes - AI-assisted, and self-corrected after re-checking against the commit instead of the working tree.
ChazY11 commented 2026-11-25 01:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:24:01Z.


Now it is actually true: #1995 has merged, and this PR is a duplicate against current main

My two earlier corrections on this PR said the opposite — that main did not lower v_swap_b32. That was correct at the time and is no longer. The
current state, verified against the commit object:

git show origin/main:tools/startup/gfx2hlsl.py | Select-String 'op_v_swap_b32'     # matches

main contains op_v_swap_b32: True
main contains the #1995 temp form (uint t =): True
main contains the #2012 form (swap_tmp):     False
main contains the a != b guard:              False

tests/startup_gfx2hlsl_swap_check.py is in the tree; its check exits 0
#1995 = MERGED     #2012 = OPEN

So the feature is landed with #1995's implementation, and the only thing this PR still adds is the if a != b: short-circuit: main emits
{ uint t = v5; v5 = v5; v5 = t; } for v_swap_b32 v5, v5.

What that short-circuit is worth

It is a genuine (small) improvement — dead code in every shader that contains a self-swap — and it is now the only difference, which makes it a
one-line follow-up rather than a competing implementation. If you want it, a fresh branch on current main with:

if a != b:
    swap = ...
    self.emit(swap if self.exec_known else 'if (exec & 1) %s' % swap)

plus one fixture line asserting that v_swap_b32 v5, v5 emits nothing, would be reviewable in a minute and would not touch the existing check file
(which #1995 added with the same name this PR would have used).

Note also that #1995's version keeps the uniformity flag across the swap (uniform = (dst in uniform_v and exec_known, …)); a rebase of this PR
should preserve that rather than replacing it with an unconditional discard, which is what the current branch does.

On my earlier comments

I got this wrong twice in opposite directions: first claiming the code was on main when my greps were reading a checked-out branch, then
correcting to "not on main" when that was true only for those hours. Both corrections were measured against the right object at the wrong time —
a reminder that "is X on main" is a statement about a commit, not about a repository.

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147355282 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012#issuecomment-7147355282). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:24:01Z. --- ## Now it is actually true: #1995 has merged, and this PR is a duplicate against current `main` My two earlier corrections on this PR said the opposite — that `main` did *not* lower `v_swap_b32`. That was correct at the time and is no longer. The current state, verified against the commit object: ```powershell git show origin/main:tools/startup/gfx2hlsl.py | Select-String 'op_v_swap_b32' # matches main contains op_v_swap_b32: True main contains the #1995 temp form (uint t =): True main contains the #2012 form (swap_tmp): False main contains the a != b guard: False tests/startup_gfx2hlsl_swap_check.py is in the tree; its check exits 0 #1995 = MERGED #2012 = OPEN ``` So the feature is landed with #1995's implementation, and the only thing this PR still adds is the `if a != b:` short-circuit: `main` emits `{ uint t = v5; v5 = v5; v5 = t; }` for `v_swap_b32 v5, v5`. ## What that short-circuit is worth It is a genuine (small) improvement — dead code in every shader that contains a self-swap — and it is now the *only* difference, which makes it a one-line follow-up rather than a competing implementation. If you want it, a fresh branch on current `main` with: ```python if a != b: swap = ... self.emit(swap if self.exec_known else 'if (exec & 1) %s' % swap) ``` plus one fixture line asserting that `v_swap_b32 v5, v5` emits nothing, would be reviewable in a minute and would not touch the existing check file (which #1995 added with the same name this PR would have used). Note also that #1995's version keeps the uniformity flag across the swap (`uniform = (dst in uniform_v and exec_known, …)`); a rebase of this PR should preserve that rather than replacing it with an unconditional discard, which is what the current branch does. ## On my earlier comments I got this wrong twice in opposite directions: first claiming the code was on `main` when my greps were reading a checked-out branch, then correcting to "not on `main`" when that was true only for those hours. Both corrections were measured against the right object at the wrong time — a reminder that "is X on main" is a statement about a commit, not about a repository. ## Notes - AI-assisted.
R0Y00 commented 2026-11-25 01:01:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:30:19Z.


Thanks for the parallel implementation. JB2WIN separately claimed this row in #1723, and #1995 is now on main. It covers the swap, self-swap, EXEC and uniformity tracking with encoded and mutation controls. Closing the overlapping patch.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147475228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2012#issuecomment-7147475228). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T23:30:19Z. --- Thanks for the parallel implementation. JB2WIN separately claimed this row in #1723, and #1995 is now on main. It covers the swap, self-swap, EXEC and uniformity tracking with encoded and mutation controls. Closing the overlapping patch.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2005
No description provided.