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

Extend Minimal TMEM cache implementation. #8350

Merged
merged 4 commits into from Oct 12, 2021
Merged

Conversation

phire
Copy link
Member

@phire phire commented Sep 6, 2019

Now works with games that deliberately avoid invalidating TMEM because they know textures are too large to fit:

  • Sonic Riders
  • Metal Arms: Glitch in the System
  • Godzilla: Destroy All Monsters Melee
  • NHL Slapshot
  • Tak and the Power of Juju
  • Night at the Museum: Battle of the Smithsonian
  • 428: Fūsa Sareta Shibuya de

TODO:

  • Restructuring
  • Why doesn't spyro work in efb2tex?
  • Save state support
  • Fix vulkan crash when removing old TMEM code

Depends on:

@phire phire added the WIP / do not merge Work in progress (do not merge) label Sep 6, 2019
@phire
Copy link
Member Author

phire commented Sep 6, 2019

Rebased for clean fifo-ci run.

Looks like I broke Spyro... This is going to need some more work
https://fifoci.dolphin-emu.org/compare/4964251-4953629/

Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.h Outdated Show resolved Hide resolved
int odd_base;
int odd_size;
};
static std::array<texture_unit_state, 8> s_unit;
Copy link
Member

Choose a reason for hiding this comment

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

Is there really no other place to place this (like in the actual cache)? This introduces more file-scope/global mutable state.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel really uneasy about how complicated texture cache is getting and just how complicated it is to understand.

