Skip to content

perf(shader): guard NaN repair regions using certified inputs - #17681

Merged
oneandonlydean merged 8 commits into
boykopovar:mainfrom
Filip722:perf/nan-region-fast-path-20261109
Nov 17, 2026
Merged

oneandonlydean merged 8 commits into
boykopovar:mainfrom
Filip722:perf/nan-region-fast-path-20261109

Conversation

@Filip722

@Filip722 Filip722 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Scalar f32 arithmetic repeatedly builds exact NaN payload and invalid-result repairs along dependent chains. This change shares those checks across pure arithmetic regions and uses a certified input guard where possible, retaining the original exact region for exceptional or out-of-range inputs.

  • Bound the speculative intermediates by powers of two and derive a runtime input threshold. A successful certificate moves the guard before arithmetic and replaces intermediate classifications with entry checks. Unsupported cases retain an aggregate NaN guard over the speculative sources.
  • Execute the original region when a guard fails and merge every IR definition, including values read implicitly by backend matchers. Exclude memory, side effects, derivatives, subgroup operations, split lane contexts, loop headers and continue targets.
  • Visit each resolved condition node once while preserving the original first matching NaN source; use the existing full shader-memory fixture as the timeout regression.
  • Extend the existing arithmetic fixture with uniform cases and add a synthetic regression for NaN predicates crossing region boundaries, directly and through a conjunction.

The fast path changes only NaN-conditioned selects to their false arms. The entry certificate bounds every skipped predicate source, including intermediate products and sums; it does not infer that arbitrary finite inputs cannot overflow. Arithmetic bounds include an extra factor of two and reject product/sum bounds above 2^126, accounting conservatively for inherited GLSL Fma precision and the fused-exact lowering. If no certificate is available, the intermediate-source magnitude guard detects the first possible difference. Any failed guard uses the unchanged region. Source priority, payloads, IEEE quieting, canonical invalid results, FTZ, tiny-product handling, signed zero, rounding and modifiers remain intact. No native NaN-propagation assumption is introduced. Vulkan precision requirements.

In the largest matched region, 68 intermediate guard sources become five entry roots with a derived threshold of ±2^35. Production GPL/LTO native code retains the early branch. The tradeoff remains material: the matched hot fragment has 8,541 static instructions versus 4,987 on main, 48 versus 32 VGPRs, unchanged 128 SGPRs and no scratch spills; theoretical occupancy is 10 versus 16 waves/SIMD. Static counts include both paths. Frequent exceptional/out-of-range inputs and other backends are unmeasured.

This is a region transformation, distinct from the closed per-operation guards #4322/#12548 and the payload-observability analysis in #17227. The retained overlap check and manual shared-file comparisons cover adjacent BDA masking, ballot and stencil changes; no duplicated implementation or ordering dependency was found.

Tested

Author follow-up (2026-11-15), head bacd603b3f8f, with pinned main fd58fa5a0213 integrated before all tests and captures. Adapted EmitNanRegion to main’s indexed definition table using the existing Erase/Emplace operations; the previous map assignment no longer built. The repaired traversal and original exact fallback remain intact.

Matched hardware validation passes 15 focused tests on each side on AMD Radeon 760M / RADV Mesa 25.0.7 / Debian 13 / Linux 7.3.3 and the NVIDIA GeForce RTX 5060 Laptop GPU / NVIDIA 615.78.08 / Bazzite 44 / Linux 7.2.9. Khronos 1.4.363 is actually inserted in every device fixture; no skipped GPU tests, missing-layer messages or VUID errors. These are author runs, distinct from the contributor reports below.

Current-head NVIDIA capture: ProsperoLight PPSA99002 01.000.110, the same fresh no-PC idle scene, 3840×2160 source buffers and 1920×1080 X11 output, GCC 15.2 Release/SPIRV-Tools ON. Two fixed warmed 10-second windows per head, with shared main controls in forward/reverse order; all ten valid windows are retained; two objectively unusable outage attempts were replaced, with no extra pairs. GPU command span/present: main 5.720 / 6.032 ms; this full PR head 6.342 / 6.356 ms. Paired reduction: -10.874% / -5.371%, mean -8.123%, 95% Student-t df1 interval [-43.082%, +26.837%] (inconclusive). This is GPU command-span efficiency at the 60 Hz cap, not an FPS increase. The #17681/#17709/#17919 comparisons measure their full prerequisite stacks, not isolated incremental gains. One stationary scene and two pairs limit scope and precision.

Cold diagnostics still show a cost relative to pinned main: maximum reported per-draw pipeline phase is 1,218.1 / 1,161.3 ms on main, 1,743.4 / 1,735.3 ms on #17681, and 1,741.0 / 1,743.4 ms on #17709. This is APS5_PROFILE_DRAW’s longest pipeline phase, not an isolated vkCreateGraphicsPipelines timer. Separate empty-cache diagnostics use two runs per arm; these data do not reproduce the extra #17709-over-#17681 cold penalty seen in the older Windows report, but the shared main-to-region penalty remains material and is not marked resolved. The same retained 5,413-code-word fragment emits 210,144 / 271,375 / 270,665 SPIR-V words on main / #17681 / #17709. All 50 replayed modules (10 requests per arm) pass SPIR-V validation.

