shader: support MIMG float image atomics (FMIN/FMAX) #837

Closed
github-bot wants to merge 1 commit from gh-pr/837/head into gh-pr/837/base
Owner

@⁠theantipopau on GitHub · 2026-09-25 20:47 UTC · original
theantipopau:mimg-float-atomics → main · +109 −6 · 11 files · 1 commits · closed without merging

Problem

MIMG_ATOMIC_OPCODE_LIST stops at 0x1a (IMAGE_ATOMIC_XOR). Opcodes 0x1e and 0x1f are float
image atomics, so a shader that uses them cannot be decoded and fails before it ever reaches
translation, the same way a missing-opcode shader fails the CFG stage in #426 and #799.

Changes

The two opcodes are wired through the whole path:

  • frontend/decode/ImageOps.cpp — 0x1e -> IMAGE_ATOMIC_FMIN, 0x1f -> IMAGE_ATOMIC_FMAX
  • frontend/decode/ShaderDecoder.h / .cpp — the Opcode enum entries and their
    InstructionToString cases
  • frontend/translate/Memory.cpp — the EmitMemory dispatch, and the atomic range end in
    MemorySourceAt so the operand layout is picked up as an atomic
  • ir/opcodes/ValueOpcodes.inc / .cpp — ImageAtomicFMin32 / ImageAtomicFMax32, classified as
    {ImageAccess::Atomic, ImageResourceClass::Storage, false} like the integer image atomics

SPIR-V has no float image atomic, so backend/spirv/spirvEmitterImage.cpp builds an
OpImageTexelPointer into the image and reuses the existing AtomicUpdate compare-exchange
machinery, with EmitFloatAtomicReplacement doing an ordered bit-level min or max. That keeps NaN
and signed-zero behaviour explicit instead of inheriting whatever the host integer atomic does
with the raw bits. The whole thing stays inside EmitValueOrZeroIfCondition, so a predicated image
atomic skips the read-modify-write the same way the integer path does.

Atomic images keep the R32ui ABI regardless of the guest numeric type, which means the image type
stays a u32 storage image and the descriptor still has to resolve to an R32Uint view. Two
validation sites had to learn about that:

  • ir/passes/ResourceMaterialization.cpp — an atomic image descriptor that was not k32UInt was
    rejected outright. It now also accepts k32Float, and the numeric class is forced back to Uint
    for atomic images so a k32Float descriptor does not trip the Sint rejection on the way in.
  • host_gpu/renderer/pipeline/descriptors.cpp — ValidateStorageTexture gains the same
    float_atomic case, and ResolveTexture forces eR32Uint for an atomic k32Float view the way
    it already did for k32SInt.

Testing

Windows, clang-cl + Ninja, Release, on upstream/main 49716600:

  • shader_cfg_tests: passes, including the new
    TestNewShaderRecompilerImageFloatAtomicTranslation. It drives both opcodes through a k32Float
    descriptor and asserts the decode names, the IR opcodes, that the image stays atomic and
    Uint-typed, OpImageTexelPointer / OpAtomicCompareExchange / OpAtomicLoad /
    OpMemoryBarrier in the binary, R32ui in the disassembly, and that none of the direct integer
    atomics leak in. The generated SPIR-V is validated.
  • resource_materialization_tests: all cases passed.
  • ngs2_sampler_tests: all cases passed.
  • kyty_emulator: clean build and link.

shader_recompiler_compute_tests does not run here: its Vulkan harness aborts at startup with
production rasterization features are not supported because this driver does not expose
VK_EXT_attachment_feedback_loop_dynamic_state. That happens before any dispatch, so it says
nothing about this change either way. No game was run.

Risk

Additive, and only reached by shaders that use these two opcodes, which could not be decoded before.
No existing opcode, image ABI, or descriptor format changes; the R32ui path the existing integer
atomics rely on is untouched.

