Recompiler: v_sin / v_cos reduce the argument in turns before scaling (#796) #818
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!818
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-818"
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?
@upipibi on GitHub · 2026-11-24 05:53 UTC · original
upipibi:fix/sincos-turns→main· +186 −11 · 6 files · 3 commits · openv_sin_*/v_cos_*take their argument in turns. XCL emittedsin(x * 6.2831853f), which rounds the phase away at radian scale before any reduction, so the error grows with the number of turns. ±MaxFloat overflows the product to infinity and gives NaN. The RDNA 2 ISA's functional examples (p.142 for f32, p.149 for f16) reduce in turns and accept every finite input:V_COS_F32(0.25) = 0,V_SIN_F32(-MaxFloat) = 0,V_COS_F32(-MaxFloat) = 1,V_SIN_F16(0x7bff) = 0. Mesa's ACO drops its explicitv_fractfrom GFX9 on ("before GFX9, v_sin_f32 and v_cos_f32 had a valid input domain of [-256, +256]").Fixes #796.
What is in it
crates/xcl/src/gpu/recomp/emit.rs: HLSL helperssin_turns/cos_turns(andtrig_nonfinite), used byv_sin_f32,v_cos_f32,v_sin_f16andv_cos_f16.x - trunc(x), which is exact in f32, and then scale.sin(-0) = -0.0xFFC00000and a NaN input gives itself, quiet. Without that guard, DXC's relaxed float math turnedsin(±inf)into 0 on the 3070 (inf - trunc(inf)was lost).crates/xcl/src/gpu/recomp/tests.rs: GPU testgpu_sin_cos_reduce_in_turns.sin/cos(2π·(x - trunc(x))), within 2^-16 (f32) or 2^-10 (f16) absolute.crates/xcl/src/gpu/dxil/prelude.rs,lower_valu.rs,lower_wide.rs(f73e6ea): the direct DXIL translator reduces in turns the same way.Lw::trig_turnsmirrorssin_turns/cos_turns/trig_nonfiniteop for op, for f32 and f16. Without it,lower_dxil::tests::f32_programs_on_the_gpu, which compares the two paths register for register, failed atv_sin_f32(-0.5)(direct -0 against HLSL +0), as DavidM1911 found. The direct cache keys on thegpu/dxilsources, so no version bump.Tested
NVIDIA, run by DavidM1911 (comment, thanks) at
f73e6eamerged with currentmain: RTX 3060 Ti, Windows 11,cargo test -p xcl --lib: all passed, 0 failed, 27 ignored; the earlierf32_programs_on_the_gpuwave32 failure is gone.AMD, run by oni-swr (comment, thanks) at the exact head
f73e6ea, as-is: Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Windows 11, debug, DXC 1.9.0.5512.gpu_sin_cos_reduce_in_turns(HLSL path),lower_dxil::tests::f32_programs_on_the_gpu(direct path; its f32-conversion case was SKIPPED on wave32 and wave64, per-lane form refused) and the newsin_and_cos_reduce_the_argument_in_turnspass;cargo test --workspace --no-fail-fast -- --test-threads=4: 1243 passed, 2 failed, 46 ignored. The 2 failures are not this PR's:fuzz_validate_and_gpu_1fails the same way onmain1a0bbe3there, andgpu_image_get_resinfo_past_last_levelcomes from this head's base, which predatesmain's fixea088a5. Only the default translator selection was run, so the two paths are covered by the two test functions, not by forcingXCL_DIRECT_DXIL.At
f73e6ea(this PR rebased ontomain426a5a74, plus the direct DXIL commit), RTX 3070 (616.56):lower_dxil::tests::f32_programs_on_the_gpupasses 3 of 3 (it failed 3 of 3 with the previous head merged ontomain96331383),f16_programs_on_the_gpupasses, andgpu_sin_cos_reduce_in_turnspasses withXCL_DIRECT_DXIL=0and=1.gpu_suite (--skip gpu_sparse_vram): 144 passed, 0 failed on both paths (main426a5a74: 143).NVIDIA GeForce RTX 3070, driver 616.56, AMD Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0, debug, DXC 1.8.2502.11
cargo test --workspace --no-fail-fast -- --test-threads=4on baf0639: 705 passed, 0 failed, 41 ignoredSKIPPED GPU tests:
gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64)The new test fails on
main(e50836b) with 21 mismatches, among themsin(100000.125) = 0.6716,sin(±MaxFloat)/cos(±MaxFloat)= NaN,cos(-0.75) = -1.9e-7,sin(12345.5) = 0.0061,V_SIN_F16(0x7bff) = 0xA648,V_COS_F16(0x7bff) = 0x3BFF. It passes with the change.Open PR #643's
gpu_transcendental_f32/_f16(its head232ee73, applied locally on top) pass both onmainand with this change. Worst errors on the 3070 from its own output:main#643 can keep its tolerances. With this PR its 2^-10 absolute allowance for sin / cos could tighten to the D3D class it uses for the others, and its skip of inputs above 256 turns could go.
Regression run
Pair for the current head
f73e6eaagainstmain426a5a7, run by ThiagoAlexsander on the retail title (comment, thanks): RTX 5080 16 GB,scripts/smoke.ps1 -Seconds 60. Pasted as printed.Earlier pair, for an earlier head, from Kalmarv's run (https://github.com/ivall/xcl/pull/818#issuecomment-7137037491), thanks:
main:
PR:
Related: #2168. The HLSL path's default fast-math changes
v_sin/v_cosresults on AMD, and the HLSLsin_turns/cos_turnshelpers this PR adds aren't markedprecise, so an AMD run of this head mattered; oni-swr's run above passes these tests.Not tested
XCL_DIRECT_DXIL); native wave64. The test's wave64 program ran in the split form on the 3070.sin(0.5)) and at a negative whole turn: the ISA prints none. This PR returns +0, matchingV_SIN_F32(-MaxFloat) = 0x00000000.v_sin/v_cosnow does atrunc, a subtraction and two compares more.AI use
🤖 Generated with Claude Code
@mastrr9 on GitHub · 2026-11-24 06:02 UTC · original
Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head
baf06391502166ef0ccec3204cd143ee3f10f10a.Code Review
x - trunc(x)) before scaling by2π, exact zero handling at whole/half turns (sin) and quarter/three-quarter turns (cos),sin(-0) = -0preservation, and explicit bit-leveltrig_nonfinitehandling (±inf -> 0xFFC00000, quiet NaN preservation) avoiding DXC relaxed-float folding ofinf - inf.gpu_sin_cos_reduce_in_turnscovers all RDNA2 ISA examples for both f32 and f16 and passes on RTX 5080. No issues found.Tested
617.42/32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll),rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC from Windows SDK10.0.26100.0, debug build.cargo build --workspace && cargo test --workspace -- --test-threads=4ok, executed on RTX 5080, not skipped):gpu::recomp::tests::gpu_sin_cos_reduce_in_turnsgpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)Not tested
AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.
@MesshM on GitHub · 2026-11-24 06:06 UTC · original
Test run of
baf06391502166ef0ccec3204cd143ee3f10f10aon AMD RDNA4. I merged it onto currentmainbeaa245locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 714 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 673 passed, 0 failed, 21 ignoredSKIPPED; the newgpu_sin_cos_reduce_in_turnspasses.Review: Reducing in turns (
x - trunc(x)) before scaling gives exact zeros at 0 / ±0.5 (sin) and 0.25 / 0.75 (cos) and 0 for |x| past 2^23, as the ISA's functional examples say, and ±inf / NaN give a quiet NaN while the sign of a zero input is kept. #643's transcendental test (open) leaves out |x| > 256, so the two do not conflict. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@Anon64 on GitHub · 2026-11-24 06:37 UTC · original
Regression runs for this PR's head
baf0639and for its basemaine50836b, on a retail title (same title, 60 s each), made withscripts/smoke.ps1(release, clean tree at each commit) and pasted unedited, for Regression run.main:
this PR:
Tested
Not tested
Report 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|AMD + native wave64 datapoint — the axis your row lists as not tested (your wave64 program ran in split form on the 3070).
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 (noXCL_SPLIT_WAVE64). Same rig as my Linux rows in #42 / #718 / #772.6|
7|Merged state: head
baf063915onto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 707 passed, 7 failed, 41 ignored (17 suites) — exactly this rig's stable Wine-lane failure set (my #42 row), nothing new, and the #718 trio stayed clean this run. Your test passes on RDNA3 native wave64:gpu_sin_cos_reduce_in_turnsok.10|
11|(First run of this head aborted mid-suite from a transient X/Wine hiccup on my desktop, not a test failure — rerun above completed all 17 suites.)
12|
13|Not tested: retail titles (none here), Windows, RDNA4.
14|Counts only, no game data.
15|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@upipibi on GitHub · 2026-11-24 10:27 UTC · original
Updated
gpu_sin_cos_reduce_in_turnswith luckyteagirl's native RX 6800M (gfx1031) results from https://github.com/ivall/xcl/issues/796#issuecomment-7123464342. The 0.125-turn rows come from the GPU's sine approximation and are compared within 1 ulp. This also fixes f16 ±Inf, which gave0x7FFFand now gives0xFE00, ince03d3e. Full suite on an RTX 3070 (driver 616.56): 705 passed, 0 failed, 41 ignored.AI-assisted (Claude Code).
@guinpereira on GitHub · 2026-11-24 11:30 UTC · original
Test report: NVIDIA RTX 5060 Ti (wave32), head
ce03d3e: 706 passed, 0 failed, 41 ignored; the newgpu_sin_cos_reduce_in_turnsruns and passesTested
stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (Windows SDK 10.0.26100.0). Debug build, noXCL_SAMPLE_*.ce03d3eas is (basee50836b, not rebased on currentmain), clean tree.cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 706 passed, 0 failed, 41 ignored (lib: 664 passed, 21 ignored).SKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware, the same as onmain.cargo test -p xcl --lib gpu_sin_cos_reduce_in_turns -- --nocapture: passed, noSKIPPEDline, so it ran on the GPU (wave64 program split into 32-lane halves). All f32 and f16 rows match, including the 1-ulpUlpsrows on NVIDIA'ssin()/cos().Not tested
scripts/smoke.ps1(no title on this machine).main.AI use: Claude Code (Claude Opus 5.5) ran the commands above and wrote this report. No code changes.
@Cecerw on GitHub · 2026-11-24 13:45 UTC · original
Tested on NVIDIA (32-lane waves): passes
ce03d3emain47efa2ece03d3e, no local changes:.\scripts\test.ps1(cargo test --workspace -- --test-threads=4): 705 passed, 0 failed, 41 ignoredmain47efa2e(no conflicts): 742 passed, 0 failed, 41 ignoredgpu_sin_cos_reduce_in_turns: ok in both, so the NVIDIA driver'ssin/cosstay within the test's one-ulp rowsNot tested: AMD, any title (no smoke run).
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@upipibi on GitHub · 2026-11-24 14:05 UTC · original
@eizispark @Anon64 thanks for the smoke pairs. Both were made on
baf0639. After them I pushedce03d3e(f16 sin / cos of ±Inf give0xFE00, from the native RDNA2 results), so the description check needs a PR block once03d3e. If either of you has a minute, one 60 ssmoke.ps1run ofce03d3ewould do; yourmainblocks can stay. Thanks @Cecerw for the RTX 3060 Ti suite run above.AI-assisted (Claude Code).
@Kalmarv on GitHub · 2026-11-24 16:03 UTC · original
Regression pair for
ce03d3eagainstmaine50836b(this PR's base), for the Regression run section. Both runs pass: no device removal, no crash, 95 % ofmain's frames, 100 % of its peak commit.Tested
scripts/smoke.ps1, the same retail title for 60 s each:mainate50836b(this PR's base, 67 commits behind today'smain) first, then this PR's head, one after the other on the same machine.maine50836b:this PR,
ce03d3e:Presents per 2 s over the whole run (from the
activity (2 s)lines):main: 0 23 60 50 33 55 60 60 60 60 60 60 60 60 59 45 53 61 60 60 54 47 40 8 0 8 5 11 23 43Both runs are at the 60-a-window cap most of the time. The 63-frame gap is two single dips in the PR's run (36 against 50 at 6-8 s, 39 against 60 at 14-16 s) and a slow phase from about 44 s that both runs have (111 frames in the last 16 s against 138). On #1244 today the same slow phase gave one pair 87 % and the next 103 %, so one pair can't separate a few percent from run-to-run spread.
Not tested
v_sin/v_coson the frames the run reaches: not counted.AI use: Claude Code (Claude Opus 5.5)
@eizispark on GitHub · 2026-11-24 06:32 UTC · original · edited 2026-11-24 17:48 UTC
Updated hardware check for new head
ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd(previous check:baf0639; verified clean merge with currentmain9e3831e): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace --no-fail-fast -- --test-threads=4:705 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none), includinggpu::recomp::tests::gpu_sin_cos_reduce_in_turns(with thehwf16±Inf -> 0xFE00and 1-ulp native RDNA2 rows) and both native-wave64 tests (gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware,console_wave64_compute_through_the_pso_hook_dispatch_and_read_back)Regression run
main(9e3831e1f570d3646e53ab753b19ec07eb8f1485):PR (
ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd):Not tested
XCL_D3D12_DEBUG=1; gameplay past the menusAI use
ce03d3eand updated this report.@JJAutoCompare on GitHub · 2026-11-25 01:40 UTC · original
Tested
The checked-in
gpu_sin_cos_reduce_in_turnstest passed through HLSL and DXC (cs_6_6) on clean PR #818 headce03d3ee92abb6ba32a4b55efbc96a16ebc63fddfor #796. GitHub still showed the PR open at that head after the run.Intel Arc A770 driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, and the unoptimized Cargo test profile with debug info disabled. The test logged dxcompiler and dxil 1.9.2609.5. The A770 capability probe reported an 8–32 lane range. The test used split wave64 and checked 64 logical lanes.
The prebuild exited 0 outside the GPU lock. The following block ran in
powershell.exe -NoProfile -ExecutionPolicy Bypasswith the same TEMP, TMP and XCL settings.0xFFC00000for f32 and0xFE00for f16.Not tested
Native wave64, the old lowering on Arc, other GPUs, the full workspace suite, and retail-title smoke runs.
AI use
Codex in T3 Code (
gpt-6.2-sol) verified the checkout, ran the test, and wrote this report.@DavidM1911 on GitHub · 2026-11-25 10:50 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1 real failure, deterministic (also fails--test-threads=1, 1098/1):A sign-bit difference (0x80000000 = -0.0/negative NaN vs +0.0) in an f32 transcendental on the GPU — likely a
v_cvt/v_rsq/v_rcpsign or NaN propagation regression. Needs a fix before merge.— Devin
@upipibi on GitHub · 2026-11-25 11:43 UTC · original
@DavidM1911 Thanks, reproduced and fixed. On an RTX 3070 the test failed 3 of 3 with #818 merged onto
main(lane 0 v9: 0x80000000 against 0x0) and passed 3 of 3 onmain.Cause: #818 changed only the HLSL path, which now reduces
v_sin/v_cosin turns (sin_turns/cos_turns). The direct DXIL translator still computedSin(x * 6.2831853), andf32_programs_on_the_gpucompares the two paths register for register. Lane 0 takesv_sin_f32(-0.5): half a turn. The HLSL helper returns an exact +0 there, while the old direct form gave -0 on NVIDIA.Fix:
f73e6ea(rebased ontomain426a5a74) addsLw::trig_turnsingpu/dxil/prelude.rs, used for f32 (lower_valu.rs) and f16 (lower_wide.rs). It mirrors the HLSL helpers op for op: thex - trunc(x)reduction, exact zeros at whole and half turns (sin) and quarter turns (cos), sin(±0) = x, ±inf →0xFFC00000, quieted NaN, and the f160xFE00for ±inf. The direct cache keys on thegpu/dxilsources, so no version bump is needed.Tested on the RTX 3070 (616.56):
f32_programs_on_the_gpupasses 3 of 3,f16_programs_on_the_gpupasses, andgpu_sin_cos_reduce_in_turnspasses withXCL_DIRECT_DXIL=0and=1.gpu_suite: 144 passed, 0 failed withXCL_DIRECT_DXIL=0and=1(main426a5a74: 143).One thing nobody has measured, as far as I can find: which zero RDNA2 itself returns at a negative half turn. Both paths now give +0 there, following the HLSL helper.
AI-assisted (Claude Code). Synthetic tests only.
@oni-swr on GitHub · 2026-11-25 12:29 UTC · original
AMD synthetic GPU run of
f73e6ea8bd94f9e143dd33933152bf20e2f9608b(exact PR head, tested as-is, not merged ontomain; the diff touches the recompiler, the direct-DXIL lowering and their tests only). Synthetic Cargo tests only: no retail title, nosmoke.ps1.Tested
Compiling xcl v0.1.0came from the PR checkout.cargo build --workspace, thencargo test -p xcl --lib <name> -- --nocapturefor each:gpu::recomp::tests::gpu_sin_cos_reduce_in_turns(the HLSL path): ok.gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(the direct-DXIL path): ok. It printed 2SKIPPEDlines for the f32 conversions case (wave32 and wave64, per-lane form: refused, unsupported V_CVT_F16_F32). The other cases ran.gpu::recomp::lower_dxil::tests::sin_and_cos_reduce_the_argument_in_turns(new in this PR): ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 1243 passed, 2 failed, 46 ignored, 7 distinctSKIPPEDlines. These are not coverage: f16 per-lane form refused (4), f32 conversions per-lane form refused (2) andheap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1. It fails the same way onmain1a0bbe3on this machine.gpu::recomp::tests::gpu_image_get_resinfo_past_last_level. This head does not containmain's commitea088a5("image_get_resinfo past the last level gives 0 sizes on AMD too"), so it is probably fixed by rebasing. I did not run the merged tree.Not tested
scripts/smoke.ps1regression run, NVIDIA, Intel, Wine/vkd3d.main.AI use
Claude Code, Claude Sonnet 5.5 ran the tests, checked the diff, and wrote this report.
@DavidM1911 on GitHub · 2026-11-26 00:23 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlierf32_programs_on_the_gpuwave32 transcendental failure is fixed.Thanks!
— Devin
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.