perf(shader): keep native f16 conversion NaN results when a startup probe matches RDNA #11351
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11351"
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 tibzejoker on 2026-10-26T07:11:41Z.
What
Step 3 of #11183. Native f16 conversions keep their own NaN result when a startup probe shows it is already RDNA's.
On a device with Float16,
RoundingModeRTE16 andDenormPreserve16,v_cvt_f16_f32and friends are oneOpFConvert, andv_cvt_f32_f16reads are oneUnpackHalf2x16(#1252, #7698). Rounding, denormals and infinities are fixed by those execution modes; the NaN is not (Vulkan lets the driver return any NaN). So every conversion rebuilds RDNA's NaN with integer ops:0x7e00 | payload >> 13): 11 extra instructions, about 52 words;ProbeFloat16Conversions(Execution/src/Float16ConversionProbe.cpp) runs when the device is created, likeProbeFloat32FlushToZero(#6503). It compiles small RDNA programs twice, with the rebuilt NaN (today's code) and with the native result, dispatches both and compares every dword:v_cvt_f32_f16over all 65,536 halves (garbage in the upper 16 bits);v_cvt_f16_f32,v_cvt_pkrtz_f16_f32andv_cvt_f16_f32followed byv_cvt_f32_f16, over 18,336 f32 values: every top-10 payload of quiet and signalling NaNs of both signs (with 4 low-bit patterns), every exponent with 16 mantissa patterns (ties, sticky bits, overflow to infinity, the largest finite values), and ties at every shift of the f16 denormal range;IEEE_MODE, and a directed f16 rounding mode withFP16_OVFL;SpirvTarget::float16WidenNans/float16NarrowNansare set per direction only when every result matches; the emitter then returns theOpFConvert/UnpackHalf2x16result directly. Both fields are in the recompile cache key. The probe runs on each device creation, so a driver update is probed again.APS5_NO_NATIVE_F16_NANSskips it. The round trip and the toward-zero programs are there because they putOpFConvertnext toOpFConvert. That caught a real problem (found by @Lander0606 on RADV, and the same on NVIDIA):v_cvt_pkrtz_f16_f32corrects the nearest-even half when it widens back above the input, and without the NaN rebuild between them the drivers folded the f32 -> f16 -> f32 pair, so 140,763 of 280,480 inputs came out nearest-even.NoContractionon the widening fixed RADV but not NVIDIA; withfloat16NarrowNansthe half is now widened with integer operations (shift, exact multiply for denormals), which leaves nothing to fold, and without it the module ismain's (the NaN rebuild still separates the two conversions): 0 differences on both GPUs here, and--verify-spirvrequires that this program has no wideningOpFConvert.Both fields are saved in recompile requests (serializer format 54, after main's shader image minimum LOD flag of format 53; 50 stays rejected as on
main; older requests read them as false, round trips of the four combinations inrequest_serializer), so a dumped request replays with the conversions of the device that wrote it. Landing order with #11483: both append to the request format; this PR lands first with 50 and #11483 then takes 51 (agreed there).agc_shader_replay --f16-widen-nans / --f16-narrow-nansforce them on as explicit overrides, so the sizes below can be reproduced.Probe results
0x7fffffff(2,046 of 65,536 halves per mode)0x7fff(9,233 of 280,480 in the test)0x7c01->0x7fc02000, RDNA gives0x7f802000), 1,022 halves; quiet NaNs, denormals and the rest match| Radeon 860M (RADV, Mesa 26.2.5, run by @Lander0606) | not probed:
float16DenormPreserveneedsdenormBehaviorIndependenceALL and RADV reports 32_BIT_ONLY | native: 0 of 220,032 probe results differ, 0 of 280,480 in the test for each of the three programs |So on the RTX 4090 nothing changes, and the f32 -> f16 direction changes on Intel and RADV.
Tested
Windows 11 Pro, MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON(spirv-val on every module), this head6740167447onmain9ab6a281ea.New test
agc_driver_float16_conversion_probe(tests/execution/Float16ConversionProbe.cpp):agc_driver_float16_conversion_probe_spirv(--verify-spirv, no device needed): with each field set, the conversion loses exactly its NaN select and keeps oneOpFConvert;agc_driver_float16_conversion_probe, on the device: the emulated results are checked against a CPU model of RDNA (v_cvt_f32_f16for all halves,v_cvt_f16_f32and the round trip for the probe set plus 2^18 random f32 values), the native results are compared with them per class (quiet NaN, signalling NaN, not NaN), and the test fails if the device chose the native path for a direction where any result differs. It does not exist onmain.Focused tests,
main9ab6a281ea(this head's base) vs this PR (6740167447),ctest -R "(^agc.*(f16|float16|f64|convert|pack|interpolation|denorm)|request_serializer|shader_memory|agc_float16_conversion)" -E "^agc_driver_bda_device$" -V,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationwithVK_LOADER_DEBUG=layer(84 / 85 layer insertions, nowas not foundline),ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1:mainVUID-lines (main / PR)Both sides pass on both GPUs. The f64 tests skip there (no Float64). Probe lines: RTX 4090 f16->f32 emulated (8184 of 262144), f32->f16 emulated (98484 of 220032); UHD 770 f16->f32 emulated (4088), f32->f16 native (0 of 220032).
RADV, Radeon 860M (Mesa 26.2.5, Fedora 44, GCC 13.3), by @Lander0606 on
f2300fd2d2(the toward-zero fix, before it was made conditional onfloat16NarrowNans) against its basemain4e43321bd6,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, validation layer 1.4.341, three runs each:main^agc(-j8)Every device creation logs
f32 to f16 NaN results: native (0 of 220032 probe results differ); the three programs of the probe test match on all 280,480 inputs. NoVUID-line, 53 / 54 layer insertions. The only full-suite failure isagc_driver_tessellation(Mesa 26.2.5 crash) on both trees. Probe time 89-115 ms. The rerun on6e17eb4b75is offered and will be posted in the comments; the change sincef2300fd2d2only affects devices withoutfloat16NarrowNans.Serializer and probe tests on this head:
request_serializer,agc_shader_memory(both updated for format 54),agc_driver_float16_conversion_probeand_spirvpass.Full agc suite on the RTX 4090, on
9f386f3a29before the rebase (ctest -R "^agc" -E "^agc_driver_bda_device$" -j12): 1061 of 1063 passed; the 2 failures (agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store) also fail onmain. Every test that opens a device now runs the probe.Size, Grand Theft Auto V compute shaders (the requests from #11265, saved on the RTX 4090, replayed with
agc_shader_replay --spvon this head; with no flag the output is word-for-wordmain's). On currentmain78 of them recompile;0x25b390800no longer does (reads or writes a converted float image with 16-bit data, which is not implemented, frommain'seb68ad3b02/ede33d56e2, the same with and without this PR):main, and this PR on NVIDIA (identical modules)Per shader, f32 -> f16 native:
0x25b393000(RCAS) 90,558 -> 73,594 (-18.7 %), both 66,544 (-26.5 %); 5 of 78 shaders change with f32 -> f16 native, 7 with both. On5b5d24cb22, where0x25b390800still recompiled, it went 503,403 -> 419,089 (-16.7 %) with f32 -> f16 native.Startup cost: the probe takes 60-80 ms when run alone (150 ms with the four float modes on either GPU, 236 ms on Intel while 4 tests ran in parallel), on every device creation.
In game (performance form), current
main1db077e876, RTX 4090 (NVIDIA 616.92), no-change control: the open-world load of Grand Theft Auto V from the same save,APS5_TRACE_SECONDS=40:80,APS5_MIMALLOC=1, an emptyANYPS5_SHADER_CACHE_DIRper run, in the order base, PR, base again. On plainmainthe game stops before the menu (#11513), then ~60 s into Story (#11425), so both arms carry #11580 and a revert of #9789 and nothing else: base0eb521ce4e, PRa02cac6c3d(= base +2b25bd1641), on the fork astest/cvt5-base/test/cvt5-pr. Traces, summaries and full digests (currentmain'strace_digest.py): fork release perf-11351-20261029.Vulkan.ComputePipeline(0x25b390800)On this GPU the probe keeps today's path, so the modules are
main's and the pair is neutral; the probe itself took 138 ms at device creation. The 17.9-18.7 s max frame of each run is the load'sDriver.Packet.memory_wait, not a compile. The first base trace dropped queue worker 0x0 events after 78.4 s, after its compile slice (+55.0 s).{"commit":"0eb521ce4ed3","dirty":false,"env":{"APS5_MIMALLOC":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"40:80"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":65295,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 40:80","first_present":416,"ms":80021.538},"presents":2006,"frame_ms":{"p50":16.819,"p90":34.585,"p99":123.235,"max":17859.073},"gpu_busy_ms_per_present":3.029,"worker_busy_pct":{"queue worker 0x0":72.895,"queue worker 0x38":23.607,"queue worker 0x20":9.176,"queue worker 0x30":4.826,"queue worker 0x28":4.224},"top_phases_ms_per_frame":{"Driver.Packet":45.128,"Driver.Packet.memory_wait":16.790,"VideoOut.Flip":13.457,"Graphics.Draw":11.570,"VideoOut.Flip.vblank_wait":11.530,"Graphics.Draw.draw_and_resource_release":10.694,"Driver.Packet.rendering_wait":9.274,"Driver.Packet.draw":9.198},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":78.429,"events_lost":32143,"totals_full":false}},"trace":"aps5-trace-0eb521ce4ed3-6904.json.gz"}
{"commit":"a02cac6c3d21","dirty":false,"env":{"APS5_MIMALLOC":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"40:80"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":65295,"title_id":"PPSA04264","title":"Grand Theft Auto V","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 40:80","first_present":455,"ms":80038.353},"presents":1897,"frame_ms":{"p50":16.805,"p90":33.589,"p99":203.153,"max":18680.495},"gpu_busy_ms_per_present":2.523,"worker_busy_pct":{"queue worker 0x0":72.994,"queue worker 0x38":1.010,"queue worker 0x20":28.604,"queue worker 0x28":10.702,"queue worker 0x30":2.442},"top_phases_ms_per_frame":{"Driver.Packet":48.503,"Driver.Packet.memory_wait":18.055,"VideoOut.Flip":17.665,"VideoOut.Flip.vblank_wait":15.721,"Graphics.Draw":13.106,"Graphics.Draw.draw_and_resource_release":12.376,"Driver.Packet.draw":11.764,"Driver.Draw":11.742},"trace_dropped":false,"trace":"aps5-trace-a02cac6c3d21-3276.json.gz"}
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:04:11Z.
Review: CHANGES_REQUESTED
Reviewed exact head
1081e2351a4b81d84ad1ce2ad627e6d29ab8368f. I found one blocking replay correctness issue:VulkanDevice::Target()now setsfloat16WidenNansandfloat16NarrowNans, and those values control which SPIR-V the live driver emits. Shader captures go throughDriver::dumpRequest()andRequestSerializer::Serialize(), but the serializer remains at format version 46 and writes neither field;Deserialize()likewise leaves both false. A captured request from a device that selected the native path therefore silently replays with the emulated NaN repair unless the user manually supplies the newagc_shader_replayflags. Those flags are a useful override, but they do not preserve the captured request's selected target behavior.Please append both fields in a versioned serializer update and add round-trip coverage (including backward compatibility for older request versions). Keep the CLI switches if they are useful for explicit overrides.
The branch is also about 142 main commits behind its merge base. The current-main merge preview is clean; the two shared paths have unrelated adjacent changes in
CMakeLists.txtanddocs/dev/BUILD.md. Please sync to currentmainand rerun conventions and the focused AGC checks against the refreshed base. The existing GPU and trace results are useful historical evidence, but they were produced from the older base.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:52:20Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head f2300fd2d20dc81095448ef7fe920f711f00a7f8. The serializer blocker is resolved: format 47 stores both flags, older requests default them to false, four flag combinations round-trip, truncation is rejected, and the cache key includes both flags. The new RADV 860M results on this exact head also address the previously pending focused GPU run. Current main advanced beyond the branch base, but none of the 42 intervening main paths overlap the PR's changed files and the merge preview is clean, so I found no new source-integration issue.
One required performance-report item remains. This PR is labeled , but its attached summary pair is for main commit and PR commit , not the final head . That trace pair also uses an RTX 4090 where the report says both native flags stay disabled, so it checks that the tested scene does not regress but does not measure the optimization. Please provide the required same-title/scene/machine main-and-final-head captures with output from a run that exercises the native path, or update the performance claim and follow the repository's reporting rule for the resulting scope. Please also bring the new RADV 860M exact-head result from the discussion into the Tested section, which still describes that rerun as pending.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:52:29Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
f2300fd2d20dc81095448ef7fe920f711f00a7f8. The serializer blocker is resolved: format 47 stores both flags, older requests default them to false, four flag combinations round-trip, truncation is rejected, and the cache key includes both flags. The new RADV 860M results on this exact head also address the previously pending focused GPU run. Current main advanced beyond the branch base, but none of the 42 intervening main paths overlap the PR's changed files and the merge preview is clean, so I found no new source-integration issue.One required performance-report item remains. This PR is labeled
perf, but its attached summary pair is for main commit14c99b52ace3and PR commit1081e2351a4b, not the final headf2300fd2d2. That trace pair also uses an RTX 4090 where the report says both native flags stay disabled, so it checks that the tested scene does not regress but does not measure the optimization. Please provide the required same-title, same-scene, same-machine main-and-final-head captures withtools/trace_digest.pyoutput from a run that exercises the native path, or update the performance claim and follow the repository's reporting rule for the resulting scope. Please also bring the new RADV 860M exact-head result from the discussion into the Tested section, which still describes that rerun as pending.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T12:08:11Z.
Review: DISMISSED
Re-reviewed exact head
20a660bea49eb726e84a3ebfe4a3a92a28e2b7b4against currentmain4e38e2388219e065eba52461f2e59234fcb57b13. Two blockers remain:Current-main serializer integration. Since the branch was refreshed from
5b5d24cb22,mainaddedColorExportPacking::Uintand updatedreadColorExportPackingto accept it. This head still caps that decoder atUnorm4_4_4_4; after merging currentmain, valid requests usingUintwould be rejected unless the new bound is retained alongside format 47’s two f16 flags.mainalso changed the shared AGC CMake and SPIR-V module-emitter files. Please merge currentmain, preserve both changes, and rerunrequest_serializerplus the focused f16 tests on the resulting head.Performance evidence does not exercise the optimized path. The body’s final-head GTA V pair is on an RTX 4090 where both native flags remain disabled and the replayed modules are word-for-word unchanged. That is useful as a no-regression control, but does not measure the claimed native-conversion optimization. The body also still says the RADV 860M rerun on this head is pending, although later comments report it. Please provide a same-title/main/final-head trace and digest on a device where the probe selects the changed path, or get maintainer direction for an applicable tooling/performance report and update the claim accordingly. Move the exact-head RADV result into
Testedas well.The policy checks pass, but the PR’s product jobs are skipped by path policy; these integration and GPU checks therefore need evidence on the refreshed head before approval.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:03:08Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
What I checked
e4c702e3312e8d9d656a1a1f9504a2498dec864bagainst fetchedmain2960e9a6e7.ShaderReplay.cpp. The pairwise preview with open #11483 conflicts inShaderMemory.cpp,ShaderReplay.cpp,RequestSerializer.cpp, andRequestSerializerTests.cpp.Blocking integration items
The branch is 232 commits behind fetched current
main, and the body says its runtime results are from the earlier baseline319621ba2e. Please refresh onto currentmain, resolve the replay conflict, and rerun the focused f16/serializer tests on that integration head.Open #11483 also uses the same request-format version slot (both branches currently append format 50). The two PRs need an agreed landing order and corresponding next-version update; record the order with
Depends onasCONTRIBUTING.mdrequires. The current merge preview with #11483 has conflicts, so I cannot treat their claims of independent topics as independent integration.The earlier performance report is useful, but neither the current-main conflict nor the paired format integration has been validated. I cannot renew the previous review until these are resolved.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:29:58Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
2b25bd1641812f1c39d5c664524eeaf89412a4fcagainst currentupstream/main4c7d275bef89d309313d16bc2bc05d37a1b50be2. The branch now includes current main, the cache format is 50 versus main’s 49, and the unsupported-format test now uses 51; that resolves the stale-main/version-number finding from my previous review.git merge-tree --write-treeis clean against main andgit diff --checkpasses.Two items remain before I can approve:
ShaderMemory.cpp,ShaderReplay.cpp,RequestSerializer.cpp, andRequestSerializerTests.cpp. Both PRs affect request serialization and are by the same author; please record an agreed landing order/dependency and preserve both changes in the final stack.e4c702e331on main319621ba2e. This head adds the version-51 rejection test and merges current main. Please rerun the focused serializer/f16 validation on this exact head and refresh the performance comparison against current main, with the same title, scene, machine and required trace artifacts.I did not run Vulkan/GPU tests locally.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T08:31:59Z.
Review: CHANGES_REQUESTED
Re-checked
2b25bd1641on currentmain: the merge is clean and the code is the one already reviewed; the only changes since are the format 50 renumbering and the version 51 rejection test. Two things are left, both in @MarcZX10's open request:ShaderMemory.cpp,ShaderReplay.cpp,RequestSerializer.cppandRequestSerializerTests.cppconflicts are then a rebase that keeps both flags). Please state it in the body and ping #11483 so both sides agree.^agc.*(f16|float16|convert|pack)|request_serializer|shader_memory, validation layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1) and the GTA V pair are frome4c702e331onmain319621ba2e. Please post the focused set on2b25bd1641for the RTX 4090 and the UHD 770, and refresh the trace pair against currentmain.Once those are posted and MarcZX10's review is renewed, it goes to the merge queue.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T00:00:48Z.
Review: DISMISSED
Re-checked — new head, changes requested
The reported focused rerun is for
da083d0e1355ac816c9d45272c2b1a17c9977b77, but that head conflicts with currentmain8a4fc62318a4b73b6895bf20a024c625efeb7c3binVulkanDevice.cpp.What I ran
Reviewed PR #11351 at head
da083d0e1355ac816c9d45272c2b1a17c9977b77, PR base381891927c2b3ff494a9853cb79fde8d5342b92d, against currentmain8a4fc62318a4b73b6895bf20a024c625efeb7c3b. The current-main merge preview did not merge cleanly. Environment: Debian GNU/Linux, Python 3.11.2, Git 2.39.5. I did not configure or build the project.Results
git diff --checkexited 0 with no output.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp; GitHub also reportsCONFLICTING/DIRTY.main7a5d9bf02a; the single UHD failure is also present onmain, with zero reportedVUID-lines. I did not run these tests locally. Author reportPrecheck output
Current-main merge-preview output
Conventions output
Findings
Blocking
mainboth changeVulkanDevice.cpp, and the merge preview conflicts there. Please rebase onto currentmain, preserve both the current-main changes and this PR's float16 probe behavior, then rerun the focused tests and conventions on the resulting head. The author-reported test results currently usemain7a5d9bf02a, not the current target8a4fc62318a4b73b6895bf20a024c625efeb7c3b.Non-blocking
Testedsection still identifies older head/base revisions; update it to point to the latest reports after the integration rebase. The attached RTX 4090 trace pair is explicitly described as a no-change control, so I have not treated it as evidence of runtime gains on the native-conversion path.Sources
Not verified
To get this to a good state
Rebase this PR onto current
main, resolve theVulkanDevice.cppconflict while retaining both sides' behavior, update theTestedrevision references, and rerun conventions plus the focused serializer/float16 tests on the resulting head. I will rerun the same no-build checks against that new head.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-01T01:41:03Z.
Review: CHANGES_REQUESTED
Re-checked against current
main(029463ceb6). The branch conflicts inRequestSerializer.cpp,RequestSerializerTests.cppandShaderMemory.cpp, and it is not only text:maintook serialization format 51 (tessellationEvaluationSubgroups) and made 50 an unsupported version (32a6bdb6d3: "Version 50 is skipped"). The two f16 NaN fields can no longer be format 50.version >= 52uinDeserialize, upper bound 52 (keeping 50 rejected), the fixtures that pin the f16 fields, and the "unsupported" test at 53. Older requests (≤ 51) read both fields as false.The rest is the code already reviewed (probe, emitter, replay flags); nothing else needs to change once it is rebased on
main.