Caveat worth stating plainly: I do not have a captured shader or a reported game that uses
0x1e/0x1f. This is a completeness fix for the opcode table, not a fix for a specific
compatibility report. If someone has a game that stops failing because of it, that would be worth a
note on the PR.

**@⁠theantipopau** on GitHub · 2026-09-25 20:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/837) `theantipopau:mimg-float-atomics` → `main` · +109 −6 · 11 files · 1 commits · closed without merging Problem `MIMG_ATOMIC_OPCODE_LIST` stops at `0x1a` (`IMAGE_ATOMIC_XOR`). Opcodes `0x1e` and `0x1f` are float image atomics, so a shader that uses them cannot be decoded and fails before it ever reaches translation, the same way a missing-opcode shader fails the CFG stage in #426 and #799. Changes The two opcodes are wired through the whole path: - `frontend/decode/ImageOps.cpp` — `0x1e` -> `IMAGE_ATOMIC_FMIN`, `0x1f` -> `IMAGE_ATOMIC_FMAX` - `frontend/decode/ShaderDecoder.h` / `.cpp` — the `Opcode` enum entries and their `InstructionToString` cases - `frontend/translate/Memory.cpp` — the `EmitMemory` dispatch, and the atomic range end in `MemorySourceAt` so the operand layout is picked up as an atomic - `ir/opcodes/ValueOpcodes.inc` / `.cpp` — `ImageAtomicFMin32` / `ImageAtomicFMax32`, classified as `{ImageAccess::Atomic, ImageResourceClass::Storage, false}` like the integer image atomics SPIR-V has no float image atomic, so `backend/spirv/spirvEmitterImage.cpp` builds an `OpImageTexelPointer` into the image and reuses the existing `AtomicUpdate` compare-exchange machinery, with `EmitFloatAtomicReplacement` doing an ordered bit-level min or max. That keeps NaN and signed-zero behaviour explicit instead of inheriting whatever the host integer atomic does with the raw bits. The whole thing stays inside `EmitValueOrZeroIfCondition`, so a predicated image atomic skips the read-modify-write the same way the integer path does. Atomic images keep the `R32ui` ABI regardless of the guest numeric type, which means the image type stays a `u32` storage image and the descriptor still has to resolve to an `R32Uint` view. Two validation sites had to learn about that: - `ir/passes/ResourceMaterialization.cpp` — an atomic image descriptor that was not `k32UInt` was rejected outright. It now also accepts `k32Float`, and the numeric class is forced back to `Uint` for atomic images so a `k32Float` descriptor does not trip the `Sint` rejection on the way in. - `host_gpu/renderer/pipeline/descriptors.cpp` — `ValidateStorageTexture` gains the same `float_atomic` case, and `ResolveTexture` forces `eR32Uint` for an atomic `k32Float` view the way it already did for `k32SInt`. Testing Windows, clang-cl + Ninja, Release, on `upstream/main` `49716600`: - `shader_cfg_tests`: passes, including the new `TestNewShaderRecompilerImageFloatAtomicTranslation`. It drives both opcodes through a `k32Float` descriptor and asserts the decode names, the IR opcodes, that the image stays atomic and `Uint`-typed, `OpImageTexelPointer` / `OpAtomicCompareExchange` / `OpAtomicLoad` / `OpMemoryBarrier` in the binary, `R32ui` in the disassembly, and that none of the direct integer atomics leak in. The generated SPIR-V is validated. - `resource_materialization_tests`: all cases passed. - `ngs2_sampler_tests`: all cases passed. - `kyty_emulator`: clean build and link. `shader_recompiler_compute_tests` does not run here: its Vulkan harness aborts at startup with `production rasterization features are not supported` because this driver does not expose `VK_EXT_attachment_feedback_loop_dynamic_state`. That happens before any dispatch, so it says nothing about this change either way. No game was run. Risk Additive, and only reached by shaders that use these two opcodes, which could not be decoded before. No existing opcode, image ABI, or descriptor format changes; the `R32ui` path the existing integer atomics rely on is untouched. Caveat worth stating plainly: I do not have a captured shader or a reported game that uses `0x1e`/`0x1f`. This is a completeness fix for the opcode table, not a fix for a specific compatibility report. If someone has a game that stops failing because of it, that would be worth a note on the PR.
MIMG_ATOMIC_OPCODE_LIST stops at 0x1a (IMAGE_ATOMIC_XOR). Opcodes 0x1e and
0x1f are float image atomics, so a shader that uses them cannot be decoded
and fails before it ever reaches translation.

