[PR #2403] [MERGED] shader_recompiler: Lower non-compute shared memory into spare VGPRs. #2705

Closed
opened 2026-02-27 22:00:55 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/2403
Author: @squidbus
Created: 2/12/2025
Status: Merged
Merged: 2/13/2025
Merged by: @squidbus

Base: mainHead: shared-to-priv


📝 Commits (1)

  • 4cb379a shader_recompiler: Lower non-compute shared memory into spare VGPRs.

📊 Changes

12 files changed (+85 additions, -94 deletions)

View changed files

📝 src/shader_recompiler/backend/spirv/emit_spirv_instructions.h (+0 -2)
📝 src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp (+0 -34)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.cpp (+2 -0)
📝 src/shader_recompiler/info.h (+2 -1)
📝 src/shader_recompiler/ir/ir_emitter.cpp (+0 -5)
📝 src/shader_recompiler/ir/microinstruction.cpp (+0 -1)
📝 src/shader_recompiler/ir/opcodes.inc (+0 -2)
📝 src/shader_recompiler/ir/passes/hull_shader_transform.cpp (+10 -23)
📝 src/shader_recompiler/ir/passes/ir_passes.h (+1 -1)
📝 src/shader_recompiler/ir/passes/lower_shared_mem_to_registers.cpp (+65 -22)
📝 src/shader_recompiler/recompiler.cpp (+4 -3)
📝 src/video_core/renderer_vulkan/vk_rasterizer.cpp (+1 -0)

📄 Description

Improves the shared memory lowering pass for non-compute by lowering into spare VGPRs instead of directly referencing the value source. This allows it to work with branching shared memory logic. The previous implementation would ignore control flow and just take the last write instruction in order before the read, but by replacing with VGPR load/store instead, we can preserve control flow.

Fixes some fragment shaders in CUSA28193 that use branching logic for writing to shared memory then read the values back later. A few shaders that would emit a validation error about non-dominating variable access are now valid.

I also fixed a few issues in the shared memory buffer binding that I spotted, with it not being accounted for in Info::AddBindings or incrementing the buffer count in Rasterizer::BindBuffers.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/2403 **Author:** [@squidbus](https://github.com/squidbus) **Created:** 2/12/2025 **Status:** ✅ Merged **Merged:** 2/13/2025 **Merged by:** [@squidbus](https://github.com/squidbus) **Base:** `main` ← **Head:** `shared-to-priv` --- ### 📝 Commits (1) - [`4cb379a`](https://github.com/shadps4-emu/shadPS4/commit/4cb379a755fd411aa032176612ac7ef866bc906d) shader_recompiler: Lower non-compute shared memory into spare VGPRs. ### 📊 Changes **12 files changed** (+85 additions, -94 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/backend/spirv/emit_spirv_instructions.h` (+0 -2) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_shared_memory.cpp` (+0 -34) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.cpp` (+2 -0) 📝 `src/shader_recompiler/info.h` (+2 -1) 📝 `src/shader_recompiler/ir/ir_emitter.cpp` (+0 -5) 📝 `src/shader_recompiler/ir/microinstruction.cpp` (+0 -1) 📝 `src/shader_recompiler/ir/opcodes.inc` (+0 -2) 📝 `src/shader_recompiler/ir/passes/hull_shader_transform.cpp` (+10 -23) 📝 `src/shader_recompiler/ir/passes/ir_passes.h` (+1 -1) 📝 `src/shader_recompiler/ir/passes/lower_shared_mem_to_registers.cpp` (+65 -22) 📝 `src/shader_recompiler/recompiler.cpp` (+4 -3) 📝 `src/video_core/renderer_vulkan/vk_rasterizer.cpp` (+1 -0) </details> ### 📄 Description Improves the shared memory lowering pass for non-compute by lowering into spare VGPRs instead of directly referencing the value source. This allows it to work with branching shared memory logic. The previous implementation would ignore control flow and just take the last write instruction in order before the read, but by replacing with VGPR load/store instead, we can preserve control flow. Fixes some fragment shaders in CUSA28193 that use branching logic for writing to shared memory then read the values back later. A few shaders that would emit a validation error about non-dominating variable access are now valid. I also fixed a few issues in the shared memory buffer binding that I spotted, with it not being accounted for in `Info::AddBindings` or incrementing the buffer count in `Rasterizer::BindBuffers`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:00:55 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#2705
No description provided.