PCSX2 / pcsx2

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

Meta: GSdx HW mipmap support #1561

Open gregory38 opened 8 years ago

gregory38 commented 8 years ago

Let's collect games that suffer from lack of mipmap. It would allow to avoid multiple bugs reports and easily see which games are impacted (and how many too).

Active issues:

Active issues, but not broken without mipmapping:

Fixed with automatic mipmapping option, but missing CRCs:

Fixed with automatic mipmapping option:

Nobbs66 commented 8 years ago

Ratchet and Clank Ratchet and Clank Going Commando/ Locked and Loaded Ratchet and Clank Up your Arsenal / 3 Ace Combat 4 Shattered Skies *Ace Combat 5 Skies of Deception

mirh commented 8 years ago

A quick search showed #168, #775, #869. Also, iirc Ace Combat zero/belkan war also exhibited the issue, but afaik not Shattered Skies.

pepiczech77 commented 8 years ago

Ratchet: Gladiator (aka Ratchet: Deadlocked) is affected as well afaik

FlatOutPS2 commented 8 years ago

Also, iirc Ace Combat zero/belkan war also exhibited the issue, but afaik not Shattered Skies.

You recalled incorrectly: http://wiki.pcsx2.net/index.php/Ace_Combat_04:_Shattered_Skies http://forums.pcsx2.net/Thread-Ace-Combat-Distant-Thunder-SCES-50410-E

MrCK1 commented 8 years ago

Wipeout Fusion, Gran Turismo 4, and Hot Shots Golf 4 have minor flickering due to lack of mip levels. I don't know if they really apply to this list; since they are minor anomalies (other than HSG4 having speed issues w/ depth)

refractionpcsx2 commented 8 years ago

Added the two Destroy All Humans games

gregory38 commented 8 years ago

I think there at least one tomb raider. But I don't know which one.

@prafullpcsx2 gives me also some cricket games with mipmap issue.

refractionpcsx2 commented 8 years ago

I could be completely wrong, but doesn't one of the Hot Shot Golf games have mipmapping as well? I can't remember. I also vaguely remember an FPS game using it as well, but I can't remember what it was.

FlatOutPS2 commented 8 years ago

There's a difference between having mipmapping, and having serious issues with mipmapping. The Everybody's Golf(the actual name of the series) games have mipmapping, but they don't have any issues with it(or it has to be the Japan only online game). The games would improve with mipmapping though, as the high res textures don't look as good at a distance.

gregory38 commented 8 years ago

Yes lots of games (maybe nearly all) use mipmapping without any real bad impacts. Nocturne uses it too, for example, the ceiling light color is wrong of 1...

Dokman commented 8 years ago

so you will implement mipmapping in hardware? this is real? : O

prafullpcsx2 commented 8 years ago

I will add many games to this list after 2-3 days (when my tournament ends).

gregory38 commented 8 years ago

Hum, please say if it is major/minor issue.

Good luck ;)

Dokman commented 8 years ago

all the people we want to play our ratchet and clank games and destroy all humans are crazy with the software render i think, because we cannot set a higher resolution and watch the correct textures in the game..

willkuer commented 8 years ago

Really.. Give that man some space. First priority is his family. After that he has to work for a living. After that he has to fulfill all desires and wishes he has. And exactly at the end after he took care about everything in his life he could take care of those who want to play R&C in higher than native or with weak hardware.

avih commented 8 years ago

I vaguely recall that one of the tomb raiders (legend? anniversary?) also had mipmap issues, though I don't recall if it's HW only.

gregory38 commented 8 years ago

Before GITHUB goes down when rumour of mipmap work goes vrial on the internet. ^^

I have no plan to work on it yet. The purpose of this issue report is to concentrate all the mipmap issue into a single report instead of dozens of them. Less noise in the tracker + easier for tester.

On a side note, my current target is to finish Grandia 2 anniversary edition ;)

FlatOutPS2 commented 8 years ago

Are you porting all the Grandia 2 AE improvements to the PS2/PCSX2 version?! :P

MonJamp commented 8 years ago

Doesn't Tribes Aerial Assault use mipmaps?

FlatOutPS2 commented 8 years ago

Doesn't Tribes Aerial Assault use mipmaps?

