Recompiler: keep clamped VOP3 pkrtz when patching 32-bit PS exports #3600

Merged
Foniass merged 1 commit from upstream-pr/3600 into main 2026-12-01 22:06:59 +00:00
Foniass commented 2026-12-01 18:07:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T18:07:58Z.


patch_ps_32bit_exports (from #3200) turns a compressed exp mrtK fed by v_cvt_pkrtz_f16_f32 into an uncompressed export of the conversion's raw f32 sources when the render target is 32-bit. It must decline when the VOP3 form has an input or output modifier, but it looked up the clamp bit as "CLMP", while the ENC_VOP3 field is named "CLAMP". An unknown field name reads as 0, so a clamped conversion was still patched and the clamp was dropped: the 32-bit render target got the unclamped f32 value instead of the value clamped to [0, 1]. V_CVT_PKRTZ_F16_F32 has no VOP3P form, so only VOP3 is affected.

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs: check "CLAMP" instead of "CLMP" (one line).
  • crates/xcl/src/gpu/dxil/core_tests.rs: ps_32bit_rt_export_declines_patch_for_clamped_vop3_pkrtz exports a VOP3 pkrtz of a large float to a 32-bit MRT. Without CLAMP it is patched; with CLAMP it is left alone, in both the HLSL and the direct DXIL backends.

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 build 26300, rustc 1.100.0 stable-x86_64-pc-windows-msvc. Suite in debug, smoke in release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 868e4662: 2905 passed, 0 failed, 51 ignored. These are the same 28 SKIPPED notices as on main:
    • 22 × no wave64 (wave64 GPU tests in gpu::recomp::lower, lower_dxil, recomp::tests, dxil::kernel)
    • 2 × no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form, bind::tests::two_pass_binds_set_the_shared_view_heap)
    • 3 × no D3D12 debug layer / d3d12SDKLayers.dll (the title under the debug layer with dred false/true, uploads_start_from_each_subresources_state)
    • 1 × cannot disable the driver cache (Windows Developer Mode is required) (shaders::tests::pso_measurement_compiles_an_exact_synthetic_record)
  • cargo test -p xcl --lib ps_32bit_rt_export: 3 passed, 0 failed on this branch. On main 6bfb5c51 with only the new test applied, it gives 2 passed, 1 failed: the new test fails at the clamped HLSL check, and the unclamped control passes. With the HLSL checks removed, it also fails on main at the direct DXIL check, because the raw 0x781d3718 is stored to RT1.

Regression run
main:

xcl-smoke v1
commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1241 (PresentX 1241)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 18333 MB

PR head:

xcl-smoke v1
commit: 868e466247463f7292036d94e367f13104d63f44
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1558 (PresentX 1558)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17140 MB

Not tested

  • AMD and wave64 hardware. All wave64 GPU tests were skipped on this adapter.
  • It is not known whether the retail title in the smoke run ever exports a clamped pkrtz to a 32-bit render target, so the smoke run is a regression check only, not a check of this path.

AI use

  • Claude Code with Claude Opus 5.5. It found the bug in a review and wrote the fix, the test and this description. The tests and smoke runs above were run on the hardware listed.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5591585012 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3600). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T18:07:58Z. --- `patch_ps_32bit_exports` (from #3200) turns a compressed `exp mrtK` fed by `v_cvt_pkrtz_f16_f32` into an uncompressed export of the conversion's raw f32 sources when the render target is 32-bit. It must decline when the VOP3 form has an input or output modifier, but it looked up the clamp bit as `"CLMP"`, while the `ENC_VOP3` field is named `"CLAMP"`. An unknown field name reads as 0, so a clamped conversion was still patched and the clamp was dropped: the 32-bit render target got the unclamped f32 value instead of the value clamped to [0, 1]. `V_CVT_PKRTZ_F16_F32` has no VOP3P form, so only VOP3 is affected. **What is in it** - `crates/xcl/src/gpu/recomp/mod.rs`: check `"CLAMP"` instead of `"CLMP"` (one line). - `crates/xcl/src/gpu/dxil/core_tests.rs`: `ps_32bit_rt_export_declines_patch_for_clamped_vop3_pkrtz` exports a VOP3 pkrtz of a large float to a 32-bit MRT. Without CLAMP it is patched; with CLAMP it is left alone, in both the HLSL and the direct DXIL backends. **Tested** - NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 build 26300, rustc 1.100.0 `stable-x86_64-pc-windows-msvc`. Suite in debug, smoke in release. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 868e4662: 2905 passed, 0 failed, 51 ignored. These are the same 28 SKIPPED notices as on main: - 22 × `no wave64` (wave64 GPU tests in `gpu::recomp::lower`, `lower_dxil`, `recomp::tests`, `dxil::kernel`) - 2 × `no heap windows` (`heap_window_out_of_memory_falls_back_to_the_switch_form`, `bind::tests::two_pass_binds_set_the_shared_view_heap`) - 3 × no D3D12 debug layer / `d3d12SDKLayers.dll` (`the title under the debug layer` with dred false/true, `uploads_start_from_each_subresources_state`) - 1 × `cannot disable the driver cache (Windows Developer Mode is required)` (`shaders::tests::pso_measurement_compiles_an_exact_synthetic_record`) - `cargo test -p xcl --lib ps_32bit_rt_export`: 3 passed, 0 failed on this branch. On main 6bfb5c51 with only the new test applied, it gives 2 passed, 1 failed: the new test fails at the clamped HLSL check, and the unclamped control passes. With the HLSL checks removed, it also fails on main at the direct DXIL check, because the raw 0x781d3718 is stored to RT1. **Regression run** main: ``` xcl-smoke v1 commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1241 (PresentX 1241) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 18333 MB ``` PR head: ``` xcl-smoke v1 commit: 868e466247463f7292036d94e367f13104d63f44 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1558 (PresentX 1558) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17140 MB ``` **Not tested** - AMD and wave64 hardware. All wave64 GPU tests were skipped on this adapter. - It is not known whether the retail title in the smoke run ever exports a clamped pkrtz to a 32-bit render target, so the smoke run is a regression check only, not a check of this path. **AI use** - Claude Code with Claude Opus 5.5. It found the bug in a review and wrote the fix, the test and this description. The tests and smoke runs above were run on the hardware listed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fromthemoonx commented 2026-12-01 19:01:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T19:01:32Z.


merge-check
base: 6bfb5c5153
head: 868e466247
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (2 files, +41 -1). No findings.

  • "CLMP" -> "CLAMP" in patch_ps_32bit_exports. Every other reader of the VOP3 clamp bit uses "CLAMP" (lower_valu.rs:36,57,535, lower_wide.rs:35), and no other "CLMP" is left in src.
  • ps_32bit_rt_export_* (3 tests, including the new ps_32bit_rt_export_declines_patch_for_clamped_vop3_pkrtz): 3 of 3 runs passed.
  • Mutation: "CLMP" back fails the new test at core_tests.rs:277. Good.
  • Worth knowing, not this PR's to fix: a declined patch exports (v8 & 0xFFFF), the packed half bits, to the 32-bit target, as before #3200. A clamped conversion could be patched to export saturate(v6) instead.
  • The test checks the generated HLSL text and the direct DXIL disassembly; no draw is read back. No retail title on this machine.
    performance: none: one field read per patched export.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
<!-- greyfinch-sync:ivall/xcl:comment:7322022914 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3600#issuecomment-7322022914). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T19:01:32Z. --- merge-check base: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c head: 868e466247463f7292036d94e367f13104d63f44 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none review: read the whole diff (2 files, +41 -1). No findings. - `"CLMP"` -> `"CLAMP"` in `patch_ps_32bit_exports`. Every other reader of the VOP3 clamp bit uses `"CLAMP"` (`lower_valu.rs:36,57,535`, `lower_wide.rs:35`), and no other `"CLMP"` is left in `src`. - `ps_32bit_rt_export_*` (3 tests, including the new `ps_32bit_rt_export_declines_patch_for_clamped_vop3_pkrtz`): 3 of 3 runs passed. - Mutation: `"CLMP"` back fails the new test at `core_tests.rs:277`. Good. - Worth knowing, not this PR's to fix: a declined patch exports `(v8 & 0xFFFF)`, the packed half bits, to the 32-bit target, as before #3200. A clamped conversion could be patched to export `saturate(v6)` instead. - The test checks the generated HLSL text and the direct DXIL disassembly; no draw is read back. No retail title on this machine. performance: none: one field read per patched export. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
throny commented 2026-12-01 19:26:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T19:26:16Z.


merge-check claim
head: 868e466247

<!-- greyfinch-sync:ivall/xcl:comment:7322816183 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3600#issuecomment-7322816183). Originally posted by [throny](https://github.com/throny) on 2026-12-01T19:26:16Z. --- merge-check claim head: 868e466247463f7292036d94e367f13104d63f44
throny commented 2026-12-01 21:05:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T21:05:41Z.


merge-check
base: f07e426dad
head: 868e466247 (same as the claim)
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; 25 SKIPPED lines (no wave64 / heap windows / driver-cache test on this adapter). A first run on main 6bfb5c51 had the lib test binary end abnormally in a coherent-window restore test (address-space race between parallel tests, unrelated to this diff); the rerun is clean
review: none after reading the whole diff (64 lines). The VOP3 guard in patch_ps_32bit_exports tested the field "CLMP", which the RDNA2 spec does not have (the field is "CLAMP", rdna2_spec.rs), so a clamped v_cvt_pkrtz_f16_f32 was patched to export raw v6; the one-word fix is right. The new test runs its body on HLSL translate() and direct DXIL (translate_pixel_rt32 + validate), needs no GPU, and asserts both the unclamped (still patched) and clamped (not patched) cases, so it fails without the fix. Scope: one fix plus its test.
performance: no cost by default: a compile-time condition in the translator that declines a patch for clamped VOP3 pkrtz; the emitted shader keeps the real conversion in that case, so a possible GPU cost is one cvt in affected pixel shaders. Reasoned, not measured. Translator source change: testers re-translate shaders.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report

<!-- greyfinch-sync:ivall/xcl:comment:7325735727 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3600#issuecomment-7325735727). Originally posted by [throny](https://github.com/throny) on 2026-12-01T21:05:41Z. --- merge-check base: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c head: 868e466247463f7292036d94e367f13104d63f44 (same as the claim) merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; 25 SKIPPED lines (no wave64 / heap windows / driver-cache test on this adapter). A first run on main 6bfb5c51 had the lib test binary end abnormally in a coherent-window restore test (address-space race between parallel tests, unrelated to this diff); the rerun is clean review: none after reading the whole diff (64 lines). The VOP3 guard in patch_ps_32bit_exports tested the field "CLMP", which the RDNA2 spec does not have (the field is "CLAMP", rdna2_spec.rs), so a clamped v_cvt_pkrtz_f16_f32 was patched to export raw v6; the one-word fix is right. The new test runs its body on HLSL translate() and direct DXIL (translate_pixel_rt32 + validate), needs no GPU, and asserts both the unclamped (still patched) and clamped (not patched) cases, so it fails without the fix. Scope: one fix plus its test. performance: no cost by default: a compile-time condition in the translator that declines a patch for clamped VOP3 pkrtz; the emitted shader keeps the real conversion in that case, so a possible GPU cost is one cvt in affected pixel shaders. Reasoned, not measured. Translator source change: testers re-translate shaders. verdict: safe to merge hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report
throny commented 2026-12-01 22:07:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T22:07:26Z.


Merged at the checked head after a combined trial of #3600, #3493, #3608 and #3607 on main f07e426d (RTX 4080 16 GB, cargo test --workspace --no-fail-fast -- --test-threads=4: 2909 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks each.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7327301605 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3600#issuecomment-7327301605). Originally posted by [throny](https://github.com/throny) on 2026-12-01T22:07:26Z. --- Merged at the checked head after a combined trial of #3600, #3493, #3608 and #3607 on `main` `f07e426d` (RTX 4080 16 GB, `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2909 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks each. AI use: Claude Code (Claude Opus 5.5).
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
xcl-dev/xcl!3600
No description provided.