[PR #757] [MERGED] video_core: Improve handling of image buffer aliases #1754

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

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/757
Author: @raphaelthegreat
Created: 9/3/2024
Status: Merged
Merged: 9/5/2024
Merged by: @raphaelthegreat

Base: mainHead: inv-fixes


📝 Commits (10+)

  • f2b714f texture_cache: Use invalidate threshhold
  • 0f2892a video_core: Allow using texture cache to validate texture buffers
  • e2b63bf texture_cache: Use buffer cache in all cases for data source
  • 36a515f texture_cache: Fix depth pitch
  • 99b8dc5 kernel: Remove missed code
  • e6325d2 clang format
  • cb66b92 video_core: Adjust depth format
  • 3c0e11f buffer_cache: Do not cache buffer views
  • a871390 thread_management: Do not call createMutex on unlock
  • e887992 temp: Revert this when pr is done

📊 Changes

18 files changed (+248 additions, -191 deletions)

View changed files

📝 src/core/libraries/kernel/thread_management.cpp (+1 -7)
📝 src/video_core/buffer_cache/buffer.cpp (+12 -24)
📝 src/video_core/buffer_cache/buffer.h (+5 -13)
📝 src/video_core/buffer_cache/buffer_cache.cpp (+91 -16)
📝 src/video_core/buffer_cache/buffer_cache.h (+7 -3)
📝 src/video_core/renderer_vulkan/vk_compute_pipeline.cpp (+7 -6)
📝 src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp (+14 -9)
📝 src/video_core/renderer_vulkan/vk_instance.cpp (+1 -0)
📝 src/video_core/renderer_vulkan/vk_platform.cpp (+2 -0)
📝 src/video_core/renderer_vulkan/vk_rasterizer.cpp (+1 -1)
📝 src/video_core/texture_cache/host_compatibility.h (+5 -4)
📝 src/video_core/texture_cache/image.cpp (+3 -2)
📝 src/video_core/texture_cache/image_info.cpp (+2 -2)
📝 src/video_core/texture_cache/image_view.cpp (+2 -1)
📝 src/video_core/texture_cache/texture_cache.cpp (+51 -63)
📝 src/video_core/texture_cache/texture_cache.h (+36 -25)
📝 src/video_core/texture_cache/tile_manager.cpp (+7 -14)
📝 src/video_core/texture_cache/tile_manager.h (+1 -1)

📄 Description

Tldr, these fixes allow Bloodborne character creator to show graphics on main, improve lighting on main game and fix the distorted motion blur

  • Fixes the pitch being wrongly set to the width of the image for depth buffer specifically.

  • Implements a new method of the buffer cache to validate buffers, SynchronizeBufferFromImage. This is specifically used for texture buffers as those are the only resources observed to rely on this aliasing so far. Bloodborne specifically uses compute shader to copy framebuffers (both depth and color) so with this change it will now work properly and without hacks.

  • Use buffer cache for not just macro tiled images but for any type of image. This means if a game uses compute to write texture data it will work and detile shader will automatically use already available GPU buffer.

  • Added a max invalidation distance heuristic. This avoid unnecessary copies by avoiding invalidating render targets far away from invalidation base address. If a shader intends to modify an image it is much more likely it will be bound exactly at or close to the image guest address.

Before this is merged the additional validation path needs to be expanded to allow for more copies inside the heuristic range, instead of looking of 1 match

image
image


🔄 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/757 **Author:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Created:** 9/3/2024 **Status:** ✅ Merged **Merged:** 9/5/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `inv-fixes` --- ### 📝 Commits (10+) - [`f2b714f`](https://github.com/shadps4-emu/shadPS4/commit/f2b714f6bb352485006e3fb59ab9acf80239521b) texture_cache: Use invalidate threshhold - [`0f2892a`](https://github.com/shadps4-emu/shadPS4/commit/0f2892a93a45e1a6c56de3bbaa77b1b2a04241c2) video_core: Allow using texture cache to validate texture buffers - [`e2b63bf`](https://github.com/shadps4-emu/shadPS4/commit/e2b63bf4c89032022ee44d26316b6bfdb2da61a8) texture_cache: Use buffer cache in all cases for data source - [`36a515f`](https://github.com/shadps4-emu/shadPS4/commit/36a515f4ee126e3e07c5be4ad95b60da5d297bdb) texture_cache: Fix depth pitch - [`99b8dc5`](https://github.com/shadps4-emu/shadPS4/commit/99b8dc54267f647962651853ce295f04feaf161b) kernel: Remove missed code - [`e6325d2`](https://github.com/shadps4-emu/shadPS4/commit/e6325d2327162ae15768c3360116755250a47591) clang format - [`cb66b92`](https://github.com/shadps4-emu/shadPS4/commit/cb66b9285496306749a3314480798c7a67d80888) video_core: Adjust depth format - [`3c0e11f`](https://github.com/shadps4-emu/shadPS4/commit/3c0e11f606f145dec91391f42e2a3790bab63610) buffer_cache: Do not cache buffer views - [`a871390`](https://github.com/shadps4-emu/shadPS4/commit/a8713904b8a1385ba34cf22b428e0216059d203c) thread_management: Do not call createMutex on unlock - [`e887992`](https://github.com/shadps4-emu/shadPS4/commit/e8879920317b3156d5e56505df9fae457ddfc0c7) temp: Revert this when pr is done ### 📊 Changes **18 files changed** (+248 additions, -191 deletions) <details> <summary>View changed files</summary> 📝 `src/core/libraries/kernel/thread_management.cpp` (+1 -7) 📝 `src/video_core/buffer_cache/buffer.cpp` (+12 -24) 📝 `src/video_core/buffer_cache/buffer.h` (+5 -13) 📝 `src/video_core/buffer_cache/buffer_cache.cpp` (+91 -16) 📝 `src/video_core/buffer_cache/buffer_cache.h` (+7 -3) 📝 `src/video_core/renderer_vulkan/vk_compute_pipeline.cpp` (+7 -6) 📝 `src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp` (+14 -9) 📝 `src/video_core/renderer_vulkan/vk_instance.cpp` (+1 -0) 📝 `src/video_core/renderer_vulkan/vk_platform.cpp` (+2 -0) 📝 `src/video_core/renderer_vulkan/vk_rasterizer.cpp` (+1 -1) 📝 `src/video_core/texture_cache/host_compatibility.h` (+5 -4) 📝 `src/video_core/texture_cache/image.cpp` (+3 -2) 📝 `src/video_core/texture_cache/image_info.cpp` (+2 -2) 📝 `src/video_core/texture_cache/image_view.cpp` (+2 -1) 📝 `src/video_core/texture_cache/texture_cache.cpp` (+51 -63) 📝 `src/video_core/texture_cache/texture_cache.h` (+36 -25) 📝 `src/video_core/texture_cache/tile_manager.cpp` (+7 -14) 📝 `src/video_core/texture_cache/tile_manager.h` (+1 -1) </details> ### 📄 Description Tldr, these fixes allow Bloodborne character creator to show graphics on main, improve lighting on main game and fix the distorted motion blur * Fixes the pitch being wrongly set to the width of the image for depth buffer specifically. * Implements a new method of the buffer cache to validate buffers, SynchronizeBufferFromImage. This is specifically used for texture buffers as those are the only resources observed to rely on this aliasing so far. Bloodborne specifically uses compute shader to copy framebuffers (both depth and color) so with this change it will now work properly and without hacks. * Use buffer cache for not just macro tiled images but for any type of image. This means if a game uses compute to write texture data it will work and detile shader will automatically use already available GPU buffer. * Added a max invalidation distance heuristic. This avoid unnecessary copies by avoiding invalidating render targets far away from invalidation base address. If a shader intends to modify an image it is much more likely it will be bound exactly at or close to the image guest address. Before this is merged the additional validation path needs to be expanded to allow for more copies inside the heuristic range, instead of looking of 1 match ![image](https://github.com/user-attachments/assets/2bcf0174-5f82-40f1-a8a4-ac23f6020f63) ![image](https://github.com/user-attachments/assets/773593b4-ceb2-4bea-a04f-388fd2b979ae) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:13:49 +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#1754
No description provided.