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-hw, TC: improve tex in rt. #3895

Merged
merged 12 commits into from
Jan 29, 2022

Conversation

iMineLink
Copy link
Contributor

@iMineLink iMineLink commented Nov 3, 2020

I improved the tex in rt code which logic is now encapsulated in the GSTextureCache::ComputeSurfaceOffset method.
The method considers two surfaces A and B, and computes the offset from B to A in terms of B coordinates.
In the tex in rt case, A is the Source object and B is the Target object.
We want to know the offset from B to A in order to associate to A the correct portion of data from B.

The improved logic is able to fix/improve:

The logic can be enabled via .ini file (UserHacks_TextureInsideRt = 1) for non Jak games, or from the GS HW hacks settings GUI.

image

Due to the nature of GS-hw TC, the logic cannot be always enabled without causing regressions.

The GSTextureCache::ComputeSurfaceOffset method is intended as future proof, potentially useful for detecting overlaps between EE writes and cached Targets, or between cached Targets alone.

Bonus 1:

The order in which Target and Source are searched in the cache is inverted, now:

  • The lookup source is executed, the call sees the target drawn in the previous draw as MRU
  • The lookup target is executed

Previously, the lookup source call saw the current target as MRU framebuffer, but this was not correct as that framebuffer was not written yet in the current draw.
This fixed in a decent way the misbehaviour of Test Drive Unlimited with tex in rt.

Bonus 2:

Targets are now readback from LRU to MRU (older data is overwritten with newer data).
Did not fix any particular issue, but it is more correct behaviour nevertheless.

Bonus 3:

The GSTextureCache::ComputeSurfaceOffset is reused to detect draws that invalidate partially a framebuffer with increased precision in Jak 2/3/X to fix striped and shimmering textures and wheels rendering in Jak X.
Unfortunately some games do not digest this change really well, so this improved logic is executed only for the games cited previously.
POSTPONED to future PR.

Bonus 4:

Partially dirty targets are now searched for valid data.

@NewMoonHD
Copy link

NewMoonHD commented Nov 4, 2020

Test Drive Unlimited didn't favor it a lot. Only HW rendering is affected (SW Renderer is safe for now)
gsdx_20201104120707.gs.zip

Update: It's fixed from later build updates.

@tadanokojin
Copy link
Member

Hello imine, good work. #563 improved and the sky issue is now fixed for Burnout Revenge. Black is still experiencing sky issues. I fear that it will be hard to debug however given the nature of it using the Burnout engine. I need a rather large dump starting at loading the level and ending when the sky is first visible. Perhaps @refractionpcsx2 can provide me with that so I can get you more details.

That being said, the reflections on the cars are still flickering. On master without tex in rt I was unable to reproduce the flickering. However, on master with tex in rt enabled the flickering is observed and worse. So I suspect there is some tuning in tex in rt for this game that is needed but this is an improvement over master's tex in rt implementation for sure.
gsdx_20201105143203
gsdx_20201105143203.gs.xz.zip

Additionally, #3694 has seen improvement with this PR. However, it still exhibits some problems. I can get you a dump if this game if you need. This is more straightforward to debug than the Burnout games.

@tadanokojin tadanokojin self-assigned this Nov 5, 2020
@legend800
Copy link

Burnout 3:

Sky is broken on first load:
2020-11-06 22_28_21-Slot_ 0 _ Speed_  82% (48 95) _ Limiter_ Normal _ OGL _ 3200x2240 _ Automatic _

