shader: lower gfx1013 v_sin_f32 and v_cos_f32 in pixel_aot #351
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/357"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-21T23:13:07Z.
Change
Advances shader translation coverage. This is an independent problem:
v_sin_f32andv_cos_f32are the remaining unported f32 transcendentals inpixel_aot. #274 lists them as left for a separate change, and no open PR lowers them. There is no prerequisite PR. The shared interface is theALUtable and the VOP arithmetic pattern intools/pixel_aot.py, which #274, #288 and #310 also extend by name. Each adds names to the same pattern, so whichever lands later needs a one-line merge.Semantics. Both instructions take revolutions: sin(2πx) and cos(2πx). LLVM 15.0.7 (
SITargetLowering::LowerTrig) selectsllvm.sinas the instruction applied to x · 1/(2π). It adds afractonly for subtargets withFeatureTrigReducedRange, which are Southern, Sea and Volcanic Islands, not GFX9 or GFX10.Lowering.
turns(x)removes the nearest integer number of turns (x - round(x)) when |x| > 0.5. That is exact in binary32 and keeps the radian argument in [-π, π].sin32andcos32then call HLSLsinandcoson that argument times 2π.sincoserror to 0.0008 absolute only within [-100π, 100π].clampuse the existing single-source ALU path.Fixture
TRIG_BODY(tests/pixel_aot_check.py):v_sin_f32_e32,v_cos_f32_e32,v_sin_f32_e64with-|x|, andv_cos_f32_e64with-xandclamp.trig_referencereduces each input in double precision and asserts that every drawn reference lies at least 0.1 step from a boundary. The smallest margin is 0.127 steps.pixel_mismatchfor all four sets:(turns(value) * 6.28318548f)replaced with(value)(radians instead of turns).value * 2π. Its count is printed astrig_unreduced_mismatches.vmcnt(0)is rejected.check_binaryassembles the program with LLVM 15 and compares the decoded lowering.tests/form_coverage_check.pyasserts the four new forms (VOP1v_sin_f32,v_cos_f32; VOP3v_sin_f32_e64,v_cos_f32_e64) and that they add exactly four covered gfx1013 forms.tests/rdna2_tools_check.pyadds a scanner case. Withmain'stools/pixel_aot.py, that case fails ontranslator_accepted.Verification
Tested at
466106aonb860dd5. The head8206536changes onlydocs/experiments.md, recording the results below. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, Python 3.13. D3D12 debug layer enabled on both backends.max_absolute_error=0anddebug_errors=0 debug_warnings=0. The four reference draws pass, and both required controls mismatch on all four sets.ctest --preset dev --no-tests=error -E '_hardware$'gives 118 passed, 0 failed.bvh_wave64_warpandwave_shuffle_warpreport their usual capability skips.tests/form_coverage_check.py,tests/rdna2_tools_check.pyandtests/docs_links_check.pypass.pixel_aot_check.py binary,ffx_dispatch_aot_check.pyandrdna2_tools_check.pywith LLVM): passed at466106ain the fork'sWindows checksrun 44960410427, together with the Windows build-and-test and Linux Python jobs.After rebasing onto
4f6c39d(head5c8fe20), to resolve the conflicts with #362:docs/experiments.mdkeeps both paragraphs.tests/form_coverage_check.pydrops this PR's olds_nop not in ACCEPTEDline, since #362 now acceptss_nop, and keeps the trig assertions.pixel_aot_hardwareandpixel_aot_warppass again, withtrig_unreduced_mismatches=0/4.gpu_alias_lookup_writes_hardware, the RDNA 4 probe in #369, which fails the same way onmain.Measured, not established:
dx.preciseflag, unlikeSinandCos. One explanation is that both drivers fold it into their own revolution scaling. That is a hypothesis; the drivers were not inspected.sin(x * 2π), I can change it.Not measured: the instruction's own precision on a gfx1013 GPU, infinities, NaN payloads and the sign of a zero result. The quantized compare cannot observe the last.
Evidence and follow-up
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocuments the lowering, the draw and its controls.LowerTrigFeatureTrigReducedRangesincos)Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T02:49:10Z.
Rebased onto
1606f7base3d8ffaand347bfe6. The conflicts were with thev_mad_f32/v_mac_f32support that landed onmain, and I kept both sides:ftz32/mad32helpers and theturns/sin32/cos32helpers;sin|cosandmad|macin the VOP opcode pattern;check_trig_drawsnext toaffine_coordinatesandcheck_affine_lod_draw.ctest --preset dev --no-tests=error -R pixel_aot -Vgivespixel_aot_hardware(RX 9070 XT) andpixel_aot_warppassed, withtrig_unreduced_mismatches=0/4as before. Fork CI run 44977654122 passed all three jobs, including the gfx1013 LLVM job.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-22T03:50:12Z.
Rebased onto
fb7547cto clear a conflict intests/pixel_aot_check.pywith the classification fixture that landed onmain. The resolution keeps both sides:main'sCLASS_BODYentry;check_trig_drawsnow runs right aftercheck_half_draw, whichmainmoved further down incheck_render.There are no other changes. Re-measured at
d7e23e9(same environment as the body):Full suite: 164 passed, 1 failed and 2 capability skips out of 167. The failure is
gpu_alias_lookup_writes_hardware(#369), the same as onmain.