Add them end to end: the opcode table, the Opcode enum and its
InstructionToString entries, the EmitMemory dispatch, the ImageAtomicFMin32
and ImageAtomicFMax32 IR opcodes, and the SPIR-V emitter.

SPIR-V has no float image atomic, so the emitter builds an OpImageTexelPointer
into the image and reuses the existing AtomicUpdate compare-exchange
machinery, with EmitFloatAtomicReplacement doing an ordered bit-level min or
max. That keeps NaN and signed-zero behaviour explicit rather than inheriting
whatever the host integer atomic does with the raw bits. The whole thing
stays inside EmitValueOrZeroIfCondition, so a predicated image atomic skips
the read-modify-write like the integer path.

Atomic images keep the R32ui ABI regardless of the guest numeric type, which
means the image type stays a u32 storage image and the descriptor still needs
resolving to an R32Uint view. Two validation sites had to learn about that: the
resource specialization pass rejected any atomic image that was not k32UInt, and
the render executor's storage view format only special-cased k32SInt. Both now
accept k32Float for atomic images, and ResourceMaterialization forces the
numeric class back to Uint so a k32Float descriptor does not trip the Sint
rejection on the way in.

Testing

Windows, clang-cl + Ninja, Release, on upstream/main 49716600:

- shader_cfg_tests: passes, including the new
  TestNewShaderRecompilerImageFloatAtomicTranslation. It drives both opcodes
  through a k32Float descriptor and asserts the decode names, the IR opcodes,
  that the image stays atomic and Uint-typed, OpImageTexelPointer /
  OpAtomicCompareExchange / OpAtomicLoad / OpMemoryBarrier in the binary, R32ui
  in the disassembly, and that none of the direct integer atomics leak in.
  The generated SPIR-V is validated.
- resource_materialization_tests: all cases passed.
- ngs2_sampler_tests: all cases passed.
- kyty_emulator: clean build and link.

shader_recompiler_compute_tests does not run here: its Vulkan harness aborts at
startup with "production rasterization features are not supported" because this
driver does not expose VK_EXT_attachment_feedback_loop_dynamic_state. That
happens before any dispatch, so it says nothing about this change either way.
No game was run.

Risk

Additive, and only reached by shaders that use these two opcodes, which could
not be decoded before. No existing opcode, image ABI, or descriptor format
changes; the R32ui path the existing integer atomics rely on is untouched.

I do not have a captured shader or a reported game that uses 0x1e/0x1f, so
this is a completeness fix for the table rather than a fix for a specific
compatibility report. If anyone has a game that stops failing, that would be
worth a note here.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:34:23 +00:00
github-bot closed this pull request 2026-11-26 09:34:23 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-25 20:56 UTC · original

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a64abb13-2fad-4894-88f4-9a5619508059

📥 Commits

Reviewing files that changed from the base of the PR and between 497166009c and 3b59f7a9b8.

📒 Files selected for processing (11)
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
  • src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/translate/Memory.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • tests/shaderCfgTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change adds decoding and IR translation for floating-point image atomic minimum and maximum operations. Atomic 32-bit float storage images use the uint storage class and an R32Uint view. The SPIR-V emitter generates atomic updates for the new operations. A regression test checks translation and validates the generated SPIR-V.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Feature

