startup: lower cube coordinate operations in gfx2hlsl #2506

Merged
lambirou merged 3 commits from upstream-pr/2514 into main 2026-11-25 20:40:58 +00:00
lambirou commented 2026-11-25 19:21:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-25T19:21:25Z.


Problem

Startup shader translation refuses the gfx1013 cube coordinate operations v_cubeid_f32,
v_cubesc_f32, v_cubetc_f32 and v_cubema_f32. The refusal census in #1723 lists
36, 35 and 35 pairs for the cube group, with no existing gfx2hlsl lowering.

Change

  • Add the four VOP3A handlers in tools/startup/gfx2hlsl.py.
  • Follow LLVM's ConstantFoldAMDGCNCubeIntrinsic: z is the major axis when |z| >= |x| and
    |z| >= |y|, otherwise y when |y| >= |x|, otherwise x. A face is negative only for a
    nonzero, non-NaN negative coordinate. v_cubema_f32 returns twice the signed major coordinate.
  • Apply clamp, source neg/abs, and reject a missing operand, a non-VGPR destination, and
    modifiers other than clamp. Temporary names are unique across blocks.
  • Add a source-built fixture covering all six faces, the y/x and z/x ties, and -0.0 on the
    major axis. The draw compares all four output words on WARP and hardware.
  • Negative controls: swapped id/sc, a changed tie order, and a dropped * 2.0f factor must
    each mismatch.

Verification

. .\tools\dev.ps1
ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_cube' -V

Result: 3/3 passed on WARP 10.0.26100.10068 and on an AMD Radeon RX 9060 XT
(driver 32.0.32029.2010, Windows 11 build 26300), with FXC vs_5_1/ps_5_1 and DXC
vs_6_0/ps_6_0. The debug layer was unavailable on this host. The full non-hardware
startup_gfx2hlsl_ selection passed 103/103.

ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_' -E '_hardware$' -j 4
python -B tests/docs_links_check.py
git diff --check

Limits

  • NaN coordinates are not drawn.
  • The fixture covers the four operations and the listed direction classes, not every one of the
    census pairs; the archive census itself uses a local cache.
  • This is a desktop translation test, not gfx1013 hardware behavior or title execution.

Refs #1723. Original contributions are under the MIT License. AI-assisted implementation and
first verification; the orchestrator reviewed the diff, ran the tests and the hardware draw.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6611951582 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-25T19:21:25Z. --- ## Problem Startup shader translation refuses the gfx1013 cube coordinate operations `v_cubeid_f32`, `v_cubesc_f32`, `v_cubetc_f32` and `v_cubema_f32`. The refusal census in #1723 lists 36, 35 and 35 pairs for the cube group, with no existing `gfx2hlsl` lowering. ## Change - Add the four VOP3A handlers in `tools/startup/gfx2hlsl.py`. - Follow LLVM's `ConstantFoldAMDGCNCubeIntrinsic`: z is the major axis when `|z| >= |x|` and `|z| >= |y|`, otherwise y when `|y| >= |x|`, otherwise x. A face is negative only for a nonzero, non-NaN negative coordinate. `v_cubema_f32` returns twice the signed major coordinate. - Apply `clamp`, source neg/abs, and reject a missing operand, a non-VGPR destination, and modifiers other than `clamp`. Temporary names are unique across blocks. - Add a source-built fixture covering all six faces, the y/x and z/x ties, and `-0.0` on the major axis. The draw compares all four output words on WARP and hardware. - Negative controls: swapped id/sc, a changed tie order, and a dropped `* 2.0f` factor must each mismatch. ## Verification ```powershell . .\tools\dev.ps1 ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_cube' -V ``` Result: 3/3 passed on WARP 10.0.26100.10068 and on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010, Windows 11 build 26300), with FXC `vs_5_1`/`ps_5_1` and DXC `vs_6_0`/`ps_6_0`. The debug layer was unavailable on this host. The full non-hardware `startup_gfx2hlsl_` selection passed 103/103. ```powershell ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_' -E '_hardware$' -j 4 python -B tests/docs_links_check.py git diff --check ``` ## Limits - NaN coordinates are not drawn. - The fixture covers the four operations and the listed direction classes, not every one of the census pairs; the archive census itself uses a local cache. - This is a desktop translation test, not gfx1013 hardware behavior or title execution. Refs #1723. Original contributions are under the MIT License. AI-assisted implementation and first verification; the orchestrator reviewed the diff, ran the tests and the hardware draw.
lambirou commented 2026-11-25 20:04:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-25T19:30:34Z.


