shader: lower gfx1013 v_ceil_f32 and v_rndne_f32 in pixel_aot #270

Merged
Vonsek merged 8 commits from upstream-pr/274 into main 2026-11-22 09:30:57 +00:00
Vonsek commented 2026-11-21 20:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T20:03:16Z.


Change

tools/pixel_aot.py now lowers two more gfx1013 rounding instructions, each in its VOP1 (_e32) and VOP3 (_e64) encoding:

  • v_ceil_f32 to HLSL ceil (DXIL Round_pi).
  • v_rndne_f32 to HLSL round, which DXC emits as Round_ne (round to nearest, ties to even). This matches the RDNA definition. Rounding half up or half away from zero would not.

They share the existing single-source ALU path, so source negation, absolute value and clamp behave as they do for v_floor_f32. The change adds two ALU table entries and two names to the arithmetic pattern.

tests/pixel_aot_check.py adds a rounding() program. It multiplies red and green by a power-of-two constant, then applies v_ceil_f32_e32 and v_rndne_f32_e32. It also applies v_rndne_f32_e64 to a constant tie and v_ceil_f32_e64 to a negated constant.

  • Controls: LLVM 15 and newer exp spellings, generated HLSL substrings, and rejection of neighbouring forms: v_ceil_f16, v_ceil_f64, v_rndne_f16, an extra source, mul:2/div:2 output modifiers, v_rcp_iflag_f32 and a descriptor register as a numeric source.
  • Binary: llvm-mc assembles the program, which is wrapped in a synthetic record, extracted, disassembled and compared with lowering the source directly.
  • Draw: two constant sets, (4.0, 2.5, 1.25) and (8.0, -3.5, -0.75), compared bitwise with a CPU reference using math.ceil and Python's ties-to-even round. Every product is exact (power-of-two scale), so only the rounding mode decides each pixel. Three negative controls must report pixel_mismatch: v_rndne_f32 replaced with v_floor_f32, v_ceil_f32 replaced with v_floor_f32, and the generated round( replaced with floor(0.5f + (the -3.5 tie then rounds half up).

tests/form_coverage_check.py asserts that the accepted programs include the four new forms (VOP1 v_ceil_f32, v_rndne_f32; VOP3 v_ceil_f32_e64, v_rndne_f32_e64) and that a passing pixel_aot_warp record counts exactly four more gfx1013 forms than the same record without them. docs/experiments.md lists the instructions and describes the draw and its controls.

v_trunc_f32 (#258, now on main) and the v_fract_f32 clamp (#267) are left to those PRs; this branch is rebased beside #258's truncation draw.

Verification

  • Linux, LLVM 18.1: tests/pixel_aot_check.py binary ... passes. With tools/pixel_aot.py reverted to main, it fails with Unsupported instruction 21: v_ceil_f32_e32 v12, v18.
  • tests/form_coverage_check.py passes; with tools/pixel_aot.py reverted it fails with the same error. tests/docs_links_check.py passes.
  • llvm-mc keeps the _e64 lines in the VOP3 encoding: v_rndne_f32_e64 v14, s45 is 0e 00 a3 d5 2d 00 00 00, and v_ceil_f32_e64 v15, -s46 is 0f 00 a2 d5 2e 00 00 20.
  • Windows: ctest --preset dev --no-tests=error -R '^pixel_aot_(warp|hardware)$' -V at 1446db3 (rebased on main d311159, beside v_trunc_f32 from #258; earlier runs at 106fd47 and 747a032 gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed, pixel_aot_hardware on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and pixel_aot_warp on the Microsoft Basic Render Driver, every draw with pixels=4096 channels=16384 max_absolute_error=0. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 136/136, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.

Evidence and follow-up

  • Measured on Windows: DXC 1.9.2602.17 compiles the translated rounding() shader with -Gis -T ps_6_0; the DXIL uses dx.op.unary 28 (Round_pi) for both ceil calls and 26 (Round_ne) for both round calls. Both constant sets match the ties-to-even reference bitwise on the RTX 5080 and on WARP, and all three negative controls report pixel_mismatch on both backends.
  • The constants keep every result away from a negative zero, so the sign of a zero result (for example ceil(-0.25)) is unmeasured. NaN and infinity inputs are also unmeasured.
  • Other uncovered VOP1/VOP2 float forms nearby include v_ldexp_f32, v_frexp_mant_f32/v_frexp_exp_i32_f32, v_madak_f32/v_madmk_f32/v_mac_f32 and v_sin_f32/v_cos_f32. Exact lowering is harder for these (unfused multiply-add, revolutions, ldexp overflow and denormal range) and they are left for separate changes.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533745675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T20:03:16Z. --- ## Change `tools/pixel_aot.py` now lowers two more gfx1013 rounding instructions, each in its VOP1 (`_e32`) and VOP3 (`_e64`) encoding: - `v_ceil_f32` to HLSL `ceil` (DXIL `Round_pi`). - `v_rndne_f32` to HLSL `round`, which DXC emits as `Round_ne` (round to nearest, ties to even). This matches the RDNA definition. Rounding half up or half away from zero would not. They share the existing single-source ALU path, so source negation, absolute value and `clamp` behave as they do for `v_floor_f32`. The change adds two ALU table entries and two names to the arithmetic pattern. `tests/pixel_aot_check.py` adds a `rounding()` program. It multiplies red and green by a power-of-two constant, then applies `v_ceil_f32_e32` and `v_rndne_f32_e32`. It also applies `v_rndne_f32_e64` to a constant tie and `v_ceil_f32_e64` to a negated constant. - Controls: LLVM 15 and newer `exp` spellings, generated HLSL substrings, and rejection of neighbouring forms: `v_ceil_f16`, `v_ceil_f64`, `v_rndne_f16`, an extra source, `mul:2`/`div:2` output modifiers, `v_rcp_iflag_f32` and a descriptor register as a numeric source. - Binary: llvm-mc assembles the program, which is wrapped in a synthetic record, extracted, disassembled and compared with lowering the source directly. - Draw: two constant sets, (4.0, 2.5, 1.25) and (8.0, -3.5, -0.75), compared bitwise with a CPU reference using `math.ceil` and Python's ties-to-even `round`. Every product is exact (power-of-two scale), so only the rounding mode decides each pixel. Three negative controls must report `pixel_mismatch`: `v_rndne_f32` replaced with `v_floor_f32`, `v_ceil_f32` replaced with `v_floor_f32`, and the generated `round(` replaced with `floor(0.5f + ` (the -3.5 tie then rounds half up). `tests/form_coverage_check.py` asserts that the accepted programs include the four new forms (VOP1 `v_ceil_f32`, `v_rndne_f32`; VOP3 `v_ceil_f32_e64`, `v_rndne_f32_e64`) and that a passing `pixel_aot_warp` record counts exactly four more gfx1013 forms than the same record without them. `docs/experiments.md` lists the instructions and describes the draw and its controls. `v_trunc_f32` (#258, now on main) and the `v_fract_f32` clamp (#267) are left to those PRs; this branch is rebased beside #258's truncation draw. ## Verification - Linux, LLVM 18.1: `tests/pixel_aot_check.py binary ...` passes. With `tools/pixel_aot.py` reverted to `main`, it fails with `Unsupported instruction 21: v_ceil_f32_e32 v12, v18`. - `tests/form_coverage_check.py` passes; with `tools/pixel_aot.py` reverted it fails with the same error. `tests/docs_links_check.py` passes. - llvm-mc keeps the `_e64` lines in the VOP3 encoding: `v_rndne_f32_e64 v14, s45` is `0e 00 a3 d5 2d 00 00 00`, and `v_ceil_f32_e64 v15, -s46` is `0f 00 a2 d5 2e 00 00 20`. - Windows: `ctest --preset dev --no-tests=error -R '^pixel_aot_(warp|hardware)$' -V` at 1446db3 (rebased on main d311159, beside `v_trunc_f32` from #258; earlier runs at 106fd47 and 747a032 gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed, `pixel_aot_hardware` on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and `pixel_aot_warp` on the Microsoft Basic Render Driver, every draw with `pixels=4096 channels=16384 max_absolute_error=0`. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 136/136, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. ## Evidence and follow-up - Measured on Windows: DXC 1.9.2602.17 compiles the translated `rounding()` shader with `-Gis -T ps_6_0`; the DXIL uses `dx.op.unary` 28 (`Round_pi`) for both `ceil` calls and 26 (`Round_ne`) for both `round` calls. Both constant sets match the ties-to-even reference bitwise on the RTX 5080 and on WARP, and all three negative controls report `pixel_mismatch` on both backends. - The constants keep every result away from a negative zero, so the sign of a zero result (for example `ceil(-0.25)`) is unmeasured. NaN and infinity inputs are also unmeasured. - Other uncovered VOP1/VOP2 float forms nearby include `v_ldexp_f32`, `v_frexp_mant_f32`/`v_frexp_exp_i32_f32`, `v_madak_f32`/`v_madmk_f32`/`v_mac_f32` and `v_sin_f32`/`v_cos_f32`. Exact lowering is harder for these (unfused multiply-add, revolutions, ldexp overflow and denormal range) and they are left for separate changes.
upstream-sync closed this pull request 2026-11-24 06:42:10 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T21:04:26Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 747a0326b7

ℹ️ 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:6008163166 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#pullrequestreview-6008163166). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T21:04:26Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `747a0326b7` <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>
Vonsek commented 2026-11-24 06:42:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T21:20:39Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6008240237 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#pullrequestreview-6008240237). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T21:20:39Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 06:48:02 +00:00 (Migrated from github.com)

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


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-21T21:04:28.613234Z 747a032 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:7069164132 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#issuecomment-7069164132). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T21:00:13Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"747a0326b7903166ff3869d0eb8fe0da65037088","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-21T21:04:28.613234Z">2026-11-21T21:04:28.613234Z</relative-time> | `747a032` | 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>
R0Y00 commented 2026-11-24 06:48:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:28:05Z.


At 0b20cc2, the merge conflicts are in tests/pixel_aot_check.py and tools/pixel_aot.py. Ceiling has landed in #270. Please rebase to just the remaining round-to-nearest-even behavior and its controls, keeping main's ceiling implementation and fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069494456 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#issuecomment-7069494456). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:28:05Z. --- At `0b20cc2`, the merge conflicts are in `tests/pixel_aot_check.py` and `tools/pixel_aot.py`. Ceiling has landed in #270. Please rebase to just the remaining round-to-nearest-even behavior and its controls, keeping main's ceiling implementation and fixture.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T21:04:26Z.

Code review location: tools/pixel_aot.py; line 323

@@ -319,7 +320,7 @@ def match(pattern):
             value = fp_operand(src, scalar, vector, pending, sample_pending)
             vector[dst] = f"alu{i}"
             lines.append(f"    precise float alu{i} = {value};")
-        elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"):
+        elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|ceil|rndne|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"):

P2 Badge Register the new rounding opcodes with the shader scanner

For an otherwise-supported pixel program using either new instruction, scan_unsupported_shaders.analyze_shader_instructions() still reports unsupported_opcodes, because both KNOWN_RDNA2_BASE_OPCODES and SUPPORTED_INSTRUCTIONS_REGEX omit these operations. I reproduced this with assembly(False) plus v_ceil_f32_e32 v12, v12, and separately with v_rndne_f32_e32 v12, v12: lowering succeeds, but tools/pso_readiness.py:37-38 checks the stale opcode classification before the successful lowering result and marks the pipeline blocked. Update the scanner's recognition and support tables alongside the lowerer so these newly supported programs are not falsely rejected by the scanner and PSO-readiness workflow.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654998554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#discussion_r4654998554). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T21:04:26Z. **Code review location:** `tools/pixel_aot.py`; line 323 ~~~~diff @@ -319,7 +320,7 @@ def match(pattern): value = fp_operand(src, scalar, vector, pending, sample_pending) vector[dst] = f"alu{i}" lines.append(f" precise float alu{i} = {value};") - elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"): + elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|ceil|rndne|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"): ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Register the new rounding opcodes with the shader scanner** For an otherwise-supported pixel program using either new instruction, `scan_unsupported_shaders.analyze_shader_instructions()` still reports `unsupported_opcodes`, because both `KNOWN_RDNA2_BASE_OPCODES` and `SUPPORTED_INSTRUCTIONS_REGEX` omit these operations. I reproduced this with `assembly(False)` plus `v_ceil_f32_e32 v12, v12`, and separately with `v_rndne_f32_e32 v12, v12`: lowering succeeds, but `tools/pso_readiness.py:37-38` checks the stale opcode classification before the successful lowering result and marks the pipeline blocked. Update the scanner's recognition and support tables alongside the lowerer so these newly supported programs are not falsely rejected by the scanner and PSO-readiness workflow. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Vonsek commented 2026-11-24 06:50:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T21:20:39Z.

Code review location: tools/pixel_aot.py; line 323

@@ -319,7 +320,7 @@ def match(pattern):
             value = fp_operand(src, scalar, vector, pending, sample_pending)
             vector[dst] = f"alu{i}"
             lines.append(f"    precise float alu{i} = {value};")
-        elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"):
+        elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|ceil|rndne|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"):

Fixed in 0b20cc2. tools/scan_unsupported_shaders.py now lists v_ceil_f32 and v_rndne_f32 as known RDNA 2 VOP1 opcodes, in SUPPORTED_ALU and in the supported-instruction pattern (both encodings), so a program that pixel_aot lowers is no longer reported with unsupported opcodes and pso_readiness no longer marks it blocked. tests/rdna2_tools_check.py adds test_rounding_instructions_accepted: the canonical pixel shader with v_ceil_f32_e32 and v_rndne_f32_e64 after the sample wait must be recognized, accepted by the translator and fully supported. It fails without the scanner change (False is not true) and passes with it; the full suite passes on Windows 11 26200.

The scanner's tables also omit other forms the lowerer already accepts (for example v_floor_f32, v_fract_f32, v_trunc_f32, v_add_f32, v_mul_f32); that predates this PR and is left for a separate change.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655061251 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/274#discussion_r4655061251). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T21:20:39Z. **Code review location:** `tools/pixel_aot.py`; line 323 ~~~~diff @@ -319,7 +320,7 @@ def match(pattern): value = fp_operand(src, scalar, vector, pending, sample_pending) vector[dst] = f"alu{i}" lines.append(f" precise float alu{i} = {value};") - elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"): + elif m := match(r"v_(log|exp|rcp|sqrt|rsq|floor|fract|ceil|rndne|add|mul|max|min|sub|subrev|mul_legacy|fma|fmac)_f32(?:_e32|_e64)? (v\d+), (.+?)( clamp)?"): ~~~~ --- Fixed in 0b20cc2. `tools/scan_unsupported_shaders.py` now lists `v_ceil_f32` and `v_rndne_f32` as known RDNA 2 VOP1 opcodes, in `SUPPORTED_ALU` and in the supported-instruction pattern (both encodings), so a program that `pixel_aot` lowers is no longer reported with unsupported opcodes and `pso_readiness` no longer marks it blocked. `tests/rdna2_tools_check.py` adds `test_rounding_instructions_accepted`: the canonical pixel shader with `v_ceil_f32_e32` and `v_rndne_f32_e64` after the sample wait must be recognized, accepted by the translator and fully supported. It fails without the scanner change (`False is not true`) and passes with it; the full suite passes on Windows 11 26200. The scanner's tables also omit other forms the lowerer already accepts (for example `v_floor_f32`, `v_fract_f32`, `v_trunc_f32`, `v_add_f32`, `v_mul_f32`); that predates this PR and is left for a separate change.
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!270
No description provided.