You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shader: lower v_swap_b32 in gfx2hlsl (Part of #1723) - #2012
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:
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 secondtests/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:
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.
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
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 startup: lower v_swap_b32 in gfx2hlsl #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.
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:
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
AI-assisted; commands listed were executed locally.