@R0Y00 — this PR is ready for maintainer review.

Cube coordinate lowering for #1723. The first planned slice, s_bitcmp0/1_b32, was already merged, so this takes the next unclaimed cube group (36/35/35 census pairs). It lowers v_cube{id,sc,tc,ma}_f32 with LLVM's major-axis and face-sign rules, clamp, source neg/abs, and a source-built draw with swapped-id/sc, tie-order and cubema-factor negative controls.

CI is green: Assemble and translate gfx1013 fixtures, Run platform-independent Python checks on Linux, and Build and test on Windows. The PR is MERGEABLE/CLEAN. Local validation: 3/3 startup_gfx2hlsl_cube on WARP and RX 9060 XT with FXC and DXC; 103/103 non-hardware startup_gfx2hlsl_ tests.

The limits are in the PR body: NaN coordinates are not drawn, the fixture does not cover every census pair, and this measures the desktop translator rather than gfx1013 hardware.

Requesting review here because this account cannot assign reviewers directly (RequestReviewsByLogin permission is refused).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7172394568 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514#issuecomment-7172394568). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-25T19:30:34Z. --- @R0Y00 — this PR is ready for maintainer review. Cube coordinate lowering for #1723. The first planned slice, `s_bitcmp0/1_b32`, was already merged, so this takes the next unclaimed cube group (36/35/35 census pairs). It lowers `v_cube{id,sc,tc,ma}_f32` with LLVM's major-axis and face-sign rules, `clamp`, source neg/abs, and a source-built draw with swapped-id/sc, tie-order and cubema-factor negative controls. CI is green: `Assemble and translate gfx1013 fixtures`, `Run platform-independent Python checks on Linux`, and `Build and test on Windows`. The PR is `MERGEABLE`/`CLEAN`. Local validation: 3/3 `startup_gfx2hlsl_cube` on WARP and RX 9060 XT with FXC and DXC; 103/103 non-hardware `startup_gfx2hlsl_` tests. The limits are in the PR body: NaN coordinates are not drawn, the fixture does not cover every census pair, and this measures the desktop translator rather than gfx1013 hardware. Requesting review here because this account cannot assign reviewers directly (`RequestReviewsByLogin` permission is refused).
RavenCurseBurg commented 2026-11-25 20:04:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T19:36:42Z.


For the compute-stage cube item in #2463 I reran the 80-byte, LLVM 15-assembled shader against this PR's translator at 7a2887ba. The fixture dispatches 18 threads: six face interiors, four nonzero tie cases and all eight combinations of signed-zero X/Y/Z. Each thread stores the raw face ID, S, T and signed major axis times two. Both DXC defaults and -Gis matched all 72 result words and 248 sentinel words. For the eight signed-zero inputs the selected face was +Z, with the original X, negated Y and original Z sign bits visible in the coordinates.

Windows 11 build 26100.9711, debug layer unavailable. Intel UHD 770 (32.0.101.5973), RTX 4060 (32.0.15.9579) and WARP (10.0.26100.9711) agreed. On each device, swapping X/Y for the face calculation, flipping S, flipping T, clearing the signed major and demoting Z on ties respectively produced 5, 18, 18, 9 and 25 mismatching words. The exact source, oracle and measurement commands are in the standalone compute fixture on this PR head.

AI-assisted with Codex (GPT-6.2 Astra, xhigh).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7172534499 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514#issuecomment-7172534499). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T19:36:42Z. --- For the compute-stage cube item in #2463 I reran the 80-byte, LLVM 15-assembled shader against this PR's translator at `7a2887ba`. The fixture dispatches 18 threads: six face interiors, four nonzero tie cases and all eight combinations of signed-zero X/Y/Z. Each thread stores the raw face ID, S, T and signed major axis times two. Both DXC defaults and `-Gis` matched **all 72 result words and 248 sentinel words**. For the eight signed-zero inputs the selected face was +Z, with the original X, negated Y and original Z sign bits visible in the coordinates. Windows 11 build 26100.9711, debug layer unavailable. Intel UHD 770 (32.0.101.5973), RTX 4060 (32.0.15.9579) and WARP (10.0.26100.9711) agreed. On each device, swapping X/Y for the face calculation, flipping S, flipping T, clearing the signed major and demoting Z on ties respectively produced 5, 18, 18, 9 and 25 mismatching words. The exact source, oracle and measurement commands are in the [standalone compute fixture on this PR head](https://github.com/RavenCurseBurg/Xbox2Windows/blob/215bfb3f811ac4fad9658940669333d3c6330377/tests/measure_compute_cube_faces.py). AI-assisted with Codex (GPT-6.2 Astra, xhigh).
R0Y00 commented 2026-11-25 20:04:48 +00:00 (Migrated from github.com)

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


