Skip to content

renderer_vulkan: Introduce shader HLE system with copy shader implementation. #1683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

squidbus
Copy link
Collaborator

@squidbus squidbus commented Dec 7, 2024

Introduces a system for implementing more efficient HLE macros for simple shaders.

In this case, implements a macro for a copy shader used by Bloodborne to copy arbitrary blocks of memory from one buffer to another. Currently this shader is responsible for big spikes in memory usage from mapping 2GB+ buffers of memory space to arbitrarily copy between. On a real console this would not be an issue since it just provides a window into the memory range, but for us this results in buffer memory allocations to cover the entire range.

By implementing this shader in HLE we can avoid these giant buffer allocations, instead only mapping much smaller areas where the copy actually occurs. This should eliminate memory spikes, reduce overall VRAM usage, and be generally more performant. We hope to have a more low-level solution for this problem in the future, but pending that this is a good way to keep memory usage under control and improve performance.

This also allows Bloodborne to go in-game on macOS (if compiled using the latest dev build of MoltenVK) since this shader was the main blocker for that. Still needs some more improvements to be fully stable.

Thanks to @raphaelthegreat for implementing the algorithm to batch the copies together.

@ngoquang2708
Copy link
Contributor

ngoquang2708 commented Dec 7, 2024

Great news for SteamDeck owner!

@GHU7924
Copy link

GHU7924 commented Dec 7, 2024

Steam Deck OLED

Build 06471fe

[Debug] page_manager.cpp:operator():36: Assertion Failed!
Operation not permitted

shad_log.txt

@ZuwasieMan
Copy link

One question @squidbus, can we expect a performance improvement in windows too? Thanks

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 7, 2024

Steam Deck OLED

Build 06471fe

[Debug] page_manager.cpp:operator():36: Assertion Failed!
Operation not permitted

Have you checked on main? This doesn't look like something that would be related to this PR.

One question @squidbus, can we expect a performance improvement in windows too? Thanks

I think so.

@StevenMiller123
Copy link
Contributor

@GHU7924 Your error comes from the texel PR, which enabled userfaultfd by default. As a result of this, you'll need to run shadPS4 with sudo

@Da-nu
Copy link

Da-nu commented Dec 7, 2024

This causes P5D (Not P3D, P4D, or P5R though) to crash after the title screen in pro mode. It causes an assertion failure on texture_cache.cpp:operator():213:
shad_log.txt

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 7, 2024

This causes P5D (Not P3D, P4D, or P5R though) to crash after the title screen in pro mode. It causes an assertion failure on texture_cache.cpp:operator():213: shad_log.txt

This PR does nothing that would effect that game, I would bet you may see that on main sometimes.

EDIT: I am indeed seeing that crash on the current main.

@GHU7924
Copy link

GHU7924 commented Dec 7, 2024

@squidbus @StevenMiller123 It looks like you're right and it doesn't apply to this PR, I'm sorry.

I recently wrote a comment about my experience playing Bloodborne on Steam Deck OLED. #1641 (comment)
The game worked for me, after that I no longer ran the emulator on the Steam Deck, deciding to check it out after a while. I downloaded your Build to give you feedback, but it didn't work out. I have also updated the Main build now and there is the same error, so once again I apologize.

Since I don't know much about Linux, I'll leave it as it is for now.

EDIT: As for Windows, I feel that performance has improved and stabilized.

@rafael-57
Copy link
Contributor

THANK YOU!! I was only able to do one test run since my PC has blue screen issues but it looks great so far.

This addresses issue #1547

@Foul-Tarnished
Copy link

Hopefully this make the 4K game patch more stable ?
And running on anything else than a 4090 😅

@Missake212
Copy link
Contributor

Made a quick video showcasing the difference if anyone's interested, pretty short and it's only in Central Yharnam but you can notice the spikes being gone in character creation
https://www.youtube.com/watch?v=jelm2Kkrrg4

@numity
Copy link

numity commented Dec 8, 2024

20241208-1216-08.0512223.mp4

I have this bug with the this new build, I think could be because of the ram fix

@numity
Copy link

numity commented Dec 8, 2024

Untitled.video.4.mp4

Here is another example of Boykimma on discord

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Please send a log as well

@numity
Copy link

numity commented Dec 8, 2024

shad_log.txt
Here is the log on my PC

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Here is the log on my PC

