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

GS: Add texture dumping and replacement system #5547

Merged
merged 4 commits into from Feb 24, 2022

Conversation

Copy link
Contributor

@stenzek stenzek commented Feb 19, 2022

Description of Changes

Something that many have requested and others have done very poorly and hackily. This one is (in my opinion) clean and mergeable.

Rough TODO:

  • Basic texture dumping.
  • Basic texture replacement.
  • Asynchronous texture dumping and loading.
  • Preloading of textures to memory.
  • Support dumping mipmaps.
  • Support loading DDS files and compressed textures.

Textures using multiple CLUTs/palettes will be dumped as multiple textures (e.g. Xenosaga). Mapping texels to CLUTs is outside the scope of this PR, since it works well enough without it in most games, and adds complexity. I might look into it later on.

Please note that while I'm not planning on changing the texture filenames or hashes, I can't guarantee that it won't change before the PR is merged. So keep that in mind if you're experimenting with it.

Rationale behind Changes

Suggested Testing Steps

Test dumping/replacement across a bunch of games, but probably wait until it's more complete first. But feel free to experiment :)

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 19, 2022

Quick notes:

  • Textures dumped go to pcsx2\textures\<SERIAL>\dumps
  • Replacements get loaded from pcsx2\textures\<SERIAL>\replacements.
  • Enable in Graphics Settings -> Advanced (Qt), Graphics Settings -> Debug (Wx).
  • Beware of SSD wear, dumping can create lots of files.

@dio-gh
Copy link

@dio-gh dio-gh commented Feb 19, 2022