This part is still WIP, this state will need to be stored somewhere, and it will need initialized to zero, and something will need to be done on DoState (either we invalidate the whole thing, or for correctness we save anything that's tagged as "cached")

Copy link
Member

@BhaaLseN BhaaLseN left a comment

Choose a reason for hiding this comment

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

Do you intend to address those FIXME in here, or in a follow-up PR?

Source/Core/VideoCommon/CMakeLists.txt Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BPStructs.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TextureCacheBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
@phire
Copy link
Member Author

phire commented Sep 7, 2019

FIFOci update:

Good news:

Average news:

Bad news:

@JMC47
Copy link
Contributor

JMC47 commented Sep 7, 2019

Are we sure those last two are really broken? Those are ancient fifologs. And Sonic's gravity boost was already broken.

@JMC47
Copy link
Contributor

JMC47 commented Sep 7, 2019

The two games mentioned as broken in those fifologs are only broken in EFB2Tex. In EFB2RAM, they render more correctly than they did before. It'd be nice for them to not black out or act weird in EFB2Tex, but that's a far, far, far less severe issue than we have now.

@JMC47
Copy link
Contributor

JMC47 commented Sep 7, 2019

Blacked out player colors are because of the fifolog.

image

@JMC47
Copy link
Contributor

JMC47 commented Sep 28, 2019

Any update on what's going on here?

@tony971
Copy link

tony971 commented Apr 7, 2020

Any hope of progress on this? Quite a few games are affected by it.

@JMC47
Copy link
Contributor

JMC47 commented Apr 23, 2020

Even though this has a regression in EFB2TEX, it would much, much, much better than the current situation if rebased/reviewed/merged.

Right now we have people resorting to making custom builds with tmem disabled for particular games, and communities are beginning to rely on these builds to play certain games.

@leoetlino leoetlino marked this pull request as draft April 28, 2020 13:33
@JMC47
Copy link
Contributor

JMC47 commented Sep 11, 2020

Can this be rebased? There's an issue report that I think this may affect but the buildbot builds are gone.

@shuffle2 shuffle2 mentioned this pull request Sep 11, 2020
@JMC47
Copy link
Contributor

JMC47 commented Sep 16, 2020

So, as a bit of a refresher, here's the current status of this Pull Request.

The EFB2RAM path of this Pull Request seems to work perfectly. It even has handled new, previously unknown cases of tmem issues that weren't known at the time of its creation. It has been verified to work in the rebased version of this PR.

The main thing this Pull Request fixes is a bunch of games with video playback issues. It appears that whatever video player that Sega used has a lot of issues with the tmem implementation in master. Both paths of this PR seem to work fine for this. Verified games that are fixed include:

Sonic Riders
Metal Arms: Glitch in the System
Tak and the Power of Juju
Sonic Riders: Zero Gravity
All the games here - https://bugs.dolphin-emu.org/issues/11164
Probably more that haven't been reported.

However, the EFB2Tex version of this PR does have some issues that aren't present on the EFB2RAM version.

Spyro: A Hero's Tail

https://fifo.ci/compare/4964271-4953579/

In EFB2TEX ONLY, the water issues return. However, using EFB2RAM you can get the correct effect. This appears to be an invalidation thing.

Sonic Riders: Zero Gravity

Fourth Player's viewport appears to flicker in EFB2Tex. EFB2RAM in this Pull Request works fine, however. It is currently broken in master too so this isn't a big issue. The fact that EFB2RAM fixes it is actually a benefit.

That's actually all that's known broken in the PR, two invalidation issues.

@JMC47
Copy link
Contributor

JMC47 commented Feb 17, 2021

I know this is marked as draft and do not merge. But at this point what currently exists here is far superior to the behavior in Master.

While the invalidation issues kind of suck, I'd rather have things 95% working so we can potentially work toward a release and then worry about the EFB2Tex path later.

@autofire372
Copy link
Contributor

This needs a rebase/rewrite; the Windows build system changed in PR #9092.

@tony971
Copy link

tony971 commented Apr 6, 2021

Just doing my annual bump

Source/Core/VideoCommon/BPStructs.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TmemBase.cpp Outdated Show resolved Hide resolved
@JMC47
Copy link
Contributor

JMC47 commented Apr 17, 2021

I went through the major cases again and they all behave the same as we remember.

Spyro: A Hero's Tail - Needs EFB2RAM but is fixed at least.
Sonic Riders and other FMV games - Fixed
NHL Slapshot - Fixed
Sonic Riders - Zero Grav - Fixed, but needs EFB2RAM for some effects.

@BlueSwordM
Copy link

So, has there been any progress in regards to this pull request?

I've merged it into my own semi-custom build for Sonic Riders and Sonic Riders ZG, and it seems to work fine(which are the only games that I own which have the TMEM issues).

The only problem is that I don't have a lot of games to do regression testing, and as such, I'm not sure if it's ready to pull in or not.

Thank you for all the work.

@phire
Copy link
Member Author

phire commented Jun 10, 2021

Status report:

This PR was rapidly implemented as a prototype to prove the idea.

It is not production ready code. I need to take some time to rewrite it. I haven't gotten around to doing this yet.

@JMC47
Copy link
Contributor

JMC47 commented Sep 11, 2021

Note that this is just cleanup. Titles fixed by this pull request are still fixed, but there's no change in behavior otherwise.

@phire
Copy link
Member Author

phire commented Sep 11, 2021

Investigations have shown that the efb2tex regressions appear to come from cdbd986

Which was actually merged slightly after the original minimal TMEM implementation: #5726

It's just that TMEM has kind of hidden the bug.

@JMC47
Copy link
Contributor

JMC47 commented Sep 11, 2021

I think my main concern is that we don't break savestates/TASing with this.

@phire
Copy link
Member Author

phire commented Oct 10, 2021

Current status: The bulk of the restructuring has been done.

The main thing that remains is deciding where the tmem state should live and then hooking it upto savestates.

@phire phire removed the WIP / do not merge Work in progress (do not merge) label Oct 10, 2021
@phire phire marked this pull request as ready for review October 10, 2021 02:55
Copy link
Contributor

@JMC47 JMC47 left a comment

Choose a reason for hiding this comment

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

Seems to be working as well as expected. The Spyro regression is something that happened after TMEM, but was hidden by the broken TMEM behavior.

Source/Core/VideoCommon/Tmem.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/Tmem.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/Tmem.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/Tmem.cpp Outdated Show resolved Hide resolved
@BlueSwordM
Copy link

BlueSwordM commented Oct 10, 2021

Everything seems to work fine on my end with the new patch.

All games that rely on proper TMem emulation for cutscenes work.

Sonic Riders Zero Gravity works and with the texture cache bug fixed, that means EFB2Texture works as well, restoring full performance to the game.

Edit: I might need to retest Zero Gravity because I'm not sure the patch itself has been applied correctly.

Edit 2: Sonic Riders Zero Gravity gravity effects work perfectly with this patch set with EFB2Texture active. This might also fix the 4-player bug, but this is yet to be tested.

Edit 3: As confirmed by JMC, my fears have been justified: 4-player multiplayer still needs EFB2RAM to work correctly, which is very weird since it is not an EFB related issue somehow(I was wrong about that as well, my memory seems to be failing).

@JMC47
Copy link
Contributor

JMC47 commented Oct 10, 2021

It is an EFB related issue and a texture cache related issue. But neither appear to be a bug with TMEM, just something masked by TMEM.

@phire phire force-pushed the fix-tmem branch 2 times, most recently from 58a7818 to 1861b7b Compare October 11, 2021 19:49
@phire
Copy link
Member Author

phire commented Oct 11, 2021

I did some squashing and added a large comment at the top of Tmem.cpp for future developers.

As far as I'm concerned, this is ready for merging.

@phire phire force-pushed the fix-tmem branch 2 times, most recently from 7e476ca to 120106c Compare October 11, 2021 21:04
@phire
Copy link
Member Author

phire commented Oct 11, 2021

Fixed a minor squash issue. Renamed Tmem to TMEM

Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/TMEM.cpp Outdated Show resolved Hide resolved
Now works with games that deliberately avoid invalidating TMEM because
they know textures are too large to fit:

 * Sonic Riders
 * Metal Arms: Glitch in the System
 * Godzilla: Destroy All Monsters Melee
 * NHL Slapshot
 * Tak and the Power of Juju
 * Night at the Museum: Battle of the Smithsonian
 * 428: Fūsa Sareta Shibuya de
Fixes issue where vulkan might crash trying to bind a deleted
texture.
@dolphin-emu-bot
Copy link
Contributor

FifoCI detected that this change impacts graphical rendering. Here are the behavior differences detected by the system:

  • fortune-street on ogl-lin-mesa: diff
  • nhl-slap on ogl-lin-mesa: diff
  • spyro-depth on ogl-lin-mesa: diff
  • fortune-street on ogl-lin-radeon: diff
  • nhl-slap on ogl-lin-radeon: diff
  • spyro-depth on ogl-lin-radeon: diff
  • fortune-street on uberogl-lin-radeon: diff
  • nhl-slap on uberogl-lin-radeon: diff
  • spyro-depth on uberogl-lin-radeon: diff

automated-fifoci-reporter

@JMC47
Copy link
Contributor

JMC47 commented Oct 12, 2021

In the words of great Aristotle, "One swallow does not make a summer, neither does one fine day; similarly one day or brief time of happiness does not make a person entirely happy." Translated to modern times, I'm pretty sure it would read, "Yolo."

...Then again, I'm not a philosopher.

@JMC47 JMC47 merged commit 6987ea0 into dolphin-emu:master Oct 12, 2021
10 checks passed
@phire phire deleted the fix-tmem branch October 12, 2021 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet