build: name the rect geometry RTV handle instead of taking a temporary's address #3313

Manually merged
github merged 401 commits from github-bot/gh-3311 into main 2026-11-29 16:28:34 +00:00 AGit
Owner

@⁠KelboLive on GitHub · 2026-11-28 08:09 UTC · original
KelboLive:fix/gfx2hlsl-scc-phi-mask → main · +2 −1 · 1 files · 1 commits · merged 2026-11-29 16:28 UTC

startup_rect_geometry.cpp passed the address of a temporary to OMSetRenderTargets:

list->OMSetRenderTargets(1, &rtv_heap->GetCPUDescriptorHandleForHeapStart(), FALSE, nullptr);

GetCPUDescriptorHandleForHeapStart() returns D3D12_CPU_DESCRIPTOR_HANDLE by value, so that is & on a class prvalue. On MSVC 14.44.35207 it is a nonstandard extension that /permissive- rejects. Compiling main's file with the target's own compile line plus the flag:

Flags Line 364
/W4 warning C4238: nonstandard extension used: class rvalue used as lvalue
/permissive- error C2102: '&' requires l-value

The project sets neither flag, which is why CI accepts the current code. A build configured with /permissive- does not.

After the change, cmake --build out/build/dev --target startup_rect_geometry compiles and links.

Scope

Rebuilt on current main as one commit:

  • The unpin_slot commit is gone. It reached main through #3309.
  • The phi_mask_ok hunk is dropped, per both reviews. It had no fixture, and it refused shapes main translates exactly. If a real mistranslation exists there, the place to decide it is where the SCC of an s_and_b32 with a lane-mask source is emitted (set_scc), with a fixture that fails on main and a negative control.

Not included: the const_cast changes in startup_gameinput_trace.cpp. reinterpret_cast<Fn>(const void*) produced no diagnostic at /W4 or /permissive-, so I could not show it fixes anything. Name the compiler that rejected the old code and I will add it back with the evidence.

**@⁠KelboLive** on GitHub · 2026-11-28 08:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3311) `KelboLive:fix/gfx2hlsl-scc-phi-mask` → `main` · +2 −1 · 1 files · 1 commits · merged 2026-11-29 16:28 UTC `startup_rect_geometry.cpp` passed the address of a temporary to `OMSetRenderTargets`: ```cpp list->OMSetRenderTargets(1, &rtv_heap->GetCPUDescriptorHandleForHeapStart(), FALSE, nullptr); ``` `GetCPUDescriptorHandleForHeapStart()` returns `D3D12_CPU_DESCRIPTOR_HANDLE` by value, so that is `&` on a class prvalue. On MSVC 14.44.35207 it is a nonstandard extension that `/permissive-` rejects. Compiling `main`'s file with the target's own compile line plus the flag: | Flags | Line 364 | |---|---| | `/W4` | `warning C4238: nonstandard extension used: class rvalue used as lvalue` | | `/permissive-` | `error C2102: '&' requires l-value` | The project sets neither flag, which is why CI accepts the current code. A build configured with `/permissive-` does not. After the change, `cmake --build out/build/dev --target startup_rect_geometry` compiles and links. ## Scope Rebuilt on current `main` as one commit: - **The `unpin_slot` commit is gone.** It reached `main` through #3309. - **The `phi_mask_ok` hunk is dropped**, per both reviews. It had no fixture, and it refused shapes `main` translates exactly. If a real mistranslation exists there, the place to decide it is where the SCC of an `s_and_b32` with a lane-mask source is emitted (`set_scc`), with a fixture that fails on `main` and a negative control. Not included: the `const_cast` changes in `startup_gameinput_trace.cpp`. `reinterpret_cast<Fn>(const void*)` produced no diagnostic at `/W4` or `/permissive-`, so I could not show it fixes anything. Name the compiler that rejected the old code and I will add it back with the evidence.
The one-lane model assumes lane masks (vcc_lo or SGPRs) are read per-lane only.
When an accumulated mask is updated via `s_and_b32 M, X, exec_lo`, the instruction
produces an SCC flag reflecting whether the *entire* masked word is nonzero. If a
later instruction reads SCC (e.g., `s_cselect`), it sees wave-wide status, not
per-lane data, causing singleton model mismatches.

This change adds an SCC liveness check in `phi_mask_ok`: if an SCC-producing write
to the accumulated mask is followed by any SCC reader before the mask is rewritten,
the block is refused. This ensures the one-lane model only runs when SCC is dead or
explicitly handled.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 08:09:33 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-28 08:54 UTC · original

