tooling: handle comments and 64-bit indices in address-window lowering #1603

Merged
tedin7 merged 2 commits from upstream-pr/1610 into main 2026-11-25 15:01:13 +00:00
tedin7 commented 2026-11-24 15:01:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:01:22Z.


What

  • tools/spirv_address_window.py:
    • lower drops trailing ; comments (preserving any ; inside quoted string literals) before matching instructions, via strip_comment.
    • word_pointer handles 64-bit OpAccessChain indices (index_kind "u64" / "s64") without re-widening them with OpUConvert, bit-casts signed 64-bit indices (OpTypeInt 64 1) to %ulong, and guards the left shift with (delta >> scale) == index (OpShiftRightLogical + OpIEqual) so an out-of-window 64-bit index cannot drop high bits and alias an in-window address. 32-bit indices are still widened with OpUConvert.
  • tests/spirv_window/check.py:
    • Added tests for trailing comments (on a rewritten access chain, on OpEntryPoint, a comment mentioning PushConstant, and a ; inside a quoted OpName string literal with a trailing comment).
    • Added tests for unsigned and signed 64-bit OpAccessChain indices, verifying spirv-as + spirv-val acceptance, absence of duplicate OpUConvert, OpBitcast %ulong for signed 64-bit, and emission of the shift-wrap guard.

Why

  • Every instruction pattern in spirv_address_window.py uses fullmatch, so a line carrying a trailing ; comment was skipped and emitted unchanged, leaving dangling IDs, appending generated interface IDs inside comments, or failing on comments mentioning PushConstant.
  • A 64-bit OpAccessChain index is valid input, but re-applying OpUConvert %ulong is rejected by spirv-val (Expected input to have different bit width from Result Type: UConvert). Moreover, unlike a 32-bit index, shifting a 64-bit index left by 2, 3, or 4 bits can silently drop high bits and wrap to an in-window offset unless the shift itself is checked against overflow; signed 64-bit indices also need OpBitcast %ulong so OpIEqual operands share the same type.

Tested

Run on Linux (spirv-as, spirv-val, spirv-cross with --target-env vulkan1.2):

python3 -B tests/spirv_window/check.py
python3 -B tests/spirv_window/address_vec4.py spirv-as spirv-val spirv-cross
python3 -B tests/spirv_window/address_float.py spirv-as spirv-val spirv-cross
python3 -B tests/spirv_window/address_signed.py spirv-as spirv-val spirv-cross
python3 -B tests/docs_links_check.py
python3 -B tests/bidi_controls_check.py
git diff --check origin/main...HEAD

All pass.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 669985cba0f0ede5ceb030f5ae0c35ae56bca813:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 3.28s (configure 1.72s)
    • Test (ctest --preset dev -R '^spirv_address_window_' --parallel 4 --no-tests=error --output-on-failure): 12/12 passed (5.64s: spirv_address_window_warp, spirv_address_window_atomic_warp, spirv_address_window_signed_warp, spirv_address_window_float_warp, spirv_address_window_vec4_warp, spirv_address_window_qword_warp and corresponding hardware/WARP variants)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 0.85s (configure 1.73s)
    • Test (ctest --preset release -R '^spirv_address_window_' --parallel 4 --no-tests=error --output-on-failure): 12/12 passed (5.51s)

