perf(shader): use fused legacy MAD on Apple #1304
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1304
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1304/head"
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?
@carbonimax on GitHub · 2026-10-09 13:25 UTC · original
carbonimax:perf/apple-fused-legacy-mad→main· +72 −1 · 4 files · 2 commits · closed without mergingLegacy MAD currently emits
NoContractionmultiply and add operations. SPIRV-Cross lowers these to[[clang::optnone]]helpers in MSL, which can cause a substantial performance cost on Apple GPUs. See SPIRV-Cross #1999 and #2156.Use one GLSL.std.450
Fmafor legacy MAD by default on Apple. Other platforms keep separate multiply/add rounding.KYTY_MAD_SEPARATE_ROUNDING=1restores the previous Apple policy;=0selects fused MAD on either platform. Invalid values use the platform default. Explicit Fma,V_FMAC_F32,V_FMAMK_F32andV_FMAAK_F32keep their existing behavior.This deliberately abandons separate legacy MAD rounding by default on Apple. Fused and separate results can differ. The default applies to all shaders on Apple, rather than to one driver version or application.
Testing
Validation on Apple M4 Pro under Rosetta, macOS 27.2, against
4c8fc53a8582543200caa697acad2a9f09937cec:=0and invalid-value cases fail;=1already passes. With the change all four pass in separate processes.shader_cfg_tests,resource_tracking_tests,resource_materialization_testsandshader_vertex_metadata_testssuites pass.In a prior measurement on an Apple M4 Pro under Rosetta with MoltenVK, a GPU-bound scene went from ~140 ms to ~75 ms per frame. This used a development MoltenVK build and one qualified run of the fused policy; these are mean frame-time equivalents calculated from FPS, not measured percentiles. The revisions differed and the cache was cold for the fused run. The result is historical motivation, not a new benchmark of this branch against upstream or a guarantee for stock MoltenVK.
Limits
No GPU was run for this PR preparation. CPU tests check emitted structure, not numerical execution or rendering equivalence on a GPU. Linux and Windows builds were not run locally. The explicit override restores the previous policy but does not remove the numerical risk of the new default.
AI assistance
This contribution was developed with the assistance of AI coding tools. They helped write the code, tests and this description, and ran the builds and tests reported above. The commit carries a
Co-Authored-Bytrailer.@chatgpt-codex-connector[bot] on GitHub · 2026-10-09 13:25 UTC · original · edited 2026-10-09 13:29 UTC
Codex Review Summary
This comment shows the latest Codex review activity on this pull request.
424e1c4ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@coderabbitai[bot] on GitHub · 2026-10-09 13:29 UTC · original · edited 2026-10-09 14:39 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
095cabb3-9e06-4d1e-92b9-5919a5668014📥 Commits
Reviewing files that changed from the base of the PR and between
424e1c485cand14973312ee.📒 Files selected for processing (3)
CMakeLists.txttests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
The SPIR-V emitter now selects MAD rounding behavior from
KYTY_MAD_SEPARATE_ROUNDING, with platform-specific defaults for unset or invalid values. When separate rounding is disabled,FPMad32emits a GLSL FMA; otherwise, it uses separate multiply and add operations. Focused tests check the emitted instructions and explicitFPFma32behavior. CTest registers configuration cases and compute-test modes, including compilation of a MAD shader without a Vulkan harness.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Other
Merge Risk: ⚪ Minimal · up to
14973The focused tests check the fused and separate modes against matching policy settings. No concrete merge-blocking behavior is established in the reviewed changes.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (3 skipped: 1 unsupported, 2 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@chatgpt-codex-connector[bot] on GitHub · 2026-10-09 13:29 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
424e1c485cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@ -109,2 +126,4 @@uint32_t EmitFPMad32(EmitterState& state, uint32_t a, uint32_t b, uint32_t c) {if (!MadSeparateRounding()) {return EmitGlsl<GLSLstd450Fma, IR::Type::F32>(state, a, b, c);@chatgpt-codex-connector[bot] on GitHub · 2026-10-09 13:29 UTC · original
When
KYTY_MAD_SEPARATE_ROUNDINGis unset or invalid on Apple, this branch replaces every legacy MAD inVectorMadF32RoundsProductwithFma, but that registered compute case still requiresOpFMulandOpFAddand expects its five legacy results to be zero (tests/ShaderRecompilerComputeTests.cpp:24710-24717; invoked byshader_recompiler_computeinCMakeLists.txt:643). A default Apple run therefore fails inCheckSpirvTextbefore dispatch, and its numerical expectations are also stale; make the case policy-aware or run its legacy assertions withKYTY_MAD_SEPARATE_ROUNDING=1.Useful? React with 👍 / 👎.
@coderabbitai[bot] on GitHub · 2026-10-09 13:29 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
fb904379-97ea-4a88-ba6a-fe492f15cc99📥 Commits
Reviewing files that changed from the base of the PR and between
4c8fc53a85and424e1c485c.📒 Files selected for processing (3)
CMakeLists.txtsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAlu.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@ -109,2 +126,4 @@uint32_t EmitFPMad32(EmitterState& state, uint32_t a, uint32_t b, uint32_t c) {if (!MadSeparateRounding()) {return EmitGlsl<GLSLstd450Fma, IR::Type::F32>(state, a, b, c);@carbonimax on GitHub · 2026-10-09 14:33 UTC · original
Fixed in
14973312ee: the compute harness forces KYTY_MAD_SEPARATE_ROUNDING=1 before initialization, preserving this fixture's separate-rounding contract in direct runs and CTest. The same fixture's SPIR-V check fails before the fix and passes after it; 9 CPU tests pass. GPU attempts are blocked before the case by MoltenVK device requirements, so numerical GPU behavior remains unvalidated.@carbonimax on GitHub · 2026-10-09 14:33 UTC · original
@coderabbitai Addressed in
14973312ee: CTest now supplies explicit fused/separate expectations to the CFG test; it no longer parses KYTY_MAD_SEPARATE_ROUNDING. All four policy cases pass, and an incorrect expectation still fails.@coderabbitai[bot] on GitHub · 2026-10-09 14:40 UTC · original
@carbonimaxThanks for the fix. Explicit CTest expectations remove the duplicated environment parsing from the CFG test. The reported incorrect-expectation failure confirms that the test can detect a policy mismatch.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.
@carbonimax on GitHub · 2026-10-10 21:17 UTC · original
Hi, was this closed for the AI policy?
For context: on Apple GPUs, the NoContraction FMul/FAdd path makes MoltenVK emit non-optimizable helpers, which made one scene about 1.85× slower in our tests; this restores a single Fma on Apple only, with an env override. The patch was written by AI agents (Claude and Codex) and tested on my M4 Pro; I reviewed it. Happy to resubmit with an AI disclosure section.
Pull request closed