Audited current-head traces, raw summary lines, trace_digest.py outputs, protocol, exact binary provenance, cold diagnostics, numeric replay counts and hardware validation. Traces contain only host timing/count data. Game files, shaders, screenshots, caches and console logs remain private. After an abrupt laptop outage, six usable original captures were retained; the seventh had zero-length recovered files and the eighth had no completed trace. Only those two were replaced, and the remaining planned windows finished after a qualified restart. The driver, binaries and scene were unchanged. Earlier excluded warmup deadline failures are also disclosed. Author work and reviewer acceptance are separate.

Current main and current-head capture summary lines (first window; all windows and digests attached)
{"commit":"fd58fa5a0213","dirty":false,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"15:10"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.78.08","os":"Linux 7.2.9-ogc2.1.fc44.x86_64","cpu":"Intel(R) Core(TM) 7 240H","cpu_threads":16,"memory_mib":15672,"title_id":"PPSA99002","title":"ProsperoLight","content_version":"01.000.110","resolution":"3840x2160","window":{"spec":"seconds 15:10","first_present":895,"ms":10016.296},"presents":600,"frame_ms":{"p50":16.688,"p90":18.355,"p99":20.51,"max":22.375},"gpu_busy_ms_per_present":5.72,"worker_busy_pct":{"queue worker 0x0":25.322},"phase_totals_ms":{"Driver.Completion":4.606,"Driver.Draw":1103.352,"Driver.Draw.device_setup":60.847,"Driver.Draw.draw_enqueued":166.414,"Driver.Draw.post_compile_prepare":5.042,"Driver.Draw.prepare":162.183,"Driver.Draw.shader_compile_and_link":688.095,"Driver.EndSubmission":10.786,"Driver.Packet":2520.12,"Driver.Packet.device_lock":12.268,"Driver.Packet.draw":1114.525,"Driver.Packet.execute":117.855,"Driver.Packet.flip_flush":80.287,"Driver.Packet.flush_between_packets":25.34,"Driver.Packet.pipeline_drain":1033.953,"Driver.Packet.pipeline_prepare":22.714,"Driver.Packet.prepare_memory":25.067,"Driver.Present":685.783,"Driver.Present.acquire_image":81.77,"Driver.Present.device_setup":1.64,"Driver.Present.gpu_mutex_wait":28.468,"Driver.Present.inflight_wait":5.559,"Driver.Present.present_display_buffer":192.211,"Driver.Present.queue_present":266.594,"Driver.Present.release_and_callback":1.787,"Driver.Present.render_fence_wait":102.398,"Driver.Present.resize":2.948,"Driver.Present.validate":0.908,"Driver.Suspend":0.85,"GpuMutex.wait.draw":4.448,"GpuMutex.wait.end":4.622,"GpuMutex.wait.flush":0.288,"GpuMutex.wait.label":1.06,"GpuMutex.wait.present":24.161,"GpuMutex.wait.wait":91.828,"Graphics.Draw":2707.314,"Graphics.Draw.draw_and_resource_release":2575.438,"Graphics.Draw.index_upload":2.235,"Graphics.Draw.validate":96.073,"Graphics.Draw.vertex_upload":14.498,"Recorder.Reap":119.636,"Recorder.Submit":416.117,"Recorder.Sync":39.308,"Recorder.WaitSerial":22.766,"Resources.Complete":268.193,"Resources.Prepare":350.273,"Shader.DrawStage":588.314,"Shader.DrawStage.capture_resources":408.147,"Shader.DrawStage.materialize":78.085,"Shader.DrawStage.prepared_invocation":95.298,"VideoOut.Flip":1640.189,"VideoOut.Flip.completion_mutex_wait":1.439,"VideoOut.Flip.config_mutex_wait":0.523,"VideoOut.Flip.frame_limit":1.91,"VideoOut.Flip.notify_game":17.825,"VideoOut.Flip.present":692.791,"VideoOut.Flip.validate":2.683,"VideoOut.Flip.vblank_wait":863.104,"VideoOut.Flip.window_prepare":2.525,"VideoOut.Flip.window_title":56.486,"VideoOut.Readiness":4.384,"VideoOut.Readiness.locks_validate":2.019,"Vulkan.Acquire":77.189,"Vulkan.Acquire.acquire_fence_wait":13.495,"Vulkan.Acquire.acquire_image":50.198,"Vulkan.Acquire.fence_reset":12.182,"Vulkan.Acquire.retired_swapchains":0.631,"Vulkan.Present":132.132,"Vulkan.Present.command_record_scale":90.561,"Vulkan.Present.pixel_upload":5.489,"Vulkan.Present.queue_submit":34.151,"Vulkan.QueuePresent":263.242,"Vulkan.QueuePresent.queue_present":261.368,"Vulkan.Retire":100.432,"Vulkan.Retire.wait":82.154},"top_phases_ms_per_frame":{"Graphics.Draw":4.512,"Graphics.Draw.draw_and_resource_release":4.292,"Driver.Packet":4.2,"VideoOut.Flip":2.734,"Driver.Packet.draw":1.858,"Driver.Draw":1.839,"Driver.Packet.pipeline_drain":1.723,"VideoOut.Flip.vblank_wait":1.439},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":10801,"Graphics.Barrier.label-run":11764,"Graphics.Barrier.present-blit":1200,"Graphics.RenderPass":5400,"Graphics.RenderPass.Close.new-batch":5400,"Graphics.RenderPass.Continued":1800},"trace_dropped":false,"trace":"aps5-trace-fd58fa5a0213-57461.json.gz"}
{"commit":"bacd603b3f8f","dirty":false,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"15:10"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.78.08","os":"Linux 7.2.9-ogc2.1.fc44.x86_64","cpu":"Intel(R) Core(TM) 7 240H","cpu_threads":16,"memory_mib":15672,"title_id":"PPSA99002","title":"ProsperoLight","content_version":"01.000.110","resolution":"3840x2160","window":{"spec":"seconds 15:10","first_present":893,"ms":10006.888},"presents":594,"frame_ms":{"p50":16.707,"p90":18.805,"p99":21.102,"max":21.396},"gpu_busy_ms_per_present":6.342,"worker_busy_pct":{"queue worker 0x0":25.859},"phase_totals_ms":{"Driver.Completion":4.746,"Driver.Draw":1156.96,"Driver.Draw.device_setup":63.129,"Driver.Draw.draw_enqueued":168.637,"Driver.Draw.post_compile_prepare":5.582,"Driver.Draw.prepare":169.677,"Driver.Draw.shader_compile_and_link":727.319,"Driver.EndSubmission":11.946,"Driver.Packet":2570.143,"Driver.Packet.device_lock":12.826,"Driver.Packet.draw":1168.455,"Driver.Packet.execute":120.561,"Driver.Packet.flip_flush":81.006,"Driver.Packet.flush_between_packets":27.12,"Driver.Packet.pipeline_drain":1011.027,"Driver.Packet.pipeline_prepare":24.266,"Driver.Packet.prepare_memory":26.644,"Driver.Present":644.754,"Driver.Present.acquire_image":82.908,"Driver.Present.device_setup":1.703,"Driver.Present.gpu_mutex_wait":24.104,"Driver.Present.inflight_wait":5.86,"Driver.Present.present_display_buffer":197.012,"Driver.Present.queue_present":278.663,"Driver.Present.release_and_callback":1.841,"Driver.Present.render_fence_wait":47.057,"Driver.Present.resize":3.049,"Driver.Present.validate":0.964,"Driver.Suspend":0.822,"GpuMutex.wait.draw":2.663,"GpuMutex.wait.end":1.886,"GpuMutex.wait.flush":0.265,"GpuMutex.wait.label":0.519,"GpuMutex.wait.present":19.653,"GpuMutex.wait.wait":90.597,"Graphics.Draw":2787.519,"Graphics.Draw.draw_and_resource_release":2649.011,"Graphics.Draw.index_upload":2.63,"Graphics.Draw.validate":102.184,"Graphics.Draw.vertex_upload":16.24,"Recorder.Reap":123.002,"Recorder.Submit":421.673,"Recorder.Sync":40.751,"Recorder.WaitSerial":22.149,"Resources.Complete":274.681,"Resources.Prepare":363.334,"Shader.DrawStage":621.343,"Shader.DrawStage.capture_resources":434.928,"Shader.DrawStage.materialize":81.783,"Shader.DrawStage.prepared_invocation":97.415,"VideoOut.Flip":1154.371,"VideoOut.Flip.completion_mutex_wait":1.857,"VideoOut.Flip.config_mutex_wait":0.381,"VideoOut.Flip.frame_limit":1.675,"VideoOut.Flip.notify_game":17.384,"VideoOut.Flip.present":652.544,"VideoOut.Flip.validate":2.692,"VideoOut.Flip.vblank_wait":416.803,"VideoOut.Flip.window_prepare":2.465,"VideoOut.Flip.window_title":57.569,"VideoOut.Readiness":4.488,"VideoOut.Readiness.locks_validate":2.05,"Vulkan.Acquire":78.207,"Vulkan.Acquire.acquire_fence_wait":12.962,"Vulkan.Acquire.acquire_image":51.554,"Vulkan.Acquire.fence_reset":12.269,"Vulkan.Acquire.retired_swapchains":0.737,"Vulkan.Present":133.409,"Vulkan.Present.command_record_scale":91.287,"Vulkan.Present.pixel_upload":5.397,"Vulkan.Present.queue_submit":35.237,"Vulkan.QueuePresent":275.101,"Vulkan.QueuePresent.queue_present":273.196,"Vulkan.Retire":46.055,"Vulkan.Retire.wait":29.044},"top_phases_ms_per_frame":{"Graphics.Draw":4.693,"Graphics.Draw.draw_and_resource_release":4.46,"Driver.Packet":4.327,"Driver.Packet.draw":1.967,"Driver.Draw":1.948,"VideoOut.Flip":1.943,"Driver.Packet.pipeline_drain":1.702,"Driver.Draw.shader_compile_and_link":1.224},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":10690,"Graphics.Barrier.label-run":11582,"Graphics.Barrier.present-blit":1188,"Graphics.RenderPass":5345,"Graphics.RenderPass.Close.new-batch":5345,"Graphics.RenderPass.Continued":1782},"trace_dropped":false,"trace":"aps5-trace-bacd603b3f8f-59717.json.gz"}

Upstream assessment after the batch: later main 2454441420d5 changes shader lowering and AGC resources. All ten retained NVIDIA shader inputs emit byte-identical SPIR-V, and five focused regression tests pass on Radeon. This is bounded compatibility evidence, not a timing measurement of later main; the results above remain tied to the exact fd58fa5a0213-based binaries.

Earlier evidence, attributed to its original revisions:

Review follow-up (2026-11-12), head e74628d2dd01: integrated main 3b7f31fa700b and bounded the shared LogicalAnd search in RegionNanCondition with an explicit work stack and visited set. It preserves the original left-to-right first-match result and avoids recursive stack growth. The unchanged #17681/main integration 6cfe0feaee34 reproduces the reported agc_shader_memory timeout at 30 s. The existing full test now passes in about 2.96–2.97 s on main and all three repaired heads (#17681, #17709 and #17919).

The same seven tests pass on main and each repaired head: agc_shader_memory, agc_spirv_branch_targets, agc_denormal_flush_elimination, agc_driver_f32_arithmetic_nan, agc_driver_f32_arithmetic_nan_fast, agc_driver_f32_min_max_nan and agc_driver_nan_quieting. Radeon 760M / RADV Mesa 25.0.7-2+deb13u1 / Debian 13 / Linux 7.3.3-x64v3-xanmod1 / GCC 15.2.0 Release; required Vulkan/cache environment, VK_LOADER_DEBUG=layer, validation layer 1.4.363. Every arm has four actual instance/device layer insertions, zero skips, no missing-layer messages and no VUID errors. Three retained requests emit byte-identical SPIR-V before/after the traversal fix at the #17681 integration; the output comparison is limited to those requests.

The following historical FPS and trace results retain their original measured revisions. The November 12 repair heads were not gameplay-retimed. Current-head NVIDIA author measurements are above; no new Radeon gameplay or cold-pipeline improvement is claimed. Reviewer acceptance remains separate.

Independent Windows/NVIDIA evidence: talha-devp's RTX 4060 report tests head 8d1a3d6e48 integrated onto main 903ca7a672, alone and with #17227. In ProsperoLight's 4K idle screen, reported median warm GPU time is 17.48 ms on main, 11.94 ms with this PR, 9.42 ms with #17227, and 9.02 ms with both. The cost is material: the slowest cold pipeline takes about 5.5 s with this PR versus 2.4 s on main (3.7 s combined), and the dominant module grows from 258,825 to 482,809 SPIR-V words. This is one contributor's different title, host and protocol; its results are not pooled with our Radeon pairs. Doorriiaann separately confirms all 113 tests passing twice on fixed head 8d1a3d6e48 and its tested main, with RTX 3070 / NVIDIA 610.57.04, no VUID or synchronization-hazard lines.

Review follow-up at 8d1a3d6e48: the unchanged prefix before the first bypassed NaN repair is emitted once before the branch. Both paths reuse it, including the required input denormal flush; the existing chained-multiply regression retains its original one-mask assertion. The performance measurements below belong to their stated earlier revisions and have not been repeated for this fix.

Radeon 760M, RADV Mesa 25.0.7, Ryzen 5 7640HS, Linux 7.3.3-x64v3-xanmod1, GCC Release, ordinary GPL/LTO pipeline construction. Frozen main 0dd2fffe3576acf91048685236cd35305c637e17 versus complete implementation 15be56b2a99c877dbe4ebf60e1ed1b0ec3b18559. All three changed files are unchanged between the frozen base and the newer main inspected by the overlap check; these timings belong to the named revisions.

The same four focused arithmetic/NaN/Fract/trig fixtures pass on main and the final candidate, each with an actual Khronos device-layer insertion and no missing layer or VUID errors. The cross-region predicate regression fails on the initial guard implementation and passes on main and the correction. A dependent synthetic chain produces 24,864 bit-identical output bytes across 24 dispatches per arm, covering mixed/uniform signaling NaNs, source priority, finite overflow followed by invalid operations, IEEE 0/1, denormal modes 0/3 and signed neighboring encodings around two certified thresholds. Both retained matched shader requests validate.

Exactly two ordinary pairs, prospectively fixed ABBA order, all four valid, no timed replacements or extra pairs:

Pair Main FPS Candidate FPS Paired change
1 27.538114 29.732075 +7.966999%
2 27.351450 29.691841 +8.556736%

Mean paired change +8.261868%, 95% Student-t interval with one degree of freedom [+4.515210%, +12.008525%]. This supports a warmed stationary 4K camp result on this machine, with limited precision from two pairs. It does not establish general gameplay, hitch or cross-engine improvements. The complete implementation is measured here; the earlier guard-only result is superseded and is not additive.

Both arms used the same visible MangoHud observer, 1280x720 X11 client, requested Immediate presentation, dummy audio, unchanged guest cap and owned warmed cache/save seeds. Excluded preparation witnessed 3840x2160 rendering. Every timed window retained focus, camp and unchanged caches; all 63 loaded modules matched except AGC, and reported clocks stayed 2,599 MHz. No builds, profiler, debugger, screenshots or input during ordinary windows. One candidate preparation omitted the reused extent-check helper and stopped before logging; it was repaired locally and retained with zero ordinary intervals.

Audited evidence: four interval CSVs, protocol, provenance, hardware/native counts and original scoped traces. The upload was verified once, byte for byte, including CSV metric reproduction and original gzip integrity. Include the first exported interval when reproducing FPS.

The required summaries below are separate eight-second normal GPU diagnostics, not ordinary FPS replicates: GPU command span 32.982 versus 30.099 ms/present, stable caches and zero dropped events. The resolution field is API metadata.

