Skip to content
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

Texture upscale shader rework (drastic perf improvement) #15109

Merged
merged 8 commits into from
Nov 7, 2021

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Nov 7, 2021

This drastically improves the performance of (Vulkan-only) compute-shader based texture upscaling, making it perform stutter-free on much more lower end GPUs.

Texture upscale shaders now each have a fixed scale factor, and instead of computing each 2x2 or 4x4 for every pixel and sampling from that, each individual thread of the compute shader writes all four or sixteen pixels that it computes anyway.

This does mean that we now only have these two variants of compute shader upscaling, but more can be added:

  • MMPX: 2x for pixel art
  • 4xBRZ: 4x upscaler, more generic

It also fixes #13679 and #15094, and removes a bunch of unused code.

Verified on NV, Intel, Adreno and Mali GPUs, plus Apple through MoltenVK.

@hrydgard hrydgard added Vulkan GE emulation Backend-independent GPU issues labels Nov 7, 2021
@hrydgard hrydgard added this to the v1.13.0 milestone Nov 7, 2021
Copy link
Collaborator

@unknownbrackets unknownbrackets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we still have an unused computeCopy bool.

-[Unknown]


// Rachet down scale factor in low-memory mode.
if (lowMemoryMode_) {
// TODO: I think really we should just turn it off?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. Nowadays it's most common on mobile:
https://report.ppsspp.org/logs/kind/724

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it as is in this PR, but yeah.

GPU/Vulkan/TextureCacheVulkan.cpp Outdated Show resolved Hide resolved
assets/shaders/tex_mmpx.csh Outdated Show resolved Hide resolved
@hrydgard hrydgard marked this pull request as ready for review November 7, 2021 15:49
@hrydgard
Copy link
Owner Author

hrydgard commented Nov 7, 2021

The 4xBRZ shader works on ARM Mali GPUs now by the way, so I removed the blacklisting.

@hrydgard hrydgard merged commit 3f4562c into master Nov 7, 2021
@hrydgard hrydgard deleted the texture-upscale-rework branch November 7, 2021 16:33
@ghost
Copy link

ghost commented Nov 7, 2021

This is also fix my issue #14530
TY ☺️

@ghost
Copy link

ghost commented Dec 11, 2021

The latest ppsspp build 4xBRZ is slow on my phone compare to this build I don't know which commit cause the lag issue.
I tried to use 4xBRZ in Radiant Mythology in causing
lag unlike before.
Screenshot_2021-12-11-21-41-40-927_org ppsspp ppsspp
recording.ppdmp.zip

@hrydgard
Copy link
Owner Author

Hm. Do you have Texture Filtering set to "Auto Max Quality"? Just wondering if that might be related, since it'll add some extra work at texture creation time.

@ghost
Copy link

ghost commented Dec 12, 2021

Hm. Do you have Texture Filtering set to "Auto Max Quality"? Just wondering if that might be related, since it'll add some extra work at texture creation time.

Yes I enable it together with 4xBRZ but after I disable auto max quality the game is still slow/lag if 4xBRZ is enable.

here's some logs idk if this is useful.

<<< log_count = 71 >>>
[12-11 20:19:30.833 23773:23773 F/DEBUG]
pid: 23632, tid: 23748, name: RenderMan  >>> org.ppsspp.ppsspp <<<

[12-11 20:19:30.858 23773:23773 F/DEBUG]
      #04 pc 00000000006ddca0  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (HandleAssert(char const*, char const*, int, char const*, char const*, ...)+248) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:19:30.858 23773:23773 F/DEBUG]
      #05 pc 00000000006bf71c  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (VulkanRenderManager::EndSubmitFrame(int)+300) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:19:30.859 23773:23773 F/DEBUG]
      #06 pc 00000000006bba84  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (VulkanRenderManager::ThreadFunc()+108) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:19:30.859 23773:23773 F/DEBUG]
      #07 pc 00000000006bfd00  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (void* std::__ndk1::__thread_proxy<std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, void (VulkanRenderManager::*)(), VulkanRenderManager*> >(void*)+64) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:20:37.972 23982:23982 F/DEBUG]
pid: 23870, tid: 23953, name: RenderMan  >>> org.ppsspp.ppsspp <<<

[12-11 20:20:37.982 23982:23982 F/DEBUG]
      #04 pc 00000000006ddca0  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (HandleAssert(char const*, char const*, int, char const*, char const*, ...)+248) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:20:37.982 23982:23982 F/DEBUG]
      #05 pc 00000000006bf71c  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (VulkanRenderManager::EndSubmitFrame(int)+300) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:20:37.982 23982:23982 F/DEBUG]
      #06 pc 00000000006bba84  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (VulkanRenderManager::ThreadFunc()+108) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

[12-11 20:20:37.982 23982:23982 F/DEBUG]
      #07 pc 00000000006bfd00  /data/app/~~r-RclirpY_XORGIAwFmxMg==/org.ppsspp.ppsspp-7CjNZogj7YSXOBuBNumSHw==/lib/arm64/libppsspp_jni.so (void* std::__ndk1::__thread_proxy<std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct> >, void (VulkanRenderManager::*)(), VulkanRenderManager*> >(void*)+64) (BuildId: 2f41c1f7a28a1b96f3abdc46a5afe6742381a376)

@hrydgard
Copy link
Owner Author

Nah, looks like those logs are from some previous crash?

I'm going to look into this properly, starting with #15229 (which also disables shader upscaling of video)

@ghost
Copy link

ghost commented Dec 12, 2021

GE Dump using ppsspp v1.12.3-453
4xBRZ.ppdmp.zip

@hrydgard
Copy link
Owner Author

hrydgard commented Dec 12, 2021

@Gamemulatorer do you think you could try to find about in which commit it slowed down? Or maybe it's just some changed setting?

Anyway, #15230 should make this a little bit faster at least (though Adreno seems to benefit more).

@ghost
Copy link

ghost commented Dec 13, 2021

Anyway, #15230 should make this a little bit faster at least (though Adreno seems to benefit more).

Why there is no android build in ppsspp buildbot for cd8493f

@unknownbrackets
Copy link
Collaborator

It's missing due to Gradle / Android SDK stability/quality issues. Requeued again...

-[Unknown]

@ghost
Copy link

ghost commented Dec 13, 2021

Still slow at 2xBRZ using ppsspp latest build

Screenshot_2021-12-12-21-42-51-525_org ppsspp ppsspp
Screenshot_2021-12-13-12-03-22-242_org ppsspp ppsspp

@hrydgard
Copy link
Owner Author

OK, thanks.

I might try to enable the GPU profiler automatically when stats are displayed, but I think I know what's going on here.

The game is rendering at 60hz, but it's doing some animation of a large background texture every couple of frames. Unfortunately, running the upscaling shader plus mipmap generation on a 512x512 texture takes ~30ms on hardware similar to yours, while due to the 60hz framerate, we have a 16ms deadline to get it done (and in practice less). So I don't think this could have ever worked smoothly on your hardware with texture upscaling enabled, unless we've changed something that previously caused it to skip upscaling.

One thing I will do is disable mipmap generation for 512x512 textures since those are hardly ever used for 3D things, but that would only happen if you had Auto Max Quality enabled anyway.. I still don't think we can hit the deadline here unless we find some really good optimizations of the upscaling algorithm, or switch to a different one.

@ghost
Copy link

ghost commented Dec 13, 2021

I just notice in the latest build that only in menu of Tales Radiant Mythology is lag but in game is smooth with 4xBRZ or 2xBRZ maybe this game is behaving the same as #12463
But in other games 4xBRZ is smooth like Tekken 6.

@hrydgard
Copy link
Owner Author

Yeah, it works fine in many games, this game is just a bit "extreme". All I'm saying is that I don't think texture scaling actually slowed down from previous builds, it's just this particular game that's using textures in a tricky way.

@hrydgard
Copy link
Owner Author

I've been messing around with it a bit more and it seems like older Mali drivers will aggressively downclock to save power if a heavy compute shader happens only every few frames. If I hack out part of the algorithm so it makes it under a frame, GPU clockspeed seems to stay high, and the scaler runs many, many times faster. So weird.

I think I'm going to set a limit at Mali-G72 or something, and below that we'll use similar rules as the software scaler - not scaling large textures that change a lot.

@unknownbrackets
Copy link
Collaborator

Maybe it's an anti bitcoin miner malware feature...

-[Unknown]

@ghost
Copy link

ghost commented Dec 16, 2021

The newest ps2 emu on android have this settings this could possibly be implemented on ppsspp?
IMG_20211216_115910

Just an idiot question/request 😂

@hrydgard
Copy link
Owner Author

That might actually be interesting to try, I just yesterday saw it mentioned in Android documentation (search for affinity in https://developer.android.com/games/optimize ).

However since in this case it's the GPU that's clocking down, it's probably not gonna help much...

hrydgard added a commit that referenced this pull request Dec 16, 2021
Applies the same rules as for software upscaling in this case.

Should fix the stutters seen in #15109
hrydgard added a commit that referenced this pull request Dec 16, 2021
Applies the same rules as for software upscaling in this case.

Should fix the stutters seen in #15109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GE emulation Backend-independent GPU issues Vulkan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4xBRZ in texture shader need highest gpu.....!!!!!
2 participants