xshader: saturate v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 #591

Merged
KainanP merged 1 commit from upstream-pr/591 into main 2026-11-30 19:01:24 +00:00
KainanP commented 2026-11-30 16:11:36 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by KainanP on 2026-11-30T16:11:36Z.


v_cvt_flr_i32_f32 and v_cvt_rpi_i32_f32 were emitted as (int)floor(x) and (int)round(x). In DXIL that cast is undefined outside the i32 range, so the result depends on the driver. With a constant source, DXC folds it to undef and the shader fails validation ("Assignment of undefined values to UAV"). Both now go through tb_cvt_i32_f32, the same saturating helper v_cvt_i32_f32 uses. This also matches what check_basic_alu_gpu.py already expects for both instructions: NaN gives 0, out-of-range values clamp.

Test: test_floor_and_round_conversions_saturate in tests/test_float_to_integer.py checks the value DXC folds for 2^31, FLT_MAX, -2^31, the float just below -2^31, -FLT_MAX, and some in-range values. DXC doesn't fold floor or round of an infinity or a NaN, so the test leaves those out.

Ran (Windows 11, DXC 1.9.2609, CPU only):

  • TUXBOX_XSHADER=… DXC=… python -m unittest tests.test_float_to_integer tests.test_rpi_rounding: OK. Without the translator change, the new test fails on all 8 out-of-range cases (4 per instruction); the in-range ones pass both ways.
  • cargo test --release -p tuxbox-xshader: passed, with no change to the host profile records.
  • cargo fmt --all --check: clean.
  • python -m unittest discover -s tests -q (translator and DXC set): 778 tests, 186 skipped, and 10 that fail the same way on main on this Windows host (test_host.MesaShaderCache, test_stage_baseline, test_prefix_pool, test_scarlett_prep, test_translator_choice, test_verify: launcher and sandbox tests).

Not run: the GPU translator checks (they need Proton, and I only have Windows here) and the game. Programs that use these two instructions get new HLSL, so their cached shaders compile again.

AI-assisted: Claude Code (Claude Opus 5.5) found the issue, wrote the change and the test, and ran the commands above.

<!-- greyfinch-sync:brcly/TuxBox:issue:5569048956 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/591). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-30T16:11:36Z. --- `v_cvt_flr_i32_f32` and `v_cvt_rpi_i32_f32` were emitted as `(int)floor(x)` and `(int)round(x)`. In DXIL that cast is undefined outside the i32 range, so the result depends on the driver. With a constant source, DXC folds it to `undef` and the shader fails validation ("Assignment of undefined values to UAV"). Both now go through `tb_cvt_i32_f32`, the same saturating helper `v_cvt_i32_f32` uses. This also matches what `check_basic_alu_gpu.py` already expects for both instructions: NaN gives 0, out-of-range values clamp. **Test:** `test_floor_and_round_conversions_saturate` in `tests/test_float_to_integer.py` checks the value DXC folds for 2^31, FLT_MAX, -2^31, the float just below -2^31, -FLT_MAX, and some in-range values. DXC doesn't fold floor or round of an infinity or a NaN, so the test leaves those out. **Ran** (Windows 11, DXC 1.9.2609, CPU only): - `TUXBOX_XSHADER=… DXC=… python -m unittest tests.test_float_to_integer tests.test_rpi_rounding`: OK. Without the translator change, the new test fails on all 8 out-of-range cases (4 per instruction); the in-range ones pass both ways. - `cargo test --release -p tuxbox-xshader`: passed, with no change to the host profile records. - `cargo fmt --all --check`: clean. - `python -m unittest discover -s tests -q` (translator and DXC set): 778 tests, 186 skipped, and 10 that fail the same way on `main` on this Windows host (`test_host.MesaShaderCache`, `test_stage_baseline`, `test_prefix_pool`, `test_scarlett_prep`, `test_translator_choice`, `test_verify`: launcher and sandbox tests). **Not run:** the GPU translator checks (they need Proton, and I only have Windows here) and the game. Programs that use these two instructions get new HLSL, so their cached shaders compile again. AI-assisted: Claude Code (Claude Opus 5.5) found the issue, wrote the change and the test, and ran the commands above.
NickStallman commented 2026-11-30 19:04:53 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T19:04:53Z.


@KainanP the GPU checks, full python tuxbox.py check at 9977e6a2, GE-Proton11-14:

  • RTX 5090 (10de:2b85, 620.70.10): 203 pass, 0 fail.
  • AMD iGPU (1002:13c0, RADV): 202 pass, 0 fail.

The check includes the translator's GPU checks (ALU and float forms). I haven't run the game with it.

Evidence: TuxBox check of 9977e6a20d, no uncommitted changes, GPU 10de:2b85: 17 passed, 0 failed, 0 not run
Evidence: TuxBox check of 9977e6a20d, no uncommitted changes, GPU 1002:13c0: 17 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7288812913 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/591#issuecomment-7288812913). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T19:04:53Z. --- @KainanP the GPU checks, full `python tuxbox.py check` at 9977e6a2, GE-Proton11-14: - RTX 5090 (`10de:2b85`, 620.70.10): 203 pass, 0 fail. - AMD iGPU (`1002:13c0`, RADV): 202 pass, 0 fail. The check includes the translator's GPU checks (ALU and float forms). I haven't run the game with it. Evidence: TuxBox check of 9977e6a20de5, no uncommitted changes, GPU 10de:2b85: 17 passed, 0 failed, 0 not run Evidence: TuxBox check of 9977e6a20de5, no uncommitted changes, GPU 1002:13c0: 17 passed, 0 failed, 0 not run
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
brcly/TuxBox!591
No description provided.