Yes, it does and it has several issues with it. I added it to the OP.

ramapcsx2 commented 8 years ago

Added Tomb Raider: Anniversary. The game has additional problems. An overlay of broken shadow maps, it looks like.

JMC47 commented 8 years ago

I have a question: assuming that mipmapping doesn't work at all on GSdx: hardware, are these the only games that actually use Mipmapping on the PS2, or is there a certain way they're using mipmapping that's causing severe issues?

I've been trying to look up more on what the games are actually doing since it seems every time a PS2 article/video/anything is posted there's someone saying "does it run R&C yet" or "useless until it runs R&C in hardware," and I'd like to at least be able to rebut them to a degree with what the games are doing and why it's not emulated in hardware.

gregory38 commented 8 years ago

Lots of game use mipmapping but base layer contains real data. GS mem is more a cache than a standard vram. Mipmap layers are only pointer to memory area. You can do anything you want with the memory. The rule is there is no rule. Now for RC, I suspect that game only write texture data of the intermediate layers. The plan is to compute in cpu the max layer of the rendering and to upload this layer to the texure (with the help of texture view)

JMC47 commented 8 years ago

So, on GSdx hardware, it's pointing to where the actual texture is, rather than where the mipmap is right now? Causing it to load garbage instead of the actual texture? Or, rather, it has no place to actually load the texture since only the mipmap is in memory and nothing is in the base layer?

TheJordanator commented 8 years ago

Jak and daxter series also has the mipmapping bug

MrCK1 commented 8 years ago

@TheJordanator That's already in the list

gregory38 commented 8 years ago

@JMC47 Hum, let's use an example On the game engine, you can compute the lod of the scene. Let's say you find 3. What you can do is

Currently GSdx HW will read the memory located at 0x1000 to generate the texture. The correct behavior will be to upload the 0x1100 part.

Potential solution will be to upload all the layers and to sample the good layer. Perf will suck. So I think we could only upload the top layer that we know will be valid (if we compute the lod on the CPU). It might be enough for some games. However it can become easily complex. So far we reference texture with the layer0 address. Nothing forbid a game to change it but to keep the same layer. We can create new texture based on the layer address (we miss tri-linear filtering). It could to handle EE write in the middle of a layer. But it might create various texture upload based on the camera position (again bad for perf).

Every time, we want to upload a texture. We need to unsizzle it, convert it to 32 bits (or upload a palette). And then ask gl driver to upload which isn't fast. If the game only upload partial mipmap, it likely means that GS mem is too small for its => likely various texture collision/invalidation writes => more texture to upload.

Conclusion we need to do something and see what is the perf. But if it works, nobody will complain anymore ;)

gregory38 commented 8 years ago

Forget to say, first step is to do a current state of the game impacted, because I can tell you that all games are likely using different tricks.

And last but not least, extend the internal GS debugger to dump the texture layer. This way we can see what happen.

JMC47 commented 8 years ago

Sounds like a total pain in the ass. I do not envy whoever tries to tackle this issue. At least I have a reference to point people to now when I see them asking about it. Also, making it a perf vs accuracy issue with no great solution helps tell users "it's not that simple."

On Wed, Sep 21, 2016 at 6:05 AM, Gregory Hainaut notifications@github.com wrote:

Forget to say, first step is to do a current state of the game impacted, because I can tell you that all games are likely using different tricks.

And last but not least, extend the internal GS debugger to dump the texture layer. This way we can see what happen.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PCSX2/pcsx2/issues/1561#issuecomment-248567332, or mute the thread https://github.com/notifications/unsubscribe-auth/AGSuQc50pjcp8JxVwqNIhTbDN5kW42NZks5qsQFagaJpZM4J6aJ4 .

gregory38 commented 8 years ago

Oh, you just found the initial name of the GS, PITA ;)

