shader: emulate DS_ORDERED_COUNT as a GDS atomic #1117

Manually merged
github merged 3 commits from gh-pr/1117/head into gh-pr/1117/base 2026-11-26 09:43:48 +00:00
Owner

@⁠NeySlim on GitHub · 2026-10-06 19:45 UTC · original
NeySlim:feat/ds-ordered-count → main · +129 −0 · 5 files · 3 commits · merged 2026-10-06 21:45 UTC

DS opcode 0x3f with the GDS bit (DS_ORDERED_COUNT) was not implemented, which aborted the CFG build for a compute shader in God of War Ragnarök (PPSA08332).

This decodes the instruction (counter index from offset0, add/swap from offset1[5:4], one dword) and emulates it as a plain GDS atomic add or swap at M0 + index * 4, with the value taken from the ADDR VGPR as the hardware does. Wave-launch ordering is not emulated: every wave still receives a unique pre-op value, which is what append-style users need, but consumers relying on the launch order will see arbitrary order. Multi-dword variants and GDS-less encodings stay unsupported.

Tested on Linux, RTX 4090.

**@⁠NeySlim** on GitHub · 2026-10-06 19:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117) `NeySlim:feat/ds-ordered-count` → `main` · +129 −0 · 5 files · 3 commits · merged 2026-10-06 21:45 UTC DS opcode 0x3f with the GDS bit (`DS_ORDERED_COUNT`) was not implemented, which aborted the CFG build for a compute shader in God of War Ragnarök (PPSA08332). This decodes the instruction (counter index from offset0, add/swap from offset1[5:4], one dword) and emulates it as a plain GDS atomic add or swap at `M0 + index * 4`, with the value taken from the ADDR VGPR as the hardware does. Wave-launch ordering is not emulated: every wave still receives a unique pre-op value, which is what append-style users need, but consumers relying on the launch order will see arbitrary order. Multi-dword variants and GDS-less encodings stay unsupported. Tested on Linux, RTX 4090.
Use the M0 base and pixel packer offset for the GDS counter. Broadcast the
previous value to every lane and preserve the counter when EXEC is empty.

Add GPU regressions for add/exchange with full, partial, and empty EXEC in
wave32 and wave64. The targeted DS and buffer atomic suite passes 63 cases.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:43:46 +00:00
github manually merged commit 3770460d72 into gh-pr/1117/base 2026-11-26 09:43:48 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:51 UTC · original · edited 2026-10-06 20:07 UTC

Review in Change Stack →

📝 Walkthrough

Walkthrough

The DS decoder now recognizes DS_ORDERED_COUNT, decodes its offsets and selector, and marks unsupported encodings. The translator dispatches the instruction and emits a shared atomic swap when secondary_offset is 1, or an atomic add otherwise. It uses a ballot to select the first active lane, performs the atomic at address zero, and broadcasts the result to the destination.

Priority: ➖ Normal

Change: Feature

Merge Risk: 🟡 Moderate · up to 5f0a8

Shaders using a nonzero M0 can receive incorrect counter values. Correct the atomic address before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change: emulating DS_ORDERED_COUNT as a GDS atomic.
Description check ✅ Passed The description explains the missing opcode support, the decoding and emulation approach, its limitations, and the reported test environment.
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.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#issuecomment-6024234723) · edited 2026-10-06 20:07 UTC <!-- 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/1117?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><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> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The DS decoder now recognizes `DS_ORDERED_COUNT`, decodes its offsets and selector, and marks unsupported encodings. The translator dispatches the instruction and emits a shared atomic swap when `secondary_offset` is 1, or an atomic add otherwise. It uses a ballot to select the first active lane, performs the atomic at address zero, and broadcasts the result to the destination. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"5f0a83f30781bc7b74e3e07837bfddb90c172022" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `5f0a8` <!-- final_review_risk_coverage:{"sourceCommitId":"5f0a83f30781bc7b74e3e07837bfddb90c172022","coveredCommitId":"5f0a83f30781bc7b74e3e07837bfddb90c172022","kind":"reviewed"} --> Shaders using a nonzero M0 can receive incorrect counter values. Correct the atomic address before merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the change: emulating DS_ORDERED_COUNT as a GDS atomic. | | Description check | ✅ Passed | The description explains the missing opcode support, the decoding and emulation approach, its limitations, and the reported test environment. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1117)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:51 UTC · original · edited 2026-10-06 20:08 UTC
On src/graphics/shader/recompiler/frontend/translate/Memory.cpp line 894 (outdated):

@@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) {
 	                                ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()}));
 }
 
