[pr-performance][shaders][AMD] New switch DARNER_LEGACY_MIN (off): legacy multiply tests min(|a|,|b|) == 0 for every factor pair #10
Loading…
Reference in a new issue
No description provided.
Delete branch "Jesper-A/Darner:pr5-legacy-mul"
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?
Contributor role (optional)
What it changes
Re-filed from CodeFloe #342 (the CodeFloe repo is gone; nothing was migrated). Same branch and commit.
Base: the branch (2 commits) is on
f2bccf656, themaincommit it was cut from.mainis nowdd2f061d5. Not rebased (we rebase only if you ask). A text-only trial merge (git merge-tree --write-tree trustno1/main pr5-legacy-mul) conflicts indocs/findings.mdonly;emit/lower.rsandREADME.mdmerge cleanly.New switch
DARNER_LEGACY_MIN, off by default (1= on). Off, the output is whatmainemits today.On AMD RDNA hosts the legacy multiply (a zero times anything is zero, as in D3D9) tests one factor for zero when that factor is known finite:
a == 0 ? 0 : a * b. With the switch on, it testsmin(|a|, |b|) == 0 ? 0 : a * bfor every pair (DXILFAbs6 andFMin36, both already emitted there). Per the author of the port, Mesa's NIR folds only the min form into one instruction (v_mul_dx9_zero_f32on RDNA); the finite-factor test stayed a compare and a select after the multiply. We did not check that ourselves.Where:
Lower::legacy_mulincrates/darner-shader/src/emit/lower.rs(the RDNA branch only; hosts that are not RDNA, or not forced withDARNER_HOST_RDNA=1, never reach it). The choice is the small functionlegacy_zero_testinemit/cost.rs, which has its own tests; the switch isRewrite::LegacyMinin the same file'sSWITCHESandOFF_BY_DEFAULT. It is documented in the README switch table, thecost.rsmodule doc anddocs/findings.md.Side effect with the switch on: the zero is +0 in every case, as on the console. Off, the product of a finite non-zero factor and a zero can be -0. A new test,
legacy_min_form_is_the_legacy_productinemit/cost.rs, checks the min formula in Rust (0, -0, inf, NaN, denormals) against the D3D9 rule. It does not check emitted DXIL.Shader cache: this base has no
TRANSLATOR_VERSION.build.rscollects every"DARNER_*"name in the translator source intoDARNER_SHADER_SWITCHES, andtranslation_fingerprint(emit/mod.rs) hashes each switch's value, so turning the switch on or off re-translates every shader. The source hash is part of the same fingerprint, so the first start after this lands also translates again once, with the switch off and the same output.Credit: port of lobomfz/VIctory-xmem PR #257 (author Jojonobody2), commit 47f5223c3. That is a PR in the xmem fork, not a Darner number. The commit keeps
Co-authored-by: Jojonobody2. The switch and the off-by-default form are ours.The author's numbers, theirs and not measured here (RX 7900 XTX, RADV shader stats, instructions without
s_delay_alu): 13,918 to 13,626; 35,684 to 35,217; 3,845 to 3,760, in three programs. No speed claim is made. The gain on AMD's Windows driver is unverified.Not a bug fix, so no
Fixes/Refs.Spec dependence
May depend on the driver and the GPU. The instruction saving was reported by the author on Mesa/RADV only; whether the Windows AMD driver fuses the same form is unknown. NVIDIA: the RDNA branch is not taken on NVIDIA unless
DARNER_HOST_RDNA=1forces it, so the default run on the RTX 2070 SUPER (Turing) is untouched. If forced, the min form is twoFAbsand oneFMinwhere the finite-factor form is one compare; whether NVIDIA's compiler turns that into a cost or a gain is untested. Off by default for that reason. Untested on any real GPU.How it was tested
91eefe7a5plus the switch change in the working tree;01c3f3569differs from that only by a doc-comment row inemit/cost.rs(per the porter), and tests and clippy were not re-run on it.cargo xtask policypassed on01c3f3569. Basef2bccf656(not rebased on the currentmain,dd2f061d5).cargo test -p darner-shader --lib --locked -- --test-threads 1 --skip in_the_pair_form_a_half_that_left --skip legacy_mul_forms_are_exact: 547 passed, 4 failed, 15 ignored. The two legacy-min tests (legacy_min_off_keeps_the_one_factor_test,legacy_min_form_is_the_legacy_product) pass. The skippedin_the_pair_form_a_half_that_lefthangs onmaintoo, as reported by the porter;legacy_mul_forms_are_exactis a 2^32-float loop, too slow in debug.trustno1/mainas well (reported to me, not re-run by me onmain):emit::barycentric_tests::first_half_values_render_on_hardware_and_warp,emit::rect::tests::rectangles_are_drawn_whole,emit::rect::tests::the_rectangle_stage_is_a_geometry_shader,emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders.cargo clippy -p darner-shader --all-targets --all-features -- -D warnings -A clippy::unnecessary_lazy_evaluations: clean, run before the doc-only edit (that one lint is allowed; it is not from this change).cargo xtask policy: passed on01c3f3569(531 files ok).cargo clippy --workspace --all-targets --locked -- -D warnings: pending. The same with--all-features: pending (only the crate-level run above was done).cargo test --workspace --locked: pending. There is no CI upstream, and nothing here claims one.legacy_mul_forms_are_exact(the exhaustive oracle) was skipped, so it did not run on this commit; no run on a real driver; no measurement of the instruction count or of speed with the switch on; shader-cache cold start not timed; the DXIL emitted with the switch on is not checked by a test, only the choice function and the formula.Checklist
main(basef2bccf656).docs/asset-policy.md(cargo xtask policypassed on01c3f3569).Checked for overlap
DARNER_LEGACY_MINor the legacy multiply. On 2026-12-03 this host had 3 issues and 5 pull requests in total (#3 by another contributor; #5 to #8 are ours, re-filed today); none is about shaders. The one open pull request (#3, ray tracing mode in F1) changeshost/menu.rs,host/panel.rsandhwrt.rs: none of this change's files. Earlier, on CodeFloe (not migrated), two pull requests touchedemit/lower.rs: CodeFloe #295 (assumed_finite,DARNER_LEGACY_FINITE; it changed thefa/fbline just above this hunk, so more factors would count as finite and this switch would apply to more multiplies; the hunks were a few lines apart and might conflict; never tried merging both) and CodeFloe #183 (wave64 ballots; no overlap seen in the legacy multiply). Neither is on this host, andDARNER_LEGACY_FINITEis not onmain(dd2f061d5).README.mdanddocs/findings.md, and #7 (long frames:docs/findings.md). Different changes; whichever lands first, the others take the new rows when they are rebased.This change was made with AI assistance (Claude Code).
WIP: [pr-performance][shaders][AMD] New switch DARNER_LEGACY_MIN (off): legacy multiply tests min(|a|,|b|) == 0 for every factor pairto [pr-performance][shaders][AMD] New switch DARNER_LEGACY_MIN (off): legacy multiply tests min(|a|,|b|) == 0 for every factor pairView command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
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.