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

Truncate vertex attribute format if it exceeds stride on MoltenVK #5094

Merged
merged 4 commits into from
May 25, 2023

Conversation

gdkchan
Copy link
Member

@gdkchan gdkchan commented May 25, 2023

Zelda Tears of the Kingdom has a few cases where it uses a 4 components format instead of a 3 components format, but everything (offset, buffer stride) are calculated for a 3 components format, and the vertex shader also only accesses 3. The fact that it uses 4 causes the vertex attribute to exceed the stride in some cases. This is invalid and causes weird bugs on Metal.

It seems MoltenVK already has some code to work around this issue:
https://github.com/KhronosGroup/MoltenVK/blob/b3ae0f48d0170570e46c7b3a8bcd8278bb71f40e/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm#L1311

However it does not take offset into account, only the format size, so it will only kick in for attributes with a offset of zero. This PR implements the same change on the emulator, but it also adds the offset to the size, so it applies to all cases where the attribute exceeds the stride, not just cases where the offset is 0 and there's no other attribute after.

Fixes vertex explosions on The Legend of Zelda: Tears of the Kingdom.
Before:
Captura de Tela 2023-05-24 às 22 25 10
Captura de Tela 2023-05-24 às 22 25 16
After:
Captura de Tela 2023-05-24 às 22 18 40
Captura de Tela 2023-05-24 às 22 18 49

Fixes vertex explosions reported on #4949.

@gdkchan gdkchan added gpu Related to Ryujinx.Graphics fix Fix something os:macOS An issue or feature request exclusively relating to macOS labels May 25, 2023
@gdkchan gdkchan requested a review from marysaka May 25, 2023 01:31
@gdkchan gdkchan added the graphics-backend:vulkan Graphical bugs when using the Vulkan API label May 25, 2023
@github-actions
Copy link

github-actions bot commented May 25, 2023

@vesper8
Copy link

vesper8 commented May 25, 2023

The hero we all need but don't deserve <3

@gdkchan gdkchan marked this pull request as draft May 25, 2023 14:43
@noahgg12
Copy link

Are we merging this to the nightly builds?

Copy link
Member

@riperiperi riperiperi left a comment

Choose a reason for hiding this comment

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

Nice catch, this makes sense. Maybe the format size method should be in FormatExtensions?

@gdkchan
Copy link
Member Author

gdkchan commented May 25, 2023

Nice catch, this makes sense. Maybe the format size method should be in FormatExtensions?

They work with the Vulkan VkFormat enum, not the Format enum in the GAL project. So it wouldn't make sense to add it there, but I can move it to the Vulkan FormatTable class.

@gdkchan gdkchan marked this pull request as ready for review May 25, 2023 19:18
@gdkchan gdkchan merged commit 2c9715a into Ryujinx:master May 25, 2023
8 checks passed
@gdkchan gdkchan deleted the trunc-attr branch May 25, 2023 20:03
@khalidahusain
Copy link

khalidahusain commented May 26, 2023

Hey, i'm trying to download it, but I'm not able to using the MacOS link or any other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something gpu Related to Ryujinx.Graphics graphics-backend:vulkan Graphical bugs when using the Vulkan API os:macOS An issue or feature request exclusively relating to macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants