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 the PSP's equal-size mips "3D texturing" #15727

Merged
merged 16 commits into from
Aug 1, 2022
Merged

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Jul 25, 2022

See #6357. Basically, the PSP has a curious ability to have mipmaps with the same size and use mipmap interpolation to interpolate between them, essentially a very limited version of multitexturing or 3D texturing. This implements that using 3D textures.

This functionality is used heavily in Misshitsu no Sacrifice, and for the water effect in the Macross series.

Vulkan-only currently, though all the other backends except ES 2.0 without GL_OES_texture_3d can support it with some work. This is done, now works on all backends.

Potentially this could also replace the hack we use for Tactics Ogre translation's text, see #5350 - though we'd still need it as a fallback just for GLES 2.0 without 3D texture support.

Strangely I don't think it looks quite as smooth as on the real PSP. I'm wondering if the second level should somehow have its own CLUT, though I don't see how that would work given that the first level uses an 8-bit CLUT that covers the whole of CLUT memory. YES there's space for a 2nd CLUT!

Remaining work before merge (but mostly ready for review):

  • Fix the flicker issue (probably give it its own uniform flag, just gotta be careful not to regress games that change the mip bias a lot like GT)
  • Implement compatibility checks for OpenGL, disable if 3D textures are not available

@hrydgard hrydgard added the GE emulation Backend-independent GPU issues label Jul 25, 2022
@hrydgard hrydgard added this to the Future-Prio milestone Jul 25, 2022
@hrydgard
Copy link
Owner Author

hrydgard commented Jul 25, 2022

image

There's some seriously suspicious stuff there in the CLUT uploads. It DOES set the mode to separate CLUTs, which we thought to be impossible with 8-bit color indices. Then it does two CLUT loads, one supposedly zero-sized, but there's an extra bit there (000040) which we currently ignore... Maybe it selects an unknown upper CLUT register for mip1, or it's just an extra bit for the size field (which would be the correct size for two 256-entry 8888 CLUTs), but then the second load seems redundant.

EDIT: OK had to check, there's nothing like this in Soul Calibur so that mystery still stands.

EDIT2: My theory seems to be correct, although I don't understand why the second CLUT load is needed.

@hrydgard
Copy link
Owner Author

hrydgard commented Jul 25, 2022

Alright, this now looks completely right, though still Vulkan-only. Work on that after the release.

@LunaMoo why don't you have a go :)

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 25, 2022

Sorry had to stay longer at work, soo far it seems to work great in Misshitsu, in Macross it works great initially, but after flying around fast it starts glitchin
including dumps of both games, but in macross it seems the dump is textureless at least where it uses mipmaps
DUMP.zip

and a video of macross water glitching(it happens after flying on the map some time passed, as if the animation desync)
https://user-images.githubusercontent.com/5485237/180888772-66725c29-da1b-4b29-b24c-03fd933532c7.mp4

Edit: a bit longer video, I thought it's caused by flying fast then by time, but I guess not as I waited long time with nothing glitching and then walked around just a bit and it triggered the problem: It's weird as in this instance it actually loaded the stage with glitching water and(I guess depends on animations the stage starts with, after a moment it corrected itself. It never wants to correct itself later on, but it seems glitching varies after some walking around.
https://user-images.githubusercontent.com/5485237/180891861-44d010d9-553b-4004-b961-865f5e5eefaf.mp4

@unknownbrackets
Copy link
Collaborator

Hm, I think we should create more tests for the second CLUT, clearly. I guess I must've forgotten to test that since I don't see any tests? So many GE features to test, so many assumptions to validate...

Not sure why the textures wouldn't dump correctly?

-[Unknown]

@hrydgard
Copy link
Owner Author

Definitely needs testing yeah, but heh, not hard to miss testing that, I haven't seen any speculation anywhere before that the CLUT memory might be larger than 1024 bytes, so this is a brand new discovery.

@hrydgard
Copy link
Owner Author

@LunaMoo Thanks for testing! That glitching does look weird yeah, and the conditions for it happening are odd... but I have a theory. We might have to set clamp instead of wrap mode on the Z dimension of the texture, for this case.

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 26, 2022

I had a thought dump might be textureless because of some settings I used in my textures.ini, but even without textures folder it doesn't dump mipmap textures.
ULJS00321_0008.zip

As for the glitching I can now reproduce by simply unthrottling in one spot, so maybe it does happen over time. If there will be any changes I could test for that I will, but in few hours I'm going to work^_^;.

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 26, 2022

Unfortunately still glitching by just using unthrottle in one spot for a while.

Noticed one thing through, the glitching is less noticeable in stages that has less water, like a river instead of the ocean, it looks like it just starts switching quickly instead of blending together. Maybe a texture cache issue or hash failure, but I tried different hashes and it didn't affect it.

@hrydgard
Copy link
Owner Author

Hm, maybe a bug with state tracking of the mip bias constant... I'll clean that code up later and see if I can get it fixed. Thanks for testing so far!

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 30, 2022

With the latest updates to this branch the glitching still happens on vulkan, also OGL behaves weirdly not drawing some mipmap textures at all depending on the player location on the map:
ULJS00321_00008
ULJS00321_0012.zip

@hrydgard
Copy link
Owner Author

Yeah, I haven't actually done any new fixes, just rebased it upon the latest code. I've been cleaning house and refactoring a lot.

More work is coming on this one soon.

@hrydgard
Copy link
Owner Author

hrydgard commented Jul 30, 2022

I've now implemented it for all the backends.

@hrydgard hrydgard changed the title Initial implementation of 3D texturing through equal-size mips Implement the PSP's equal-size mips "3D texturing" Jul 30, 2022
@hrydgard hrydgard marked this pull request as ready for review July 30, 2022 22:23
…6357)