If you toggle to Software render:
2020-11-06 22_25_48-Slot_ 0 _ Speed_ 100% (59 94) _ Limiter_ Normal _ SW _ 640x448 _ Automatic _ ${o

Then back to HW, it's finally correct (until you return to menus):
2020-11-06 22_26_34-Slot_ 0 _ Speed_  89% (53 29) _ Limiter_ Normal _ OGL _ 3200x2240 _ Automatic _

Burnout Dominator:
Same, except if you switch to Software, sky is black and toggling to HW doesn't fix.

2020-11-06 22_36_08-Slot_ 0 _ Speed_  78% (46 95) _ Limiter_ Normal _ OGL _ 3200x2240 _ Automatic _

@tadanokojin
Copy link
Member

I will try to do some debugging today and provide some information about Burnout/Black.

@iMineLink
Copy link
Contributor Author

Thanks kojin, I agree the Burnout engine is not easy to debug unfortunately. I saw previously on discord that Burnout Dominator was working though, but now it seems not, maybe due to the recent PR update.

Maybe having also a gsdump for #3694 can be of help.

@tadanokojin
Copy link
Member

Yeah I suspect that will be easier and will give you something to look at in the meantime
driving emotion s.zip

You're looking for the draw where depth/color gets downsized. They're going to copy them into a temp buffer and color is going to be right under depth but using the same address, then sampled back later (after EE processing) from a different address.

@iMineLink
Copy link
Contributor Author

The replay of Driving Emotion S you gave me looks fine here.

image

Here the first draw call that uses tex in rt:

T:Oth	ID:258	S:Cache	=> TC: Lookup Target(Color) 1280x1024, hit: 2 (0x800, C_32)
T:Oth	ID:258	S:Cache	=> TC: Lookup Source <0,0 => 128,128> (0x1d80, C_32, BW: 2)
T:Oth	ID:258	S:Cache	=> TC: ComputeSurfaceOffset - Cached HIT element (size 1), [B] BW 2, PSM C_32, BP 0x1c80 (END 0x1e7f) + OFF <0,128 => 128,256> ---> [A] BP 0x1d80 (END: 0x1e7f).
T:Oth	ID:258	S:Cache	=> TC: dst Color hit (full): 118 (0x1d80, C_32)
T:Oth	ID:258	S:Cache	=> TC: Remove Src Texture: 119 (0x800)

@tadanokojin
Copy link
Member

Alright, it might have been fixed since you added new commits. Let me give it a shot.

@iMineLink
Copy link
Contributor Author

iMineLink commented Nov 7, 2020

The new commits were:

  1. fixing some bugs in the offset computation itself (Jak was not working anymore lol)
  2. doing the tex in rt search in a second round in LookupSource w.r.t. same BP Source-Target check; this fixed test drive unlimited, where the tex in rt was stealing the correct target lookup (same BP); the reason behind this is that the TC supports overlapping targets for the same PSM, which is a very tricky feature to have along with tex in rt.

@tadanokojin
Copy link
Member

Looks like there's an issue with it over time:
gsdx_20201107122459
DES.zip
I start seeing graphical issues as the race continues. Here you can see the artifacting at the top. Not sure if a dump can help you with this one though, because the issue is different in my dump vs what I saw when I dumped it. An issue of debugging cache issues like this I'm sure.

@RedDevilus
Copy link
Contributor

HW mode pics:
gsdx_20201107211953
SLES-54681 PAL - Burnout dominator on commit 82438e0
Black sky when you change from default settings (even including SW mode)
gsdx_20201107212126

SW mode pics:
gsdx_20201107212255
gsdx_20201107212356

When you restart race the sky looks fixed but the car dissapears:
gsdx_20201107212520

But then it recovers on both SW and HW:
gsdx_20201107212635

No idea why it's inconsistent on testing situations. (upscaling / native resolution + Switch between SW and HW mode + starting fresh and restarting races)
You do see a cool lightning halo effect at a certain distance (right side of rails and partially trees on picture:
gsdx_20201107212812

@tadanokojin
Copy link
Member

tadanokojin commented Nov 7, 2020

Okay, testers are obviously confused so let me explain.

The Burnout engine is a special case for this. The game renders the sky to a texture. It then samples that texture back with a different offset. This means that the part of the texture it wants for the sky will be at a different memory address than where it was rendered. This is the problem tex in rt solves.

However, unlike other examples (jak eyes, driving emotion s) where the texture is rendered to every frame, Burnout only renders the texture when the level is loading. Additionally, sw rendering doesn't experience this problem because it's a different cache implementation. So when you load the level in software, it renders the texture to GS memory and then is able to invalidate it correctly and so when it gets sampled back, it is found. If you switch to HW renderer after this, the HW renderer will read the texture out of GS memory as it would any other texture transferred in from the EE. This is why that workaround works.

This has additional complications due to the fact that the HW renderer will not invalidate rt back into GS memory. This is a problem that is outside the scope of this PR but has some side effects when switching from HW to SW when the level is loaded in HW or opening the config for example.

@RedDevilus
Copy link
Contributor

I see, it does seem to have improved the sky, just was surprised the black sky problem was also happening in SW mode (first in HW mode and then switching to SW) but was fine after 2 restarts of the race.

Sorry :o

@CookiePLMonster
Copy link
Contributor

Fixes pause menu in The Getaway not working properly in Hardware mode. Without this PR, pause shows the last frame of Software mode (or nothing), with this PR it properly shows a "screenshot" of the underlying game.

image

@iMineLink iMineLink marked this pull request as draft December 13, 2020 18:20
@iMineLink iMineLink force-pushed the gsdx-hw-tc-improve-tex-in-rt branch 2 times, most recently from 9ddc75c to ef462ec Compare December 13, 2020 22:38
@iMineLink
Copy link
Contributor Author

I gave up on Driving Emotion S in this PR.
Open to discuss about the Jak 2/3/X only change in TC (crc based code inside TC already exists in the codebase); In any case, it's just a small commit.
I think this might be given a round of tests in Burnout, I don't think this can improved any further without severely interfering with framebuffer cache invalidation.

@iMineLink iMineLink marked this pull request as ready for review December 13, 2020 22:55
@ghost
Copy link

ghost commented Dec 13, 2020

I don't agrea with the jak only fix, this should be a general fix as it improves burnout, gateway and probably many others.

@iMineLink
Copy link
Contributor Author

iMineLink commented Dec 13, 2020

I better specified in the PR description what is the Jak only change: it is a small bonus part of the PR, that uses the same logic of the tex in rt, but applied to framebuffer invalidation.
The PR is mainly about tex in rt instead, which code is now always run.

@ghost
Copy link

ghost commented Dec 13, 2020

Ok, thanks for the explaination.

@MrCK1
Copy link
Member

MrCK1 commented Dec 13, 2020

Tested the updated code in Burnout 3, works fine on my end with no performance issues that I could see. Only issue I noticed is that closing the GS window and reopening will cause the sky to be black again, but I don't think there's much we can do about that unless I'm mistaken.

Ignore me, I was informed I missed a previous conversation regarding these issues.

@legend800
Copy link

Skybox is still not being loaded up correctly on HW on latest commit. It's blue but missing clouds and has bad banding. Sky turns black after toggling to Software and is broken until you start again from menus.

Burnout 3 HW at load:
2020-12-13 15_35_17-Slot_ 0 _ Speed_  70% (41 78) _ Limiter_ Normal _ OGL _ 3200x2240 _ None _ ${omo

Burnout 3 SW at load:
2020-12-13 15_37_03-Slot_ 0 _ Speed_  66% (39 54) _ Limiter_ Normal _ OGL _ 3200x2240 _ None _ ${omo

Burnout 3 HW at load:
2020-12-13 15_39_01-Slot_ 0 _ Speed_  76% (45 27) _ Limiter_ Normal _ OGL _ 3200x2240 _ None _ ${omo

Burnout Takedown SW at load:
2020-12-13 15_39_53-Slot_ 0 _ Speed_ 100% (59 94) _ Limiter_ Normal _ SW _ 640x448 _ None _ ${omodec

- this avoids the currently used target to
become the MRU in its cache and correctly keeps
the target used by the previous draw as the MRU
during the lookup source call.
Also move any target BW update from InvalidateVideoMem to LookupTarget.
Fixes Indiana Jones map rendering in cutscenes.
Improves Beyond Good & Evil shadow.
@iMineLink iMineLink force-pushed the gsdx-hw-tc-improve-tex-in-rt branch from 531d267 to 6970ebb Compare January 28, 2022 23:18
@iMineLink iMineLink force-pushed the gsdx-hw-tc-improve-tex-in-rt branch from 6970ebb to 045775a Compare January 28, 2022 23:45
@refractionpcsx2 refractionpcsx2 merged commit 6361cd8 into PCSX2:master Jan 29, 2022
@iMineLink iMineLink deleted the gsdx-hw-tc-improve-tex-in-rt branch January 29, 2022 00:19
@rtj503
Copy link

rtj503 commented Jan 30, 2022

So I tested this added option in Xenosaga 3 with the Zarathustra Dungeon.
gs_20220128213456
It didn't actually have any effect. There are two areas where it's most prominent. One area is this one right before the crystallized section. The other is just beyond this part where you can step on switches on the floor to make transparent panels move.
Zarathustra Panel Room
For comparison, here's how it's all supposed to look in Software Mode.
gs_20220128213527

@RedDevilus
Copy link
Contributor

Ref made this for easily seeing if the function gets triggered if anyone is interested, enable HW hacks and tex in rt and check the program log/ console:

pcsx2-avx2-texrtlog.zip

image

@rtj503
Copy link

rtj503 commented Jan 30, 2022

I downloaded that. That launcher just made the game really slow. I didn't notice any text in the Program Log that said Tex in RT had been activated. So maybe it's not activating.

@iMineLink
Copy link
Contributor Author

Regarding xenosaga 3, I have a gs dump from the "crystallized section" that works correctly now on master. Can you try forcing the tex in rt option active from the hw hacks section? Maybe the CRC of your game version is not registered for auto enabling the tex in rt logic.

@rtj503
Copy link

rtj503 commented Jan 31, 2022

Maybe that's the issue. I have a save from the Zarathustra Dungeon that I used on my AMD laptop and my Desktop that has an RTX 3060 graphics card. The graphical problem still occurs on both. I enabled the option in the HW hacks section, and I looked to see if it was enabled in the ini file. (I'm not a computer programmer, although I'd like to contribute with code, I don't have the knowledge, so don't ask anything too advanced, lol).

Here's what the program log said, I assume this was the relevant section:

Patches: No CRC found, using 00000000 instead.
(SYSTEM.CNF) Detected PS2 Disc = cdrom0:\SLUS_214.17;1
(SYSTEM.CNF) Software version = 1.00
(SYSTEM.CNF) Disc region type = NTSC
ELF (cdrom0:\SLUS_214.17;1) Game CRC = 0x2088950A, EntryPoint = 0x00120008
(SYSTEM.CNF) Detected PS2 Disc = cdrom0:\SLUS_214.17;1
(SYSTEM.CNF) Software version = 1.00
(SYSTEM.CNF) Disc region type = NTSC

So first it mentions not having a CRC code to apply a patch, but then it says midway through that it has a CRC code.

@refractionpcsx2
Copy link
Member

hmm that CRC is in there... can you try it on #5433 ?

@rtj503
Copy link

rtj503 commented Jan 31, 2022

hmm that CRC is in there... can you try it on #5433 ?
Is that a build, or would that require compilation? Just looks like a problem page to me.
I ran it all on the 1.7.2282 AVX2 64bit build. I tried compiling PCSX2 from source in Visual Studio once...didn't work. Not certain what happened. Did accomplish it in Linux once though a while back. Maybe don't have it depend on the CRC code?

@refractionpcsx2
Copy link
Member

refractionpcsx2 commented Jan 31, 2022

if you go to the checks at the bottom of #5433, then click on the "details" next to one of the windows builds, then go to "summary", there are builds in there.

@rtj503
Copy link

rtj503 commented Jan 31, 2022

I did that, I downloaded the AVX 64bit build. Same glitch still popping up. Perfectly willing to do more testing for you guys after some more work was done on it.
For reference, I posted some testing I did for Xenosaga 3 on the forums with pretty thorough documentation. https://forums.pcsx2.net/Thread-Xenosaga-Episode-III-Also-Sprach-Zarathustra-SLUS-21389-U--28443
I'm user tgg22. I tested on both my AMD laptop with integrated graphics, and my HP Omen Desktop with an AMD CPU and Nvidia GPU. Testing is admittedly for older builds, but those specs are representative of the options I typically like to pick. In case that helps.

@refractionpcsx2
Copy link
Member

@rtj503 can you provide a GSDump of Xenosaga, please? might make testing easier.

@rtj503
Copy link

rtj503 commented Feb 1, 2022

What's a GSDump and how do I do that? Sorry for asking the beginner questions. I'm perfectly fine helping out, but I need guidance doing since I don't know anything about the software other than what's on PCSX2 website. I couldn't find that in the PCSX2 documentation. I do have a memory card file. I've found Memory Cards work well finally in the newer builds.

@refractionpcsx2
Copy link
Member

Here's an explanation how to make one https://forums.pcsx2.net/Thread-How-to-create-a-proper-GS-dump

@rtj503
Copy link

rtj503 commented Feb 1, 2022

Here's an explanation how to make one https://forums.pcsx2.net/Thread-How-to-create-a-proper-GS-dump

Okay, I followed the directions, and posted the GS Dump in the forums. Link here: https://forums.pcsx2.net/Thread-GSdx?pid=624888#pid624888
Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.