mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-25 15:56:00 +03:00
[PR #3327] [MERGED] shader_recompiler: Rework sharp tracking for robustness #3393
Labels
No labels
Bloodborne
bug
contributor wanted
documentation
enhancement
frontend
good first issue
help wanted
linux
pull-request
question
release
verification progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/shadPS4#3393
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/shadps4-emu/shadPS4/pull/3327
Author: @raphaelthegreat
Created: 7/26/2025
Status: ✅ Merged
Merged: 7/28/2025
Merged by: @squidbus
Base:
main← Head:sharp-track📝 Commits (8)
d7e5c2eshader_recompiler: Remove remnants of old discard9fc3d68resource_tracking_pass: Rework sharp tracking for robustnessfe57b5aresource_tracking_pass: Add source dominance analysisc024904resource_tracking_pass: Fix immediate checkc0755e7resource_tracking_pass: Remove unused template type45e666areadlane_elimination_pass: Don't add phi when all args are the samead2cb2dresource_tracking_pass: Allow phi in disable aniso patterne9317b9resource_tracking_pass: Handle not valid buffer sharp and more phi in aniso pattern📊 Changes
20 files changed (+303 additions, -242 deletions)
View changed files
📝
CMakeLists.txt(+1 -0)📝
src/shader_recompiler/backend/spirv/spirv_emit_context.cpp(+5 -5)📝
src/shader_recompiler/frontend/control_flow_graph.cpp(+1 -20)📝
src/shader_recompiler/frontend/control_flow_graph.h(+0 -1)📝
src/shader_recompiler/frontend/structured_control_flow.cpp(+5 -24)📝
src/shader_recompiler/frontend/translate/scalar_flow.cpp(+3 -5)📝
src/shader_recompiler/frontend/translate/translate.cpp(+6 -6)📝
src/shader_recompiler/frontend/translate/translate.h(+4 -3)📝
src/shader_recompiler/frontend/translate/vector_memory.cpp(+11 -10)📝
src/shader_recompiler/info.h(+14 -16)📝
src/shader_recompiler/ir/basic_block.cpp(+2 -2)📝
src/shader_recompiler/ir/basic_block.h(+8 -0)📝
src/shader_recompiler/ir/ir_emitter.cpp(+5 -5)📝
src/shader_recompiler/ir/ir_emitter.h(+3 -3)📝
src/shader_recompiler/ir/opcodes.inc(+2 -2)📝
src/shader_recompiler/ir/passes/constant_propagation_pass.cpp(+14 -0)📝
src/shader_recompiler/ir/passes/readlane_elimination_pass.cpp(+11 -1)📝
src/shader_recompiler/ir/passes/resource_tracking_pass.cpp(+203 -139)📝
src/shader_recompiler/ir/reg.h(+1 -0)📝
src/video_core/amdgpu/resource.h(+4 -0)📄 Description
On main image+sampler sharp tracking was kinda broken in a silly way. PatchImageSharp would call BreadthFirstSearch on the image instruction itself. Before https://github.com/shadps4-emu/shadPS4/pull/3015 that was fine because there was a single handle argument and image address components are very unlikely to come from user data or read const instruction.
However that PR added a sampler handle argument at the end of the instruction, which caused the image tracking to search in the sampler instruction tree first (because BreadthFirstSearch iterates instruction arguments in reverse order). Thankfully the sampler argument is a composite so it wouldn't get expanded at the first level of the tree. If the image handle was a read const/user data instruction then it would get picked. But if it was a phi, then next iteration the sampler tree would be searched next, leading to the tracking sometimes picking sampler sharps instead of image sharps.
Fix this by reworking sharp tracking for robustness. Instead of searching a single source, traverse the phi tree (only the image handle this time) and find all possible sources. Then attempt to prune these sources, based on dominance analysis. If a source is dominated by another one then the former can be removed as control flow is guaranteed to pass the dominator. This also implicitly performs reachability analysis as the function will also return true if no path from source to resource access block exists in general.
This fixes the rear mirror in Driveclub without reverting the PR mentioned above.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.