shader: improve v_log_f32 accuracy near unity (NEW-58) #2158
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2160"
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 TheGrayOrange on 2026-11-25T06:41:02Z.
Direct3D Log allows an absolute error of "2^-21" on inputs in "[0.5, 2]". RDNA2 documents 1-ULP accuracy and exact positive zero at unity for "V_LOG_F32". On the original lowering, "0x3f7fffff" produced "0xb24b4000" on RTX 4070 Ti SUPER and "0xb3e00000" on WARP, versus rounded reference "0xb3b8aa3c". Both host results meet the Direct3D bound. "Direct3D Log" (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/log--sm4---asm-) · "AMD RDNA2 ISA, p. 141" (https://docs.amd.com/api/khub/documents/Et
wpu9gFfl7d9q0QZ~Og/content#page=149)The correction now covers "|x − 1| ≤ 1/8". It splits the linear term so the leading product is exact, then evaluates the remaining degree-eight Taylor terms in two grouped Horner chains. The conservative bound is below 0.859 true reference-binade ULP for this band, under the specified binary32 arithmetic ordering, permitting local multiply-add contraction but not reassociation. Outside it, the lowering preserves DXIL Log, including the existing accuracy gap. Of 66 sampled fallback inputs, errors reached 8.928844 ULP on NVIDIA and 3.648209 ULP on WARP.
The permanent regression generates runtime operands and computes its expected bounds from an independent binary64 atanh reference. It keeps the unrounded 1-ULP check and removes the generated table and standalone tool. The CPU model swept all 3,145,729 in-band encodings with representative contraction schedules. Device execution was sampled. Both adapters passed 260 permanent inputs plus exact positive zero at unity. Earlier equivalent-shader verification covered 244 additional in-band inputs on each adapter and preserved sampled fallback and modifier behavior. The maximum sampled in-band error was 0.605534 ULP on both adapters, and SDK DXIL validation passed.
Synthetic execution cost
On RTX 4070 Ti SUPER, matched native D3D12 timings put the grouped correction about 17% below degree nine for long dependency chains and 3% below for long throughput batches. Short throughput differences were inconclusive. The old-band long throughput medians were 19.456 µs for original, 55.296 µs for published degree five and 70.656 µs for degree nine in the earlier run. A separate matched run measured 70.656 µs for degree nine and 68.608 µs for grouped degree eight. The correction still adds execution cost, including for fallback inputs. This is synthetic workload evidence from one physical NVIDIA GPU. Native machine-code measurements, physical RDNA2 verification and game-data validation were outside the scope.
Validation
On base "
940d32f", normal Windows workspace tests went from 695/5/10 to 696/5/10 and all-feature tests went from 700/5/10 to 701/5/10 (passed/failed/ignored). The same five existing failures affect descriptor capacity, dynamic slot allocation, unbound buffer reads, structured-buffer stride and NaN-coordinate gathers. Warning-denied workspace Clippy passed in both modes, as did full and staged asset policy. The formatter reports the existing base differences.A merge preview against newer upstream "
13f91ca" completed without conflicts. The merged tree has not yet been built or tested. Upstream CI has yet to validate this revision.Developed with Strata/Qwen3.8 assistance and independently verified and integrated with Codex under human supervision. "Community claim NEW-58" (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7151324372)
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:54:18Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. v_log_f32 accuracy improved near unity (NEW-58) — log precision fix near 1.0; numerical-accuracy work, hardware validation still needed on Windows.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T07:41:54Z.
Update (head
6001af3): I re-ran the same probe: the same 1,202 inputs, |x − 1| from 2^-7 to 1/8 on both sides of 1.0, step 2^-7/40, scored against a correctly roundedlog2in exact arithmetic. It ran on an RTX 3070 (driver 616.56, Windows 11 26100.9711) and on WARP.At
6001af3both backends returned the same bits for all 1,202 inputs: 0 above 1 ULP, max 1 ULP against the correctly rounded value (0.565 ULP against the unrounded one), and 27 inputs 1 ULP off the correctly rounded value.v_log_f32_near_unity_meets_rdna2_one_ulppasses on both backends (worst in-band error 0.606 ULP; fallback probes past 1/8 up to 8.93 ULP on the 3070 and 3.65 ULP on WARP).As a control, the same probe on main
f3578e3(no correction) matches the table below in the three bands above 2^-6 (RTX 3070: 154/37, 300/38, 590/19; WARP: 47/12, 42/5, 12/2, as >1 ULP count / max ULP). In the first band, 2^-7 to 2^-6, main has 82 of 82 inputs above 1 ULP on the RTX 3070 (max 117 ULP) and 36 of 82 on WARP (max 17); the table below shows that band on the PR's earlier head, not on main. (Edited: the first version said main reproduced the whole table.) This input set stops at 1/8, so it says nothing about the band edge from outside.Data on how far the near-unity correction needs to reach. Your test at
636d222passes on an RTX 3070 (Ampere, driver 616.56, Windows 11) and on WARP. I added a local probe to it, not pushed: 1,202 inputs from |x − 1| = 2^-7 to 1/8 on both sides of 1.0, each result compared with a correctly roundedlog2computed in exact arithmetic. The comparison reproduces your reference rows and the0x3f7fffffcase.| |x − 1| | inputs | RTX 3070 > 1 ULP | RTX 3070 max | WARP > 1 ULP | WARP max |
|---|---|---|---|---|---|
| 2^-7 – 2^-6 (inside the series band) | 82 | 0 | 0 | 0 | 0 |
| 2^-6 – 2^-5 | 160 | 154 | 37 ULP | 47 | 12 ULP |
| 2^-5 – 2^-4 | 320 | 300 | 38 ULP | 42 | 5 ULP |
| 2^-4 – 2^-3 | 640 | 590 | 19 ULP | 12 | 2 ULP |
Worst cases on the 3070:
0x3f839333→0x3d22c82e(correctly rounded0x3d22c809) and0x3f855333→0x3d70dc12(0x3d70dbec).So inside the band the series meets the 1-ULP contract, but just outside it NVIDIA's
Logis still tens of ULP off. RDNA2 isn't: boykopovar/AnyPS5#2880 measured gfx1036 withtools/hw-oraclewithin 1 ULP of correctly rounded on all 2,368 rows 1 ± 2^-k(1 + m/64) and on a dense sample over [0.875, 1.375]. It found the NVIDIA driver up to 29,121 ULP off there. AnyPS5's fix takes a series in d = x − 1 for |d| ≤ 1/8: eight terms with fused multiply-adds stayed within 2 ULP of the hardware on all 9,280 inputs in that band, six terms reached 9 ULP, and a 1/4 band needed eleven terms. Widening the band to 1/8, with more terms, would cover what this probe shows. I haven't measured past 1/8.AI-assisted (Claude Code). Synthetic inputs only; the probe and the script that scores it are local.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:04:09Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
636d2222ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:24:44Z.
Automated triage for the maintainers.
Merge candidate. The branch is rebased (
ac40854) and merges cleanly. The earlier asks are met. The standalone generator and generated table are gone, so the diff touches onlyemit/lower.rsandemit/valu_tests.rs.Lower::log_f32has a short comment. The band is widened to |x − 1| ≤ 1/8. The evidence is the RDNA2 ISA'sV_LOG_F32contract (1 ULP, exact +0 at 1.0). An independent RTX 3070 and WARP probe on6001af3found no in-band input more than 1 ULP off. Outside the band, and for NaN or infinity, the orderedOLEselect keeps DXILLogunchanged. The regression computes its reference at run time (atanh series in binary64), not from a table.For the maintainers: every
v_log_f32now runs the series as well as DXILLog, and the cost is measured only synthetically.Nits: the test comments cite
VIC-0018andVIC-0005, which are not in this repo, so please drop them. The new arm_ if name == "v_log_f32"could be23 =>like its neighbours.CI: not run. The workflow for this head is waiting for maintainer approval (
action_required).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-25T14:36:46Z.
Received.
I'll simplify the regression by replacing the generated table and standalone reference generator with a compact runtime reference, subject to validating its accuracy. I'll also shorten the implementation comments.
The measurements outside the current correction interval are particularly helpful. I'll investigate extending the interval toward |x − 1| ≤ 1/8 while retaining the 1-ULP accuracy target, and measure the shader execution overhead against both main and the current PR.
I'll report the resulting accuracy coverage, remaining limitations, and performance measurements before updating the PR.
upstream-sync referenced this pull request2026-11-25 17:05:02 +00:00
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-25T22:06:01Z.
I've updated the PR to address the feedback.
The correction now covers an inclusive "|x − 1| ≤ 1/8" and uses a grouped degree-eight approximation with an exact leading product. The conservative error bound is below 0.859 ULP in that interval. Both reported RTX encodings now pass, and the permanent NVIDIA and WARP runs passed all 260 nonzero in-band inputs and exact positive zero at unity.
The regression now computes its independent binary64 reference at runtime and applies the 1-ULP bound against the unrounded reference. The standalone generator and generated table are gone, and the lowering comments have been shortened. DXIL Log remains the fallback, with sampled errors outside the new band reaching 8.93 ULP on the tested NVIDIA adapter.
I also measured the original lowering, published correction and wider correction, then investigated lower-cost alternatives. Matched native D3D12 timing on RTX 4070 Ti SUPER showed about 17% lower long dependency-chain time and 3% lower long throughput-batch time for the final grouped implementation compared with the intermediate degree-nine correction. Short throughput results were inconclusive. The correction still costs more than original Log and the previously published degree-five revision in the synthetic workloads.
The updated PR description includes the numerical results, performance measurements and remaining limitations. Local Windows validation reproduced the same five baseline failures in both workspace configurations. Upstream CI remains pending.
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-25T22:10:31Z.
I've updated the PR to address the feedback.
The correction now covers an inclusive "|x − 1| ≤ 1/8" and uses a grouped degree-eight approximation with an exact leading product. The conservative error bound is below 0.859 ULP in that interval. Both reported RTX encodings now pass, and the permanent NVIDIA and WARP runs passed all 260 nonzero in-band inputs and exact positive zero at unity.
The regression now computes its independent binary64 reference at runtime and applies the 1-ULP bound against the unrounded reference. The standalone generator and generated table are gone, and the lowering comments have been shortened. DXIL Log remains the fallback, with sampled errors outside the new band reaching 8.93 ULP on the tested NVIDIA adapter.
I also measured the original lowering, published correction and wider correction, then investigated lower-cost alternatives. Matched native D3D12 timing on RTX 4070 Ti SUPER showed about 17% lower long dependency-chain time and 3% lower long throughput-batch time for the final grouped implementation compared with the intermediate degree-nine correction. Short throughput results were inconclusive. The correction still costs more than original Log and the previously published degree-five revision in the synthetic workloads.
The updated PR description includes the numerical results, performance measurements and remaining limitations. Local Windows validation reproduced the same five baseline failures in both workspace configurations. Upstream CI remains pending.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T23:20:18Z.
I resolved the conflict in
valu_tests.rson an integration branch at8739b74. Your exact6001af3is its first parent, with both authored commits preserved. The only conflict was the insertion point for your log test and the upstream legacy-multiply test. Both are included.On app-local WARP SM 6.6 with DXIL validation, your same fixture reported 114 violations on
842b0cband zero at8739b74. The 260 in-band values had a worst error of 0.605534 ULP at the integrated head and unity returned exact positive zero. The legacy-multiply regression, the 36 VALU tests, strict shader Clippy and the asset policy also passed. The integration merges cleanly with842b0cb; you can fast-forward your branch to it.upstream-sync referenced this pull request2026-11-26 02:07:05 +00:00
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:00:51Z.
I ran the entire inclusive
[0.875, 1.125]interval as translatedv_log_f32on WARP 1.0.22 with Agility 1.620.2 and SDK DXIL validation. The same synthetic shader consumed every binary32 encoding from a buffer and echoed the input beside its result. The comparison used binary64ln_1p(x - 1) * log2(e)and the unrounded reference’s binary32 binade spacing.63bcca40x3f7fffffac408540x3f603a70ac40854combined with63bcca40x3f603a70Unity returned the exact positive-zero word. Both immediate out-of-band neighbors, ±0, +∞ and 2.0 match upstream bit for bit. This sweep measures WARP. The physical-adapter results are the samples already reported in the PR.
The opt-in test is 20dd20f, a test-only commit on your exact head. With SM 6.6 WARP and the SDK validator set up:
If you reuse the probe, please retain its Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:26:22Z.
Review: APPROVED
The
t = hi + losplit (emit/lower.rs:2168-2206) makesC1 * hiexact in binary32, the ordered<= 1/8band (OLE) includes both endpoints while falling back to DXILLogfor out-of-band values, infinities, zeros, and NaNs, and1.0returns bit-exact+0.0(0x0000_0000). Exhaustive modeling across all 3,145,729 in-band binary32 encodings stayed within0.721567 ULP(0.677041 ULPunder FMA contraction).Non-blocking notes:
origin/main(63bcca43),emit/lower.rsgrows to523,781 B(only 507 B under the524,288 Bpolicy cap) — worth keeping in mind before stacking otherlower.rsPRs.valu_tests.rs:2642-2645, the comment saysOne 24th of a ULPwhile the code uses2^-24(2f64.powi(-24)), and gating the per-inputVIC6 BITS/VIC6 FALLBACKprints behind an env var would keep default test output concise.Local verification at
ac40854b(and cleanly merged ontoorigin/mainatee4ef6e5):xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets(defaultand--all-features, 0 warnings), SDKdxil.dllvalidation,emit::valu_testson both RTX 5090 and WARP (36/36), andv_log_f32_near_unity_meets_rdna2_one_ulp(checked=278,in_band=260,violations=0,worst_in_band_ulp=0.605534on both RTX 5090 and WARP) all passed. Approving.Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-26T19:36:20Z.
Thank you @andrewpozdnakov7-jpg @fuzeofficlal for verification, particularly the exhaustive WARP execution sweep and RTX 5090 coverage. It's encouraging to see the numerical results reproduced across additional environments.
I'll address the remaining comment, opcode matching and diagnostic-output cleanup without changing the numerical implementation.
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-26T19:49:50Z.
Addressed the remaining cleanup feedback in
4f7f699:23 =>.VICTORY_LOG_F32_VERBOSE=1.The focused WARP regression passed in both output modes. All 342 results and both validated DXIL containers remain identical to the previous verification.
The numerical implementation is unchanged.
Again, thanks @andrewpozdnakov7-jpg @fuzeofficlal for the testing and review.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T22:30:48Z.
Review: APPROVED
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).v_log_f32accuracy near unity meets the RDNA2 1-ULP bound cleanly on both discrete NVIDIA hardware and WARP.cargo test -p victory-shader --lib emit::valu_tests::v_log_f32_near_unity_meets_rdna2_one_ulp -- --test-threads=1: passed on RTX 5090 andVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 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.