fix(agc): support packed 16-bit storage images #6218
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6218"
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 harry-z-kang on 2026-10-15T04:39:47Z.
What
Fixes #6119: guest format 133 (5_6_5_UNORM) fails when NVIDIA does not expose the packed format as a storage image. Formats 134 (5_5_5_1_UNORM) and 136 (4_4_4_4_UNORM) have the same capability gap.
Keep the packed image and native sampled/attachment formats, but write through a compatible R16_UINT storage view. Materialize storage descriptors with the original conversion format and pack stores into the original 16-bit guest layout, including half-precision inputs. Restrict each view's usage to the operations its format supports.
Packing reuses
EmitFormatStoreComponentinSpirvBackend/src/SpirvMemory/SpirvFormatConvert.cppand the existing packed texture channel mappings. Vulkan's format compatibility classes, extended image usage and normalized fixed-point conversion define the view compatibility and clamping/scaling. AMD/PS5 comparison of rounding ties and NaN handling remains unverified and is recorded with the existing packed-texture entry indocs/dev/debt/libSceAgcDriver.md.The branch retains merged native format-43 repacking (#7271), converted 32-bit sampling (#5958), R8/RG8 sRGB copy handling (#6054), D16 SINT stores (#5899) and float-mode handling (#5943). No open PR is required.
Tested
Local validation on
main001d132f4(including merged #8087) and rebased PR headf30acac3c: Windows 11 (NT build 26300), NVIDIA GeForce RTX 5080, driver 617.42, WinLibs GCC 15.2.0, Release,BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF.Rebuilt the six focused GPU test targets and their driver/runtime/shader dependencies on main and the PR. This pass did not repeat the full default build or
libsbuild; both passed in the previous validation on base9b34cba9e.Ran the same nine focused cases on main's implementation and the PR with the identical regression harness. Both runs used
ANYPS5_GPU=5080,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.Command:
ctest --test-dir build -R '^agc_driver_(image_(converted_unorm|packed16_load|store_sint|sint8|repacked_float|packed16_storage_(133|134|136))|fmask_image_reads)$' -V --parallel 1.Main passed the six existing cases and refused the three new packed-storage cases because their formats cannot be used as storage images. The PR passed 9/9 with zero skipped, including all three packed-storage cases; the final restored-PR run took 3.56 s.
Used Khronos validation 1.4.365 from the official Windows CI artifact, commit
aea761f4d54b86682be4099c428dba27b6609940, supplied through a workspace-localVK_LAYER_PATH. Loader logs confirm insertion in every test. Neither log contains a missing-layer warning or anyVUID-error: zero on main, zero on the PR.The rebase applied cleanly. All three commit patches are unchanged. Conventions, whitespace and registration of all nine focused cases passed.
The wider suite was not repeated in this focused validation pass. Its previously reported image-table reuse failure was reproduced on the older main
60fb8078c.Three new packed-format cases cover channel order, 2,048-texel bit-exact sampled-load/store round trips, full/partial masks, swizzles, 32-bit/half-precision stores, clamping and NaN/infinity inputs, sampling after repeated stores and packed guest-memory write-back.
Title and Linux validation reported by @snoozedDev, on the original main
d92a8dad3plus PR heads8322164f1and628767b52: Linux kernel 7.2.5, GCC 16.2.1, RTX 3090, NVIDIA 610.57.04, Release withANYPS5_ENABLE_SPIRV_TOOLS=ON.All 81 selected Linux tests passed on both heads, including the three packed-storage cases.
Cyberpunk 2077 PPSA04029 v02.120.000 had no storage-format exception in six PR runs; both baseline runs reproduced it. The
628767b52run recorded 645 presents and 1,497 completed draws before the later clip-control refusal.Later stops are the separate
CLIP_DISABLE/PA_CL_CLIP_CNTLrefusal and the intermittent watchdog tracked in #4634. This PR fixes the reported storage-format stop; it does not establish complete title compatibility.The packed-storage additions are unchanged. No new title run on the rebased head, AMD/PS5 packed-store comparison or lavapipe run is claimed.
Checklist
Based on current
main; no other open PR implements the same functionsOne topic per PR; follow-ups go in a new PR
No comments in code except technical debt
Unimplemented paths throw (
NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt fileNo notes, investigation
.mdfiles 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: Fixes #6119
Unblocks: PPSA04029 #3308 past the format-133 storage-image stop, confirmed by the issue reporter
GPUs tested: NVIDIA GeForce RTX 5080, driver 617.42, Windows 11 (local, main/PR Khronos validation comparison); NVIDIA GeForce RTX 3090, driver 610.57.04, Linux kernel 7.2.5 (reported by @snoozedDev on the earlier heads above)
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harry-z-kang on 2026-10-15T05:46:36Z.
Reviewed both PRs in the overlap report. Neither is a prerequisite, so
Depends on: noneremains accurate.628767b52f17a4dcdc39e559d912eddac6373fe2keeps our half-to-float conversion inPackImageTexel, leavingStoreTexelunchanged from main and removing the conflict with #5899.Using the overlap checker's normalized merge procedure, the updated branch merges cleanly with #5899 at
8c1193744ac5and #5958 at8338defe54dd, in either order, and with both combined. No fixed merge order is required for those heads. These are merge checks; combined runtime builds were not run.The updated standalone branch passed the full build,
libs, all 98 related tests on the RTX 5080, and conventions/whitespace checks. Cyberpunk remains untested. The PR description now records the dependency review; the scheduled overlap report can refresh against the new head.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T16:30:14Z.
Review: COMMENTED
Tested on Apple as another vendor. This is the case where the new path actually runs: MoltenVK reports no
STORAGE_IMAGEfor any packed-16 format (R5G6B5, A1R5G5B5, R4G4B4A4…) in optimal tiling, so the R16_UINT reinterpret view is what gets exercised, and it works.agc_driver_image_packed16_storage_133,_134,_136andagc_driver_image_converted_unormall pass.AGC graphics: guest storage texture format <N> cannot be used as a storage image(format 4, 8 and 3 respectively),so the tests do guard the new path.
^agcsuite: 13 failures, same set as the base (all pre-existing on MoltenVK). No new failures from this PR.So the Metal reinterpret from the packed-16 formats to
r16Uint(MUTABLE / EXTENDED_USAGE) holds up on Apple silicon.Method: macos-port @ b7eb6b6b + ImportWatched + PR diff, not main. Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta, driver SDK MoltenVK 1.4.2.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by harry-z-kang on 2026-10-15T16:35:34Z.
Addressed the updated overlap report and incorporated the issue reporter's title/Linux validation into the description, with attribution and the tested commit IDs. The format failure is confirmed fixed on those heads; later clip-control and watchdog stops remain separate.
Rebased onto main
0029e62f9. The packed-storage code is unchanged. Its limitations are now consolidated into the existing packed-texture entry indocs/dev/debt/libSceAgcDriver.md, so this PR no longer changesdocs/dev/debt/shader.md. The merge check against #5943 is clean; its float-to-half instruction changes are not a prerequisite for our half-to-float store conversion.I manually reviewed the shared-file diffs of all 51 PRs in the bot's uncompleted-comparison table, including the repeated AOT patches, depth/sample paths, storage lifetime/cache work, sampler changes and CMake test registration changes. None supplies a prerequisite or duplicates the packed-storage conversion.
Depends on: noneremains accurate. Several of those branches already conflict with main; this review does not claim they all merge or run together.Current local validation:
relinker,libsand all 70 related test executables built, and 100/100 selected tests passed on RTX 5080 / NVIDIA 617.42 / Windows 11. Conventions, whitespace and registration checks passed. The full test build encountered an unchanged upstream MinGW alignment error inGpuIndirectArgumentsMisalignedWriterAhead.cpp:25; it is documented in the PR and is outside this change.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-18T14:55:19Z.
Repeated @jotitadev's MoltenVK check on Linux, on the current head and plain
main:5d3a43196merged ontomaina62c724c3, lavapipe (llvmpipe, Mesa 26.2.4, LLVM 23.1.1), GCC 16.2.1, Release,ANYPS5_ENABLE_SPIRV_TOOLS=ON. lavapipe reports no optimal-tilingSTORAGE_IMAGEforR5G6B5,A1R5G5B5orB4G4R4A4_UNORM_PACK16(it does forR16_UINT), somainrefuses these three formats here, as on the RTX 3090 in #6119. By readingTexture.cpp, the PR sends them through theR16_UINTview on every device, not only on drivers without the bit.agc_driver_image_packed16_storage_{133,134,136},agc_driver_image_packed16_loadandagc_driver_image_converted_unorm: 15/15 passed (3 repeats).main(the PR's tests andCMakeLists.txtkept), the three packed-storage tests fail with the #6119 error,guest storage texture format 4 cannot be used as a storage imagefor 133, and format 8 and 3 for 134 and 136. With the PR sources restored, all 5 pass again.ctest: 1 failure out of 1,451 (65 skipped),agc_compute_pipeline_replay(replay did not export a pipeline cache header). It fails the same way with those six files frommain, and the PR does not touch it.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:23:49Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main8d5d4df96(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) atb74c8abf4: 1641/1643 with this PR, against 1638/1640 onmain. The two failures are the same on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).The PR's three new ctest entries (
agc_driver_image_packed16_storage_133,_134and_136) all run and pass here; none is skipped. No other ctest entry is added, skipped or removed compared withmain.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T18:40:58Z.
Cyberpunk 2077 PPSA03974 (v02.120.000, the same title as #6119 under another region's ID) on Windows 11 26200, RTX 5090, NVIDIA 617.42, WinLibs GCC 15.2.0.
mainb13183e59stops 160 s in:mainc70524a3d): that stop is gone and the title runs for 440 s, then stops with the #6806 line: That base predates #8046, which accepts this value onmainnow.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-20T08:28:33Z.
Hardware data for the packed stores on RDNA 2: RX 6700 XT (gfx1031), raw ISA through the HIP runtime of AMD's Windows driver 32.0.21045.5002, so the conversion is the hardware's, not a Vulkan driver's.
Method:
image_store v[4:7] ... dmask:0xf dim:SQ_RSRC_IMG_2D unorm glcthrough a linear 2D T# of each format (GFX10 codes), thenimage_loadof the same texel through a16_UINTT# over the same memory. First, one-channel stores of 1.0 locate each field. Then each channel gets 0, -0, 0x00000001, 0.25, 0.5, 0.5 ± 1 ulp, 1, 1 + 1 ulp, 2, -1, ±inf, ±NaN, a signalling NaN, 1/3 and 2/3, plus the f32 neighbours of every rounding midpoint (k + 0.5) / (2^n - 1) of its field. The same rows ran at IEEE 0 and 1, DX10_CLAMP 0 and 1, and with f32 denormals flushed and kept, and again withd16half-precision data for the special values.5_6_55_5_5_1, W in bit 15)4_4_4_4Per field, in every mode, f32 and d16 alike:
x * (2^n - 1)rounded to nearest, notfl32(x * scale)rounded: 429 of 429 rows for 133, 252 of 252 for 136, and the same for 134/135 except the tie below. Roundingfl32(x * scale)misses 32 to 78 rows per format.So
NormStoreBits' round-half-to-even differs from the hardware on that tie: it stores 0, the GPU stores 1. With f32 or f16 inputs, a 1-bit field at exactly 0.5 is the only tie that can occur: a tie needsx = (2k + 1) / (2 (2^n - 1)), which is a binary fraction only for n = 1. So rounding exact ties up would only change that case. The test'sStoreFieldusesstd::nearbyint, which rounds half to even too, andStoreValuescontains 0.5, so the test expects 0 for that W bit as well.This is desktop RDNA 2, not a PS5. I haven't run the PR's Vulkan tests here.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T06:30:57Z.
First run on AMD's Windows Vulkan driver. It shows a different failure on
mainthan on NVIDIA and lavapipe.Setup: Windows 11 Pro 26200, AMD Radeon 680M (RDNA 2 iGPU,
1002:1681), AMD driver 32.0.21030.2001 (Vulkan 1.4.315), WinLibs GCC 15.2.0 r7, Release.main1ff5c8ac5. This PR's head4adf40588merged into it cleanly. Khronos validation layer from SDK 1.4.363 (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation), plusANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1. The command is the PR's own nine-casectest -R '^agc_driver_(image_(converted_unorm|packed16_load|store_sint|sint8|repacked_float|packed16_storage_(133|134|136))|fmask_image_reads)$' -V -j1. On themainside,main's implementation is built with only this PR'sImageConvertedUnorm.cppand its test registration, so both sides run the same cases.This driver reports optimal-tiling
STORAGE_IMAGEforR5G6B5,B5G6R5,A1R5G5B5,R5G5B5A1,B4G4R4A4andR4G4B4A4_UNORM_PACK16(vulkaninfo --show-formats). Somaindoes not refuse these formats here, as it does on the RTX 3090 and lavapipe. It uses them, and the result is wrong:mainagc_driver_image_packed16_storage_133packed image load/store changed guest bytes for format 133agc_driver_image_packed16_storage_134... for format 134agc_driver_image_packed16_storage_136... for format 136No
VUID-lines on either side, and nowas not found but was requested by env var VK_INSTANCE_LAYERS.On AMD's Windows driver,
maindoesn't stop on these formats the way it does on NVIDIA. It writes the wrong guest bytes without any error, so a title would render wrongly instead of stopping. This PR's route through theR16_UINTview gives the bit-exact round trip on this driver too.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T06:32:56Z.
@harry-z-kang a useful data point from @DavidSamir: on AMD's Windows driver, which reports storage support for these packed 16-bit formats,
mainsilently writes the wrong guest bytes for formats 133, 134 and 136, and this PR'sR16_UINTroute round-trips them exactly. Thanks @DavidSamir; that makes this a correctness fix on that driver, not just a refusal-to-support change. The gate on currentmainis next.