-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
Download the artifacts for this pull request: Experimental GUI (Avalonia)GUI-less (SDL2)Only for Developers
|
The hero we all need but don't deserve <3 |
Are we merging this to the nightly builds? |
There was a problem hiding this 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?
They work with the Vulkan |
Hey, i'm trying to download it, but I'm not able to using the MacOS link or any other. |
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.
![Captura de Tela 2023-05-24 às 22 25 10](https://private-user-images.githubusercontent.com/5624669/240776914-5465f06c-d477-4531-8561-daca8c8a6ab5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyMjg2MDUsIm5iZiI6MTcyMjIyODMwNSwicGF0aCI6Ii81NjI0NjY5LzI0MD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FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDhhNDhmZGUwNDNmZmVmMzc1MjhlNjc1ODdkMWNhNmVjYWU5NmJiNDBjNzUxNDBiZGNlZDQ3YTE2NjI4MzdhMSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.k9XR5mtm966LVelejVzvKGQuJhA167rTWb3hOvt-BYw)
![Captura de Tela 2023-05-24 às 22 18 40](https://private-user-images.githubusercontent.com/5624669/240776981-37a38649-5af4-434d-a036-cfe61edbaf17.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyMjg2MDUsIm5iZiI6MTcyMjIyODMwNSwicGF0aCI6Ii81NjI0NjY5LzI0MDc3Njk4MS0zN2EzODY0OS01YWY0LTQzNGQtYTAzNi1jZmU2MWVkYmFmMTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjlUMDQ0NTA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDE4NDYyM2FhYmE4NzliMTY1MWJmNDA0Nzg3NzFiMzIyNDkxMmVlNmFkYTUxZTFkMTk5NzNmNTQ0OWQwZmU5ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.VKQ1YQEuDxfTkE0VZmJNxWlGcOYSgkigcpe5Mb-ANkI)
![Captura de Tela 2023-05-24 às 22 18 49](https://private-user-images.githubusercontent.com/5624669/240776992-7e7308a7-5346-4797-8313-83ad4dcbb4ef.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyMjg2MDUsIm5iZiI6MTcyMjIyODMwNSwicGF0aCI6Ii81NjI0NjY5LzI0MDc3Njk5Mi03ZTczMDhhNy01MzQ2LTQ3OTctODMxMy04M2FkNGRjYmI0ZWYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjlUMDQ0NTA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2VjZjNlNmZiOWE5NjhlNjEzMTI2MjdiMzk0YWJiNjU4ZmM1YjFmZjg0NzY2NzQ1NTZiMGViNGM5Y2M3NjUyYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.7JgQk1KAvuZzeTtCbaUWZSJcCaYJKseIJ9OZGsyJNYo)
Before:
After:
Fixes vertex explosions reported on #4949.