Audited, nothing found

  • tools/spirv_ballot_extract.py, tools/spirv_sampler_views.py: no defect found.
  • tools/spirv_address_window.py: the 64-bit wrap guard (addition + shift), end constants, alignment masks, atomic failure-semantics bits, compare-exchange loops and phi-parent renaming hold.
  • tools/spirv_sampler_split.py: only exotic spellings are refused (hexadecimal or octal literals, OpDecorateString); spirv-dis does not emit them, so nothing is changed.
  • tools/x87_lower.py: stack-depth tracking, FIST/FISTP rounding, FRNDINT and FBSTP matched an independent exact model on about 3,000 edge cases.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584752133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:01:22Z. --- ## What - `tools/spirv_address_window.py`: - `lower` drops trailing `;` comments (preserving any `;` inside quoted string literals) before matching instructions, via `strip_comment`. - `word_pointer` handles 64-bit `OpAccessChain` indices (`index_kind` `"u64"` / `"s64"`) without re-widening them with `OpUConvert`, bit-casts signed 64-bit indices (`OpTypeInt 64 1`) to `%ulong`, and guards the left shift with `(delta >> scale) == index` (`OpShiftRightLogical` + `OpIEqual`) so an out-of-window 64-bit index cannot drop high bits and alias an in-window address. 32-bit indices are still widened with `OpUConvert`. - `tests/spirv_window/check.py`: - Added tests for trailing comments (on a rewritten access chain, on `OpEntryPoint`, a comment mentioning `PushConstant`, and a `;` inside a quoted `OpName` string literal with a trailing comment). - Added tests for unsigned and signed 64-bit `OpAccessChain` indices, verifying `spirv-as` + `spirv-val` acceptance, absence of duplicate `OpUConvert`, `OpBitcast %ulong` for signed 64-bit, and emission of the shift-wrap guard. ## Why - Every instruction pattern in `spirv_address_window.py` uses `fullmatch`, so a line carrying a trailing `;` comment was skipped and emitted unchanged, leaving dangling IDs, appending generated interface IDs inside comments, or failing on comments mentioning `PushConstant`. - A 64-bit `OpAccessChain` index is valid input, but re-applying `OpUConvert %ulong` is rejected by `spirv-val` (`Expected input to have different bit width from Result Type: UConvert`). Moreover, unlike a 32-bit index, shifting a 64-bit index left by 2, 3, or 4 bits can silently drop high bits and wrap to an in-window offset unless the shift itself is checked against overflow; signed 64-bit indices also need `OpBitcast %ulong` so `OpIEqual` operands share the same type. ## Tested Run on Linux (`spirv-as`, `spirv-val`, `spirv-cross` with `--target-env vulkan1.2`): ``` python3 -B tests/spirv_window/check.py python3 -B tests/spirv_window/address_vec4.py spirv-as spirv-val spirv-cross python3 -B tests/spirv_window/address_float.py spirv-as spirv-val spirv-cross python3 -B tests/spirv_window/address_signed.py spirv-as spirv-val spirv-cross python3 -B tests/docs_links_check.py python3 -B tests/bidi_controls_check.py git diff --check origin/main...HEAD ``` All pass. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `669985cba0f0ede5ceb030f5ae0c35ae56bca813`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `3.28s` (configure `1.72s`) - Test (`ctest --preset dev -R '^spirv_address_window_' --parallel 4 --no-tests=error --output-on-failure`): **12/12 passed** (`5.64s`: `spirv_address_window_warp`, `spirv_address_window_atomic_warp`, `spirv_address_window_signed_warp`, `spirv_address_window_float_warp`, `spirv_address_window_vec4_warp`, `spirv_address_window_qword_warp` and corresponding hardware/WARP variants) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `0.85s` (configure `1.73s`) - Test (`ctest --preset release -R '^spirv_address_window_' --parallel 4 --no-tests=error --output-on-failure`): **12/12 passed** (`5.51s`) ## Audited, nothing found - `tools/spirv_ballot_extract.py`, `tools/spirv_sampler_views.py`: no defect found. - `tools/spirv_address_window.py`: the 64-bit wrap guard (addition + shift), end constants, alignment masks, atomic failure-semantics bits, compare-exchange loops and phi-parent renaming hold. - `tools/spirv_sampler_split.py`: only exotic spellings are refused (hexadecimal or octal literals, `OpDecorateString`); `spirv-dis` does not emit them, so nothing is changed. - `tools/x87_lower.py`: stack-depth tracking, FIST/FISTP rounding, FRNDINT and FBSTP matched an independent exact model on about 3,000 edge cases. AI-assisted; commands listed were executed locally.
