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

Implement transform feedback emulation for hardware without native support #5080

Merged
merged 9 commits into from Jun 10, 2023

Conversation

gdkchan
Copy link
Member

@gdkchan gdkchan commented May 24, 2023

This implements partial support for transform feedback emulation, for platforms that do not have native support for this feature (like macOS).

Test results

I tested some games that uses transform feedback locally to validate that the implementation is working. Below I show the results and also some observations regarding issues that I found.

Pokémon Scarlet/Violet:
Captura de Tela 2023-05-23 às 20 25 06
This test was done with buffer mirrors (#4899). Without it, the performance is abysmal and for some reason, some objects are flickering (maybe related to the low performance) (The performance issue was fixed on 5447548). No InvalidResource error with and without mirrors.

Pokémon Legends Arceus:
Captura de Tela 2023-06-08 às 15 50 00
This was tested without buffer mirrors. (Can also reach 30 fps without mirrors now). With buffer mirros, it can reach 30 fps, but there are a lot of InvalidResource errors which prevents the game from rendering properly, so I don't recommend right now.

SNK Heroines: Tag Team Frenzy:
Captura de Tela 2023-05-23 às 20 33 47
Tons of InvalidResource error with and without mirrors. But the characters does render when it is not erroring, which shows that transform feedback is working. Can reach 60 fps with and without mirrors.

Xenoblade Chronicles Definitive Edition:
Captura de Tela 2023-05-23 às 20 41 32
Title screen render fine (the grass uses transform feedback). In-game it starts having a lot of InvalidResource errors and does not render properly unfortunately:
Captura de Tela 2023-05-23 às 20 43 22
I did not test with mirrors.

Pokkén Tournament:
Captura de Tela 2023-05-23 às 20 47 11
Captura de Tela 2023-05-23 às 20 47 21
Works, no InvalidResource errors, can reach 60 fps. I did not test with mirrors.

Metroid Prime Remastered:
Captura de Tela 2023-05-23 às 21 16 43
What is uses transform feedback for (Samus shadows) is not really working since it does it from a geometry shader. But at least the game doesn't crash anymore.

Donkey Kong Country: Tropical Freeze:
Captura de Tela 2023-05-25 às 23 34 31
Tested without mirrors, looks fine and runs at 60 fps the entire time.

Note: All tests performed on 2020 MacBook Air.

What's still not supported:

So I mentioned before that this is partial support, because there are a few cases that are not yet supported:

  • Indirect instanced draws. Should be easy to support, we just need to read the vertex count from the indirect data, but I'm not aware of any game that uses this to test.
  • Indexed draws. This one is complicated to support (we have no way to tell from which "index" the invocation corresponds to on the vertex shader). It might also have only one invocation per vertex. So this case needs a separate pass to re-order the feedback data.
  • "Strip" topologies. Same problem as indexed draws, needs shuffling of the feedback output to match the correct primitive order.
  • Continued feedback with more than one draw. But that is already not supported reliably even when the host does support transform feedback right now, because the backend can reset the transform feedback operation to match API requirements.
  • Transform feedback from geometry or tessellation. For geometry is technically not a problem on macOS right now since it doesn't support geometry shaders at all. For tessellation, I don't know how it would work, but again no game does this.

What is implemented on this PR matches what is on the macos1 build, however the actual implementation here is different and makes use of the new methods I implement on the shader and backend to represent buffer access for emulator reserved buffers.
Contributes to #4062.
Closes #5068, closes #4889.

@gdkchan gdkchan added gpu Related to Ryujinx.Graphics fix Fix something os:macOS An issue or feature request exclusively relating to macOS labels May 24, 2023
@Malus120
Copy link

Malus120 commented May 27, 2023

Xenoblade Chronicles 3 / Future Connected (DLC Wave 4)

This PR enables the game to boot and run for the first time on master (previously it only "ran" on macos1.)
There is severe graphical artifacting but performance and stability are (much) improved vs macos1.
On macOS1 loading up a save at the Anu Shoals Camp typically performs poorly and crashes within 5-10 seconds whereas on this build loading up the same save the game seems to be able to run indefinitely. I have attached two videos that show artifacting and gameplay (past minute 1 / video 2 have spoliers for a late game area)
Note: For some reason when this PR and buffer mirrors (#4899) are used together the game crashes right before the title screen loads in.
(All testing was done on a 14" M1 Max MBP (32GB RAM)

Screen.Recording.2023-05-27.at.12.39.16.mp4
Screen.Recording.2023-05-27.at.12.39.16-2.mp4

@gdkchan
Copy link
Member Author

gdkchan commented May 28, 2023

@Malus120 Vertex explosions should be fixed by #5118, can you merge it locally and re-test?

@marysaka marysaka requested review from marysaka, riperiperi and a team May 28, 2023 06:40
@TSRBerry
Copy link
Member

TSRBerry commented May 28, 2023

@gdkchan would it make sense to rebase this PR onto #5118 and add a note to the description saying this PR depends on that one?

I know it doesn't really depend on it, but it might help to avoid getting reports about issues that are fixed by that.

@gdkchan
Copy link
Member Author

gdkchan commented May 28, 2023

@gdkchan would it make sense to rebase this PR onto #5118 and add a note to the description saying this PR depends on that one?

I don't think it's necessary, it only affects Xenoblade and is otherwise not related to this change at all.

@Black-Hill852

This comment was marked as off-topic.

@gdkchan gdkchan force-pushed the tfb-as-sb branch 2 times, most recently from 152d0f4 to 681a51d Compare June 3, 2023 23:23
@gdkchan gdkchan marked this pull request as ready for review June 3, 2023 23:23
@shinra-electric
Copy link
Contributor

shinra-electric commented Jun 4, 2023

I was testing with Hellblade which requires TFB, and it now works (getting 30fps without mirrors).

But I noticed a new warning that doesn't appear on macos1:

00:00:07.744 |E| .NET ThreadPool Worker Gpu : Background Compilation failed: Unexpected API error "ErrorInitializationFailed".
00:00:07.744 |E| .NET ThreadPool Worker output of type uint4 is not compatible with a MTLPixelFormatBGRA8Unorm_sRGB color attachement..

I thought it might be related to #5203, since it mentions BGRA.

Ryujinx_1.1.0+7980acb_2023-06-04_07-28-02.log

@marysaka marysaka requested a review from riperiperi June 9, 2023 09:07
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.

LGTM, nice work!

@gdkchan gdkchan merged commit eb0bb36 into Ryujinx:master Jun 10, 2023
8 checks passed
@gdkchan gdkchan deleted the tfb-as-sb branch June 10, 2023 21:31
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 os:macOS An issue or feature request exclusively relating to macOS
Projects
None yet
7 participants