PCSX2 / pcsx2

PCSX2 - The Playstation 2 Emulator
https://pcsx2.net
GNU General Public License v3.0
11.73k stars 1.62k forks source link

[BUG]: Dark Cloud (SCUS-97111): Mipmap issues on HW renderer (DX and Vulkan) #5660

Closed tealsuki closed 1 year ago

tealsuki commented 2 years ago

Describe the Bug

Unusual pop-in and blending errors on mipmapped and blend textures in the game, when using the DirectX hardware renderer. Game relies quite aggressively on blending between LOD, which makes the issue more obvious.

A user reports similar issues with Vulkan:

[...] I can confirm that something's broken about the hills. In SW rendering, the top portion of the hills is green and gradually fades out to the more high-res grass+rock texture seen up close on the hill walls. In HW rendering however, the emulator doesn't fade the grass texture out, it outright removes it and leaves just the high-res one below to show. As a result, there's a fair bit of pop-in. I am unsure if this is actually some form of mipmapping or otherwise, or if it's even related to the issue reported. See video:

https://user-images.githubusercontent.com/11655762/149131774-2df2faa3-6d37-4bac-82e2-715b1e3f5a14.mp4

Originally posted by @coornio in https://github.com/PCSX2/pcsx2/issues/5323#issuecomment-1010941039

Reproduction Steps

Visible in the following areas, while using HW mode (D3D11 in my case, and VK in other user's case):

Norune Village: the hills have severe pop-in and the upper grass texture completely disappears at close distance. Standing in a corner very close to where the green hilltops are at their highest LOD, and swapping between Bird's Eye (Georama) and on foot also shows that there's lag when swapping the detail textures out. At certain angles, the green grass texture is still present, but incorrectly blended with the high detail texture. You can tell when switching between HW and SW that there's a gentle smoothing effect in SW on the detail texture as well.

Sun and Moon Temple (Outer area): The buildings are at a large enough scale that it shows off the smooth blending of SW mode, and the hard pop in of HW mode

Expected Behavior

Smoother LOD transitions in areas where HW and SW don't have parity. That being said, Matataki Village, Queens, Queens Dock, Yellow Drops, Moon Factory, Dark Heaven Castle (Outer and Inner), and Demon Shaft all behave "normally", either both having smooth texture transitions, or being deliberately crunchy.

I think the devs may have learned the limitations of their engine by the late game and deliberately designed areas to mask it, but those two areas mentioned above highlighted an edge case.

The fact that the behavior also occurs on the other user's VK renderer makes me question if this isn't related to DX's lower blending accuracy. I would suggest @coornio try higher blend settings to test that behavior in the VK renderer

PCSX2 Revision

v1.7.2455 (64-bit SSE4)

Operating System

Windows 10 (64bit)

If Linux - Specify Distro

No response

CPU

Intel i7 3630QM (4C8T@2.4Ghz)

GPU

Intel(R) HD Graphics 4000 (Driver Version: 10.18.10.5161, HP whitelist)

GS Settings

Tested with all defaults, and default display filtering enabled and disabled.

Emulation Settings

Tested on Safe preset.

GS Window Screenshots

No response

Logs & Dumps

Attached is a gdrive link to multi-frame dumps, and a memory card with a completed save https://drive.google.com/drive/folders/1et24nCoqp1gEGP8SvE9uYkFsDXae6miX?usp=sharing

If you slow them down to about 5fps on DX mode, you can see there's actually an LOD transition occurring, but much faster and less smoothly than the SW renderer (except for the bird's eye mipmap, which lags)

(Is it a bug if I crash PCSX2 by trying to run them after loading and unloading the game?)

tealsuki commented 2 years ago

Also: the GS dumps may have recorded an alternate CRC, this is intentional, it's a version that patched a minor programming error that broke an item table, none of the graphical code was touched and this occurs on the unpatched version as well.

refractionpcsx2 commented 2 years ago

did you make sure to enable Trilinear Filtering and Mipmap Basic?

Dreadmoth commented 2 years ago