Here the SW implementation

            if(mipmap)
            {
                if(m_vt.m_lod.x > 0)
                    gd.sel.ltf = context->TEX1.MMIN >> 2;
                else
                    // TODO: isbilinear(mmag) != isbilinear(mmin) && m_vt.m_lod.x <= 0 && m_vt.m_lod.y > 0

                gd.sel.mmin = (context->TEX1.MMIN & 1) + 1; // 1: round, 2: tri
                gd.sel.lcm = context->TEX1.LCM;

                int mxl = std::min<int>((int)context->TEX1.MXL, 6) << 16;
                int k = context->TEX1.K << 12;

                if((int)m_vt.m_lod.x >= (int)context->TEX1.MXL)
                {
                    k = (int)m_vt.m_lod.x << 16; // set lod to max level

                    gd.sel.lcm = 1; // lod is constant
                    gd.sel.mmin = 1; // tri-linear is meaningless
                }

                if(gd.sel.mmin == 2)
                    mxl--; // don't sample beyond the last level (TODO: add a dummy level instead?)

                if(gd.sel.fst)
                    gd.sel.lcm = 1;

                if(gd.sel.lcm)
                {
                    int lod = std::max<int>(std::min<int>(k, mxl), 0);

                    if(gd.sel.mmin == 1)
                    {
                        lod = (lod + 0x8000) & 0xffff0000; // rounding
                    }

                    gd.lod.i = GSVector4i(lod >> 16);
                    gd.lod.f = GSVector4i(lod & 0xffff).xxxxl().xxzz();
                }
                else
                {
                    gd.mxl = GSVector4((float)mxl);
                    gd.l = GSVector4((float)(-0x10000 << context->TEX1.L));
                    gd.k = GSVector4((float)k);
                }

                GIFRegTEX0 MIP_TEX0 = TEX0;
                GIFRegCLAMP MIP_CLAMP = context->CLAMP;

                GSVector4 tmin = m_vt.m_min.t;
                GSVector4 tmax = m_vt.m_max.t;

                static int s_counter = 0;

                for(int i = 1, j = std::min<int>((int)context->TEX1.MXL, 6); i <= j; i++)
                {
                    switch(i)
                    {
                    case 1:
                        MIP_TEX0.TBP0 = context->MIPTBP1.TBP1;
                        MIP_TEX0.TBW = context->MIPTBP1.TBW1;
                        break;
                    case 2:
                        MIP_TEX0.TBP0 = context->MIPTBP1.TBP2;
                        MIP_TEX0.TBW = context->MIPTBP1.TBW2;
                        break;
                    case 3:
                        MIP_TEX0.TBP0 = context->MIPTBP1.TBP3;
                        MIP_TEX0.TBW = context->MIPTBP1.TBW3;
                        break;
                    case 4:
                        MIP_TEX0.TBP0 = context->MIPTBP2.TBP4;
                        MIP_TEX0.TBW = context->MIPTBP2.TBW4;
                        break;
                    case 5:
                        MIP_TEX0.TBP0 = context->MIPTBP2.TBP5;
                        MIP_TEX0.TBW = context->MIPTBP2.TBW5;
                        break;
                    case 6:
                        MIP_TEX0.TBP0 = context->MIPTBP2.TBP6;
                        MIP_TEX0.TBW = context->MIPTBP2.TBW6;
                        break;
                    default:
                        __assume(0);
                    }

                    if(MIP_TEX0.TW > 0) MIP_TEX0.TW--;
                    if(MIP_TEX0.TH > 0) MIP_TEX0.TH--;

                    MIP_CLAMP.MINU >>= 1;
                    MIP_CLAMP.MINV >>= 1;
                    MIP_CLAMP.MAXU >>= 1;
                    MIP_CLAMP.MAXV >>= 1;

                    m_vt.m_min.t *= 0.5f;
                    m_vt.m_max.t *= 0.5f;

                    GSTextureCacheSW::Texture* t = m_tc->Lookup(MIP_TEX0, env.TEXA, gd.sel.tw + 3);

                    if(t == NULL) {ASSERT(0); return false;}

                    GSVector4i r;

                    GetTextureMinMax(r, MIP_TEX0, MIP_CLAMP, gd.sel.ltf);

                    data->SetSource(t, r, i);
                }

                s_counter++;

                m_vt.m_min.t = tmin;
                m_vt.m_max.t = tmax;
}

Basically I want to do the same but with a single texture lookup loop (not 6 in worst case).

for(int i = 1, j = std::min<int>((int)context->TEX1.MXL, 6); i <= j; i++)

Hopefully it will be good enough to avoid most of the glitches. It won't be perfect, some game won't be supported but it would be a good start.