+void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) {
+	// Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a
+	// unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4.
+	const auto memory = MemoryInfoFromDecoded(inst);
+	const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32
+	                                                : IR::ValueOpcode::SharedAtomicIAdd32;
+	WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()},
+	                               AddMemoryInfo(memory, inst.pc)));

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Perform one atomic operation per wave.

When multiple lanes are active, this IR executes the atomic for each active lane. DS_ORDERED_COUNT instead takes the ADDR value from the first active lane and performs one counter operation per wave. A wave with four active lanes and an increment of one can therefore advance the counter by four and receive different pre-operation values. Select the first active lane’s value, issue one atomic, and distribute its result to the required lanes. (docs.amd.com)

✅ Addressed in commit 5f0a83f

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#discussion_r4199793928) · edited 2026-10-06 20:08 UTC On `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` line 894 (outdated): ```diff @@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) { ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()})); } +void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) { + // Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a + // unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4. + const auto memory = MemoryInfoFromDecoded(inst); + const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32 + : IR::ValueOpcode::SharedAtomicIAdd32; + WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()}, + AddMemoryInfo(memory, inst.pc))); ``` **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** **Perform one atomic operation per wave.** When multiple lanes are active, this IR executes the atomic for each active lane. `DS_ORDERED_COUNT` instead takes the ADDR value from the first active lane and performs one counter operation per wave. A wave with four active lanes and an increment of one can therefore advance the counter by four and receive different pre-operation values. Select the first active lane’s value, issue one atomic, and distribute its result to the required lanes. ([docs.amd.com](https://docs.amd.com/api/khub/documents/UkT_UPQL21KfKAMUBFnZTw/content?utm_source=openai)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:b099f5e8e1ddcb580f72874d --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 5f0a83f
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:51 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e833093b-d615-46e8-9cd7-b30215f8b020
📥 Commits

Reviewing files that changed from the base of the PR and between 199d0a9d92 and 7e5d02f22c.

📒 Files selected for processing (4)
  • src/graphics/shader/recompiler/frontend/decode/MemoryOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/translate/Memory.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translator.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#pullrequestreview-5433824624) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `e833093b-d615-46e8-9cd7-b30215f8b020` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 199d0a9d9225e560432301e39439296d57fa0e34 and 7e5d02f22c6246326cbc5a925441ac48d2ce5438. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/shader/recompiler/frontend/decode/MemoryOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=35db0f26-c56b-4593-86f9-6036bbdc5fd5 attempt=a2c7d70b-8828-45a5-90fc-4ab22d879884 batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-06 19:57 UTC · original
On src/graphics/shader/recompiler/frontend/translate/Memory.cpp line 894 (outdated):

@@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) {
 	                                ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()}));
 }
 
+void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) {
+	// Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a
+	// unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4.
+	const auto memory = MemoryInfoFromDecoded(inst);
+	const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32
+	                                                : IR::ValueOpcode::SharedAtomicIAdd32;
+	WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()},
+	                               AddMemoryInfo(memory, inst.pc)));

Right, thanks. Fixed in 5f0a83f: the first active lane (from the ballot) issues the single atomic with its ADDR value, and the pre-op result is read back from that lane and written to every lane.

**@⁠NeySlim** on GitHub · 2026-10-06 19:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#discussion_r4199845465) On `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` line 894 (outdated): ```diff @@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) { ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()})); } +void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) { + // Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a + // unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4. + const auto memory = MemoryInfoFromDecoded(inst); + const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32 + : IR::ValueOpcode::SharedAtomicIAdd32; + WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()}, + AddMemoryInfo(memory, inst.pc))); ``` Right, thanks. Fixed in 5f0a83f: the first active lane (from the ballot) issues the single atomic with its ADDR value, and the pre-op result is read back from that lane and written to every lane.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 20:07 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Use M0 as the GDS atomic base. · Memory.cpp:887-909

src/graphics/shader/recompiler/frontend/translate/Memory.cpp:887-909
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use M0 as the GDS atomic base.

When a supported shader sets M0 to a nonzero value, DS_ORDERED_COUNT still passes zero as the atomic address. The GDS backend uses that argument to select the counter, so the operation can update or read the wrong counter. Pass the mapped M0 operand.

Suggested fix
-	const auto result = ir.Emit(opcode, {IR::U32(IR::Value(0u)), value, is_first},
+	const auto result = ir.Emit(opcode, {ReadU32(MemorySourceAt(inst, 0)), value, is_first},
 	                            AddMemoryInfo(memory, inst.pc));

The defect is a reachable wrong-result case, but the inspected code does not show broad usage or impact that warrants a major classification.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ce1904a-f231-4c10-a8c4-6bd958f8aa04
📥 Commits

Reviewing files that changed from the base of the PR and between 7e5d02f22c and 5f0a83f307.

📒 Files selected for processing (1)
  • src/graphics/shader/recompiler/frontend/translate/Memory.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/graphics/shader/recompiler/frontend/translate/Memory.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 20:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#pullrequestreview-5433992820) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟡 Minor</strong> · Use M0 as the GDS atomic base. · <code>Memory.cpp:887-909</code></summary><blockquote> > > `src/graphics/shader/recompiler/frontend/translate/Memory.cpp:887-909` > **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** > > **Use M0 as the GDS atomic base.** > > When a supported shader sets M0 to a nonzero value, `DS_ORDERED_COUNT` still passes zero as the atomic address. The GDS backend uses that argument to select the counter, so the operation can update or read the wrong counter. Pass the mapped M0 operand. > > <details> > <summary>Suggested fix</summary> > > ```diff > - const auto result = ir.Emit(opcode, {IR::U32(IR::Value(0u)), value, is_first}, > + const auto result = ir.Emit(opcode, {ReadU32(MemorySourceAt(inst, 0)), value, is_first}, > AddMemoryInfo(memory, inst.pc)); > ``` > > </details> > > The defect is a reachable wrong-result case, but the inspected code does not show broad usage or impact that warrants a major classification. > > <!-- cr-comment:v1:d6dc04c76b1dfdfaf0714539 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3ce1904a-f231-4c10-a8c4-6bd958f8aa04` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7e5d02f22c6246326cbc5a925441ac48d2ce5438 and 5f0a83f30781bc7b74e3e07837bfddb90c172022. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * src/graphics/shader/recompiler/frontend/translate/Memory.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=5f9bc69a-f5cc-4ffe-a4ff-678029becece attempt=77bec2d0-8082-4e0b-a601-a7ddf087d4db batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 20:09 UTC · original
On src/graphics/shader/recompiler/frontend/translate/Memory.cpp line 894 (outdated):

@@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) {
 	                                ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()}));
 }
 
+void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) {
+	// Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a
+	// unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4.
+	const auto memory = MemoryInfoFromDecoded(inst);
+	const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32
+	                                                : IR::ValueOpcode::SharedAtomicIAdd32;
+	WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()},
+	                               AddMemoryInfo(memory, inst.pc)));

@NeySlim, thanks for the fix. The updated implementation issues one atomic from the first active lane with its ADDR value, then broadcasts the pre-operation result.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 20:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#discussion_r4199949181) On `src/graphics/shader/recompiler/frontend/translate/Memory.cpp` line 894 (outdated): ```diff @@ -883,6 +884,16 @@ void Translator::DS_SWIZZLE_B32(const Decoder::Instruction& inst) { ReadU32(MemorySourceAt(inst, 1)), ir.GetExec()})); } +void Translator::DS_ORDERED_COUNT(const Decoder::Instruction& inst) { + // Wave-launch ordering is not emulated: a plain GDS atomic still gives every wave a + // unique result. The ADDR VGPR carries the value; the counter sits at M0 + index * 4. + const auto memory = MemoryInfoFromDecoded(inst); + const auto opcode = inst.secondary_offset == 1u ? IR::ValueOpcode::SharedAtomicSwap32 + : IR::ValueOpcode::SharedAtomicIAdd32; + WriteOperand(inst.dst, ir.Emit(opcode, {IR::U32(IR::Value(0u)), ReadU32(inst.src0), ir.GetExec()}, + AddMemoryInfo(memory, inst.pc))); ``` `@NeySlim`, thanks for the fix. The updated implementation issues one atomic from the first active lane with its ADDR value, then broadcasts the pre-operation result. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=DS_ORDERED_COUNT%20needs%20one%20atomic%20per%20wave%E2%80%94not%20per%20active%20lane.%20Use%20the%20first%20active%20lane%E2%80%99s%20ADDR%2C%20then%20broadcast%20the%20result.%20Catch%20correctness%20bugs%20with%20%40coderabbitai%20%F0%9F%90%87%20Try%20it!&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1117%23discussion_r4199793928)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-06 21:30 UTC · original

@⁠NeySlim Hey. This is wrong impl. I ll push fix

**@⁠Nmzik** on GitHub · 2026-10-06 21:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1117#issuecomment-6025823092) @⁠NeySlim Hey. This is wrong impl. I ll push fix
This discussion has been locked. Commenting is limited to contributors.
No description provided.