Full Mipmapping seems to match the behaviour of software mode in the provided dumps, blending modes and trilinear filtering don't appear to change it significantly. Tested on Vulkan and Direct3D11.

Software

Basic Mipmapping

Basic Mipmapping + Trilinear Ultra

Full Mipmapping

refractionpcsx2 commented 2 years ago

Trilinear doesn't work with Full mipmapping, which is why I said Basic. Ultra Trilinear might but that's basically forcing Trilinear always on.

tealsuki commented 2 years ago

Full mipmap seemed to fix it on my end, however now I occasionally have degenerate surfaces, Trilinear didn't seem to affect it. gs_20220315051520_Dark Cloud _NTSC-U__SCUS-97111 gs_20220315051621_Dark Cloud _NTSC-U__SCUS-97111 gs_20220315052412_Dark Cloud _NTSC-U__SCUS-97111

refractionpcsx2 commented 2 years ago

sigh I'll just talk to myself, shall I? Full mipmapping disables Trilinear, you need to use Basic Mipmapping.

tealsuki commented 2 years ago

sigh I'll just talk to myself, shall I? Full mipmapping disables Trilinear, you need to use Basic Mipmapping.

Apologies, I tested both. Basic didn't fix the issue with or without trilinear. I'll test it with forced. Also, when loading from a static GS dump, it looks fine, but movement causes the missing textures. I can take more moving GS dumps if required

refractionpcsx2 commented 2 years ago

okay thanks, if full mipmapping does it on its own, then the solution will be adding that to the GameDB. That defo solves it yea?

tealsuki commented 2 years ago