Thanks for this. I checked head 8f1ce018 against main 3f780716. It merges cleanly (git merge-tree --write-tree origin/main pr3311 exits 0) and CI passes. There are a few things to fix before it's ready:

  1. The first commit is already on main. ca165ed9 (the unpin_slot fix) came in through #3309 (git branch -r --contains ca165ed9 → origin/main). GitHub still lists src/xmem_mapped_pages.cpp under Files changed. Could you rebase onto main so that commit drops out?

  2. Please split the PR. The title and body only describe the warning fixes in startup_gameinput_trace.cpp and startup_rect_geometry.cpp, but the branch also changes phi_mask_ok in tools/startup/gfx2hlsl.py. AGENTS.md asks for one reviewable behavior per PR, so the .cpp fixes and the translator change would each be easier to review on their own.

  3. The new SCC refusal has no test. I ran tests/startup_gfx2hlsl_compute_check.py against main's gfx2hlsl.py, which is the PR without its 9/−1 hunk, and it still passes (exit 0). Nothing goes red if the change is removed.

  4. It refuses shapes that main translates exactly. I added cases to the existing phi() harness in that check, each with zeroing s_mov_b32 s20, 0 and the read v_cndmask_b32 v5, v5, v6, s20 after the join:

    • Block v_cmp_gt_u32 vcc_lo, 3, v0; s_and_b32 s20, vcc_lo, exec_lo; s_cselect_b32 s24, 1, 0, with s24 dead at the join: main accepts it, and this PR refuses it with definition of s20, live where the block joins. Swapping the operands to s_and_b32 s20, exec_lo, vcc_lo gives the same result.
    • The same block with s24 read after the join: main already refuses it (s_cselect_b32 ... definition of s24, live where the block joins).

    execz_refusals already refuses SCC and any SCC-derived register that is live at the join. A wave-wide SCC read inside the block therefore can't reach anything observable in the cases I tried. If you have a case where main mistranslates, please add it as a fixture together with a negative control, and explain why the two shapes above should now be refused. Otherwise, I'd suggest dropping the hunk.

  5. Smaller points about the hunk, if you keep it:

    • scc_live is set only by an s_and_b32 into M and is cleared whenever M is rewritten. SCC is actually overwritten by any SALU write, and an s_and_b32 into a temporary is never tracked.
    • In 'exec_lo' in ops[1:] or 'exec_lo' in ops[2], the second test is a substring check that the first already covers.
    • The phi_mask_ok docstring doesn't mention the new rule.
  6. The .cpp changes look right to me: const_cast ahead of the reinterpret_cast of const void*, and a named local instead of taking the address of a temporary. Could you name the compiler that rejected the old code in the body? MSVC CI accepts both versions, so CI can't confirm the fix.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-28 08:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3311#issuecomment-7236886673) Thanks for this. I checked head 8f1ce018 against main 3f780716. It merges cleanly (`git merge-tree --write-tree origin/main pr3311` exits 0) and CI passes. There are a few things to fix before it's ready: 1. **The first commit is already on main.** ca165ed9 (the `unpin_slot` fix) came in through #3309 (`git branch -r --contains ca165ed9` → `origin/main`). GitHub still lists `src/xmem_mapped_pages.cpp` under Files changed. Could you rebase onto main so that commit drops out? 2. **Please split the PR.** The title and body only describe the warning fixes in `startup_gameinput_trace.cpp` and `startup_rect_geometry.cpp`, but the branch also changes `phi_mask_ok` in `tools/startup/gfx2hlsl.py`. AGENTS.md asks for one reviewable behavior per PR, so the `.cpp` fixes and the translator change would each be easier to review on their own. 3. **The new SCC refusal has no test.** I ran `tests/startup_gfx2hlsl_compute_check.py` against main's `gfx2hlsl.py`, which is the PR without its 9/−1 hunk, and it still passes (exit 0). Nothing goes red if the change is removed. 4. **It refuses shapes that main translates exactly.** I added cases to the existing `phi()` harness in that check, each with zeroing `s_mov_b32 s20, 0` and the read `v_cndmask_b32 v5, v5, v6, s20` after the join: - Block `v_cmp_gt_u32 vcc_lo, 3, v0; s_and_b32 s20, vcc_lo, exec_lo; s_cselect_b32 s24, 1, 0`, with s24 dead at the join: main accepts it, and this PR refuses it with `definition of s20, live where the block joins`. Swapping the operands to `s_and_b32 s20, exec_lo, vcc_lo` gives the same result. - The same block with s24 read after the join: main already refuses it (`s_cselect_b32 ... definition of s24, live where the block joins`). `execz_refusals` already refuses SCC and any SCC-derived register that is live at the join. A wave-wide SCC read inside the block therefore can't reach anything observable in the cases I tried. If you have a case where main mistranslates, please add it as a fixture together with a negative control, and explain why the two shapes above should now be refused. Otherwise, I'd suggest dropping the hunk. 5. **Smaller points about the hunk, if you keep it:** - `scc_live` is set only by an `s_and_b32` into M and is cleared whenever M is rewritten. SCC is actually overwritten by any SALU write, and an `s_and_b32` into a temporary is never tracked. - In `'exec_lo' in ops[1:] or 'exec_lo' in ops[2]`, the second test is a substring check that the first already covers. - The `phi_mask_ok` docstring doesn't mention the new rule. 6. The `.cpp` changes look right to me: `const_cast` ahead of the `reinterpret_cast` of `const void*`, and a named local instead of taking the address of a temporary. Could you name the compiler that rejected the old code in the body? MSVC CI accepts both versions, so CI can't confirm the fix. This comment was AI-assisted.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 13:05 UTC · original · reviewed

Two additions to the review above, both on the phi_mask_ok hunk at head 8f1ce018. Code reading only, nothing was built or run.

  1. SHOULD — the check is only reached when M itself is live at the join. tools/startup/gfx2hlsl.py:3301-3302: phi_mask_ok is called only for cand, the masks written in the block that are in live_in[t]. The commit message describes a hazard on SCC, not on M. For a block s_and_b32 s20, vcc_lo, exec_lo; s_cselect_b32 s24, 1, 0 where s20 is dead at the join, s20 is not in cand, phi_mask_ok is never called for it, and the new lines 3675-3676 do not run. The same pair outside any s_cbranch_execz block is not seen either. So the hunk refuses the wave-wide SCC read only in the subset of cases where the mask happens to be a live i1 phi, which is unrelated to whether the SCC read is exact. If there is a real mistranslation, the place that decides it is where the SCC of an s_and_b32 with a lane-mask source is emitted and tracked (set_scc, comment at :6150), with a fixture that fails on main.

  2. SHOULD — scc_live is cleared by writes that leave SCC untouched. tools/startup/gfx2hlsl.py:3677-3678 clears the flag on any write of M. A VOPC write of M (v_cmp_* M, ..., which mask_write_class accepts as 'zero') does not write SCC. In s_and_b32 s20, vcc_lo, exec_lo; v_cmp_gt_u32_e64 s20, 3, v0; s_cselect_b32 s24, 1, 0 the s_cselect still reads the SCC of the s_and_b32, and the hunk accepts it. This is the opposite direction from point 5 above (which covers the reads it refuses although another SALU op has overwritten SCC): here the rule misses the case it was written for.

**@⁠Leyukaka** on GitHub · 2026-11-29 13:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3311#pullrequestreview-6102995527) · **reviewed** Two additions to the review above, both on the `phi_mask_ok` hunk at head 8f1ce018. Code reading only, nothing was built or run. 1. **SHOULD — the check is only reached when M itself is live at the join.** `tools/startup/gfx2hlsl.py:3301-3302`: `phi_mask_ok` is called only for `cand`, the masks written in the block that are in `live_in[t]`. The commit message describes a hazard on SCC, not on M. For a block `s_and_b32 s20, vcc_lo, exec_lo; s_cselect_b32 s24, 1, 0` where s20 is dead at the join, s20 is not in `cand`, `phi_mask_ok` is never called for it, and the new lines 3675-3676 do not run. The same pair outside any `s_cbranch_execz` block is not seen either. So the hunk refuses the wave-wide SCC read only in the subset of cases where the mask happens to be a live i1 phi, which is unrelated to whether the SCC read is exact. If there is a real mistranslation, the place that decides it is where the SCC of an `s_and_b32` with a lane-mask source is emitted and tracked (`set_scc`, comment at :6150), with a fixture that fails on main. 2. **SHOULD — `scc_live` is cleared by writes that leave SCC untouched.** `tools/startup/gfx2hlsl.py:3677-3678` clears the flag on any write of M. A VOPC write of M (`v_cmp_* M, ...`, which `mask_write_class` accepts as 'zero') does not write SCC. In `s_and_b32 s20, vcc_lo, exec_lo; v_cmp_gt_u32_e64 s20, 3, v0; s_cselect_b32 s24, 1, 0` the `s_cselect` still reads the SCC of the `s_and_b32`, and the hunk accepts it. This is the opposite direction from point 5 above (which covers the reads it refuses although another SALU op has overwritten SCC): here the rule misses the case it was written for.
Author
Owner