However I'm not sure how to handle texture size/clamp behavior etc... Hum, I need to check if mipmap is available with integer texture coordinate.

gregory38 commented 8 years ago

@prafullpcsx2 do you remember how this game used to be rendererd (HW, 2x) :stuck_out_tongue_winking_eye:

nice

gregory38 commented 8 years ago

@ramapcsx2, is it me or we could see the main character in the painting ? tomb_raider

prafullpcsx2 commented 8 years ago

@gregory38 : Yes, I do remember omg

And from your screenshots, I am way too excited now. :+1: With gregory impossible is nothing.

avih commented 8 years ago

@prafullpcsx2 do you remember how this game used to be rendererd (HW, 2x) 😜

I'm just amazed that for someone who does a lot of stuff with graphics, your font (at the window title) uses full hinting and no subpixel antialiasing.. this is so 90's (so actually maybe appropriate) ;)

gregory38 commented 8 years ago

As Napoleon said, "The word impossible is not French." :stuck_out_tongue:

Don't expect too much. Solution is quite hacky and only on gs dump. Strangely it seems to require 8 bit textures. However when I compare with SW renderer. Some parts are better on the HW side, some parts are better on the SW side.

I'm just amazed that for someone who does a lot of stuff with graphics, your font (at the window title) uses full hinting and no subpixel antialiasing.. this is so 90's (so actually maybe appropriate) ;)

Don't you know that I'm blind (nah kidding). Yes I'm an old guy, I enabled subpixel aliasing. Will see on the next reboot (not sure it is required), if there is any diff.

gregory38 commented 8 years ago
UserHacks_mipmap = 1

on latest git. Only positive feedbacks are accepted.

avih commented 8 years ago

UserHacks_mipmap = 1

We need some automatic GUI for all the hidden options.

ramapcsx2 commented 8 years ago

Works in Tomb Raider for the picture on the wall! Not much else yet though ;p

Dokman commented 8 years ago

so we can expect a hw mip mapping in the near future? : O

FlatOutPS2 commented 8 years ago

on latest git. Only positive feedbacks are accepted.

Okay. I think it's great how this make the mipmapping issue worse on Jak II compared to no mipmapping. :+1:

pepiczech77 commented 8 years ago

Seems to help Jak 3, do you want screenshots? Edit: sort of

Dreadmoth commented 8 years ago

Only positive feedbacks are accepted.

Distant textures in Ratchet & Clank don't shimmer as badly as they used to. Ocean in Jak 3 seems more accurate. Tree branches in Tribes: Aerial Assault no longer invisible at a distance. No noticeable performance impact in games I've tried so far.

widesrceen not work hahahahah

In a specific game, or in general? I haven't encountered any problems (with in-game widescreen modes or with hacks).

Dokman commented 8 years ago

@Dreadmoth how you have configurewd it? i don't know how i can do it :( i've gone gsdx and added those hack but... not works :(

gregory38 commented 8 years ago

Note: you need to enable mipmap support on the SW renderer too. Anyway, I'm currently working on Ratchet & Clank. There is something wrong somewhere. I will keep you updated if I find the issue.

prafullpcsx2 commented 8 years ago

Fifa and cricket games look a lot better now, Jurassic park is still very buggy. Overall it's a very positive step forward. :+1:

gregory38 commented 8 years ago

I'm pretty confident that situation will be better when I find a fix for RC. The first line of the texture is good. Remaining is bad. I suspect a wrong buffer width/line size somewhere. So I'm still uploading wrong data to the GPU in some cases.

MrCK1 commented 8 years ago

Jak 1 and Gran Turismo 4 "scattered" mipmap levels I guess you could say

gsdx_20160924114430

gregory38 commented 8 years ago

OMG, new improvements on master. @ramapcsx2 @prafullpcsx2 @Dreadmoth could you please retest your game.

gregory38 commented 8 years ago

Because I'm quite happy of my code. Here a nice screenshot. rc

Arg, looking closely it isn't perfect. But it is already a huge improvement.

willkuer commented 8 years ago

I have the feeling this is a huge joke. You decide like some days ago to work on it. Do something like copy pasting from sw to hw and get instantly good results without performance impact? The fuck?