Added two dumps to the folder, they're marked as "FULLMIP (game) Degenerate textures". On full mip D3D11 what I'm seeing is textures either missing or coming from entirely the wrong (and semi-random) source. (It even applied a model's face texture to the cave at one point)

GPU Palette conversion appears to fix this.

(also worth noting that despite my anemic setup, didn't get a performance hit at native resolution, so hopefully this fix works for everybody)

coornio commented 2 years ago

To clarify, when that video was captured, I was running on Vulkan with Full blending. I've been doing so since Vulkan dropped since its performance in blending meant I could afford the extra blending accuracy.

That said, when tested again on r2455 (the one I had at the moment), the blending level makes no difference. No mipmapping takes place. I have to "force" mipmapping into fast or slow for the popping to occur. Trilinear filtering has no effect for me (still on vulkan), regardless of mipmapping setting and blending setting. Either the mipmaps are present (and broken with popping) or not at all. No black holes like seen in the earlier picture for me.

One unrelated issue I found in hardware rendering is the presence of this weird horizontal pixel-height bar on the bottom of the screen when near a light source that appears as if it's slowly baking with the colors of the lightmap you're standing near of:

gs_20220315170027_Dark Cloud _NTSC-U__SCUS-97111 Here's a dump of it: gs_20220315170027_Dark Cloud _NTSC-U__SCUS-97111.zip

tealsuki commented 2 years ago

@coornio Did you test the “GPU Palette Conversion” setting? EDIT: Disregard

coornio commented 2 years ago

@coornio Did you test the “GPU Palette Conversion” setting? That + full mip (slow) was what fixed it for me EDIT: I saw the original version of your post in my email just now, that’s purple sprite lines glitch you saw and then edited out was an upscaling issue, texture filtering and upscaling both cause that but I think there’s a GameDB fix for that already

GPU palette conversion was also on during my tests. As for the purple lines, ignore that, some setting goofed somewhere (had problems in more games than this) and nuking the install with a fresh one fixed them all.

tealsuki commented 2 years ago

Okay, something's very wrong here. I tried 2470 and with Fullmip and GPU palette conversion I got the problem behaviour, loaded up my 2455 archive and got it there too. Disabled GPU palette conversion on both and it fixed it with the correct mipmap behaviour, but with the missing/incorrect textures. What the heck did I do the other day?

tealsuki commented 2 years ago

Okay, I think I've figured it out.

From default settings:

GPU Palette conversion turns off or otherwise breaks mipmapping, hence why I stopped seeing the texture holes

I experimented with Trilinear filtering because i managed to confuse myself into thinking it was doing something, but it turns out all it was doing was breaking the sprites, hence the purple lines.

coornio commented 2 years ago

Fullmip + Hash Cache texture preloading fixes the holes and the mipmapping. Tested at multiple scales. Tested in multiple builds as far back as 2455. All fine.

/insert "are_you_sure_about_that.gif" gs_20220322161320_Dark Cloud _NTSC-U__SCUS-97111.zip

It's mostly fine, but not perfect. There's still seams that seem to occur with the camera angle if you look carefully. That said, while most holes seem fixed, occasionally the big one you showed me appearing beneath the gate to the cave also rears its ugly head. Appears random, I can't reliably make it appear.

gs_20220322161320_Dark Cloud _NTSC-U__SCUS-97111

tealsuki commented 2 years ago

I broke something else, or rather, I keep finding something not quite right. To recap, this is a scene [link to dump] in software mode, note the top of the hill/cliff/whatever: gs_20220531150231_Booting PS2 BIOS  And the same scene rendered by DX11 (current build 2855 and previous build 2579 (i've been away)) gs_20220531150249_Booting PS2 BIOS

It's a LOD/mipmap thing, because in dumps earlier in the thread, we can see that changes in distance really shag things up. So first step was enabling mipmap settings. Basic doesn't do anything, full starts to work some magic. DC1 BLENDBAND STATIC Dark Cloud _NTSC-U__SCUS-97111

What I didn't notice back in March, is that this is close, but not quite matching Software mode. Also it mangles the entire scene with missing/incorrect textures everywhere. [see above]

Interestingly, it turns out Hash-cache fixes this problem... for the most part. Now we're only missing one piece of geometry gs_20220531141444

With some twiddling, based on the suggestion of @refractionpcsx2 to test Basic Trilinear with Basic Mipmapping (which didn't help because basic mipmapping doesn't go far enough here, and fullmip doesn't work with basic trilinear), it turns out Ultra Trilinear Filtering and Full Mipmapping (with Hash Cache) fixes the extra missing geometry, AND brings it 99% of the way to matching software mode.

This dump is from the same location (unfortunately captured at a dark moment). Without Ultra Trilinear, you can see a band between the two textures that are supposed to be blended. which moves with the camera. I can't explain why that happens.

THE ONLY PROBLEM IS

Ultra trilinear filtering (or any filtering at all) slightly mangles the sprites the game uses for UI, among other things, causing lines and a purple fringe. gs_20220531143736_Dark Cloud _NTSC-U__SCUS-97111

tl;dr i don't wanna touch this game again but i hope i documented enough things this weird engine does, because I saw a recent PR (#6045) that helped some VRAM stuff that was going on. I'm gonna take a mulligan on this one but thanks y'all for your hard work. Each build keeps getting more and more amazing!

lightningterror commented 1 year ago

@tealsuki can this be retested?

refractionpcsx2 commented 1 year ago

It's still broken

tealsuki commented 1 year ago

Hi, sorry for the late response. Did you happen to fix the relationship between full mipmap emulation and basic Trilinear filtering? As of 1.7.3662 using Full Mipmap and Trilinear Filtering (the basic option, not Ultra) seems to be the winning combination. Proper blending of the mipmapped detail textures occurs, and the issues where I needed Hash Cache to keep pieces of geometry from disappearing seems to have been fixed too. Basic Trilinear filtering also doesn't mangle the sprite grids anymore as well.

@coornio @refractionpcsx2 Are you able to confirm this on your end as well?

EDIT: if you happen to notice model LOD pop-in or shadow pop-in that happens in software mode too. No idea if that matches bare metal but HW==SW is p much the goal here?

stenzek commented 1 year ago

Full mipmaps and trilinear PS2 should render pretty close to what the console does.

Basic mipmapping generates the mipmaps using the host's GPU, instead of getting them from the game. In some games, this is "close enough", but when the artists used "mip tricks" (i.e. higher mipmaps being different to lower), it will be incorrect.

tealsuki commented 1 year ago

@stenzek I was just combing through your commits on #7095 and saw how the new behaviour works, wasn't immediately obvious from the pull description that the behaviour that @refractionpcsx2 described above had changed, but I'm glad to see we got more accurate rendering, thanks!

I'm futzing around in the game right now, and testing a handful of other areas, everything seems to be just fine in my eyes, I'm sure the few other DC players on here can confirm this too.

Thanks to the mostly accurate PS2 filtering behaviour, integer scaling now works in game too, without marginally breaking the sprite alignment. Fractional doesn't quite work (glitches on the menu screen where the blurred/dimmed background is futzed) but that's unrelated to this.

(also sorry to lightning for mistakenly tagging you in the comment above)

With appropriate confirmation, I'm willing to say this matches software perfectly and can be closed if adding the settings to GameDB doesn't break anything for anybody else.

stenzek commented 1 year ago

The behaviour for basic vs full hasn't changed, it was just semi-broken before. Trilinear was definitely broken :)

We can add mipmap=full and trilinear=ps2 to the gamedb, to be honest, it should be the default - but afaik there's still some games which don't like it.

Refraction mentioned on discord that there's still pop-in in DC though. Haven't had a chance to look into it yet.

refractionpcsx2 commented 1 year ago

I could have sworn there was still pop in, maybe I'm mistaken? Probably a good idea we test this, yeah.

refractionpcsx2 commented 1 year ago

This seems to have been fixed and we've now added mipmapping to the DB.

coornio commented 1 year ago

@refractionpcsx2 Are you sure? I just updated to latest, left it on automatic fixes, but this mipmap flicker behavior still occurs.

New dump: https://www.mediafire.com/file/kjv0wph7cax2hrx/Dark+Cloud_SCUS-97111_20230225132644.gs.zst/file (give it a few minutes since message posting, uploading)

settings, for reference: image image

refractionpcsx2 commented 1 year ago

I can't really see it in that dump, if I'm honest, it looks smooth to me. It looks more like you were trying to show the combing from the deinterlacing in that dump.

coornio commented 1 year ago

I can't really see it in that dump, if I'm honest, it looks smooth to me. It looks more like you were trying to show the combing from the deinterlacing in that dump.

No no, look at the greenery on the background, atop the hill as I swivel the camera around. It'll be easier to catch if you put it in slow-mo. It's ultimately still the same as it was in the original video posted, so I'm not sure how this was considered fixed. Have I made a mistake somewhere perhaps?

refractionpcsx2 commented 1 year ago

can you try disabling GPU Palette, as it needs trilinear and it doesn't work if you have GPU Palette on

coornio commented 1 year ago

can you try disabling GPU Palette, as it needs trilinear and it doesn't work if you have GPU Palette on

That was it. Now it's behaving properly. Thanks for pointing it out. I usually keep that on since the GPU can better handle the load compared to my CPU :p

refractionpcsx2 commented 1 year ago

There shouldn't be that much in it these days tbh, but yeah now we know :)

bigol83 commented 1 year ago

I downloaded the dump and noticed something weird, did some testing.

So, on latest build with game fixes on setting mipmapping to off gives much better textures. If i set to mapmapping auto the mountains and rocks have lower details. In both cases i have no flickering,

Isn't it weird that with mipmapping OFF the game has better textures?

I see mipmap flickering only if i choose Basic Generated Mipmaps, or if i have enabled GPU palette conversion.

refractionpcsx2 commented 1 year ago

It's not weird at all, that's how mipmapping works. and trilinear transitions smoothly between "layers" so you don't get the popping.

coornio commented 1 year ago

So, on latest build with game fixes on setting mipmapping to off gives much better textures. If i set to mapmapping auto the mountains and rocks have lower details. In both cases i have no flickering, Isn't it weird that with mipmapping OFF the game has better textures?

Not at all. If you switch to software mode, you'll see how the terrain textures are supposed to look. It was intentionally designed this way, and the lower resolution mipmap layers are the green part, while the higher res ones are used for the rock wall face. They're pulling some efficiency trickery like that to conserve texture space.

bigol83 commented 1 year ago

Ok, cool, thanks for explaining.