The graphics draw and RavenCurseBurg’s separate compute readback give both stage paths a reference. #2035 already carries overlapping cube-coordinate helpers and a separate cube texture sampling change. Please coordinate with its author so there is one implementation for the four operations, keep the compute face/tie/signed-zero fixture and its controls, and leave cube-image sampling in its own slice. Keep any NaN behavior scoped to the evidence you have.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7173117955 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514#issuecomment-7173117955). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T20:03:03Z. --- The graphics draw and RavenCurseBurg’s separate compute readback give both stage paths a reference. #2035 already carries overlapping cube-coordinate helpers and a separate cube texture sampling change. Please coordinate with its author so there is one implementation for the four operations, keep the compute face/tie/signed-zero fixture and its controls, and leave cube-image sampling in its own slice. Keep any NaN behavior scoped to the evidence you have.
upstream-sync closed this pull request 2026-11-25 21:01:13 +00:00
tedin7 commented 2026-11-25 21:01:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:40:47Z.

Review: COMMENTED


Review of head c3bb1ee8 (comment only).

Checked:

  • The four lowerings in tools/startup/gfx2hlsl.py follow LLVM's ConstantFoldAMDGCNCubeIntrinsic. I compared face id, sc, tc and ma for all three major axes, and the tie order (z, then y, then x). Negative faces use < 0.0f, so -0.0 and NaN are not negative, as the PR states.
  • Refusals: wrong operand count, non-VGPR destination, and modifiers other than clamp. Temp names are unique per use.
  • Tests: a pure-Python control set, a binary reassembly check, and a WARP and hardware draw compared with the reference. CTest entries and the windows.yml line are added, and the PR's own CI run exercised the changed workflow (all jobs green).
  • Mutations I made on the lowering: dropping * 2.0f in cubema fails the Python control. The tie-order change (>= to >) is not caught by the Python control. It is covered only by the draw test, which the PR describes as its negative control.
  • No other open or merged PR covers the cube ops (an earlier attempt, #2035, is closed).
  • No startup-progress claim, so no game run is needed.

Commands executed locally: gh pr update-branch, python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD, python3 -I -B tests/startup_gfx2hlsl_cube_check.py (plain and with two mutations, then reverted).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064679686 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514#pullrequestreview-6064679686). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:40:47Z. **Review:** COMMENTED --- Review of head c3bb1ee8 (comment only). Checked: - The four lowerings in `tools/startup/gfx2hlsl.py` follow LLVM's `ConstantFoldAMDGCNCubeIntrinsic`. I compared face id, sc, tc and ma for all three major axes, and the tie order (z, then y, then x). Negative faces use `< 0.0f`, so `-0.0` and NaN are not negative, as the PR states. - Refusals: wrong operand count, non-VGPR destination, and modifiers other than `clamp`. Temp names are unique per use. - Tests: a pure-Python control set, a binary reassembly check, and a WARP and hardware draw compared with the reference. CTest entries and the `windows.yml` line are added, and the PR's own CI run exercised the changed workflow (all jobs green). - Mutations I made on the lowering: dropping `* 2.0f` in cubema fails the Python control. The tie-order change (`>=` to `>`) is not caught by the Python control. It is covered only by the draw test, which the PR describes as its negative control. - No other open or merged PR covers the cube ops (an earlier attempt, #2035, is closed). - No startup-progress claim, so no game run is needed. Commands executed locally: `gh pr update-branch`, `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD`, `python3 -I -B tests/startup_gfx2hlsl_cube_check.py` (plain and with two mutations, then reverted). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 21:01:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:40:48Z.


Win2025 WARP receipt for head c3bb1ee8 after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 30.18s (configure 2.26s)
    • Test (ctest --preset dev -R '^startup_gfx2hlsl_cube' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (2.82s: startup_gfx2hlsl_cube_controls 0.10s, startup_gfx2hlsl_cube_warp 2.68s, startup_gfx2hlsl_cube_hardware 2.69s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 69.29s (configure 2.05s)
    • Test (ctest --preset release -R '^startup_gfx2hlsl_cube' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (3.18s: startup_gfx2hlsl_cube_controls 0.11s, startup_gfx2hlsl_cube_warp 3.02s, startup_gfx2hlsl_cube_hardware 3.03s)
  • Windows Python checks: tests/mesh_heap_sampler_check.py ok (0.7s), tests/startup_buffer_address_check.py ok (0.4s), tests/startup_buffer_format_word3_table_check.py ok (0.1s), tests/startup_compute_request_offline_check.py ok (0.7s), tests/startup_compute_translate_check.py ok (0.3s), tests/startup_flat_param_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_check.py ok (0.1s), tests/startup_gfx2hlsl_add_sub_co_ci_check.py ok (0.2s), tests/startup_gfx2hlsl_bit_alu_check.py ok (0.6s), tests/startup_gfx2hlsl_capture_check.py ok (1.0s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.2s), tests/startup_gfx2hlsl_compare_dst_check.py ok (0.1s), tests/startup_gfx2hlsl_compute_check.py ok (0.4s), tests/startup_gfx2hlsl_cselect_mask_check.py ok (0.1s), tests/startup_gfx2hlsl_cvt_alu_check.py ok (0.1s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.2s), tests/startup_gfx2hlsl_f32_nan_check.py ok (4.7s), tests/startup_gfx2hlsl_getpc_refusal_check.py ok (0.1s), tests/startup_gfx2hlsl_handler_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_arity_check.py ok (0.1s), tests/startup_gfx2hlsl_image_get_lod_check.py ok (0.1s), tests/startup_gfx2hlsl_int_med3_check.py ok (0.1s), tests/startup_gfx2hlsl_join_symbols_check.py ok (0.2s), tests/startup_gfx2hlsl_loop_constants_check.py ok (0.1s), tests/startup_gfx2hlsl_mask_overwrite_check.py ok (0.1s), `tests/startup_gfx2hlsl_operand_count
  • sccache: -195/-196 hits; wall 164.3s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7174029361 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2514#issuecomment-7174029361). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:40:48Z. --- Win2025 WARP receipt for head c3bb1ee8 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `c3bb1ee8e9db1ef94f8f76aedf927c789858e3d6`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2`): `30.18s` (configure `2.26s`) - Test (`ctest --preset dev -R '^startup_gfx2hlsl_cube' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`2.82s`: `startup_gfx2hlsl_cube_controls` `0.10s`, `startup_gfx2hlsl_cube_warp` `2.68s`, `startup_gfx2hlsl_cube_hardware` `2.69s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2`): `69.29s` (configure `2.05s`) - Test (`ctest --preset release -R '^startup_gfx2hlsl_cube' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`3.18s`: `startup_gfx2hlsl_cube_controls` `0.11s`, `startup_gfx2hlsl_cube_warp` `3.02s`, `startup_gfx2hlsl_cube_hardware` `3.03s`) - **Windows Python checks**: `tests/mesh_heap_sampler_check.py` ok (`0.7s`), `tests/startup_buffer_address_check.py` ok (`0.4s`), `tests/startup_buffer_format_word3_table_check.py` ok (`0.1s`), `tests/startup_compute_request_offline_check.py` ok (`0.7s`), `tests/startup_compute_translate_check.py` ok (`0.3s`), `tests/startup_flat_param_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_add_sub_co_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_add_sub_co_ci_check.py` ok (`0.2s`), `tests/startup_gfx2hlsl_bit_alu_check.py` ok (`0.6s`), `tests/startup_gfx2hlsl_capture_check.py` ok (`1.0s`), `tests/startup_gfx2hlsl_cmp16_check.py` ok (`0.2s`), `tests/startup_gfx2hlsl_compare_dst_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_compute_check.py` ok (`0.4s`), `tests/startup_gfx2hlsl_cselect_mask_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_cvt_alu_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_f32_lg_check.py` ok (`1.2s`), `tests/startup_gfx2hlsl_f32_nan_check.py` ok (`4.7s`), `tests/startup_gfx2hlsl_getpc_refusal_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_handler_arity_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_image_arity_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_image_get_lod_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_int_med3_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_join_symbols_check.py` ok (`0.2s`), `tests/startup_gfx2hlsl_loop_constants_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_mask_overwrite_check.py` ok (`0.1s`), `tests/startup_gfx2hlsl_operand_count - `sccache`: -195/-196 hits; wall `164.3s` AI-assisted; commands listed were executed locally.
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!2506
No description provided.