fix(libSceAgcDriver): export FP16_ABGR into UINT color targets #14243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14243"
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 Tamalero on 2026-11-01T03:34:20Z.
What
mainthrowscolor export format 4 into an unsigned integer target is unsupportedwhen a draw exportsFP16_ABGRinto a UINT color target. This PR gives that pair a defined path, matching what RDNA2 hardware stores (measured in #11513):Behaviour. Each half is widened to the 32-bit float it represents; a NaN gets its quiet bit set (
0x7c01→0x7fc02000), as on the hardware. Those 32 bits go to the attachment as an unsigned integer, clamped to the channel. A 32-bit channel holds the float's bits. An 8- or 16-bit channel holds 0 for +0.0 and its maximum for every other half, -0.0 included.Widening. For the UINT packings,
WidenedHalfWordwidens the exported half bits with integer operations, so the result does not depend on how the driver implementsUnpackHalf2x16(which may flush subnormals and need not keep NaN bits). It is selected by the packing specialization constant; float targets keep theUnpackHalf2x16path unchanged.Output type. The fragment output reaches the attachment as
uint4through the existing unsigned packing:SpecializeFragmentOutputsretypes the float4 output and bitcasts each store, as for the raw 32-bit exports. This answers request 1 of #12795. 32-bit channels keepUint.Clamp. Two new packings,
UintClamp8andUintClamp16, cover 8- and 16-bit channels (HalfExportPackingin State.cpp). ForFP16_ABGRexports only,SelectExportPackingtakes theUMinof each word and a limit chosen by the packing specialization constant (0xff,0xffff, otherwise0xffffffff).Identity. The packing is carried in
targetExportPacking. That value is already in:Recompiler.cpp);The emitter change also moves the shader cache version, which is hashed from the recompiler sources. The draw test checks that
Uint,UintClamp8/UintClamp16and no packing each give their own pipeline variant.Debt entry. Sentences added for
FP16_ABGR(measured behaviour, how the shader implements it, the untested uncompressed case) andFP16_ABGRtaken out of the list of exports that throw. The existing sentences about the 32-bit path are unchanged.UNORM16_ABGR,SNORM16_ABGRandSINT16_ABGRinto UINT targets still throw. SINT targets are not touched.Tested
Head
f0170da8b5, based onmain3ee28266a3.Paired validation run (CONTRIBUTING), RTX 4090, NVIDIA 615.78.08, Linux 7.3 (CachyOS):
ctest -V -R '^(agc_driver_uint_color_target|agc_driver_graphics)$'withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, onmain3ee28266a3and on this branch. Both pass, neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and both report the same single VUID,VUID-vkCreateDevice-ppEnabledExtensionNames-01387at device creation (VK_KHR_present_mode_fifo_latest_readywithoutVK_KHR_swapchain), so the change adds none. The logs are in the comment below.agc_driver_uint_color_target_tests:FP16_ABGRdraws intoR32_UINT,R32G32B32A32_UINT,R16_UINT,R16G16B16A16_UINT,R8_UINTandR8G8B8A8_UINT, tiled and linear, and throughUintClamp8andUintClamp16intoR32_UINT. A 32-bit channel cannot saturate, so those draws show the shader's clamp itself, whatever the driver does with out-of-range integers.s0/s1into the exported registers, and the test requires every input of a target to use the same pipeline variant, so the values are not folded into the shader.0x7c01,0xfe00). Every channel is read back and compared with the measured result.Negative controls (each one a local edit of
SpirvModuleEmitter.cpp, built and run on its own):0x80000000stored,0xffexpected0x1ff0x1ffstoredUnpackHalf2x16instead of the integer widening0x7c01stored as0x7fffffff0x7f802000The V620 and llvmpipe runs are on Ubuntu 24.04 without a validation layer.
agc_driver_graphics_tests:uintTargetTestsnow decodesFP16_ABGRintoR32_UINT,R8_UINT,R8G8B8A8_UINT,R16_UINTandR16G16B16A16_UINTtoUint,UintClamp8andUintClamp16with blending dropped. This replaces the check that pinned the refusal.UintClamp8.Marvel's Guardians of the Galaxy (PPSA01748), RTX 4090 (first commit; the second changes only the widening and the tests):
color export format 4 into an unsigned integer target is unsupported(exit 134).tools/check_conventions.py: 0 errors. Onedebt-lengthwarning on the UINT entry, which was already over the limit onmain(1,391 characters, now 2,119).Checklist
main; no other open PR implements the same functions (#6235 carries the attachment numeric type for the raw 32-bit modes; it does not coverFP16_ABGR)NotImplemented_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)Tested and written by Claude (AI assistant) on a contributor's machine.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T04:03:13Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The format mapping and shader clamp path look consistent on source inspection, but the required paired validation-layer evidence for AGC and shader changes is missing.
What I ran
Reviewed head
91eb8504f6e6f0ab0cc743b19ed815ebd3b976a8against PR base6135e61f4538611fc82aeb69dbf73f36221b1aec; the merge preview against currentmain8728104b26178cd05433390b79d3e71fde7a2b1cwas clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. I did not build or run CTest locally.Results
FP16_ABGRgetsUint,UintClamp8, orUintClamp16by target width; the emitter clamps widened half bits withUMinfor narrow UINT channels. I found no source-level mismatch in the inspected paths.tests/execution/*.cppby the AGC CMake configuration. These are heuristic false positives.main8728104b26178cd05433390b79d3e71fde7a2b1c.annotate_moduletimed out; 549/550 CTests passed. The timeout is in an unrelated test, and its cause is not established here.mainrun or paired VUID comparison is provided.Raw output excerpts
Precheck conventions output:
Windows relinker CTest output:
Negative control
Findings
Blocking
CONTRIBUTING.mdrequires the same focused tests onmainand the change withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1, with both logs checked for the requested-layer marker and compared for new VUIDs. This PR changes AGC state decoding and shader emission, but its report supplies only change-side results and no pairedmainlog or VUID comparison. Please attach the matched logs and comparison for the focused UINT color-target test before approval.Non-blocking
The PR says the execution test also passes when the newly added clamp is disabled on each tested driver. That means its pixel readback assertions do not pin the clamp itself. A focused SPIR-V/emitter assertion or another safe control that fails when the
UMinpath is removed would make this central behavior regression-testable.Sources
Not verified
I did not run the paired
main/PR validation tests, inspect raw GPU logs, or test on a PS5. The hosted Linux product job was skipped. The author-reported GPU results were not independently repeated.To get this to a good state
Attach the required same-machine, same-GPU
mainand PR validation logs and VUID comparison for the focused UINT color-target test. I will rerun applicable checks on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T09:17:31Z.
Review: COMMENTED
Re-checked — new head, paired validation evidence posted
The paired
mainand PR validation-layer runs requested in the earlier review are now in the thread atf0170da8b5, and the new half-float widening matches the binary16 layout for the cases I checked; I did not re-run the GPU tests.What I ran
f0170da8b54b28f09530a01688a4298253a6f0f7(commits949abf859bandf0170da8b5). The earlier changes-requested review was at91eb8504f6e6f0ab0cc743b19ed815ebd3b976a8, which is no longer on the branch.b5f72708e5221b14ed5328eb2a51797eb2a4b1f9, the PR's base at review time. The live stack check reports the PR as mergeable.The precheck's ABI and test-quality helpers failed because the head tree has no
tools/directory, so both were run by hand as listed above.Results
possible-unregistered-cpp-testfindings, both false positives.UintColorTarget.cppis collected by thefile(GLOB ... tests/execution/*.cpp)incore/libs/prx/libSceAgcDriver/CMakeLists.txtline 551;Graphics.cppis an existing test source included by the AGC test buildWidenedHalfWord0x7c01to0x7fc02000,0x7e00to0x7fc00000,0x7fffto0x7fffe000,0xfe00to0xffc00000) match the formulaf0170da8b5Author-reported, not re-run by me: a paired validation run on an RTX 4090 with NVIDIA 615.78.08,
ctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, foragc_driver_uint_color_targetandagc_driver_graphicsonmain3ee28266a3and on this PR. The comment reports both as passing, the requested-layer marker absent in both logs, and only the sameVUID-vkCreateDevice-ppEnabledExtensionNames-01387in both. It also reports the clamp-removal and widening-replacement negative controls failing on all three drivers.Findings
Blocking: none found in the source paths I read.
Non-blocking:
FormatTestswithUintClamp8andUintClamp16(tests/execution/UintColorTarget.cpp, lines 377-381 at head). I read the call sites but did not read the full test body, so the negative-control claims remain author-reported.Sources
SpirvModuleEmitter.cppline 672:github.com/boykopovar/AnyPS5@f0170da8b5/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp (L672-L689)State.cpplines 1023 and 1870:github.com/boykopovar/AnyPS5@f0170da8b5/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp (L1023-L1027)andgithub.com/boykopovar/AnyPS5@f0170da8b5/core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp (L1870)Not verified
f0170da8b5. The paired logs and negative controls above are author-reported.UintColorTarget.cppwas not read line by line.My earlier changes-requested review on
91eb8504f6stays in place until a re-review of this head is complete.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T22:36:25Z.
Review: APPROVED
Reads right, and I checked the widening exhaustively. I modelled
WidenedHalfWord(core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp) instruction for instruction in Python and compared it, for all 65,536 half bit patterns, with an IEEE binary16-to-binary32 conversion that sets the NaN quiet bit: 0 mismatches. That includes subnormals (0x0001->0x33800000), both zeros, both infinities and every NaN (0x7c01->0x7fc02000, your example). TheUMinclamp then gives what the description says: as unsigned words,+0.0is 0 and every other half's pattern exceeds0xffff, so 8- and 16-bit channels hold 0 or their maximum.Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto current
main:agc_driver_graphicsandagc_driver_uint_color_targetpass, nothing skipped, the second on this machine's GPU. A negative control can't build: withmain's recompiler andState.cppthe tests stop compiling atColorExportPacking::UintClamp8, which only this PR adds.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T23:08:12Z.
Review: APPROVED
Reviewed — approved
FP16_ABGRexports into UINT targets now go through theUint/UintClamp8/UintClamp16packings with integer half widening. The change builds, its focused tests pass, the validation comparison shows no new VUIDs, and a partial negative control (emitter only) fails as expected.What I ran
Head
f0170da8b54b28f09530a01688a4298253a6f0f7,main5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged with--no-ffinto treec00dcd4c809fbce38f0647c802254ccf865c6e23. Debian 13 VM (Xeon Gold 6136, AVX2/FMA), GCC 14.2.0, Release/Ninja, Vulkan on lavapipe (Mesa 26.1.6, LLVM 19), no GPU.Results
git diff --checkcheck_conventions.pydebt-lengthwarning on the UINT color targets entry (2,119 characters; it was already over the limit onmain, as the description says)libs(script)agc_driver_uint_color_targetagc_driver_graphicsmain(script, 759 tests)agc_driver_image_sample_lod_clamp_shader_lanemain, not this PR: it still fails with all five production files restored frommainunwrap_self_..._destination_directory_groupos.chown→EINVALin the sandbox's/tmp) in atools/Python test that this PR does not touchfixed:unwrap_selftools/file), most likely a baseline difference (baseline_sha096c4557≠main)lod-clamp failure, same with main's production files
Negative control
main: the changed tests no longer compile ('UintClamp8' is not a member of 'ShaderRecompiler::ColorExportPacking',UintColorTarget.cpp:321). This matches what BunnyFl reported.SpirvModuleEmitter.cppfrommain, with the enum, serializer, specialization check andState.cppfrom the PR:agc_driver_uint_color_targetbuilds and fails on the first clamped draw. This matches the author's "clamp removed" row on llvmpipe:output
I did not run a control for the widening alone (integer widening vs.
UnpackHalf2x16). The author reports that llvmpipe passes either way, so on this machine that control could not tell the two apart.After the controls I restored the merged files and rebuilt;
git status --porcelainis empty and both tests pass again.Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp:699, used withWidenedHalfWordat:676).wordsis created for everymode == 4export, including those into float targets. Each enabled component then carries the full widening chain plus anOpSelect, andSelectExportPackingadds aUMinagainst0xffffffff(:468). The specialization constant makes this dead code for float targets, so the results are correct. But it enlarges the SPIR-V of the most common export format, and how much the host compiler folds depends on the driver. Optional: note it, or check that pipeline-build time for FP16 float shaders does not regress.R8G8_UINTandR16G16_UINTare not covered. They getUintClamp8/UintClamp16(core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp:1024-1025), but neither the decode test nor the execution test uses them. They take the same path as the 1- and 4-channel formats, so this is minor.agc_driver_graphicsruns over 30 s here (33.6 s and 34.9 s on lavapipe), and the NVIDIA bot reported 32.2 s. This PR only adds fiveDecodeStatecalls to it, so the overrun is not caused here. It is still worth a separate split, per CONTRIBUTING's 30 s rule.Other points I checked and found fine:
Uint= 4,UintClamp8= 5,UintClamp16= 6) agree with the serializer bound, theSpecializeFragmentOutputsbound and the>= Uintcomparison.State.cpp:1881.ColorExportPacking::Uintwhere the clamp variants would be missed.On earlier reviews: I confirm oneandonlydean's request (the clamp test must hold whatever the driver does). With the shader clamp removed, the
R32_UINTdraws throughUintClamp8fail here. MarcZX10's non-blocking point about the clamp is resolved at this head.Not verified
agc_driver_depth_clear_hleVUID from the NVIDIA bot. The PR does not touch that path, and lavapipe shows no new VUIDs.