Main:

{"commit":"0dd2fffe3576","dirty":false,"env":{"APS5_NO_PAD_INPUT":"1","APS5_OUTPUT_RESOLUTION":"3840x2160","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_BENCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"524288","APS5_TRACE_SECONDS":"40:8","APS5_TRACE_SUMMARY_EVERY":"1"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.3.3-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 40:8","first_present":1146,"ms":8010.275},"presents":224,"frame_ms":{"p50":35.674,"p90":36.334,"p99":37.177,"max":37.55},"gpu_busy_ms_per_present":32.982,"worker_busy_pct":{"queue worker 0x0":78.242},"top_phases_ms_per_frame":{"Driver.Packet":27.876,"Driver.Packet.draw":25.409,"Driver.Draw":25.372,"Driver.Draw.draw_enqueued":21.84,"Recorder.Sync":20.661,"VideoOut.Flip":7.257,"VideoOut.Flip.present":7.191,"Driver.Present":7.177},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-0dd2fffe3576-31569.json.gz"}

Candidate:

{"commit":"15be56b2a99c","dirty":false,"env":{"APS5_NO_PAD_INPUT":"1","APS5_OUTPUT_RESOLUTION":"3840x2160","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_BENCH":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"524288","APS5_TRACE_SECONDS":"40:8","APS5_TRACE_SUMMARY_EVERY":"1"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.3.3-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 40:8","first_present":1190,"ms":8009.591},"presents":244,"frame_ms":{"p50":32.881,"p90":33.484,"p99":34.338,"max":34.684},"gpu_busy_ms_per_present":30.099,"worker_busy_pct":{"queue worker 0x0":77.854},"top_phases_ms_per_frame":{"Driver.Packet":25.45,"Driver.Packet.draw":22.959,"Driver.Draw":22.921,"Driver.Draw.draw_enqueued":19.365,"Recorder.Sync":18.18,"VideoOut.Flip":6.568,"VideoOut.Flip.present":6.504,"Driver.Present":6.491},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-15be56b2a99c-80159.json.gz"}

Independent later-title report: @klosixgaming-arch's Cyberpunk 2077 intro check used this head bacd603b3f merged onto main e4caa07950 as b77d1721d7, Ubuntu 26.04.1 / Linux 7.0.0-43, NVIDIA RTX 2080 Ti / 595.99.02, GCC 15.2 Release, PPSA03974 02.120.000. They report no measurable warm intro difference (50.0 vs 50.8 presents per 10 seconds, base vs PR), from three base boots and two warm PR boots. Their separate first PR boot rebuilt 1,420 cache entries and stalled; it is retained in their report as cold-cache preparation. No driver failure, abort, or NotImplemented was reported. These are their observations, not author-run timing or validation-layer evidence, and are separate from the existing cold-pipeline diagnostics and the Sons of Sparta results.

Checklist

  • Based on current main; no other open PR implements the same functions — fd58fa5a0213 pinned before validation; subsequent upstream assessment above
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: author current-head runs: NVIDIA GeForce RTX 5060 Laptop GPU, NVIDIA 615.78.08, Bazzite 44 / Linux 7.2.9; AMD Radeon 760M, RADV Mesa 25.0.7-2+deb13u1, Linux 7.3.3-x64v3-xanmod1; independent Cyberpunk game report: NVIDIA GeForce RTX 2080 Ti, NVIDIA 595.99.02, Ubuntu 26.04.1 / Linux 7.0.0-43 (exact earlier main/merge and limitations above)
  • AI-assisted: yes

@Filip722
Filip722 marked this pull request as draft November 9, 2026 10:10
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6416 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 6751 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 7392 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 7642 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 10193 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 13928 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 13929 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 16952 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp
PR 18530 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Nov 9, 2026
@Doorriiaann

Copy link
Copy Markdown
Contributor

The description has RADV only, so here is an NVIDIA run of the float tests:

NVIDIA GeForce RTX 3070 (8 GB), driver 610.57.04, Debian 13, kernel 6.12.115+deb13.1-amd64
Commit: merge-base 0dd2fffe35 and PR head 94856d4feb, GCC 13.3.0 Release, only the test targets rebuilt per commit
Command: ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R '^(agc.*(f32|f16|f64|nan|denorm|float|fract|trig|mullit|arith|sin_cos|transcend).*|agc_spirv_branch_targets)$' -V, 2 runs per commit; validation layer vulkan-sdk-1.4.335.0. The pattern selects 113 tests, including agc_driver_f32_arithmetic_nan and agc_driver_f32_arithmetic_nan_fast (with this PR's new uniform-region cases on the head), agc_spirv_branch_targets (with the new cross-region NaN case), agc_driver_f32_min_max_nan, agc_driver_nan_quieting, agc_f32_nan_result_selects, the f16/f32/f64 denormal-mode and FTZ tests, and the fract, trig and mullit tests.

merge-base 0dd2fffe35 this PR 94856d4feb
113 tests × 2 runs 226/226 passed 226/226 passed
skipped 0 0

Result: no change on NVIDIA; the guarded regions give the same results as main in every float test here, including the new uniform finite, invalid-product and NaN-priority cases. I did not measure frame rate or shader size on NVIDIA.
Validation layer loaded (no "was not found" line). New VUID- errors vs merge-base: none (no VUID- or SYNC-HAZARD- line in any of the 4 runs).

AI-assisted: yes (run and drafted with an AI agent, checked by me)

@github-actions github-actions Bot added the perf Performance change label Nov 9, 2026
@Filip722 Filip722 changed the title perf(shader): guard scalar arithmetic regions against NaN repair perf(shader): guard NaN repair regions using certified inputs Nov 9, 2026
@Filip722
Filip722 marked this pull request as ready for review November 9, 2026 10:51
@Doorriiaann

Copy link
Copy Markdown
Contributor

Re-ran the same 113 tests on the new head 15be56b2a9 (same machine and command as above, 2 runs per commit). One test now fails on both runs, and it does not use the GPU (it counts the SPIR-V the recompiler emits), so it should fail on any machine:

agc_denormal_flush_elimination
  2 f32 exponent masks, expected 1
two chained v_mul_f32 keep only the input flush of the first source
merge-base 0dd2fffe35 94856d4feb 15be56b2a9
agc_denormal_flush_elimination passed 2/2 passed 2/2 failed 2/2
the other 112 tests 224/224 passed 224/224 passed 224/224 passed

DenormalFlushElimination.cpp is unchanged by this PR, so the extra mask comes from the SpirvFlowEmitter.cpp change in 15be56b2a9. The Windows job on this head ran one selected test, so CI does not show it. No VUID- or SYNC-HAZARD- line in any run; NVIDIA RTX 3070, 610.57.04, GCC 13.3.0 Release.

AI-assisted: yes (run and drafted with an AI agent, checked by me)

@Filip722

Filip722 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@Doorriiaann Fixed in 8d1a3d6. I reproduced the two-mask failure at 15be56b2a9 and the pass at the preceding 94856d4feb.

The entry guard duplicated the unchanged prefix, including the first input flush, into the fast and exceptional paths. The emitter now shares the prefix before the first bypassed repair and branches only around the remaining suffix. The original one-mask assertion passes unchanged; no denormal rule or repair is removed. Both paths retain the shared definitions, and the suffix still merges all definitions needed by backend matchers.

Matched runs on frozen main 0dd2fffe35 and the fixed tree selected the same 113 float/NaN/denormal/trig and branch-target tests: 112 passed on each, with the same agc_driver_float16_unused_nan_payloads capability skip. Radeon 760M, RADV Mesa 25.0.7, actual Khronos instance/device layer insertions in 102 tests per arm; no missing-layer messages or VUID errors. This is Radeon verification; your RTX 3070 report remains separately attributed.

The same fix is carried into #17709. The PR body distinguishes the earlier measured revisions from this unretimed correction.

AI-assisted: yes (Codex).

@talha-devp

Copy link
Copy Markdown
Contributor

Windows and NVIDIA numbers for 8d1a3d6e48, alone and combined with #17227. Both touch the NaN rules: #17227 drops NaN-result selects in the IR before emission, and this PR guards the selects that are left. They share no files and merge cleanly together.

Setup. RTX 4060, driver 621.14, Windows 10 19045, Ryzen 5 5600, MSYS2 GCC 16.2.0 Release. Four local builds:

Title and program. ProsperoLight (PPSA99002 01.000.110, free homebrew), idle screen, 3840x2160. Most of its GPU time is one fragment program, 0x217e15000 (5,413 code words).

main this PR #17227 both
0x217e15000 SPIR-V words (agc_shader_replay, no cache) 258,825 482,809 198,895 375,305
conditional branches / OpPhi in it 85 / 135 207 / 1,364 85 / 135 207 / 1,369
slowest pipeline creation, cold run (pipeline= of APS5_PROFILE_DRAW), two runs 2.24 / 2.55 s 5.47 / 5.46 s 1.57 / 1.50 s 3.71 / 3.69 s
GPU busy per present, warm, median of 4 windows (min to max) 17.48 ms (16.75 to 18.24) 11.94 ms (11.86 to 12.02) 9.42 ms (9.26 to 9.44) 9.02 ms (8.96 to 9.15)
frame p50, warm 20.9 ms 16.7 ms 16.7 ms 16.7 ms

Method.

Results.

Tests. The focused f32/NaN set (13 tests, plus agc_nan_payload_elimination where #17227 is in), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The layer was inserted, and no log has a VUID- line.

  • At 8d1a3d6e48, every test passes on all four arms.
  • At 15be56b2a9, agc_denormal_flush_elimination failed here too with 2 f32 exponent masks, expected 1, and the fix clears it.

Not measured: other titles, AMD and Intel GPUs, and the first-run stop of HUI titles on the same renderer, such as Surround Sound Studio. #11183 and #17227 tie that stop to this program's pipeline creation time.

Summary lines, main and this PR, first warm window
{"commit":"903ca7a672e9","dirty":false,"env":{"APS5_DUMP_FRAMES":"100000","APS5_DUMP_FRAMES_EVERY":"30","APS5_DUMP_SCALE":"8","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"15:10","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4060","driver":"NVIDIA 621.14","os":"Windows 10.0.19045","cpu":"AMD Ryzen 5 5600 6-Core Processor","cpu_threads":12,"memory_mib":32678,"title_id":"PPSA99002","title":"ProsperoLight","content_version":"01.000.110","resolution":"3840x2160","window":{"spec":"seconds 15:10","first_present":657,"ms":10018.151},"presents":451,"frame_ms":{"p50":22.113,"p90":23.089,"p99":24.85,"max":25.947},"gpu_busy_ms_per_present":18.239,"worker_busy_pct":{"queue worker 0x0":11.008},"top_phases_ms_per_frame":{"Driver.Packet":2.398,"Graphics.Draw":2.254,"Graphics.Draw.draw_and_resource_release":2.197,"Driver.Packet.draw":0.797,"Driver.Draw":0.79,"VideoOut.Flip":0.711,"Driver.Packet.pipeline_drain":0.682,"Driver.Draw.shader_compile_and_link":0.604},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-903ca7a672e9-6272.json.gz"}
{"commit":"6c4a17df2e91","dirty":false,"env":{"APS5_DUMP_FRAMES":"100000","APS5_DUMP_FRAMES_EVERY":"30","APS5_DUMP_SCALE":"8","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"15:10","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4060","driver":"NVIDIA 621.14","os":"Windows 10.0.19045","cpu":"AMD Ryzen 5 5600 6-Core Processor","cpu_threads":12,"memory_mib":32678,"title_id":"PPSA99002","title":"ProsperoLight","content_version":"01.000.110","resolution":"3840x2160","window":{"spec":"seconds 15:10","first_present":894,"ms":10005.153},"presents":595,"frame_ms":{"p50":16.685,"p90":17.149,"p99":21.231,"max":30.302},"gpu_busy_ms_per_present":11.856,"worker_busy_pct":{"queue worker 0x0":14.291},"top_phases_ms_per_frame":{"Driver.Packet":2.351,"Graphics.Draw":2.12,"Graphics.Draw.draw_and_resource_release":2.066,"VideoOut.Flip":1.832,"VideoOut.Flip.vblank_wait":1.182,"Driver.Packet.pipeline_drain":0.75,"Driver.Packet.draw":0.642,"Driver.Draw":0.636},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-6c4a17df2e91-4240.json.gz"}

AI-assisted: yes. Claude Code ran the builds, tests and runs and drafted this comment.

@Doorriiaann

Copy link
Copy Markdown
Contributor

Thanks. NVIDIA on the fixed head 8d1a3d6e48, same 113 tests and command as above (RTX 3070, 610.57.04, GCC 13.3.0 Release, 2 runs per commit): merge-base 0dd2fffe35 226/226 passed, 8d1a3d6e48 226/226 passed, including agc_denormal_flush_elimination (2/2) and agc_spirv_branch_targets. No VUID- or SYNC-HAZARD- line in any run.

AI-assisted: yes

@Filip722

Filip722 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@Doorriiaann Thanks for confirming the fixed head on NVIDIA. @talha-devp I added your separately attributed four-arm Windows/RTX 4060 results to the description, including the cold-pipeline cost and larger SPIR-V module alongside the warm GPU-time reduction. The #17227 composition remains your tested result; it is not pooled with our Radeon pairs or treated as a cross-vendor gameplay claim. No source change or new timing cohort was needed for this evidence update.

AI-assisted: yes (Codex).

@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows GPU check of head 8d1a3d6e48, merged onto main 8fbe687d16 (b730ba879b, clean merge). Run through the Windows FIFO, job db4f4af77fd24417ade156470e8ff05d, exit 0 with cleanup verified.

Setup: Windows 11 Enterprise 22621, AMD Radeon RX 6700 XT (driver 32.0.21045.16010), WinLibs GCC 15.2 UCRT, Release, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1.

  • agc_driver_f32_arithmetic_nan and agc_driver_f32_arithmetic_nan_fast pass in 3 of 3 runs each, 6 of 6, none skipped.

All 408 test and .prx hashes matched the prepared build when the job started.

AI-assisted: yes.

@Doorriiaann

Copy link
Copy Markdown
Contributor

agc_shader_memory never finishes with this PR, and the hang is in RegionNanCondition, which this PR adds. @ycbuzi found it on #17919 on Windows. Here it is on Linux, with ctest -R '^agc_shader_memory$' -V --timeout 120 and the validation layer (RTX 3070, NVIDIA 610.57.04, Debian 13, GCC 13.3.0 Release):

tree agc_shader_memory
main 6e6d9d9 passed in 3.5 s
this PR 8d1a3d6 timeout at 120 s
#17709 180bfe8 timeout at 120 s
#17919 4339df6, alone and merged onto main 6e6d9d9 timeout at 120 s

A backtrace with gdb after 60 s looks the same on all three heads. The main thread is about 610 frames deep in RegionNanCondition calling itself:

main
 verifyHalfWaveReduction()                          tests/ShaderMemory.cpp
  ShaderRecompiler::Recompile -> RecompileImpl -> compileVariant -> emitVariant
   SpirvEmitter::Emit -> EmitProgram -> EmitControlFlow
    RegionNanCondition -> RegionNanCondition -> ...   (~610 frames)

RegionNanCondition (SpirvFlowEmitter.cpp, added in b3ff1bc) recurses into each argument of every LogicalAnd and returns at the first match, without remembering the values it already visited. If the half-wave reduction's condition is a deep LogicalAnd DAG with shared operands, that walk takes exponential time, which would fit what I see. A visited set or memo in that walk should bound it, but I haven't tried that.

AI-assisted: yes

@Filip722

Copy link
Copy Markdown
Contributor Author

@Doorriiaann Fixed in e74628d2dd01 and carried into #17709 (dec8809c5f2e) and #17919 (d6846f065d1c). Main 3b7f31fa700b is integrated in each branch.

I reproduced the unchanged #17681/main integration timing out at 30 s. RegionNanCondition now uses a work stack and visited set, preserving the original left-to-right first match while visiting each resolved node once. The existing shader-memory regression now completes, and three retained requests emit byte-identical SPIR-V before/after this correction.

The same seven focused tests pass on main 3b7f31fa700b and all three repaired heads, including the full agc_shader_memory, branch-target and denormal regressions, exact/fast arithmetic, min/max and quieting. Radeon 760M / RADV Mesa 25.0.7 / Debian 13 / GCC 15.2 Release, Khronos 1.4.363: four actual layer insertions per arm, zero skips, missing-layer messages or VUIDs. agc_shader_memory is 2.96–2.97 s in all four runs.

The description records these exact revisions. Existing gameplay timings/traces remain attached to their original commits; these heads have not been gameplay-retimed.

AI-assisted: yes (Codex).

@Filip722

Filip722 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@Doorriiaann @talha-devp Integrated pinned main fd58fa5a0213 into bacd603b3f8f and fixed the resulting build break: EmitNanRegion now replaces definitions through main’s indexed table. The DAG traversal fix remains intact.

The same 15 focused tests pass on main/head on both Radeon 760M and the RTX 5060 laptop, with Khronos 1.4.363 actually inserted and no VUIDs or skips.

ProsperoLight 4K on RTX 5060/NVIDIA 615.78.08/Bazzite reproduces the cold-cost tradeoff: longest draw pipeline phase 1.743/1.735 s versus main 1.218/1.161 s. The retained 5,413-word fragment grows from 210,144 to 271,375 SPIR-V words. Warm GPU span is 6.342 / 6.356 ms versus main 5.720 / 6.032 ms; the scene is capped at 60 Hz, so this is not an FPS claim. Two fixed pairs; two outage-damaged attempts were replaced across the shared batch, retaining every usable original. The cold penalty remains open for review.

Both warm spans are higher than main; with only two pairs the interval crosses zero, so no improvement is established. The shared batch spans a reboot: six valid original windows were retained, two unusable attempts replaced, and four windows completed after restart; no extra pairs.

Upstream assessment after the batch: later main 2454441420d5 changes shader lowering and AGC resources. All ten retained NVIDIA shader inputs emit byte-identical SPIR-V, and five focused regression tests pass on Radeon. This is bounded compatibility evidence, not a timing measurement of later main; the results above remain tied to the exact fd58fa5a0213-based binaries.

Hosted CI for this exact head passed, including Windows, all three relinkers, ASan and conventions; the conditional full Linux job was skipped. The matched local/remote device runs above are the hardware-validation evidence.

Audited evidence, all traces/digests, exact revisions and limitations. Descriptions updated. AI-assisted: yes (Codex).

@klosixgaming-arch

Copy link
Copy Markdown
Contributor

Tested on Cyberpunk 2077 on Linux. No measurable difference in the intro once the shader cache is warm. The first PR boot was slow only because this PR changes the shader output, so that boot compiled everything again.

Setup: Ubuntu 26.04.1 (Linux 7.0.0-43), NVIDIA GeForce RTX 2080 Ti (595.99.02), Xeon E5-2699 v3, GCC 15.2.0 Release. Base: main e4caa07950 (it includes #19071). This PR's head bacd603b3f merged on top (b77d1721d7, clean merge), built in a separate tree. Cyberpunk 2077 PPSA03974 02.120.000, intro movie, no input, warm shader caches. Boots alternate base and PR, three each; each number is the mean of the 10 s summary windows from 40 s to 160 s.

boot build presents per 10 s, windows 40 s to 160 s mean
1 base 50 48 50 48 47 49 49 49 48 49 49 48.7
2 this PR 36 8 22 55 54 52 53 40.0
3 base 53 52 53 53 49 51 51 51 50 51 50 51.3
4 this PR 51 51 52 52 47 51 50 52 52 52 52 51.1
5 base 53 51 50 52 48 49 50 51 50 49 48 50.1
6 this PR 52 51 52 52 49 50 50 49 50 50 50 50.5
  • The first PR boot rebuilt the shader disk cache, because the shader source version changes with this PR: 1,420 misses and 1.36 GB written in its first window. It stalled until about 110 s and ran at 52 to 55 after that. I leave it out as a cold-cache boot, not a slowdown.
  • Warm boots: base 50.0 on average (48.7 to 51.3), this PR 50.8 (50.5 to 51.1): +1.6 %, inside the spread between base boots. That is only two warm PR boots against three base boots.
  • No driver failure, abort or NotImplemented line in any of the six boots.

@Filip722

Copy link
Copy Markdown
Contributor Author

@klosixgaming-arch Added your separately attributed Cyberpunk report and exact main/merge revisions to the description. It records no measurable warm intro gain, the unequal three-base/two-warm-PR boot counts, and the separate cache-rebuild boot. Your results remain distinct from the existing pipeline-creation diagnostics and our other-title timings.

AI-assisted: yes (Codex).

@oneandonlydean
oneandonlydean merged commit ce80711 into boykopovar:main Nov 17, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants