[PR #3306] [MERGED] shader_recompiler: Use VM bit for conditional discard #3372

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

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/3306
Author: @raphaelthegreat
Created: 7/23/2025
Status: Merged
Merged: 7/23/2025
Merged by: @georgemoralis

Base: mainHead: better-discard


📝 Commits (1)

  • 8e469a5 shader_recompiler: Use VM bit for conditional discard

📊 Changes

5 files changed (+1 additions, -13 deletions)

View changed files

📝 src/shader_recompiler/frontend/control_flow_graph.cpp (+0 -8)
📝 src/shader_recompiler/frontend/control_flow_graph.h (+0 -1)
📝 src/shader_recompiler/frontend/structured_control_flow.cpp (+0 -1)
📝 src/shader_recompiler/frontend/translate/export.cpp (+1 -1)
📝 src/shader_recompiler/ir/basic_block.h (+0 -2)

📄 Description

Shader export instructions have 2 special bits, the DONE bit is set for the last export instruction in the shader and can be safely ignored. The VM bit is also set on a single export and makes that export responsible for informing the color buffer which pixels are valid and which have been discarded. So use that to insert the conditional discard instead of guessing from the number of predecessors.

This fixes the blocky shadows in Driveclub, the fragment shader used for rendering tree shadows read the alpha value from the texture and did a conditional discard based on it. But because there was no control flow, the predecessor check failed, resulting in the whole shader being eliminated as dead code.


🔄 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/3306 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 7/23/2025 **Status:** ✅ Merged **Merged:** 7/23/2025 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `better-discard` --- ### 📝 Commits (1) - [`8e469a5`](https://github.com/shadps4-emu/shadPS4/commit/8e469a52c89db8d2ddf22f953490d838cef9d99d) shader_recompiler: Use VM bit for conditional discard ### 📊 Changes **5 files changed** (+1 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/frontend/control_flow_graph.cpp` (+0 -8) 📝 `src/shader_recompiler/frontend/control_flow_graph.h` (+0 -1) 📝 `src/shader_recompiler/frontend/structured_control_flow.cpp` (+0 -1) 📝 `src/shader_recompiler/frontend/translate/export.cpp` (+1 -1) 📝 `src/shader_recompiler/ir/basic_block.h` (+0 -2) </details> ### 📄 Description Shader export instructions have 2 special bits, the DONE bit is set for the last export instruction in the shader and can be safely ignored. The VM bit is also set on a single export and makes that export responsible for informing the color buffer which pixels are valid and which have been discarded. So use that to insert the conditional discard instead of guessing from the number of predecessors. This fixes the blocky shadows in Driveclub, the fragment shader used for rendering tree shadows read the alpha value from the texture and did a conditional discard based on it. But because there was no control flow, the predecessor check failed, resulting in the whole shader being eliminated as dead code. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:03:28 +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#3372
No description provided.