Vulkan-only currently, though all the other backends except ES 2.0
without GL_OES_texture_3d can support it with some work.
…ared CLUTs for 8-bit indices.

Not sure yet what limitations apply, regarding using it for even more
16-bit colors, etc...
@hrydgard
Copy link
Owner Author

hrydgard commented Jul 31, 2022

@LunaMoo can you test Macross again? If it looks good now, let's get this in.

(Also please test on multiple backends. If the movement is slightly different, like slightly choppier, on D3D9, that's expected for now, but should be identical to Vulkan in OpenGL and D3D11).

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 31, 2022

Works great in both vulkan and OGL, the glitching is fixed, in both d3d modes it's missing textures/bugged in same way:
ULJS00321_00009
(which part of the terrain are missing change while walking)

@hrydgard
Copy link
Owner Author

hrydgard commented Jul 31, 2022

Thanks for testing, that is super weird! Could you get a savestate of a situation where that happens? If lucky might be able to get a frame out of one even if the GE dump doesn't work...

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 31, 2022

Sure, made one right after starting the stage:
PPSSPP_STATE.zip

Edit:
BTW it's the same thing which happened in OGL when I tested before it was implemented on all backends(#15727 (comment)), just back then in OGL ther was a pale color, in d3d modes now it's black, maybe that's a hint where it broke.

Also additional note: effect is working where it does show textures:). As for smoothness in d3d9 maybe a bit less smooth, but hardly noticeable and in misshitsu series it's pretty much same and doesn't have any issues.^_^

This effect might be a little less smooth on all backends than I remember on real PSP, but will have to move my saves back to psp to check, also since it works same as in software renderer I suppose it's all just because PSP's I have suffer from screen ghosting and post shader simulating it would make it look exactly same.;3
Edit after PSP test: yeah it works same now:), the slight ghosting makes it subtly smoother, but can be seen it's nothing more than that:).

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 31, 2022

A video might give a better hint how d3d fails:

ULJS00321_2022-07-31_15-11-45.mp4

@hrydgard
Copy link
Owner Author

Thanks, will look into it some more soon. Likely some ordering issue in binding the 3D texture (d3d is kinda picky sometimes), or something...

@hrydgard
Copy link
Owner Author

Alright, that should take care of it, I think.

@hrydgard
Copy link
Owner Author

hrydgard commented Jul 31, 2022

Also I just realized that to make this work with max quality filtering (auto gen missing mipmaps), for the animation to work we really need to mipmap-filter the levels separately (and not have them mush together in the distance as 3D mipmaps would), which means array textures plus manual filtering in the depth direction is probably the way to go instead of 3D textures. This would only be available on Vulkan and D3D11. Anyway, that's for another day...

@LunaMoo
Copy link
Collaborator

LunaMoo commented Jul 31, 2022

Works great now.:) Thanks!

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Thanks for your testing!

@hrydgard hrydgard enabled auto-merge August 1, 2022 06:35
@hrydgard hrydgard disabled auto-merge August 1, 2022 06:35
@hrydgard hrydgard merged commit e1956b4 into master Aug 1, 2022
@hrydgard hrydgard deleted the texture-3d branch August 1, 2022 06:35
@unknownbrackets
Copy link
Collaborator

The dump from #15727 (comment) looks strangely dark. I guess this must be from the second CLUT being ignored by GE frame dump recording.

Anyway, software does render this dump slightly incorrectly. Here's the PSP output:
#15727_ULJS00251_misshitsu_3dtex1

The software output (it's visually very close):
#15727_ULJS00251_misshitsu_3dtex1_softgpu

The same dump looks like this on Vulkan:
#15727_ULJS00251_misshitsu_3dtex1_vulkan

This already suggests to me that the second CLUT theory isn't true on the real PSP (confirming my prior attempts to reproduce it.) If I revert the secondary CLUT change I get (Vulkan):
#15727_ULJS00251_misshitsu_3dtex1_vulkan2

That said, it's been reported that it looks better and I'm not against enhancements. I'll just make this a bit safer in case some game accidentally triggers this behavior unintentionally...

-[Unknown]

unknownbrackets added a commit to unknownbrackets/ppsspp that referenced this pull request Aug 21, 2022
Can't replicate this behavior on a real PSP.

In case a game sets the separate CLUT flag by accident, ignore except
in a safe case that occurs in Misshitsu no Sacrifice.  See hrydgard#15727.
unknownbrackets added a commit to unknownbrackets/ppsspp that referenced this pull request Aug 21, 2022
Not available on a real PSP, but used in an enhancement (see hrydgard#15727.)
hrydgard added a commit that referenced this pull request Dec 10, 2022
It broke when we introduced the 3D texture support, in #15727

Fixes #16354
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.

3 participants