upstream-sync changed title from [PR #1610] tooling: keep address-window lowering valid for commented lines and 64-bit indices to [PR #1610] tooling: handle comments and 64-bit indices in address-window lowering 2026-11-24 16:03:15 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 16:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:17:06Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 669985cba0

ℹ️ 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6041993577 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610#pullrequestreview-6041993577). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:17:06Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `669985cba0` <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". 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". </details>
tedin7 commented 2026-11-24 16:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:27:45Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042196586 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610#pullrequestreview-6042196586). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:27:45Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 16:03:33 +00:00 (Migrated from github.com)

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


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-24T15:17:08.891027Z 669985c Draft marked ready
ℹ️ 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:7135660758 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610#issuecomment-7135660758). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:13:24Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"669985cba0f0ede5ceb030f5ae0c35ae56bca813","has_any_findings":true,"has_unresolved_findings":true,"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-24T15:17:08.891027Z">2026-11-24T15:17:08.891027Z</relative-time> | `669985c` | Draft marked ready | <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>
chatgpt-codex-connector[bot commented 2026-11-24 16:03:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T15:17:06Z.

Code review location: tools/spirv_address_window.py; line 330

@@ -312,8 +325,24 @@ def merge_pointer_types(lines):
     return "\n".join(re.sub(ID, lambda m: aliases.get(m[0], m[0]), line) for line in kept) + "\n"
 
 
+def strip_comment(line):
+    """Drop a trailing ; comment, keeping any ; inside a string literal."""
+    quoted = escaped = False

P2 Badge Preserve quote state across assembly lines

For a valid multiline OpString/OpSource literal whose continuation contains ;, resetting this state for each line interprets the literal's semicolon as a comment. Adding %text = OpString "first line\nint tmp = 0; }" to the atomic fixture preserves the full string on the parent commit, but here the continuation is truncated to int tmp = 0, deleting the closing quote and making the lowered assembly invalid. Carry quote/escape state across the entire module, or reuse spirv_sampler_views.strip_comments, which already handles multiline literals.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4682173935 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610#discussion_r4682173935). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T15:17:06Z. **Code review location:** `tools/spirv_address_window.py`; line 330 ~~~~diff @@ -312,8 +325,24 @@ def merge_pointer_types(lines): return "\n".join(re.sub(ID, lambda m: aliases.get(m[0], m[0]), line) for line in kept) + "\n" +def strip_comment(line): + """Drop a trailing ; comment, keeping any ; inside a string literal.""" + quoted = escaped = False ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve quote state across assembly lines** For a valid multiline `OpString`/`OpSource` literal whose continuation contains `;`, resetting this state for each line interprets the literal's semicolon as a comment. Adding `%text = OpString "first line\nint tmp = 0; }"` to the atomic fixture preserves the full string on the parent commit, but here the continuation is truncated to `int tmp = 0`, deleting the closing quote and making the lowered assembly invalid. Carry quote/escape state across the entire module, or reuse `spirv_sampler_views.strip_comments`, which already handles multiline literals. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 16:03:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:27:45Z.

Code review location: tools/spirv_address_window.py; line 330

@@ -312,8 +325,24 @@ def merge_pointer_types(lines):
     return "\n".join(re.sub(ID, lambda m: aliases.get(m[0], m[0]), line) for line in kept) + "\n"
 
 
+def strip_comment(line):
+    """Drop a trailing ; comment, keeping any ; inside a string literal."""
+    quoted = escaped = False

Addressed in 008558b3d08ac4dbaf744de3e6c93b2f7f315b6c: replaced per-line strip_comment with logical_lines() in tools/spirv_address_window.py so quote and backslash-escape state carries across lines and multiline string literals keep their inner newlines, spacing, and semicolons intact while stripping trailing ; comments. Added a multiline OpString regression test (%text = OpString "first line\n int tmp = 0; }" ; note) in tests/spirv_window/check.py.

Verified locally:

  • python3 tests/spirv_window/check.py (pass)
  • python3 tests/docs_links_check.py (pass)
  • python3 tests/bidi_controls_check.py (pass)
  • Windows Server 2025 Debug (--preset dev) and Release /O2 (--preset release) ctest -R '^spirv_address_window_': 12/12 passed in both configurations.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4682328607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1610#discussion_r4682328607). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:27:45Z. **Code review location:** `tools/spirv_address_window.py`; line 330 ~~~~diff @@ -312,8 +325,24 @@ def merge_pointer_types(lines): return "\n".join(re.sub(ID, lambda m: aliases.get(m[0], m[0]), line) for line in kept) + "\n" +def strip_comment(line): + """Drop a trailing ; comment, keeping any ; inside a string literal.""" + quoted = escaped = False ~~~~ --- Addressed in `008558b3d08ac4dbaf744de3e6c93b2f7f315b6c`: replaced per-line `strip_comment` with `logical_lines()` in `tools/spirv_address_window.py` so quote and backslash-escape state carries across lines and multiline string literals keep their inner newlines, spacing, and semicolons intact while stripping trailing `;` comments. Added a multiline `OpString` regression test (`%text = OpString "first line\n int tmp = 0; }" ; note`) in `tests/spirv_window/check.py`. Verified locally: - `python3 tests/spirv_window/check.py` (pass) - `python3 tests/docs_links_check.py` (pass) - `python3 tests/bidi_controls_check.py` (pass) - Windows Server 2025 Debug (`--preset dev`) and Release `/O2` (`--preset release`) `ctest -R '^spirv_address_window_'`: 12/12 passed in both configurations. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 15:01:24 +00:00
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!1603
No description provided.