Skip to content

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

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Foniass:fix/recomp-ps32-export-clamp
Dec 1, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Foniass:fix/recomp-ps32-export-clamp

Conversation

@Foniass

@Foniass Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

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 868e466: 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 6bfb5c5 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

patch_ps_32bit_exports turns a compressed `exp mrtK` fed by
v_cvt_pkrtz_f16_f32 into an uncompressed export of the conversion's raw
f32 sources, and must decline the patch when the VOP3 form carries an
input or output modifier. It looked the clamp bit up as "CLMP", but the
encoding table names the ENC_VOP3 field "CLAMP"; field_value returns
None for an unknown name, which the lookup turns into 0. So a clamped
conversion was never declined and its clamp was dropped: a render target
with a 32-bit format received the unclamped f32 value instead of the
value the title clamped to [0, 1].

The new test exports a VOP3 pkrtz of a large float to a 32-bit MRT: it
is patched without CLAMP and left alone with CLAMP, in both the HLSL
and the direct DXIL backends. It fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 6bfb5c5
head: 868e466
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 Recompiler: patch console FP16 PS exports for 32-bit render targets #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)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 868e466

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: f07e426
head: 868e466 (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 6bfb5c5 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

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny
throny merged commit e572f89 into xcl-dev:main Dec 1, 2026
3 checks passed
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants