[pr-performance][shaders] Shaders: legacy products (0 times anything is 0) in the short form on every card, not only AMD #304
Loading…
Reference in a new issue
No description provided.
Delete branch "cafe/legacy-products-any-card"
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)
Cafe#9189What it changes
v_mul_legacy_f32and the like are written in the short form (rdna::LEGACY: a plain product, plus one comparisonmin(|a|,|b|) == 0where a factor may be an infinity or NaN) only on AMD RDNA cards or withDARNER_HOST_RDNA=1. Every other card gets the long form: a product, two comparisons, an OR and a select.host.rsalready calls bit 2 host-neutral.The short form gives the same results on any card, except that a zero result may have the other sign (as on AMD today). This change keeps
DARNER_RDNA_FLOAT's host-neutral bits on every card (rdna::NEUTRAL = LEGACY); the other bits (MAX_MIN, MED3, FRACT) stay AMD-only.DARNER_RDNA_FLOAT=0still turns it off. The bits are already in the shader cache key (host_settings), so translations made before are not reused.DARNER_LEGACY_FINITEstays off by default, as onmain.emit/lower.rs: on a non-RDNA host,host_rdna()keepsbits & rdna::NEUTRALinstead of 0.emit/mod.rs:rdna::NEUTRAL, with why it holds on every host.DARNER_RDNA_FLOATrow says which bits count on which cards.How it was tested
Tested revision:
mainf3840d73d, switched byDARNER_HOST_RDNA=1(which turns on all four bits, not only this one); gates onf3840d73d+ this commit (6f070e3f4).Changes a default: yes, for every card that is not AMD RDNA (NVIDIA, Intel). The shaders are rebuilt once.
A/B result (RTX 2080 Ti, house save, the same 50 s after the world shows, pipelines warm):
maindefaults)DARNER_HOST_RDNA=1: all four bits)About -1.2 ms, from a single base run. An earlier
main(de8d42006, withDARNER_LEGACY_FINITEon at the time), bit 2 alone on the same card, withDARNER_VIEW_START_FAST=1on both sides: 51.8/51.4 -> 48.8/48.9 ms, 18.73/18.85 -> 19.72/19.79 fps.Picture: a recorded frame of the house, translated again with
DARNER_HOST_RDNA=0and=1(all four bits): 1,571 shaders differ, the replayed picture is the same to the pixel. The replay has no ray tracing.Gates run on
6f070e3f4:cargo build --locked --release -p darnerok;cargo clippy --locked --release -p darner-shader -p darner-gpu --all-targets -- -D warningsok;cargo test --locked --release -p darner-shader --lib -- --skip oracle64: 488 passed, 67 failed, the same 67 as onmainf3840d73don this PC (they need a Shader Model 6.6 device, which Windows 10's own D3D12 lacks, or DXIL validation). Not run this time: thedarner-gputests (they create a D3D12 device). Not run: the whole-workspace gates.Gameplay: RTX 2080 Ti, Windows 10 22H2, Series S profile, 2560x1440 output, DLSS Performance, hardware ray tracing, no frame generation.
Shader wave sizes tested: 32 lanes (NVIDIA).
Hardware dependence: untested on Intel cards by us (#38 measured this form on an Arc A770). No change on AMD RDNA cards (all bits already count there).
Coverage gaps: not measured with bit 2 alone on
f3840d73d(the A/B above has all four bits); no check by eye in play.Checklist
main.docs/asset-policy.md.Checked for overlap
DARNER_LEGACY_MIN: another change in the same lowering), #31 (Intel host detection).DARNER_INTEL_LEGACY_MUL, and changes the same lines ofhost_rdna(). This also covers the Intel case of draft #38. If #38 lands first, I'll rebase on it and keep its Intel switch.The signed-zero caveat changes an observable result on NVIDIA and Intel with the new default. For
v_mul_legacy_f32with a literal2.0and a runtime-0.0, the current non-RDNA zero guard selects0x00000000. The short path drops the guard because the literal is finite and nonzero, so the product can store0x80000000. I checked the two expressions with a small CPU bit-pattern fixture. The repo'soracle64::legacy_mulexpects positive zero in that case.Could you keep bit 2 explicit opt-in on non-RDNA for now? An A/B on this exact head with
DARNER_RDNA_FLOAT=0versus=2would isolate the speedup from the other three bits. For a default change, a small shader that stores the result as a uint would cover the difference the house-frame comparison misses.Thanks for this. I read the change against
6f070e3f4andmainf3840d73d. We also saw andrewpozdnakov7-jpg's comment (signed zero, bit 2 opt-in off RDNA, an=0against=2A/B, a uint-store test); what follows adds to it.What I checked
legacy_mul,lower.rs:4680on the head) is the product, or 0 wheremin(|a|,|b|) == 0. With the D3D/DXIL minimum rule as we understand it (a NaN operand returns the other operand; we could not look the sentence up in the spec text, so please correct us if it differs), the cases agree with the long form: 0NaN and 0inf give 0, NaN5 gives NaN, NaNNaN gives NaN.lower.rs:4690-4691):a == b, both factors assumed finite (only withDARNER_LEGACY_FINITE), and a finite non-zero literal factor (not_zero,lower.rs:4690). The last one is what gives the signed-zero difference in the comment above: 2.0 times a runtime -0.0 returns the product, -0.0, not +0 as the long form gives (as the commenter says). The first two cannot differ in value (the value times itself, or two finite numbers); the sign of a zero can. So "only the zero's sign can differ" holds, but it is more than a rare corner: any finite non-zero literal factor takes it.host_rdna()now returnsbits & NEUTRALoff RDNA (lower.rs:1098-1105),NEUTRAL = LEGACY(emit/mod.rs:544). The bits stay in the cache key (lower.rs:1078), so old translations are not reused.The A/B does not measure the PR alone
DARNER_HOST_RDNA=1, which turns on all four bits, not only bit 2.main(de8d42006) withDARNER_LEGACY_FINITEon, so it is not this code.6f070e3f4:DARNER_RDNA_FLOAT=0against the default (which is bit 2 off RDNA), on our RTX 2070 SUPER (Turing), as launch pairs in ABBA order, and post the numbers with n and the spread here. Say if you would rather we didn't.mainf3840d73d,DARNER_HOST_RDNA=1 DARNER_RDNA_FLOAT=2on an NVIDIA card gives the same shaders as this PR (host.rs:2495-2496sets the flag;host_rdna()then returnsrdna_float()). We greppedHOST_RDNA: the four bits and the cache key (lower.rs:1078) are its only readers on the host.A stale comment
legacy_finite()'s comment (lower.rs:786-787) still saysDARNER_LEGACY_FINITE"only acts where the legacy products are guarded (host_rdna: AMD RDNA cards, orDARNER_HOST_RDNA=1)". After this PR it acts on every card whenever it is set. The same comment records that value 31 gave dark speckled blotches on roads at sunset (PR #76 test), so someone with it set on an NVIDIA card would now get that. Please update the comment. We found no README row forDARNER_LEGACY_FINITE.Picture check
The replay check used all four bits and had no ray tracing. That is fine for this bit; could you add one line to the PR saying so?
Gates
As on #303, the PR says the workspace gates were not run. For a default change please run
cargo clippy --workspace --all-targets --locked -- -D warnings, the same with--all-features,cargo test --workspace --locked, and thedarner-gputests. Or say so and we will run them on our PC (Windows 11, RTX 2070 SUPER) and report here on6f070e3f4.Overlap
Our own #10 (
DARNER_LEGACY_MIN, off by default) changes the same lowering inside the RDNA branch. After #304, withDARNER_LEGACY_MINon, #10's min form would reach every card. We will rebase or close ours if you ask. The Intel case (#38) is covered by the PR's own note.This comment was written with AI assistance (Claude Code).
@Jesper-A Microsoft's DXIL spec confirms that FMin returns the other operand when exactly one operand is NaN. It also describes denormal handling separately. DXIL FMin
I put the explicit opt-in in 9fc872a on top of
6f070e3f4. This keeps the current AMD RDNA defaults and enables the shorter multiply on other cards only when its bit is explicitly selected. I also updated the legacy-finite comment to cover this path.In a CPU fixture using the production settings parser and host selection, the non-RDNA default for the signed-zero example went from
0x80000000to0x00000000. Explicit=2still produced0x80000000, and all six AMD settings cases matched the PR head. The focused shader type check and asset policy passed. The proposed RTX 2070 SUPER comparison would still be useful for measuring the opt-in.If you cherry-pick or rebase the contribution, please keep the Git author. If you fold it into your own commit, please add this trailer.
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>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.