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

Generate "Ubershaders" that can handle all lighting configurations #16104

Merged
merged 3 commits into from
Sep 25, 2022

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Sep 25, 2022

Instead of a ton of specific shaders for every little difference.

Applies to Vulkan, DX11 and GLES3.

This drastically reduces or removes the shader compile stutter that happens when a lot of new light setups are created, like on the first punch in Tekken 6.

There's more stuff that might benefit from being made dynamic like this. These branches are very cheap on modern GPUs since they're branching on a uniform variable, so no divergence.

I think we'll need to keep the old path too for gpus like Mali-450...

Tested in VK, D3D11, and OpenGL/ES.

Also! TODO: this need to somehow take doLight from shade mapping into account.

@hrydgard hrydgard added the GE emulation Backend-independent GPU issues label Sep 25, 2022
@hrydgard hrydgard added this to the v1.14.0 milestone Sep 25, 2022
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.

Yeah, this is probably one of the better areas to "uber" combine. It's a shame about Mali and older GPUs since this'll complicate things a bit... but seems worth it to me as well.

Wish we had lighting right before this, though...

-[Unknown]

GPU/Common/ShaderUniforms.h Outdated Show resolved Hide resolved
if (chanEnabled) {
id.SetBits(VS_BIT_LIGHT0_COMP + 4 * i, 2, gstate.getLightComputation(i));
id.SetBits(VS_BIT_LIGHT0_TYPE + 4 * i, 2, gstate.getLightType(i));
if (g_Config.bLightUberShader) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this also check bitwiseOps?

-[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.

Changed it so that the ubershader is now a GPU_FEATURE flag, and it's set depending on whether bitwise ops work.

@hrydgard
Copy link
Owner Author

Indeed would be nice to have lighting correct, but the duplicated changes will at least be very nearby and easy to port, once we find what's wrong.

And yeah, this will get a round of fixes before it's time to review, thanks for looking though :)

@hrydgard
Copy link
Owner Author

GLES being a pedant about signed vs unsigned again, of course. Fixing.

@hrydgard hrydgard marked this pull request as ready for review September 25, 2022 16:54
@hrydgard hrydgard changed the title Experiment: Generate "Ubershaders" that can handle all lighting configurations Generate "Ubershaders" that can handle all lighting configurations Sep 25, 2022
@hrydgard hrydgard marked this pull request as draft September 25, 2022 16:55
@hrydgard
Copy link
Owner Author

Wait, forgot the shade mapping part.. it might be working but I need to check, heh.

@hrydgard
Copy link
Owner Author

hrydgard commented Sep 25, 2022

Oh, the shade mapping (env mapping) is working, but there's some old cruft to clean out... actually never mind, I'll leave it as-is.

@hrydgard hrydgard marked this pull request as ready for review September 25, 2022 17:00
…gurations

This drastically reduces the shader compile stutter that happens when a lot of new
light setups are created, like on the first punch in Tekken 6.

There's more stuff that might benefit from being made dynamic like this.
These branches are very cheap on modern GPUs since they're branching on
a uniform variable, so no divergence.

Only tested on Vulkan. I think we'll need to keep the old path too for
gpus like Mali-450...
@hrydgard
Copy link
Owner Author

Fixed the test, should be mostly finished now, I think.

@unknownbrackets unknownbrackets merged commit 391320d into master Sep 25, 2022
@unknownbrackets unknownbrackets deleted the light-ubershader branch September 25, 2022 21:52
@ghost
Copy link

ghost commented Sep 25, 2022

This fixes #13480 and #15239 thank you!!! ;)

Edit: vulkan only in opengl there's still stutter :(

hrydgard added a commit that referenced this pull request Sep 26, 2022
In #16104, we drastically reduced the number of shader variants for
games that use flexible lighting setups. I looked at a few games and it
seems that a lot of games have the same shaders with fog on/off, while
fog is super cheap to compute. So let's just always do it, reducing
vertex shader variants further (though the amount of pipelines will probably
remain the same, since we still specialize the fragment shader).

Might also be worth adding a dynamic bool for the fragment shader, but
if so, doing it separately.
@hrydgard
Copy link
Owner Author

@Gamemulatorer #16111 plus #16112 might help a bit more.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants