Shaders: lower v_trig_preop_f64 argument reduction #2986
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2988"
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 Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T02:25:07Z.
Summary
Lower v_trig_preop_f64 by reading the selected 53-bit window of 2/pi, applying the large-input scale and packing both binary64 words with truncation. The table uses the measured 1184-bit RDNA2 prefix. All operations use i32 DXIL under VIctory's current f64 denormal model.
Verification
Sources: AMD RDNA2 ISA guide, RDNA2 table measurements, and hardware result rows.
AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:37:25Z.
Review: COMMENTED
Verified: correct Payne-Hanek window semantics — segment&31 *53 + max(0, exp-1077) indexes the 2/pi bitstream, the 1968 large-exp boost shifts by +128 (table clamp to the zero tail handles overflow), and the pack path normalizes the 53-bit window via leading-zero count with a truncate-toward-zero subnormal path. Exponent-only input handling is sound (inline consts are all below the shift threshold; abs/neg don't touch the exponent). The test rows pin the exact 1077 and 1968 boundaries plus sel=0x20 wrap and inf/NaN inputs.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:58:38Z.
Review: APPROVED
Code review on
9b0f44f0(static source & bit-exact integer model verification; emitted DXIL was not executed on hardware):crates/victory-shader/src/emit/lower.rs:6319wiresv_trig_preop_f64intocrates/victory-shader/src/emit/lower/trig_preop.rs:49-101, checking the destination register pair, masking the selector, bounding table loads/shifts (:158-230), and writing both output words under the active execution guard.semantics_tests.rs:3022.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T02:48:34Z.
Independent test report: Windows, software WARP only, synthetic inputs only. Not a code review.
Head
9b0f44f0c3d62470cb25a23b1d2a6c052ccc9c84; exact parent63bcca43c6a00a758510398fa43096ce7e4f7df0.Setup:
VICTORY_WARP=1,VICTORY_D3D12_WARP=1,VICTORY_DXILset to the Windows SDK 10.0.26100.0 x64dxil.dll(1.8.2502.11), and a dedicatedCARGO_TARGET_DIR. Before any dispatch,cargo test -j 4 --locked -p victory-gpu --features diagnostics --lib -- --exact host::tests::warp_adapter_accepts_only_software --nocapturereportedEnumWarpAdapter: vendor=0x1414, flags=0x2(software). WithVICTORY_WARP=1,Host::newtakes the WARP device for both ofcheck()'s hosts, so the "hardware" label in the output is also WARP. No physical GPU was used.Results (
cargo test -j 4 --locked -p victory-shader --lib -- <test> --exact --nocapture --test-threads=1):binary64_trig_preop_returns_the_argument_reduction_segmentemit::semantics_tests::(whole module)not lowered: GFX10 code at 0x44/0x48/0x58: v_trig_preop_f64 is not supported, 2/2 runsIndependent reference: I wrote a Python model from the RDNA2 ISA pseudocode. Its 2/π bits come from mpmath at 1600 bits of precision, not from the PR's table. The model's rules:
(S1 & 31) * 53 + max(0, exp - 1077)It matches all 48 rows of the PR's test exactly.
Sweep: 16,704 rows, with the expected values taken from that model:
Limitation: table length. If the model uses the full 1201-bit table that the ISA text gives (
(2/PI)[1200:0]), 144 of the 16,704 rows differ from this head's WARP output. Those are exactly the rows whose 53-bit window reaches past fractional bit 1184. Two examples: exp 1968–1975 with selector 5, and exp 2040–2047 with selector 4. In each case the head returns zeros for the low bits. Truncating the model's table to 1184 bits removes every mismatch, which matches the PR's documented 1184-bit measured table. I can't confirm on RDNA2 silicon which length is right. The PR's own rows don't distinguish the two lengths: all 48 match both. A measured hardware row whose window reaches past bit 1184 (for example exp 1968, selector 5) would pin it.Disclosure: tested with Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T03:05:14Z.
Thanks for checking both tables. I also compared the 96 published trig results in AnyPS5 #447. Both models match those cells. The width comes from its separately reported Radeon 660M end-of-table sweep.
313acc3 adds three model-derived cases that distinguish the widths. I ran the same fixture on Agility WARP with the production table and with a temporary 1201-bit table.
The production table passed all 106 cases. The extended table failed these three cases in each modifier form. The table here contains model and WARP results. Direct RDNA2 observations for these three input pairs would provide a separate check of the reported tail width.
Original hardware sweep
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:44:30Z.
Automated triage for the maintainers.
Verdict: merge candidate. This lowers
v_trig_preop_f64, whichmainrefuses, in a newemit/lower/trig_preop.rs. It's a new capability, and the evidence is stated: the RDNA2 ISA pseudocode plus published RDNA2 hardware rows.The lowering reads a 53-bit window of 2/pi starting at
(sel & 31) * 53 + max(0, exp - 1077), adds the +128 scale whenexp >= 1968, and packs the binary64 result, truncating subnormals. All of it is i32 DXIL, with no f64 ops needed. The table is the 1184-bit prefix the hardware sweep measured, not the ISA text's 1201 bits, and the code comment says so. The three tail cases added in313acc3pin that choice. An independent tester above matched 16,704 rows against an mpmath model.operand64_dwordsis split out of the existing 64-bit operand read without a behaviour change, apart from a checkedreg + 1.One point to check before merging: the source
Const(128..=208)arm uses 0 as the high word. For a 64-bit operand I'd expect the negative inline integers (193-208) to be sign-extended, giving a high word of0xffffffff(exponent 0x7ff). If so, those few forms should be refused or given that high word. No compiler is likely to emit them for this opcode.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:57:01Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP +dxil.dll):v_trig_preop_f64in its ownemit/lower/trig_preop.rssubmodule keepslower.rswithin the 512 KiB file-size policy limit and verifies argument reduction end-to-end on GPU.cargo test -p victory-shader trig_preop -- --test-threads=1(RTX 5090 & WARP): all tests passed on both.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.