fix(shader): load and store 16-bit data of converted packed images #11580
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11580"
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 QRMOE on 2026-10-26T21:15:52Z.
What
Since #8898,
11_11_10_FLOATstorage images take the in-shader conversion path that10_11_11_FLOATand11_11_10_UNORMalready used (an R32_UINT view, packed and unpacked in the shader). That path refused every image access with 16-bit data (D16):ResourceMaterializerrejected the descriptor and the SPIR-V emitter failed withreads or writes a converted float image with 16-bit data, which is not implemented. Before #8898 these images were nativeB10G11R11_UFLOATstorage images, so D16 stores to them worked. RESIDENT EVIL requiem (PPSA31246) stops about 135 s into boot on this error (compute shader 0x210689b100).This implements D16 for converted unorm and float images, for every input:
RequireConvertedUnormAccessis removed, so each half goes through the same encoder as a 32-bit store of its exact f32 value.uvec4. A D16 load now packs them as halves (f32 to f16, round to nearest even,EmitPackHalf2x16) instead of truncating each word to its low 16 bits (LoadedTexelResult). This also fixes D16 loads of the other converted formats with float results.ResourceMaterializerno longer drops the converted modes of an image that has a D16 access, and refuses D16 only for converted unorm samples, which stay unimplemented (samples a converted unorm image with 16-bit data).image_loadis always a sampled-class resource, and sampled10_11_11/11_11_10FLOAT images are read through their nativeB10G11R11_UFLOATview (nativeRepacked). D16 float loads therefore already worked and do not take this path; the test still checks them on both layouts, including a load and store of the same image. The converted D16 load path runs for11_11_10_UNORM.The f16 rounding of these accesses is not measured on hardware. That is recorded in
docs/dev/debt/shader.md: stores are exact, and UNORM loads are rounded twice (to f32, then to f16).agc_driver_image_converted_unorm(ImageConvertedUnorm.cpp) now:image_storewith DMASK 0x7 and 0x5 on both float layouts (10_11_11 and 11_11_10). The halves include ±0, ±1, ±Inf, NaNs with high and low payloads, f16 denormals, the largest half, values past the format's largest finite value, and round-to-even ties in 5- and 6-bit mantissas. Each texel must match a 32-bit store of the widened values, and texels made of exact values must also match their known encoding;image_loadon both float layouts, alone and followed by a D16 store to the same image, over 1024 texels (every exponent/mantissa edge, then hashed bit patterns). It checks every half exactly (any NaN for a NaN field), that only two result dwords are written, and that the store writes every non-NaN field back unchanged;image_loadof11_11_10_UNORMover 2048 texels with swizzles X Y Z 1 and Z Y X 1 (within one f16 ULP), and D16image_storewith DMASK 0x7 and 0x5. These replace the two assertions that D16 is refused.Tested
Windows 11, MinGW GCC (
x86_64-w64-mingw32), Release build. I checked that the test catches the bugs, each tried separately and then reverted:mainfails withreads or writes a converted float image with 16-bit data, which is not implemented, the RE Requiem error;image_load d16 X Y Z 1;image_store d16 dmask:0x7 of R10_G11_B11_FLOAT.Validation-layer comparison on
main(18ef6be0cd) and this branch, same machine and GPU. Both runs usedANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R "agc_driver_image_(converted_unorm|packed16)" -V:mainagc_driver_image_packed16_storage_133/134/136agc_driver_image_packed16_loadagc_driver_image_converted_unormVUID-/ other validation messageswas not found but was requested by env var VK_INSTANCE_LAYERSBroader run on this branch: 204 of 206 tests matching image, storage, D16, format, shader, SPIR-V, recompiler and resource tests pass (
ctest -R "agc_driver_(image|storage|d16|format|tbuffer|flat_d16|depth_storage|depth_surface|fmask|bindless|runtime_images|cached_image)|shader|spirv|recompiler|resource|materializ" -j2). The other two,agc_driver_image_plane_address_on_line_implicit_lodandagc_driver_image_plane_bias_on_single_level_volume, were not built: their dependency-file paths exceed the Windows path limit in this checkout. Neither uses D16 or a converted format.Not run against RESIDENT EVIL requiem from this branch. Reverting #8898 locally lets the title boot past this point.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)compute shader 0x210689b100introduced by #8898🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T22:15:56Z.
Review: CHANGES_REQUESTED
The focused GPU evidence is unusually complete: it compares the same five tests on
mainand this change on the same RX 9070 XT/driver with the validation layer, reports no VUIDs, and records the layer-insertion checks. I also inspected the overlap warnings; the edits I checked in the neighboring resource/image paths are in separate blocks, though the stale conflicted PR comparisons need to remain manually tracked as these branches are integrated.\n\nThere is one repository checklist blocker:CONTRIBUTING.mdrequires a title-fixing PR to name the title ID and its Game bring-up discussion on theUnblocksline. The current line explicitly says no discussion exists, and a repository search forPPSA31246finds none. Please create or locate the title’s Game bring-up discussion, add thePPSA31246 #<discussion>reference, and list this open PR/local changes there. I’ll recheck the updated checklist and discussion before approval.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T00:16:23Z.
Review: APPROVED
Re-reviewed exact head
dbf2107ba6276e2394bc7fddbfcf0d9a665ef68dafter the requested Game bring-up entry was added. The fix has a focused before/after negative control: baseline refuses converted D16 access, dropping the new half packing breaks loads, and dropping store widening breaks float stores. The test covers both float layouts and converted UNORM loads/stores, with format boundaries, masks, swizzles, same-image load/store, and write-width checks. The reported Windows RX 9070 XT validation-layer comparison has no new VUIDs and confirms layer insertion; independent Linux RTX 4080 SUPER and Windows RTX 3070 reports also show the former title stop no longer reproduces. #11599 now lists #11580 and the title’s blocker order. The acknowledged hardware rounding limitation for D16 UNORM loads is recorded in debt; no exact console rounding claim is made. Hosted policy checks pass; product/relinker checks are skipped by path policy. I found no remaining blocker in this focused review.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:20:27Z.
Review: APPROVED
Re-checked — approved
The only commit after my previous approval removes three tests that asserted unrelated converted-image border/gather/LOD paths must refuse. The D16 load/store implementation and its positive coverage are unchanged, and the removed assertions no longer pin behavior that has since changed elsewhere in the shader path. The PR continues to list its Game bring-up reference in #11599.
Hosted Windows, relinker, conventions, eligibility, labels, and report checks pass; Linux product tests are skipped. The author’s matched validation-layer comparison and negative controls are documented in the PR, but I did not rerun GPU tests for this test-only cleanup.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T06:34:15Z.
Review: APPROVED
Reviewed — approved
The D16 load/store change merges cleanly onto current
main, builds, passes the focused AGC tests with the validation layer on Linux NVIDIA (0VUID-on bothmainand the merge), and its test fails without the production change.What I ran
fedf3e91a70676e839b89d2abdf97fca4deda6bemain:2960e9a6e7e1fc99c4ed180c71495b5eb83464c7All build and test commands ran in a clean worktree, inside a sandbox with no network.
Results
mainResourceMaterializer.cpp,SpirvImageEmitter.cpp,docs/dev/debt/shader.md)git diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.libs), merged tree andmainmainmain'sagc_driver_image_converted_unormstill asserts the D16 refusal)VUID-linesmain, 0 on the mergewas not found but was requested by env var VK_INSTANCE_LAYERSagc_spirv_module,agc_shader_type_zero_image_materializationandagc_driver_guest_memory_lifetime_converteddon't log a layer insertionagc_driver_image_converted_unormrun timemaincode (see below)Merged tree, focused tests
main, focused testsNegative control
mainproduction code with this PR'sImageConvertedUnorm.cpp:agc_driver_image_converted_unormfails withShaderRecompiler::Recompile: reads or writes a converted float image with 16-bit data, which is not implemented, the error from the description.LoadedTexelResult, I replaced the finalResultVector(..., OpBitcast to vec4 f32, IrTextureNumericClass::Float, ...)with the oldResultVector(ctx, access, unpacked, numericClass, ...). The test fails withimage_load d16 X Y Z 1: texel 0 component 1 is 0x00000000, expected 1.000000 within one half ULP.Both match what the author and DeveshB-1 reported. I didn't repeat the store-widening control.
Findings
Blocking
None.
Non-blocking
Line numbers below are at the PR head.
RequireConvertedUnormAccessalso removes it from the filtered converted-unorm sample inEmitSampleOp. At the PR head,SpirvImageEmitter.cpp:1694-1695still passesUnpackImageTexel's f32-bituvec4toResultVectorwith the image'sUintnumeric class. For a D16 access, that takes the integer branch and keeps the low 16 bits of each f32 pattern (1.0 becomes0x0000), which is the bugLoadedTexelResultfixes for loads. Today the materializer refuses that combination (ResourceMaterializer.cpp:276, andconvertedSampleCompatibleatResourceMaterializer.cpp:1403-1404requiresdepthBitsCompatible), so I found no input that reaches it. But if a later change lets one through, the result is silently wrong instead of a refusal. A cheap fix is to keep actx.Fail(access.inst, "samples a converted unorm image with 16-bit data, which is not implemented")inEmitSampleOpwhen the conversion format is unorm andmem.dataBits == 16u. Alternatively, send that result through the same f32-to-f16 packing asLoadedTexelResult.Not verified
docs/dev/debt/shader.md, and I didn't check it on hardware either.RuntimeImageModes) on the GPU, or the full test suite.