[PR #1644] [MERGED] shader_recompiler: Implement manual barycentric interpolation path #2221

Closed
opened 2026-02-27 21:15:38 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/1644
Author: @raphaelthegreat
Created: 12/1/2024
Status: Merged
Merged: 12/2/2024
Merged by: @raphaelthegreat

Base: mainHead: bary-fix


📝 Commits (5)

  • 77cfdb1 shader_recompiler: Implement manual barycentric interpolation path
  • 84d745f clang format
  • a9798d0 emit_spirv: Fix typo
  • 83de6b7 emit_spirv: Simplify variable definition
  • b775f47 spirv_emit: clang format

📊 Changes

9 files changed (+128 additions, -57 deletions)

View changed files

📝 src/shader_recompiler/backend/spirv/emit_spirv.cpp (+6 -2)
📝 src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp (+44 -41)
📝 src/shader_recompiler/backend/spirv/emit_spirv_special.cpp (+3 -0)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.cpp (+54 -13)
📝 src/shader_recompiler/backend/spirv/spirv_emit_context.h (+6 -1)
📝 src/shader_recompiler/profile.h (+1 -0)
📝 src/video_core/renderer_vulkan/vk_instance.cpp (+7 -0)
📝 src/video_core/renderer_vulkan/vk_instance.h (+5 -0)
📝 src/video_core/renderer_vulkan/vk_pipeline_cache.cpp (+2 -0)

📄 Description

Credits to @vladmikhalin for initially investigating this issue.

In some areas in Bloodborne some instanced objects can have noticeable flicker, specifically on Nvidia GPUs, when moving in relation to them. This is hard to show in plain screenshots so I've recorded a video.

https://github.com/user-attachments/assets/be057dc6-013b-4fc7-98a2-588710c83ddd

This is because the shader used for rendering those objects passes the gl_InstanceIndex to the fragment shader using varying float attributes instead of a flat integer attribute. Nvidia has a different interpolation method compared to AMD hw, so 3 identical floats aren't interpolated to exactly the same value, which causes the instance index to get truncated to zero for some pixels and to one for others. This problem is also noted on other emulators like Xenia and RPCS3. To fix this we use the VK_KHR_fragment_shader_barycentric extension to manually interpolate the attributes according to the 2 step AMD formula (credit to Triang3l for providing the appropriate formula in their issue). This is only applied on Nvidia drivers that support the extension, which means Turing and newer GPUs. If your GPU is older than that you are probably out of luck.

https://github.com/user-attachments/assets/f7259e86-5691-457f-ab4b-2ee7764ed4d1


🔄 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/1644 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 12/1/2024 **Status:** ✅ Merged **Merged:** 12/2/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `bary-fix` --- ### 📝 Commits (5) - [`77cfdb1`](https://github.com/shadps4-emu/shadPS4/commit/77cfdb18feb202051ab9f17b7fc6e2650d154d82) shader_recompiler: Implement manual barycentric interpolation path - [`84d745f`](https://github.com/shadps4-emu/shadPS4/commit/84d745fcc489cf663583a1dfaaf0176263ec557c) clang format - [`a9798d0`](https://github.com/shadps4-emu/shadPS4/commit/a9798d04fb2e58ca8629167fa8174599fa13a64b) emit_spirv: Fix typo - [`83de6b7`](https://github.com/shadps4-emu/shadPS4/commit/83de6b7d4c29a3e476e7a83afbc49b57cca66069) emit_spirv: Simplify variable definition - [`b775f47`](https://github.com/shadps4-emu/shadPS4/commit/b775f4794cb31ea4723e6f790591e86521699a30) spirv_emit: clang format ### 📊 Changes **9 files changed** (+128 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/backend/spirv/emit_spirv.cpp` (+6 -2) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp` (+44 -41) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_special.cpp` (+3 -0) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.cpp` (+54 -13) 📝 `src/shader_recompiler/backend/spirv/spirv_emit_context.h` (+6 -1) 📝 `src/shader_recompiler/profile.h` (+1 -0) 📝 `src/video_core/renderer_vulkan/vk_instance.cpp` (+7 -0) 📝 `src/video_core/renderer_vulkan/vk_instance.h` (+5 -0) 📝 `src/video_core/renderer_vulkan/vk_pipeline_cache.cpp` (+2 -0) </details> ### 📄 Description Credits to @vladmikhalin for initially investigating this issue. In some areas in Bloodborne some instanced objects can have noticeable flicker, specifically on Nvidia GPUs, when moving in relation to them. This is hard to show in plain screenshots so I've recorded a video. https://github.com/user-attachments/assets/be057dc6-013b-4fc7-98a2-588710c83ddd This is because the shader used for rendering those objects passes the gl_InstanceIndex to the fragment shader using varying float attributes instead of a flat integer attribute. Nvidia has a different interpolation method compared to AMD hw, so 3 identical floats aren't interpolated to exactly the same value, which causes the instance index to get truncated to zero for some pixels and to one for others. This problem is also noted on other emulators like [Xenia](https://github.com/xenia-project/xenia/issues/2012) and [RPCS3](https://github.com/RPCS3/rpcs3/issues/13755). To fix this we use the VK_KHR_fragment_shader_barycentric extension to manually interpolate the attributes according to the 2 step AMD formula (credit to [Triang3l](https://github.com/Triang3) for providing the appropriate formula in their issue). This is only applied on Nvidia drivers that support the extension, which means Turing and newer GPUs. If your GPU is older than that you are probably out of luck. https://github.com/user-attachments/assets/f7259e86-5691-457f-ab4b-2ee7764ed4d1 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:15:38 +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#2221
No description provided.