Merge Risk: ⚪ Minimal · up to 3b59f

No actionable merge-blocking defect was established. The float-image atomic path is ready for normal checks, though runtime behavior has not been tested in a game.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 3b59f

The new operations use the existing storage-image binding rules and atomic update mechanism. No new security bypass was identified, but runtime behavior and some floating-point edge cases remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly reachable write affects a descriptor-selected storage-image texel on the host GPU. The inspected path does not show a new raw-address sink or a way to select an arbitrary host storage-view format.

Trust Boundaries and Controls

  • observed — Guest-specified image format crosses into host image binding only after resource and descriptor validation; the accepted float-atomic case is bound through an R32Uint view, with a separate storage-view compatibility check.

Resilience and Maintainability Implications

  • observed — The atomic update retries compare-exchange after interference rather than issuing a separate non-atomic image write. The available evidence does not establish a contention bound or independent runtime containment behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 9 files. (2 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: support for MIMG floating-point image atomics, specifically FMIN and FMAX.
Description check ✅ Passed The description directly explains the opcode decoding, translation, SPIR-V emission, validation changes, testing, and known limitations.
Full details: Docstring Coverage

Explanation

Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 9 files. (2 skipped: 1 unsupported, 1 too large.)


Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-25 20:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/837#issuecomment-5839500840) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/837"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `a64abb13-2fad-4894-88f4-9a5619508059` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 497166009c8c0dd663fa1ffce3805a31bdc40d0e and 3b59f7a9b84f48b4f58e2003c3dbcc6c929bf515. </details> <details> <summary>📒 Files selected for processing (11)</summary> * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h` * `src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change adds decoding and IR translation for floating-point image atomic minimum and maximum operations. Atomic 32-bit float storage images use the uint storage class and an R32Uint view. The SPIR-V emitter generates atomic updates for the new operations. A regression test checks translation and validates the generated SPIR-V. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"3b59f7a9b84f48b4f58e2003c3dbcc6c929bf515" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `3b59f` <!-- final_review_risk_coverage:{"sourceCommitId":"3b59f7a9b84f48b4f58e2003c3dbcc6c929bf515","coveredCommitId":"3b59f7a9b84f48b4f58e2003c3dbcc6c929bf515","kind":"reviewed"} --> No actionable merge-blocking defect was established. The float-image atomic path is ready for normal checks, though runtime behavior has not been tested in a game. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `3b59f` The new operations use the existing storage-image binding rules and atomic update mechanism. No new security bypass was identified, but runtime behavior and some floating-point edge cases remain unverified. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The newly reachable write affects a descriptor-selected storage-image texel on the host GPU. The inspected path does not show a new raw-address sink or a way to select an arbitrary host storage-view format. **Trust Boundaries and Controls** - _observed_ — Guest-specified image format crosses into host image binding only after resource and descriptor validation; the accepted float-atomic case is bound through an R32Uint view, with a separate storage-view compatibility check. **Resilience and Maintainability Implications** - _observed_ — The atomic update retries compare-exchange after interference rather than issuing a separate non-atomic image write. The available evidence does not establish a contention bound or independent runtime containment behavior. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 inconclusive) | Check name | Status | Explanation | Resolution | | :----------------: | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ❓ Inconclusive | Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 9 files. (2 skipped: 1… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Title check | ✅ Passed | The title clearly and concisely identifies the main change: support for MIMG floating-point image atomics, specifically FMIN and FMAX. | | Description check | ✅ Passed | The description directly explains the opcode decoding, translation, SPIR-V emission, validation changes, testing, and known limitations. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 9 files. (2 skipped: 1 unsupported, 1 too large.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠Nmzik on GitHub · 2026-09-26 11:19 UTC · original

Credited

**@⁠Nmzik** on GitHub · 2026-09-26 11:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/837#issuecomment-5845823054) Credited

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.