This is using an unofficial build outside of this PR, need the issue to be confirmed comparing main shadPS4 releases to builds from this PR.

@numity
Copy link

numity commented Dec 8, 2024

sorry my bad, give me 2 minutes

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Also needs to be with no mods, just to be sure.

@numity
Copy link

numity commented Dec 8, 2024

shad_log.txt
Here is the correct log, please let me know if this work

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Here is the correct log, please let me know if this work

You still have patches enabled. I need to know that this issue happens with this PR and no patches, and does not happen on main with no patches.

@numity
Copy link

numity commented Dec 8, 2024

Okay, I just delete the user folder and now boot the game from fresh, no patch, no mod.
Here is the log file:

https://github.com/user-attachments/assets/ea72ad6e-d802-4a85-9bc7-8e67b4fccbf5
shad_log.txt

@boykimma
Copy link

boykimma commented Dec 8, 2024

Here is my log
shad_log.txt

diegolix29 added a commit to diegolix29/shadPS4 that referenced this pull request Dec 8, 2024
@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Issue is determined to be an existing one that is exposed more heavily by this PR. Would be fixed with completed version of #1451

diegolix29 added a commit to diegolix29/shadPS4 that referenced this pull request Dec 8, 2024
@squidbus
Copy link
Collaborator Author

squidbus commented Dec 8, 2024

Pushed something that should fix the issue for now. Subresource uploads will likely provide a more efficient fix but this should provide a good fallback to catch any cases where ObtainViewBuffer is used with partial GPU-modified overlap.

diegolix29 added a commit to diegolix29/shadPS4 that referenced this pull request Dec 9, 2024
@AxeKeeper
Copy link

AxeKeeper commented Dec 9, 2024

shadPS4.exe.2024.12.09.-.13.47.27.03.1.mp4

Here i found another two. Above the door 1st one

@AxeKeeper
Copy link

shadPS4.exe.2024.12.09.-.13.54.17.04.1.mp4

@AxeKeeper
Copy link

shad_log.txt

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 9, 2024

Needs comparison to main releases.

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 9, 2024

Actually from your log it looks like you are already on main, those issues are not relevant to this PR.

@AxeKeeper
Copy link

Actually from your log it looks like you are already on main, those issues are not relevant to this PR.

Oh. Ok. I just don’t know which PR to send them to. I thought it was the same problem and sent it here.

@squidbus
Copy link
Collaborator Author

squidbus commented Dec 9, 2024

Oh. Ok. I just don’t know which PR to send them to. I thought it was the same problem and sent it here.

It's only relevant if its something that happens with this PR builds and not on main releases.

@Missake212
Copy link
Contributor

Actually from your log it looks like you are already on main, those issues are not relevant to this PR.

Btw these are not issues, it's just the lod, it happens on PS4 too I just checked

@AxeKeeper
Copy link

Actually from your log it looks like you are already on main, those issues are not relevant to this PR.

Btw these are not issues, it's just the lod, it happens on PS4 too I just checked
Ooh. I didn't even know about it. I thought Sony didn’t like even this kind of "issues". Well, if so, I'm glad it's not related to the emulator.

@Missake212
Copy link
Contributor

This PR allows BB to be played on an iGPU now, great work !
https://www.youtube.com/watch?v=v5ouCyh5NtY

@raphaelthegreat raphaelthegreat merged commit e5e1aba into shadps4-emu:main Dec 10, 2024
20 checks passed
@Foul-Tarnished
Copy link

Great amazing work now bb no longer asserts on igpu (fixes #765) i

warp to Hunter's Dream causes vertex explosions Might be a regression

Man this is so unrelated to what this PR touched.

Also vertex explosions are pretty random

diegolix29 pushed a commit to diegolix29/shadPS4 that referenced this pull request Dec 11, 2024
…ntation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient

---------

Co-authored-by: TheTurtle <[email protected]>
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
Xcedf added a commit to Xcedf/shadPS4 that referenced this pull request Dec 28, 2024
…mentation. (shadps4-emu#1683)

* renderer_vulkan: Introduce shader HLE system with copy shader implementation.

Co-authored-by: TheTurtle <[email protected]>

* buffer_cache: Handle obtaining buffer views partially within buffers.

* vk_shader_hle: Make more efficient
@squidbus squidbus deleted the copy-shader-hle branch January 27, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.