fix(shader): select an f32 add or sub NaN result once #11490
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11490"
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 parl0v on 2026-10-26T17:10:53Z.
What
An f32
v_add_f32,v_sub_f32orv_subrev_f32result now goes through one NaN select instead of three.propagatedNanResultF32picks the NaN to return from the sources first (first source, then second, then0xffc00000, the same order as before) and selects it only when the host result is NaN.floatBinaryuses it for FPAdd32 and FPSub32; FPMul32 and the FMA paths keepnanResultF32. The returned bits are the same in every case. LikenanResultF32, it returns the host result unchanged whenAPS5_FAST_F32is set.New test
agc_f32_nan_result_selectsrecompiles a chain of four adds and subs and checks that every hostOpFAdd/OpFSubresult reaches the register through exactly one NaN select.Based on
maind59584e603.Why
Human Fall Flat (PPSA02429) sits on a black screen after the splash on a cold first boot. The game is not deadlocked: the GPU queue worker is inside
vkCreateComputePipelines(nvgpucomp64.dllunderAgcDriver::CreateComputePipeline, one core busy), so the render thread waits on its EOP equeue and the main thread waits on the render thread.The pipelines are two Unity compute shaders of 18,640 code words each (wave64, 16x8 threads) that are 16,384 dependent
v_sub_f32 v1, v1, vN. Each becomes about 2.63 M SPIR-V words, and on an RTX 3060 with driver 617.42 each takes about 5 minutes to create. Runs stopped before that never save the pipelines, so every short run looks like a hang. Once both are in the pipeline cache, they take 40 to 49 ms and the title screen comes up.NVIDIA's compile time grows faster than the shader: 3.3 s at 1,000 subs, 20.8 s at 4,000 and 290 s at 16,384. I timed variants of the 4,000-sub shader on an earlier
main(97d33464c5) to find the cause:The cost is in the three dependent selects that each add or sub result passed through on the dependency chain, not in the instruction count. Only the variant this PR implements keeps the results bit-exact. The reordering is exact because for an f32 add or sub a NaN source always makes the host result NaN (the module declares
SignedZeroInfNanPreserve), so testing the result first and choosing among the source NaNs inside that branch returns the same bits as before.The
guest context signal=0x1elines in the HFF log are the IL2CPP GC stopping the world throughsceKernelRaiseException. In a traced run every raise (114) reached its handler and returned, and every collection got all of its acks, so the GC is not involved in the black screen.Measured
Windows 10, RTX 3060 12 GB, NVIDIA 617.42, i5-12400F.
main48c160c58bagainst this PR 91317d3438 (the head before the rebase ontod59584e603), same machine and session. The traces, summary lines, digests andperformance_compare.pyoutputs are in hff-traces-pr11490.zip.Cold first boot to the title screen, the scene where the pipelines are built. Shader cache and driver shader cache emptied before each run,
APS5_TRACE_SECONDS=0:640(main) and0:400(this PR) so that the window covers both pipelines,APS5_TRACE_EVENTS=1048576:Vulkan.ComputePipeline, first shaderVulkan.ComputePipeline, second shadertrace_digest.py)Warm title screen, as the Performance report form describes (scene run once, title restarted,
APS5_TRACE_SECONDS=30:30, no other trace or profile switch): frame p50 28.9 / 28.9 ms, p90 32.5 / 31.9 ms, p99 36.0 / 35.1 ms, GPU busy 19.1 / 18.8 ms per present (main / this PR). The two shaders run only at boot, so with warm caches this PR changes no frame time, and I make no frame-time claim.Caveats:
Vulkan.ComputePipelineslices, not the frame percentiles.main, HFF runs that print to the console window often stop at about 475 presents before the pipelines are built: 2 of 4 boots ofmainand 7 of 9 boots of this PR did that, and all 3 boots of this PR with the log in a file got through. Sincemainstalls the same way, that is a separate problem from this PR. Logging does not change pipeline creation time.dropped: yes.Pipeline creation in a replay harness: the captured layout replayed with the SPIR-V each build generates,
main570089a806, every SPIR-V new to the driver cache:Tested
Windows 10 (19045), RTX 4060 8 GB, NVIDIA 617.42, MinGW GCC 15.2 Release build, on
maind59584e603and this PR022191e803, same machine and session. Khronos validation layer from Vulkan SDK 1.4.363.0 on (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_KHRONOS_VALIDATION_REPORT_FLAGS=error,warn,ANYPS5_REQUIRE_VULKAN=1); the loader inserted it in all 16 GPU tests on both builds and it reported 0 errors and 0 warnings (no VUID).mainran with onlyF32NanResultSelects.cppand its CMake fragment added. Command, from each build directory:maind59584e603022191e803agc_f32_nan_result_selectsagc_redundant_value_elimination,agc_denormal_flush_elimination,agc_integer_folding,agc_f32_denorm_preserve.agc_driver_f32_arithmetic_nan,agc_driver_f32_arithmetic_nan_fast(APS5_FAST_F32=1),agc_driver_f32_add_mul_denormal_modes,agc_driver_f32_denormal_flush,agc_driver_f32_output_modifier,agc_driver_f32_result_clamp,agc_driver_dx10_clamp,agc_driver_nan_quieting,agc_driver_f32_min_max_nan,agc_driver_fma_legacy,agc_driver_fma_rounding,agc_driver_division,agc_driver_f32_separate_rounding,agc_driver_f32_constant_factor_tininess,agc_driver_lds_add_f32andagc_driver_sdwa_cvt_f32_ubyte.agc_driver_f32_add_mul_denormal_modespasses on both but runs 0 of its 4 modes on this GPU (the test reports that they need DenormPreserve 32).Related
nanResultF32for all its users. That leaves 2 NaN selects on an add or sub result's chain, and it tests NaN withFPIsNan32. The two compose: #4287 keeps covering mul, FMA and the othernanResultF32users, and with this PR on top, add and sub go throughpropagatedNanResultF32with 1 select. They merge without conflicts in either order.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-26T17:15:17Z.
Review: CHANGES_REQUESTED
I reviewed the new helper and the add/sub call sites. The source-priority order and
quietNan32handling match the previousnanResultF32path, and the new structural test checks the result-dependent select chain. I also verified#4287is still open and that the two current PR heads merge cleanly in either order; I found no conflict there.Two repository gates remain:
main(check_main_sync.py --strict); the current-main tree differs from the tested base inOperandAccess.cpp, which this PR also changes. Please sync the branch and rerun the focused shader tests, including the NaN behavior tests, on the updated base/head. Current hosted checks are conventions, eligibility, intake, labels and report only; product/GPU jobs are skipped by path policy. I did not independently run the GPU suite.tools/trace_digest.pymain/change summaries or trace attachments. The repo's speed-claim rule requires those captures from the same machine and scene. Please add the prescribed evidence, or revise the speed claim if that capture protocol cannot measure this shader-pipeline case.The checklist says
Unblocks: PPSA02429without a Game bring-up discussion reference. I found no matching issue or discussion by title ID in the repository; please link the relevant discussion if one exists, otherwise mark the fieldnone.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T07:54:04Z.
Review: CHANGES_REQUESTED
Re-review — changes requested
The author addressed the prior evidence and checklist requests: the PR now includes matched summary lines, linked traces/digests, reports no frame-time claim, and sets
Unblocks: none. The remaining blocker is that the tested base is stale and currentmainchanged the same shader paths.What I checked
91317d34389f88d66829f098190a0ff24330d8dbagainst currentmain4c7d275bef89d309313d16bc2bc05d37a1b50be2.mainchangedFloatInstructions.cpp,TranslationContext.hpp, and the AGC test CMake file, all also touched by this PR.git diff --checkis clean andtools/check_conventions.pypasses against currentmain.Required before approval
Please integrate current
mainand rerun the NaN-select structural test plus the focused recompiler and GPU arithmetic tests on the updated base and change using the same GPU and validation-layer settings. The existing Windows/NVIDIA and Linux/AMD runs are strong evidence for their reported heads, but they precede currentmain's edits to the affected translator paths.The matched HFF capture evidence is already present in the PR body and linked archive. I am not asking you to repeat those captures as part of this integration request.
Not verified
I did not run a local shader build or GPU tests; no Vulkan device is exposed in this workspace.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T09:46:47Z.
Review: CHANGES_REQUESTED
Re-checked — new head, focused tests still needed
The branch now includes its merge from
main, but the current-head Windows job compiled the new test executable without showing that CTest ran it, so I cannot clear the existing validation request.What I ran
Reviewed head
9636fb02138145a97283dc335bcdabcf02609033against its recorded basec2ba690bfc6597c3b33084057a02ffa7f0f49d10and currentmain26fa1212b82f76dd49cf12d65e445d6ff3e0844c. The exact-head merge preview against currentmainis clean. Environment: Debian GNU/Linux 12, Python 3.11.2, GCC 12.2.0 for repository tooling. I did not build or run C++ tests locally.Results
26fa1212b82f76dd49cf12d65e445d6ff3e0844c; the branch's second parent isc2ba690bfc6597c3b33084057a02ffa7f0f49d10. The only latermainhunk inInstructionTranslator.cppchanges mesh-shader group indexing, not the f32 add/sub translation under review.agc_f32_nan_result_selectsis registered in the new CMake fragment. The heuristic's possible-unregistered-test warning is a false positive.agc_f32_nan_result_selects_tests.exe. Its logged CTest result shows only one unrelated conventions test; it does not showagc_f32_nan_result_selectsexecuting.91317d34389f88d66829f098190a0ff24330d8db, not merge head9636fb02138145a97283dc335bcdabcf02609033.Unedited selected output from the exact-head Windows job
Negative control
9636fb02138145a97283dc335bcdabcf02609033Findings
Blocking
The existing review asked for focused validation after integrating the shader-path changes from
main. Although this branch now mergesmain, the current-head CTest log does not show the added structural test or the focused arithmetic tests running, and the PR's reported test results are for the prior head. Please runagc_f32_nan_result_selectsand the focused f32/NaN arithmetic tests on currentmainand this exact head, using the same machine/GPU and validation-layer settings, then post the commands, heads, and results. The Windows CI build confirms compilation of the new executable but is not evidence that its test ran.Non-blocking
The branch is behind current
main, but the live merge preview is clean and the later main change inInstructionTranslator.cppis in the unrelated mesh-shader prologue; I am not asking for another rebase on that basis. The performance evidence already in the PR compares the unchanged shader implementation; I am not asking for new captures in this follow-up.Sources
Not verified
No local build or CTest, no current-head Linux GPU run, and no console behavior were verified in this session. The older author-run shader/GPU test data does not cover the exact merge head.
To get this to a good state
Post focused results for the updated base and exact head, including the actual
agc_f32_nan_result_selectsCTest output and the validation-layer status. I will rerun the same review checks on the new head.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T14:31:36Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(4f41f4c375): head 9636fb02138145a97283dc335bcdabcf02609033 conflicts incore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/FloatInstructions.cppPlease rebase it onto current
main. I will review the change once it merges cleanly.