perf(shader): simplify float max with a positive zero lhs #12287
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12287"
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 boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-28T07:35:43Z.
What
max(+0, value)currently uses the general f32 min/max lowering, including NaN classification, a signed-zero check and multiple selects. The camp scene executes this sequence repeatedly in a costly fragment shader.value > +0comparison and selectvalueor+0.max(value, +0)or a negative-zero left operand.The simplification preserves negative/zero/NaN results, positive finite values, infinity, native denormal comparison behavior and the surrounding IEEE signaling-NaN handling. An earlier focused compilation of the game-emitted fragment produced 1,858 native instructions from 1,911, retaining 32 VGPRs, 128 SGPRs and no spills on RADV. Its assembly matches the private diagnostic prediction; this is a focused compiler result, not exact linked-capture ISA or an elapsed-time estimate.
Tested
Integrated main
98ddd9c1792bbab016ceed5db267a93d1d61f00ainto headd67548414c84007e254229861781250f205cbd1a. On both revisions,agc_driver_dx10_clamp,agc_driver_f32_min_max_denormal_modes,agc_driver_f32_min_max_nan, andagc_driver_f32_result_clamppass with required Vulkan, shader cache disabled and Khronos validation on AMD Radeon 760M, RADV Mesa 25.0.7-2+deb13u1, Debian 13 / Linux 7.2.12-x64v3-xanmod1. Both logs confirm the GPU and layer, with no VUIDs, missing layers or skips. Main uses its own test fixtures. Conventions and whitespace checks pass.One predeclared warmed pair on the same stationary PPSA28997 camp scene, machine and session compares these exact revisions: 20.92836 → 20.97523 FPS (+0.224%), GPU 44.102 → 43.967 ms/present. One pair does not establish repeatability or a cross-title/vendor result. Both pass the scene, focus, input, library and trace-drop audits; no timed exclusions or extra runs. The PR arm reported two shader-cache misses during startup, before the measurement window; the cache audit found no changes during the window.
Lossless traces, summaries, digests, protocol and provenance were downloaded and hash-verified. The timing-only bundle includes the identical private observer used on both arms, disclosed by dirty flags. The prior three-pair result on
f7f03dafand05842baremains available in its evidence bundle; it does not measure this integration.A1
seconds 90:12 from present 2481: 252 presents, frame p50 47.8 / p90 48.3 / p99 48.6 / max 49.0 ms, GPU busy 44.1 ms per present
AMD Radeon 760M (RADV PHOENIX), radv Mesa 25.0.7-2+deb13u1, Linux 7.2.12-x64v3-xanmod1, 1920x1080, commit
98ddd9c179(dirty), dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 44.1, Driver.Packet 35.4, Driver.Packet.draw 33.7, Driver.Draw 33.6, Driver.Draw.draw_enqueued 29.2, Recorder.Sync 28.8, Driver.WorkerWait 9.7, Driver.WorkerWait.idle_and_completion_poll 9.7, VideoOut.Flip 9.2, Driver.Present 9.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
B1
seconds 90:12 from present 2474: 252 presents, frame p50 47.7 / p90 48.2 / p99 48.7 / max 48.8 ms, GPU busy 44.0 ms per present
AMD Radeon 760M (RADV PHOENIX), radv Mesa 25.0.7-2+deb13u1, Linux 7.2.12-x64v3-xanmod1, 1920x1080, commit
d67548414c(dirty), dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 43.9, Driver.Packet 35.3, Driver.Packet.draw 33.6, Driver.Draw 33.5, Driver.Draw.draw_enqueued 29.4, Recorder.Sync 28.9, Driver.WorkerWait 9.7, Driver.WorkerWait.idle_and_completion_poll 9.7, VideoOut.Flip 9.1, Driver.Present 9.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:51:47Z.
Review: CHANGES_REQUESTED
The focused min/max coverage and paired scene measurements are detailed, but the required comparison is against a stale base: the report pins
mainatd5140548fc79and says it later advanced tob99bbebacd; currentmainis now87b810a1db14. Since this is a shader-recompiler change, the repository requires the same focused validation tests onmainand the change. Please update the branch to currentmain, rerun the focused min/max tests on that base and head with the prescribed validation settings, and refresh the performance pair if the updated production source changes the tested code path. Until then I cannot treat the old baseline as a current-main review.Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-28T18:45:00Z.
Review: APPROVED
macOS / MoltenVK data point. Apple M4 Pro, macOS 27.2, MoltenVK 1.4.2, x86_64 Release under Rosetta.
maindoesn't run titles on macOS yet, so the base is a support branch, notmain:main750cf6cf48+ only the macOS boot PRs #7631 #10552 #11249 #11447 #11554 #10669 #7804, + #12529 (the revert of #10337, which roughly doubles the GPU time on this GPU and would hide smaller changes). Change: that base + eight open shader performance PRs merged together (#12287 #11952 #12299 #12280 #11368 #11265 #8716 #8958, all clean merges). I did not measure each PR alone.Two alternated runs per side, warm shader cache,
APS5_TRACE_SUMMARY_EVERY=10:Together they don't raise the GPU time on MoltenVK. I'm checking open shader performance PRs on this GPU because #10337 was measured on RADV and doubled it here.
Focused tests below ran with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon the same two trees; the layer was found and both logs have the sameVUID-lines (12VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, 20VUID-vkCreateDescriptorSetLayout-support-09582, from tests that fail the same way on the base).This PR on MoltenVK:
agc_driver_dx10_clamp,agc_driver_f32_min_max_denormal_modes,agc_driver_f32_min_max_nanandagc_driver_f32_result_clamppass on the base and with the change, so the new literal-zero rows also hold on Apple's GPU. The fast path is one ordered compare and a select in place of the classify-and-select lowering, which is cheaper on any backend; I see no case where it changes the result. Approving from the macOS side.AI-assisted: yes (Claude Code ran the builds, runs and tests and drafted this review)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:16:52Z.
Review: APPROVED
Re-checked — approved
The exact head
67d3a64e80321e65f5478b8573570ba58b5e6273has the requested current-main comparison. The author reports the four focused min/max, denormal, and clamp fixtures passing on both sides, with zero VUIDs or skips; a Windows/NVIDIA repeat also passed 4/4 on both sides in three runs. The testedSpirvModuleEmitter.cppis byte-identical between the measured base and refreshed main, and the PR includes matched scene/machine performance summaries and trace digests.The current-main merge preview is clean and the changed paths have no additional main-side edits since the tested refresh. Hosted policy and Windows jobs pass; Linux product CI is skipped. I did not run GPU tests locally.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:36:14Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
1b2135eb827012c3008dd8b57337d554d5c7cb24. The current-main focused validation report is useful, but the performance refresh is explicitly pending and the old captures are not a compliant report for this integration. Theperflabel check also confirms the required same-title, same-scene, same-machinemain/changeaps5-summary.jsonllines, attached traces, andtools/trace_digest.pyoutput are absent. Please add that report before approval. I did not run GPU tests locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T01:06:34Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The new report resolves the missing-evidence point on its pinned revisions, but current
mainhas since added shader-recompiler handling forFPMax32, so the report does not validate this change against today’s implementation.What I ran
0821cd0771c89a2352cc9602c891a919610cbc6b; PR base and report baseline:fd9b3f62d43d6753d28a31a7c285e1f51e9c1b42; currentmain:f6fddd60d826831f70f7c62e25423610ee742bcc.git diff --checkand conventions pass.SpirvAluEmitterMath.cppchanged onmain; the new matcher explicitly handlesIrOpcode::FPMax32. This PR changesEmitMinMaxF32Valuefor FPMax, so the new path is relevant to the operation under review.Results
214eccae3fb96f5bcd2321ee533636420b080a51git diff --checkSpirvAluEmitterMath.cppadds 276 lines and removes 3; it introduces FPMax32 wave-reduction matchingfd9b3f62d43dand the PR head, with zero VUIDs, missing-layer warnings or skips; this report predates the current-mainFPMax32changemainUnedited local command output
git diff --checkproduced no output and exited 0.Findings
Blocking
mainand the updated PR head with the prescribed Khronos validation settings. The newFPMax32reduction matcher postdates the report baseline and may affect compilation or execution involving this opcode; the existing report does not exercise the combined current-main tree.perfreport against currentmainand the updated PR head on the same title, scene, machine and settings. The existing samples remain useful for their pinned revisions, but do not measure the present integration after the interveningFPMax32change.Non-blocking
The current branch merges cleanly, and the author’s report is internally described as mixed FPS evidence rather than a repeatable frame-rate claim.
Sources
FPMax32reduction handlingFPMax32lowering changeNot verified
I did not build or run the focused tests, validation layers, or performance captures locally. Those results are author-reported. Linux product and specialized hosted jobs were skipped.
To get this to a good state
Integrate current
main, publish the focused validation comparison and a matched current-main performance pair, then request re-review. I will rerun the same non-build checks on the resulting head.