Just to clarify, what happens if the dimensions of the replacement texture mismatches the original (i.e. if it's bigger)?

In other words, is the feature suitable for creating high-res texture packs?

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 19, 2022

Just to clarify, what happens if the dimensions of the replacement texture mismatches the original (i.e. if it's bigger)?

It's scaled in the same way that target copies are; in other words, high res packs will work as expected.

@OriginalSwayze
Copy link

@OriginalSwayze OriginalSwayze commented Feb 19, 2022

No idea if i can even comment here just want to thank you and everyone working on PCSX2 you guys rock

@Gunlaus
Copy link

@Gunlaus Gunlaus commented Feb 19, 2022

Excellent work. Will DDS support (in the future) come with compression support as well? (DXT)

@RedDevilus
Copy link

@RedDevilus RedDevilus commented Feb 19, 2022

Excellent work. Will DDS support (in the future) come with compression support as well? (DXT)

Support loading DDS files and compressed textures. Looks that way.

@Etokapa
Copy link

@Etokapa Etokapa commented Feb 19, 2022

Just did a quick test and it seems to be working well for the most part. Some textures have garbage where I assume would usually be empty space, and some texture replacements do not load such as the font texture seen below. Going to try more experiments to see if I can see what I'm doing wrong.
Be very careful with using upscaled textures, as it may give a warning about PBO Map size and crash the emulator.
I'm very excited to see this feature in the works! Thank you!😃

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 20, 2022

Be very careful with using upscaled textures, as it may give a warning about PBO Map size and crash the emulator.

Should be fixed with the last push (both GL and Vulkan).

@stenzek stenzek force-pushed the gs-texture-replacements branch 2 times, most recently from fe2009d to 704eda7 Compare Feb 20, 2022
@stenzek
Copy link
Author

@stenzek stenzek commented Feb 20, 2022

Asynchronous loading added (so it won't cause GS thread stutter while it loads from disk), as well as caching for known replacement textures. Note that new replacements added while the game is running won't register now until it rescans them, the easiest way is to just toggle software on and off, but I'll add a proper hotkey for this in the future (at least in Qt).

DDS textures should load now, and BC1(DXT1)/BC2(DXT2-3)/BC3(DXT4-5)/BC7 compressed formats will be natively uploaded to the GPU.

Replacement filename was changed, sorry, it was missing some bits which are needed to uniquely identify the texture. Hopefully the last change though.

Main things missing now are just mipmap dumping and preloading/precaching.

@stenzek stenzek changed the title [WIP] GS: Add texture dumping and replacement system GS: Add texture dumping and replacement system Feb 20, 2022
@Gunlaus
Copy link

@Gunlaus Gunlaus commented Feb 20, 2022

What's the hashing algo used?

@xtremegat
Copy link

@xtremegat xtremegat commented Feb 21, 2022

Most of the dumped Persona 3 FES textures are semi-transparent and if you try to replace them with a normal upscaled one it won't show up
ApplicationFrameHost_E7GMdSkF7B
Photoshop_vhDdPgXDev
pcsx2-qtx64-avx2_YQSy0qw7ob

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 21, 2022

What's the hashing algo used?

xxhash

Most of the dumped Persona 3 FES textures are semi-transparent

Working as intended. Most of these textures have an alpha of 128, even in 32bit CLUT mode. You can ignore the alpha channel, or scale it before and after editing.

@Harkyzera
Copy link

@Harkyzera Harkyzera commented Feb 23, 2022

worked well for AI upscale on SOTC
image

image

@TheKrzysiek
Copy link

@TheKrzysiek TheKrzysiek commented Feb 23, 2022

In Ace Combat 04 many textures are broken, especially the terrain textures.
The HUD main texture file is ok, but some others like the title screen look like this.
ebc423b1d7df5c81-b72f85daefae6045-00002a93

I've also tried Ace Combat Zero and there are some broken textures there too, but a lot fewer, mostly the terrain.
image

@RedDevilus
Copy link

@RedDevilus RedDevilus commented Feb 23, 2022

If it already is broken , it's likely a Texture Cache issue which this PR won't solve.

@refractionpcsx2
Copy link

@refractionpcsx2 refractionpcsx2 commented Feb 23, 2022

yes considering how broken Ace Combat 04 is in hardware mode, I wouldn't use that to gauge reliability of this PR, I would consider that out of scope.

Texture replacements wont fix games with broken graphics, that's not the intention of this feature.

@TheKrzysiek
Copy link

@TheKrzysiek TheKrzysiek commented Feb 23, 2022

With the no interlacing code and changing some settings, 04 actually works fine aside missing some effects like volumetric clouds.

Eitherway, if it's not something that could be easily fixed then too bad.

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 24, 2022

The HUD main texture file is ok, but some others like the title screen look like this.

That's probably correct, you'll find multiple dumps with the same first part of the filename (the texture data/indices hash), but a different second part (palette/clut hash). I specifically addressed this in the OP:

Textures using multiple CLUTs/palettes will be dumped as multiple textures (e.g. Xenosaga). Mapping texels to CLUTs is outside the scope of this PR, since it works well enough without it in most games, and adds complexity. I might look into it later on.

@fbievan
Copy link

@fbievan fbievan commented Feb 24, 2022

/home/evan/.source/pcsx2/common/Linux/LnxHostSys.cpp(69) : assertion failed:
    Function:  void SysPageFaultSignalFilter(int, siginfo_t*, void*)
    Thread:    MTGS
    Condition: false
    Message:   Unhandled page fault @ 0x00000000

Stacktrace:
[00] 0x0x55d039a4af07                            
[01] 0x0x7fb6fe4e2560                            
[02] 0x0x55d039724ce9                            
[03] 0x0x55d039795d9b                            
[04] 0x0x55d03978ec12                            
[05] 0x0x55d03978f9fc                            
[06] 0x0x55d0397902d1                            
[07] 0x0x55d03977903a                            
[08] 0x0x55d03973d0cb                            
[09] 0x0x55d0397449b0                            
[10] 0x0x55d039761af1                            
[11] 0x0x55d039711bc5                            
[12] 0x0x55d0395301d5                            
[13] 0x0x55d039a3036a                            
[14] 0x0x55d039a32b1a                            
[15] 0x0x7fb6fe52d5c2                            
[16] clone                                       

When trying to dump, I get this error soon after startup, Cant really say much, if you want more details just ask.

https://www.youtube.com/watch?v=1Nn3Q9QQFhU
(yes the classic jet fan )

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 24, 2022

That backtrace is meaningless. Need to run under gdb, ideally with symbols.

@mntorankusu
Copy link

@mntorankusu mntorankusu commented Feb 24, 2022

For the palette/CLUT thing, would it be possible to (optionally) dump indexed textures and palettes for them separately? So instead of dumping a different texture for each texture and palette combination, we can just have one indexed texture and then a bunch of .pal files (or whatever) next to them. Then have it apply the original CLUT to any loaded texture that doesn't have the second hash in the filename. I think there are cases where doing it this way would be much, much easier on people trying to do texture edits.

@stenzek
Copy link
Author

@stenzek stenzek commented Feb 24, 2022

It's a possibility, sure. But outside of the scope of this PR; personally I'm more in the camp of resolving palettes prior to dumping.

@refractionpcsx2 refractionpcsx2 merged commit 5a25cc1 into PCSX2:master Feb 24, 2022
15 checks passed
@LuismaSP89
Copy link

@LuismaSP89 LuismaSP89 commented Feb 24, 2022

worked well for AI upscale on SOTC image

image

Sorry good lord, but where I can download that textures for sotc? Looks **cking nice.

@danny199012
Copy link

@danny199012 danny199012 commented Feb 25, 2022

Amazing work but i have an odd issue with it i made warriors textures and bumped them massively it works but i always get Hash Cache has used x amount of Vram Disabling then i get black screen but Vram it hits about 2GB then i get warning but i have a RTX3090 24GB iv'e tried all 3 settings seems more usable with opengl compared to vulkan but still getting hit with hash cache

@Harkyzera
Copy link

@Harkyzera Harkyzera commented Feb 25, 2022

worked well for AI upscale on SOTC image
image

Sorry good lord, but where I can download that textures for sotc? Looks **cking nice.

unfortunately there is nowhere to download, I used some programs to increase the texture using artificial intelligence

@danny199012
Copy link

@danny199012 danny199012 commented Feb 26, 2022

IMG_20220225_141309.jpg

Amazing work but my invisible car could this becaused by Hash Cache disabling no matter what option I use I always get that message and it's when this happens could it because textures to big for cache and I've tried deleting all junk textures also but didn't fix so unsure if it could be mips related

@refractionpcsx2
Copy link

@refractionpcsx2 refractionpcsx2 commented Feb 26, 2022

looks like you messed up your alpha values

@SayakaMaizono
Copy link

@SayakaMaizono SayakaMaizono commented Feb 26, 2022

Hey. I've got all the settings on to dump textures under the Advanced Graphics tab, but it hasn't generated any folders for me.
I can see there's code that should check and create those though. Any assistance as to what I've done wrong?

image

@Mrlinkwii
Copy link

@Mrlinkwii Mrlinkwii commented Feb 26, 2022

@SayakaMaizono see if creating atextures folder helps

@FuxorLuck
Copy link

@FuxorLuck FuxorLuck commented Feb 26, 2022

Hey. I've got all the settings on to dump textures under the Advanced Graphics tab, but it hasn't generated any folders for me. I can see there's code that should check and create those though. Any assistance as to what I've done wrong?

image

Craete a folder inside pcsx2 called "textures"
This worked for me.

Also I think next pcsx2 build should come with an emptey folder called "textures"

@SayakaMaizono
Copy link

@SayakaMaizono SayakaMaizono commented Feb 26, 2022

@SayakaMaizono see if creating atextures folder helps

Wow I swear I tried that before and it didn't work. That solved it, thanks!

@jlnhlfan
Copy link

@jlnhlfan jlnhlfan commented Feb 26, 2022

Screenshot_February_26_2022_09_38_34_AM

There are two glitched textures here in NHL 09- one for Jaromir Jagr's portrait, and another for Avangard Omsk's logo- in fact, ALL of the logo and portrait textures appear to be glitched. The only ones that don't appear glitched for NHL 09 (and would likely apply to 2005 through 08 as well) when dumped are some UI elements and text.

@certainmorning
Copy link

@certainmorning certainmorning commented Feb 27, 2022

Trying this feature with Shadow Hearts (SLUS-20347), sadly it doesn't dump any 2d backgrounds.
It also dumps like 100+ instances of every character and enemy texture with different alpha values, for example:

dump

@TheKrzysiek
Copy link

@TheKrzysiek TheKrzysiek commented Feb 27, 2022

Trying this feature with Shadow Hearts (SLUS-20347), sadly it doesn't dump any 2d backgrounds. It also dumps like 100+ instances of every character and enemy texture with different alpha values, for example:

dump

Similar thing happens in some other games that I tried, mainly all Ace Combat games.
However i didn't notice any difference in alpha for them, and they just keep going if you dump while looking at terrain or any model.

@SayakaMaizono
Copy link

@SayakaMaizono SayakaMaizono commented Feb 27, 2022

Would it be possible to detect and seperate any texture which has an alpha channel?

For bulk upscaling just to get an idea of how amazing this feature can become, It'd be nice to be able to seperate alpha textures or else they look broken without special care. Testing this on Ratchet and Clank 3 right now.

@Dogmander
Copy link

@Dogmander Dogmander commented Feb 27, 2022

Trying this feature with Shadow Hearts (SLUS-20347), sadly it doesn't dump any 2d backgrounds. It also dumps like 100+ instances of every character and enemy texture with different alpha values, for example:
dump

Similar thing happens in some other games that I tried, mainly all Ace Combat games. However i didn't notice any difference in alpha for them, and they just keep going if you dump while looking at terrain or any model.

Yeah, when I tried some textures were repeated multiple times, probably due to them moving in memory. It would be nice if the textures weren't repeated a crap ton of times, it would make finding the specific texture(s) you need easier and save your disk space.

@CelestePolo
Copy link

@CelestePolo CelestePolo commented Feb 27, 2022

Hi,
Thanks for the amazing feature ! I've AI upscaled almost all Shadow of the Colossus. (See some pictures below)
I noted these points and questions:

  • Files named with only two hex number (hex-hex) are either junk (look like screenshots) OR correct texture/dumps. Although correct they can't be replaced. (In SotC there is only one texture worth upscaling in this case)
  • Full mipmap (PS2) + Vulkan or D3D breaks the loaded textures, it is not the case with OpenGL. I didn't dump and replaced mipmaps perhaps this is the reason?
  • Will a texture pack be compatible between different versions of the same game (EU, US, JPN) ?
  • I have 20 000 files of an effect, could it be possible to avoid dumping these pictures again by specifying the first hex number ?
  • Last hex number seems to be related to picture size.

https://ibb.co/ynhLk43
https://ibb.co/196gRhL (not upscaled for comp.)
https://ibb.co/Jn71x56
https://ibb.co/2SJxQMW (not upscaled for comp.)
https://ibb.co/YPKRd06
https://ibb.co/ZKjmj5P
https://ibb.co/SXQTCHW

@LuismaSP89
Copy link

@LuismaSP89 LuismaSP89 commented Feb 27, 2022

Hi, Thanks for the amazing feature ! I've AI upscaled almost all Shadow of the Colossus. (See some pictures below) I noted these points and questions:

* Files named with only two hex number (hex-hex) are either junk (look like screenshots) OR correct texture/dumps. Although  correct they can't be replaced. (In SotC there is only one texture worth upscaling in this case)

* Full mipmap (PS2) + Vulkan or D3D breaks the loaded textures, it is not the case with OpenGL. I didn't dump and replaced mipmaps perhaps this is the reason?

* Will a texture pack be compatible between different versions of the same game (EU, US, JPN) ?

* I have 20 000 files of an effect, could it be possible to avoid dumping these pictures again by specifying the first hex number ?

* Last hex number seems to be related to picture size.

https://ibb.co/ynhLk43 https://ibb.co/196gRhL (not upscaled for comp.) https://ibb.co/Jn71x56 https://ibb.co/2SJxQMW (not upscaled for comp.) https://ibb.co/YPKRd06 https://ibb.co/ZKjmj5P https://ibb.co/SXQTCHW

Sorry, would you mind to share the upscaled textures? I tried mysefl using AI programs and online webs, but they're not free and I can just upload one image at the same time. Is there any website or program to do this with a lot of images at the same time?

Thanks!

@refractionpcsx2
Copy link

@refractionpcsx2 refractionpcsx2 commented Feb 27, 2022

Sorry we're not allowing textures to be shared on our github, discord or forums due to the amount of copyrighted material that could be floating around, if you wish to share texture packs, you are all welcome to set up your own website and share them there, and if there is moderation and vetting to make sure no copyrighted assets are being used, we'll even link to it. But directly, we don't have the man power to deal with it, so please do not share them here.

@PCSX2 PCSX2 locked as resolved and limited conversation to collaborators Feb 27, 2022
@stenzek stenzek deleted the gs-texture-replacements branch Apr 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.