@⁠KelboLive on GitHub · 2026-11-29 16:22 UTC · original

Rebuilt as a single commit on current \main; the body now carries the compiler evidence for the one change that remains.

The branch name \ ix/gfx2hlsl-scc-phi-mask\ is now stale. GitHub does not let me rename a pull request's head branch in place, so it stays unless this is reopened from a differently named branch. Say the word if you would rather I do that.

**@⁠KelboLive** on GitHub · 2026-11-29 16:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3311#issuecomment-7258858052) Rebuilt as a single commit on current \main\; the body now carries the compiler evidence for the one change that remains. The branch name \ ix/gfx2hlsl-scc-phi-mask\ is now stale. GitHub does not let me rename a pull request's head branch in place, so it stays unless this is reopened from a differently named branch. Say the word if you would rather I do that.
github-bot changed title from 'Fix compiler warnings in tests' to build: name the rect geometry RTV handle instead of taking a temporary's address 2026-11-29 16:28:33 +00:00
github-bot force-pushed github-bot/gh-3311 from 8f1ce01882 to b27cff1bb6 2026-11-29 16:28:34 +00:00 Compare
github manually merged commit c4b8a41b0d into main 2026-11-29 16:28:34 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-29 16:28 UTC · original

Re-reviewed at b27cff1bb6. The branch sits directly on main 36914379, with 0 commits behind. I read the code but didn't compile it here, since this host has no MSVC.

All the earlier points are resolved: ours on 8f1ce018 and both from the other review. The branch is one commit, and ca165ed9 is gone. The phi_mask_ok hunk is gone too: git diff origin/main touches only tests/startup_rect_geometry.cpp, +2/−1. The title now matches the change. The body gives the compiler and flags that show the problem: MSVC 14.44.35207, C4238 at /W4 and C2102 at /permissive-.

What I checked:

  • The fix. GetCPUDescriptorHandleForHeapStart() returns the handle by value. The named const local lives past the OMSetRenderTargets call, which reads the handle during the call. ClearRenderTargetView on the line above already takes the handle by value and is unchanged.
  • No other copies. git grep -E '&[A-Za-z_>.-]*(->|\.)Get(CPU|GPU)DescriptorHandleForHeapStart\(\)' finds 1 match on main (this line) and 0 at the head.
  • Merge and CI. git merge-tree --write-tree origin/main exits 0, and git diff --check exits 0. CI on b27cff1b: 3 success, 2 skipped.

NIT

  1. Nothing stops this from coming back, because the build passes neither /permissive- nor /we4238. A separate PR could enable one of them for the test targets, if the rest of the tree is clean under it.
  2. You don't need to reopen this to fix the branch name. The stale name only shows up in the merge commit's subject.

No MUST or SHOULD. Merged as c4b8a41b.

AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-29 16:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3311#issuecomment-7258930474) Re-reviewed at b27cff1bb632df5d3d7bb3e413f9770a82b0139b. The branch sits directly on main 36914379, with 0 commits behind. I read the code but didn't compile it here, since this host has no MSVC. All the earlier points are resolved: ours on 8f1ce018 and both from the other review. The branch is one commit, and ca165ed9 is gone. The `phi_mask_ok` hunk is gone too: `git diff origin/main` touches only `tests/startup_rect_geometry.cpp`, +2/−1. The title now matches the change. The body gives the compiler and flags that show the problem: MSVC 14.44.35207, C4238 at `/W4` and C2102 at `/permissive-`. What I checked: - **The fix.** `GetCPUDescriptorHandleForHeapStart()` returns the handle by value. The named `const` local lives past the `OMSetRenderTargets` call, which reads the handle during the call. `ClearRenderTargetView` on the line above already takes the handle by value and is unchanged. - **No other copies.** `git grep -E '&[A-Za-z_>.-]*(->|\.)Get(CPU|GPU)DescriptorHandleForHeapStart\(\)'` finds 1 match on main (this line) and 0 at the head. - **Merge and CI.** `git merge-tree --write-tree origin/main` exits 0, and `git diff --check` exits 0. CI on b27cff1b: 3 success, 2 skipped. **NIT** 1. Nothing stops this from coming back, because the build passes neither `/permissive-` nor `/we4238`. A separate PR could enable one of them for the test targets, if the rest of the tree is clean under it. 2. You don't need to reopen this to fix the branch name. The stale name only shows up in the merge commit's subject. No MUST or SHOULD. Merged as c4b8a41b. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.