fix(shader): emulate image atomics on 8- and 16-bit integer texels #27887
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27887"
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 superSniper4576154 on 2026-11-27T18:42:09Z.
What
An integer image atomic whose T# has data format 8_UINT, 8_SINT, 16_UINT or 16_SINT was refused at recompile time with
atomic image descriptor uses an unsupported format N. PPSA38500 ends there: a pixel shader (0x106e0bc000) issues an image atomic on an 8_UINT surface (atomic image descriptor uses an unsupported format 5).Hardware: unmeasured. The RDNA2 ISA, LLVM and RADV only allow image atomics on 32- and 64-bit texels, and no GPU I can reach exposes sub-dword image atomics, so nothing here is checked against a console or a hardware oracle. The rule I chose follows what the 32-bit formats already do (measured on gfx1100/gfx1031 in #7939): the atomic acts on the texel's raw bits whatever the numeric format. It wraps at the texel width (
smin/smaxcompare at that width) and returns the old bits zero-extended for both UINT and SINT. The debt fragment records this as assumed.Design:
LockedDeviceUpdate, keyed by a hash of the texel coordinates). All 13 integer ops (swaptodec) are covered.shaderStorageImageReadWithoutFormatandshaderStorageImageWriteWithoutFormat, which the narrow modes need anyway. The modes are only offered when both are supported.Unknown, because a narrow mode shares the uint storage binding with other formats. The lock-emulated 64-bit path keeps theRg32uideclaration from #21749. A device without formatless storage reads and writes (the Intel UHD Windows driver in #21749) keeps refusing narrow atomics, asmaindoes.APS5_NO_NARROW_IMAGE_ATOMICS=1turns the narrow modes off and brings back the refusal (ENVIRONMENT.md row added).LockedDeviceUpdate) and return 0, as a native atomic in a helper has no effect: the loop readsOpIsHelperInvocationEXTwhere demote is available,gl_HelperInvocationotherwise. Without it a pixel program running the atomic in whole quad mode put helpers into the loop, where a compare-exchange has no effect and an undefined result (found by Mhamednoui).ImageStoreSintrefusedimage_atomic_addon 16_SINT as its unsupported-format case. It now uses 8_8_SINT (format 19), which is still refused.Limitations (also in the debt fragment):
Tested
Windows 11 Pro (build 26300), NVIDIA GeForce RTX 3090 (driver 621.40, subgroup size 32), MinGW-w64 GCC 16.2.0, Ninja, Release,
-DBUILD_TESTING=ON, onmain61426d5bf1. Every test log showsSelected GPU name=NVIDIA GeForce RTX 3090.Test
agc_driver_image_atomics_narrow(tests/execution/ImageAtomicsNarrow.cpp) checks:addandumaxfrom 32 groups × 64 threads on 8 texels, at wave32 and wave64;addand withswap: each lane's returned old value and stored texel, and every other byte of the surface, are checked individually, on all four formats;addwhose data has bits above the texel width, so a width bug shows without any ordering between lanes.The test skips on a device without both formatless storage capabilities.
b4c6a87464: 88/88 passed (agc_driver_image_atomics_narrowincluded).faac9e0f55(adds the neighbour and single-lane cases):agc_driver_image_atomics_narrowpassed in 3.0 s, and the 9 image atomic,image_store_sintandimage_sint8tests passed.main+ only the unrelated change of another branch of mine (it touches only wave64 pixel half-wave scans): 87/87 passed (the new test is not in that tree).5e93d36429(helpers skip the lock loop): the newagc_driver_pixel_helper_image_atomics(24 triangles with edges inside a 64x32 target;s_wqm_b64 exec, exec, oneimage_atomic_add, exec restored; 8_UINT, 16_UINT and 32_UINT at wave64 and wave32, on each pixel's texel and with every pixel on texel 0; checks every texel) passed, as didagc_driver_image_atomics_narrow,image_atomics,image_atomics64,image_atomics_bitwise,image_atomics_float,pixel_helper_lanes,pixel_helper_lane_masks,pixel_helper_waterfall,pixel_quad_perm_helpersandquad_pixel_mask. The new test also passes on this RTX 3090 with the fix taken out, so it does not reproduce the device loss Mhamednoui saw on an RTX 4060 (driver 621.14).APS5_NO_NARROW_IMAGE_ATOMICS=1:agc_driver_image_atomics_narrowfails withatomic image descriptor uses an unsupported format 5, which ismain's behaviour.python tools/check_conventions.pyandpython tools/debt_fold.py --check: clean. Overlap (the bot's pr-overlap comment): #14871 and #19852 change theImageResourcefield-countstatic_assertinShaderDiskCache.cpp(#14871 also changesResourceMaterializer.hppL78-81), and #22628 changesRecompiler.cppL439 and the sameShaderDiskCache.cpplines. Those are textual conflicts with unrelated features (1D image arrays, buffer read extents, TYPE 2 and 3 buffer descriptor destinations); none adds narrow image atomics, so this PR depends on none of them and whichever merges second resolves the conflict.tools/pr_overlap.py --branchcannot compare the 173 PRs that conflict withmain. I looked at the ones that share the recompiler files (#27670, #27648, #26593, #5371): none adds narrow image atomics or changes the atomic format check.Mhamednoui ran the validation comparison on Windows 11, RTX 4060, driver 621.14, layer 1.4.363, at
faac9e0f55: no newVUID-lines, and the same one failure on both sides (agc_driver_linear_target_import_creation). Still not run withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon this machine: no Khronos validation layer is installed here, so the Windows run (main and this PR, comparingVUID-lines) is still owed. JJenkx ran the image atomics tests at9ece009800with the layer inserted on AMD Linux (RX 6650 XT, RADV Mesa 26.3.1): 6/6 passed, noVUID-lines.PPSA38500: written against the refusal in shader
0x106e0bc000. I have not run the title on this branch alone, only on a local integration branch that also carries other open PRs.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T18:51:22Z.
Review: COMMENTED
Actionable comments posted: 1
df104c10-1121-4656-b962-b79ed9bda3e9Reviewing files that changed from the base of the PR and between
c0c80ae850and9ece009800.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageAtomicsNarrow.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageStoreSint.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/IntermediateRepresentation/src/IrProgram.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvAnalysis.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvDescriptors.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/fix-agc-narrow-image-atomics.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T19:20:34Z.
Review: DISMISSED
Reviewed — comments
The patch adds narrow image atomic emulation and tests, but the implementation needs further review because the changed code contains a concrete issue with swap preserving surrounding texel bits.
What I ran
Reviewed head
9ece009800bac311e6b6bccdfb7b9d8014df3109. No commands or tests were run; this review used the prepared diff and repository reader.Results
Findings
Blocking
LockedNarrowImageAtomicbuildsnextfor swap by OR-ing the new value withold & (held - 1)(core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:710). The lock word is an acquisition state, not a texel byte offset or lane mask, so this expression does not preserve the other packed texels in the containing storage word. For R8/R16 views, writing component zero can overwrite neighboring texels; the test checks neighbors only in rows not touched by its atomic dispatch (core/libs/prx/libSceAgcDriver/tests/execution/ImageAtomicsNarrow.cpp:318-328). Preserve neighboring bits by deriving the texel's byte/halfword position and merging the new field into the loaded storage word, or use a storage path that guarantees sub-word writes.Non-blocking
Not verified
review/description.md,review/commits.md,review/manifest.json,review/diff.patch, plus the changed sections ofVulkanDevice.cpp,Texture.cpp,ResourceMaterializer.cpp,SpirvImageEmitter.cpp, andSpirvModuleSetup.cpp.files.jsonwas unavailable through the reader; the file listing identified all changed paths and inclusion status. Most changed files were not read in full.To get this to a good state
Fix the swap merge so it retains neighboring texels without relying on the lock value, then rerun the narrow atomic tests including adjacent texels that share the same 32-bit storage word.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T11:51:06Z.
Review: COMMENTED
Reviewed — comments
The reviewed excerpts show the narrow atomic path and its stated assumptions, but the review is incomplete because several changed files and runtime checks were not inspected.
What I ran
No commands or tests were run. Inspected the prepared diff and targeted source excerpts at head
b4c6a87464100eb77295eab481b7b1b76de2d587.Results
Findings
Blocking
None verified.
Non-blocking
Not verified
review/description.md,review/commits.md,review/manifest.json,review/diff.patch; targeted excerpts fromResourceMaterializer.cpp,SpirvImageEmitter.cpp,SpirvEmitterHelpers.cpp, andVulkanDevice.cpp.VulkanDevice.cppandTexture.cpp. Other changed files listed in the manifest were not fully read; the test implementation was reviewed only in the diff excerpt.To get this to a good state
Nothing is required. Optional: verify the assumed atomic semantics on console hardware and run the validation-layer comparison when available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T18:53:25Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
faac9e0f55f887bbc56c8254f41fb73dee55c926. Read the prepared description, commits, manifest, and full diff, then inspected changed code and related context with the repository reader. I did not run tests or other commands; the test results in the description are author-reported.Results
Negative control
Not run by this review. The description reports that enabling
APS5_NO_NARROW_IMAGE_ATOMICS=1restores the prior rejection behavior.Findings
Blocking
None.
Non-blocking
Not verified
VulkanDevice.cppandTexture.cpp; I read their changed lines through the reader. The review artifact listing marks these two files as excluded fromfiles/because they were too large. I reviewed the complete prepared diff and the included changed-file text/context for the remaining changed files.To get this to a good state
Nothing is required. Optional: confirm the assumed narrow-atomic semantics and store-race behavior against console hardware when available.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T17:46:32Z.
Review: COMMENTED
Actionable comments posted: 1
072c4632-b4a5-4d4d-be82-1ec8af52c1ffReviewing files that changed from the base of the PR and between
faac9e0f55ande4a15f22a1.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/execution/PixelHelperImageAtomics.cppcore/shader/recompiler/Optimization/include/Optimization/ResourceMaterializer.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hppcore/shader/recompiler/SpirvBackend/src/SpirvEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/fix-agc-narrow-image-atomics.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T17:54:42Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed code paths I inspected show no verified blocking defect; I did not run checks, and narrow atomic semantics remain unmeasured on console hardware.
What I ran
e4a15f22a10e83c428e804d6b6a5846b85b07749; no commands or tests were run.repo_read.py.Results
Findings
Blocking
None.
Non-blocking
The narrow atomic semantics and interaction with plain image stores remain unmeasured on console hardware, as the PR description and debt entry state. Keep that limitation visible until a hardware result is available.
Not verified
No checks were run. I did not verify behavior on a console or hardware oracle. The PR description reports that no test covers a race between plain image stores and narrow atomics.
To get this to a good state
Nothing is required.
Optional point: report console measurements when they become available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T20:46:24Z.
Review: COMMENTED
Reviewed — comments
The implementation has no verified blocking defect in the inspected changes, but the narrow atomic semantics remain unmeasured on console hardware.
What I ran
Reviewed head
2e5121572886530069fc86e5cf70df445fc84272using the prepared diff and the pinnedrepo_read.pyreader. No build or tests were run.Results
Findings
Blocking
None verified in the inspected changes.
Non-blocking
Not verified
No tests, build, validation-layer run, or console run was performed in this review. The full text of
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppwas excluded from the prepared folder; their changed lines were reviewed indiff.patch. The other changed paths and hunks were inspected through the prepared diff, including the added tests and documentation. The repository file listing reports the two excluded files as too large for the review folder.To get this to a good state
Nothing is required. Optional: confirm the assumed narrow-format semantics on console hardware and characterize atomics racing with ordinary image stores.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T10:17:23Z.
Review: COMMENTED
Reviewed — comments
Material parts of the change were inspected at head
0fae9972ca78c5981bbe923491720c3edcacb2c5; no blocking defect was verified, but this review is incomplete and does not support a formal approval.What I ran
Read the prepared description, commit list, manifest, and diff, then inspected targeted code using the pinned
repo_read.pyreader. No tests or builds were run.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
Not verified
The full contents of most changed files were not read, including both new execution tests and the remaining recompiler, cache, documentation, and test changes.
VulkanDevice.cpp,Texture.cpp, and the narrow atomic emitter/materializer sections were inspected through the reader; those two large files were excluded from the preparedfiles/bundle but accessible through the reader. The review manifest lists 23 changed files; only targeted portions were inspected. Tests, builds, title behavior, and console hardware behavior were not independently verified.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and independently run the relevant checks before relying on this review as merge approval.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:03:39Z.
Review: APPROVED
I read the diff at
0fae9972ca. Windows 11, GCC 15.2, merged intomainat6c6b29320fetogether with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_image_atomics_narrow,agc_driver_pixel_helper_image_atomicsandagc_driver_image_store_sint: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.Not checked: a console (as the debt entry says, the 8- and 16-bit rules are assumed), PPSA38500, or a race between a plain store and a narrow atomic.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:55:18Z.
Review: COMMENTED
How does the texel lock behave when two storage views address the same texel at different view-relative coordinates?
LockedNarrowImageAtomichashesCoordU32directly, whileStorageTexture::createViewcan offset the base array layer. If two overlapping views can point to the same image layer with different Z coordinates, their atomics can acquire different locks and lose an update even though both operations are atomic. Could the tests cover that alias or establish where resource binding rejects it? The current contention cases use one view.Source review at
0fae9972ca. The head trial-merges onto6ef4f2f73b. Focused Linux checks are queued.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.