Recompiler: v_med3_f32 / _f16 with a NaN operand give the min of the others (#678) #686
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!686
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-686"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@joeypercia on GitHub · 2026-11-24 03:29 UTC · original
joeypercia:recompiler-med3-nan→main· +54 −3 · 4 files · 3 commits · openWith a quiet NaN operand the hardware's
v_med3_f32/v_med3_f16returnv_min(v_min(s0, s1), s2), the smaller of the two other operands, as LLVM'samdgcn_fmed3folding documents (AMDGPUInstCombineIntrinsic.cpp).med3fcomputedmax(min(a, b), min(max(a, b), c)), which givesmax(a, b)for a NaN incandb/afor a NaN ina/b. It now takes the min of the others when an operand is NaN; the median path is unchanged. Fixes #678.What is in it
crates/xcl/src/gpu/recomp/emit.rs:med3f(used byv_med3_f32andv_med3_f16) handles a NaN operandcrates/xcl/src/gpu/recomp/tests.rs:gpu_med3_with_a_nan_operand_is_the_min_of_the_others, f32 and f16: a NaN in each position with both operand orders, the clamp form, two NaNs, and a no-NaN controlcrates/xcl/src/gpu/dxil/prelude.rs(by @milesah3ad, from the parity sweep on #1269): the direct DXIL backend'smed3fgets the same NaN rule, so the test passes withXCL_DIRECT_DXIL=1toocrates/xcl/src/gpu/recomp/lower.rs(by @milesah3ad):check_f32_three_sourceexpects the NaN rule; with this PR on currentmain,lower_dxil::tests::f32_programs_on_the_gpufailed on both paths without itmain(aa9ab8a), which now has the direct backendTested
cargo test --workspace --no-fail-fast -- --test-threads=2on8c60272: RTX 4070 Ti 1083 passed, 0 failed, 46 ignored; RDNA2 1082 passed, 1 failed, 46 ignored. The failure isgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 540,res[833] = 0x7, CPU0x6, no med3 in the program); it fails the same way onmainaa9ab8a(2 runs of 2)XCL_DIRECT_DXIL=1on both GPUs:gpu_med3_with_a_nan_operand_is_the_min_of_the_othersandlower_dxil::tests::f32_programs_on_the_gpupassSKIPPED: RTX 4070 Ti the wave64 / per-lanelowerandlower_dxilGPU tests (no wave64); RDNA2 the mesh tests (no mesh shaders); both: thef16_programs_on_the_gpuper-lane forms refused by #1426 (V_MUL_F16/V_PK_MUL_F16/V_CVT_F16_F32)emit.rsback tomain, the new test fails: 8 wrong (all four non-clamp NaN positions, f32 and f16) on the RTX 4070 Ti and on RDNA2gfx1031, rawv_med3_f32/v_med3_f16on the hardware): a quiet NaN in any position gives the min of the other two, as this PR does; signaling NaNs differ with the IEEE mode bit on (src0/src1sNaN givessrc2); sNaN cases are left out (see Not tested)Regression run
RTX 4070 Ti (driver 616.56), release builds, 60 s each,
scripts/smoke.ps1 -Title retail-titleon the newer retail title, mainaa9ab8aand this PR's head8c60272(no uncommitted changes). (@Anon64's earlier runs, on an RTX 3060 for the previous head3115aae, were equally clean.)main:
PR:
Not tested
v_med3with a NaN operand outside the clamp form. They use the instruction a lot: itsshaders.rpf(xcl shaders --json, 26 503 shaders) has 58 722v_med3_f32in 8 050 shaders (and 21v_med3_f16). The 60 s runs above show no regression but cannot tell whether such a NaN occurs.AI use
@lordon1a on GitHub · 2026-11-24 03:58 UTC · original
Independent test report on
3115aae:Tested
616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200),rustc 1.100.0(x86_64-pc-windows-gnullvm), debug build, DXC1.9.2609.5(01b62ad4)cargo test -p xcl --lib gpu_med3_with_a_nan_operand_is_the_min_of_the_others -- --nocapture0.56s(gpu_med3_with_a_nan_operand_is_the_min_of_the_othersok)Not tested
AI use
3115aaein a detached worktree, audited the diff, ran the test, and posted this report.@ItsMrDubey on GitHub · 2026-11-24 04:57 UTC · original
Test report for
3115aae56b659ada6714fac41628b364dbedbd37(this PR's head)Tested
stable-x86_64-pc-windows-msvc), debug; DXC 1.9.2602.17 from Windows SDK 10.0.2610016 test binaries: 692 passed, 1 failed, 41 ignored. Same machine,
main64b3f3559: 700 passed, 1 failed, 41 ignored.This PR's tests:
gpu::recomp::tests::gpu_med3_with_a_nan_operand_is_the_min_of_the_others: okFailures:
hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memoryfails on this machine on every run, on this PR's head and onmain64b3f3559alike (5 of 5 reruns onmain), so it is not from this PR. #650 fixes it here.16 test binaries instead of
main's 17 because this branch predatestests/sparse_reinit.rs; nothing crashed.SKIPPED (no wave64 on this GPU):
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.AI use: Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report from their output.
@zhouzhidong3-hash on GitHub · 2026-11-24 05:30 UTC · original
Independent Release result at 3115aae56b659ada6714fac41628b364dbedbd37. On NVIDIA RTX 5070 (driver 591.86), Rust 1.100.0 MSVC and DXC 1.8.2502.11, the unmodified gpu_med3_with_a_nan_operand_is_the_min_of_the_others test passed in an optimized build. Command:
cargo test --locked --release -p xcl --lib gpu_med3_with_a_nan_operand_is_the_min_of_the_others -- --nocapture. One passed, zero failed, 673 filtered out, no runtime skip. Scope: synthetic f16/f32 quiet-NaN and control cases in this fixture. No signaling NaNs, retail smoke or full Release suite tested. OpenAI Codex ran the check and drafted this report.@luckyteagirl on GitHub · 2026-11-24 05:59 UTC · original
Native RDNA2 signaling-NaN check for #678
I measured
v_med3_f32andv_med3_f16on a Radeon RX 6800M (gfx1031), Windows 11 build 26200, display driver30.0.13002.13003, and AMD OpenCL3302.6 (PAL,LC). The kernel passed raw input bits to both instructions. It changed and read back only the IEEE bit ofHW_REG_MODE, then restored the original bit. The default readback was 1.11src0orsrc1, finite operands 1 and 2 in both orders1src2src2, finite operands 1 and 2 in both orders1For example,
(sNaN, 1, 2)gave1with IEEE off and2with it on.(2, 1, sNaN)gave1with it off and0x7FC00011(f32) or0x7E11(f16) with it on, from input0x7F800011or0x7C11. The numeric control(5, 1, 2)returned2in both modes. Four work-items per case agreed.This confirms the quiet-NaN behavior in the PR and gives separate signaling-NaN cases to use if IEEE-mode handling is extended.
Not tested
The PR's translated HLSL, other GPUs, and combinations with multiple signaling NaNs plus an exceptional third operand.
AI use
OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report.
@Anon64 on GitHub · 2026-11-24 06:31 UTC · original
Regression runs for this PR's head
3115aaeand for its basemain91f9a5e, on a retail title (same title, 60 s each), made withscripts/smoke.ps1(release) and pasted unedited, for Regression run.main:
this PR:
Tested
cargo build --release -p xclat each commit, clean treeNot tested
v_med3with a NaN operand; this is a regression check onlyReport written with Claude Code (Claude Opus 5.5) from runs on this machine.
@SlopTart on GitHub · 2026-11-24 06:40 UTC · original
2|
3|Release-build suite datapoint — the axis your row lists as not tested (and your regression runs were pending).
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross
x86_64-pc-windows-gnu, release profile,XCL_NETWORK=0, native wave64. Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
3115aae56onto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 10 failed, 41 ignored (17 suites). The 10 = this rig's 7 stable Wine-lane failures (my #42 row) + the known #718 flaky trio (~2 of 5 hit rate at threads=4, PR-independent). Nothing new fails. Your new test passes on RDNA3:gpu_med3_with_a_nan_operand_is_the_min_of_the_othersok.10|
11|Not tested: retail titles (none here, so no title regression run either), Windows, sNaN input payloads.
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@Diskuss on GitHub · 2026-11-24 08:36 UTC · original · edited 2026-11-24 09:29 UTC
Tested on AMD Radeon RX 9070 XT (RDNA4) at
3115aae56b659ada6714fac41628b364dbedbd37AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029; Ryzen 7 5700X3D; 32 GB RAM; Windows 11 Pro build 26300.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build.
Tested:
cargo build --workspace: OK.cargo test --workspace --no-fail-fast -- --test-threads=4: 693 passed, 0 failed, 41 ignored.cargo test -p xcl --lib gpu_med3_with_a_nan_operand_is_the_min_of_the_others -- --test-threads=1: 1 passed, 0 failed.1ec4c98gave 715 passed, 0 failed, 41 ignored. The lower passed count is expected: this branch is 34 commits behind main.Not tested: retail title /
scripts/smoke.ps1(no game files), release build.Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.
Correction (hidden skips): "0 SKIPPED" above means no
SKIPPEDline appeared in the normal run. A later-- --nocapturerun on this machine shows that two tests skip silently, because the D3D12 debug layer is not installed (no Graphics Tools /d3d12SDKLayers.dll). libtest captures their output, so they show asok:e2e::test_title_draws_with_a_root_signature_under_the_debug_layerandtexture_states::uploads_start_from_each_subresources_state. Neither is related to this change, and all other GPU tests ran on the RX 9070 XT.@Cecerw on GitHub · 2026-11-24 13:45 UTC · original
Tested on NVIDIA (32-lane waves): passes
3115aaemain47efa2e3115aae, no local changes:.\scripts\test.ps1(cargo test --workspace -- --test-threads=4): 693 passed, 0 failed, 41 ignoredmain47efa2e(no conflicts): 742 passed, 0 failed, 41 ignoredgpu_med3_with_a_nan_operand_is_the_min_of_the_others: ok in bothNot tested: AMD, any title (no smoke run).
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@milesah3ad on GitHub · 2026-11-25 01:01 UTC · original
The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269:
gpu_med3_with_a_nan_operand_is_the_min_of_the_othersandlower_dxil::tests::f32_programs_on_the_gpupass withXCL_DIRECT_DXIL=1with the patch below. Without it they fail on the direct path.med3fingpu/dxil/prelude.rswasmax(min(a, b), min(max(a, b), c))for every input. The patch adds your NaN rule there: any NaN operand givesmin(min(a, b), c). A second commit updates a test that landed onmainafter this PR:check_f32_three_sourceinrecomp/lower.rscomputes the expected med3 with Rust'smin/max, which ignore a NaN. With this PR merged ontomain,lower_dxil::tests::f32_programs_on_the_gpufailed on both paths (lane 0: 4.0 against an expected 16.0), so it needs that update whether or not you take the direct fix.How to take it: this PR predates the direct backend on
main, so rebase it ontomainfirst (your commit rebases cleanly onto7994cd1), thengit amthe patch below. Feel free to fold it into your PR with aCo-Authored-By: milesah3ad <[email protected]>line. I didn't open a separate PR, so this doesn't add another review.patch (2 commits, for
git am)Tested
main7994cd1plus this patch:gpu_med3_with_a_nan_operand_is_the_min_of_the_othersandlower_dxil::tests::f32_programs_on_the_gpupass with and withoutXCL_DIRECT_DXIL=1.cargo test -p xcl --lib --no-fail-fast -- --test-threads=4onmain7994cd1with #587, #686, #1159 and #1296 all merged and the four direct patches applied: 948 passed, 4 failed, 25 ignored, the same in both settings. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3, which fail the same way on plainmainhere (944 passed, 4 failed). The +4 are the PRs' own tests.Not tested: wave64 hardware (the wave64 cases SKIP here), AMD, any title, the full workspace suite (lib only).
AI use: Claude Code (Claude Opus 5.5) wrote the fix and ran the tests on the machine above. I checked the results.
@JJAutoCompare on GitHub · 2026-11-25 01:41 UTC · original
Tested
Intel Arc A770 (driver 32.0.101.9175) on clean PR head
8c6027287752346710624075516b980feb2e77f0. I verified the live head before and after the run. The host was an AMD Ryzen 7 3800X running Windows 11 Enterprise Evaluation 26200.9974 with Rust 1.100.0 (x86_64-pc-windows-msvc). The test process logged dxcompiler 1.9.2609.5 (01b62ad4) and dxil 1.9.2609.5.I prebuilt outside the GPU lock in the unoptimized test profile with
CARGO_INCREMENTAL=0,CARGO_PROFILE_DEV_DEBUG=0andCARGO_PROFILE_TEST_DEBUG=0. I ran the resulting libtest executable under the shared Arc lock withXCL_ADAPTER=A770,XCL_DXC_DIRset to the verified x64 DXC directory, andXCL_DIRECT_DXILunset.1 passed, 0 failed, 0 ignored, 0 skipped. The wave32 HLSL/DXC dispatch matched all ten bit-exact results for each of
v_med3_f32andv_med3_f16. The cases cover a quiet NaN in each source position with both orders of the finite operands, the clamp form, a negative finite minimum, two quiet NaNs with one finite operand, and a finite median control. Libtest filtered out 1,059 tests.Not tested
Signaling NaNs, direct-DXIL parity, native or split wave64, other GPUs, the full workspace suite, and retail smoke runs.
AI use
Codex in T3 Code (
gpt-6.2-sol) ran the checked-in test and wrote this report.@raylitebull on GitHub · 2026-11-25 02:03 UTC · original
CI \Build and test\ passed on \
8c60272, and the direct DXIL \med3f\ + \lower.rs\ expectation updates look clean.\n\nRemaining before merge:\n1. Fix/re-run the \PR description\ check (none reported yet on branchecompiler-med3-nan\ / \8c60272).\n2. Re-verify on an AMD GPU on the updated head \
8c60272\ (previous AMD runs covered \3115aae; current \8c60272\ has RTX 5080 + Arc A770).@DavidM1911 on GitHub · 2026-11-25 12:10 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.