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

Allow binding depth as 565 by going through depal #15859

Merged
merged 13 commits into from
Aug 21, 2022
Merged

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Aug 18, 2022

Fixes #6105

Details: #6105 (comment)

This is an attempt at a fix for #6105 (Ratchet & Clank particles visible through things).

But there's still weird glitchiness, if we don't apply a bit of deswizzling, same as seen with the software renderer. There's a pass during rendering that scrambles the mini depth buffer by using a triangle mesh. But it doesn't really look like a swizzle... It just flips portions of the image so that after downsacling, each set of 4 lines (at original resolution) is upside down. Maybe that's somehow the difference between depth swizzle and color swizzle? Plus there's some horizontal stretch somewhere that's not quite right.

Things left to fix:

  • See if we can avoid the compat flag in some reasonable way (it only controls swizzle, the rest is solidly compat-flag-free). (I really don't see how... and emulating swizzle properly would be difficult and possibly not possible at high res)
  • In-game resolution change doesn't work (breaks the deswizzle)

Normally when games use color as depth they texture with a swizzle flag in the address but this doesn't, so it indeed seems like swizzle compensation. We undo it during color->depth conversion (a special version of the color->depth copy shader).

image

After conversion to depth, it looks like this:

image

This results in weird artifacts like this:

image

With the latest changes here that applies a deswizzle operation:

image

@hrydgard hrydgard added the GE emulation Backend-independent GPU issues label Aug 18, 2022
@hrydgard hrydgard added this to the v1.14.0 milestone Aug 18, 2022
@hrydgard hrydgard force-pushed the depal-depth-565 branch 2 times, most recently from 33b1fb0 to f18a61b Compare August 20, 2022 08:13
@hrydgard
Copy link
Owner Author

hrydgard commented Aug 20, 2022

Rebased on main.

@hrydgard
Copy link
Owner Author

This now works on all backends except D3D9 for some reason, but will debug that some other time.

@unknownbrackets
Copy link
Collaborator

I usually look at this for depth swizzle:

http://hitmen.c02.at/files/yapspd/psp_doc/chap10.html#sec10.2

It does look like maybe it flips the chunks vertically...

-[Unknown]

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 20, 2022

Oh yeah, indeed does look like it. Still, to accurately track swizzle state through the pipeline to avoid the compat flag, we would have to detect that the game actually undoes it with a triangle mesh, without using the 6mb address trick in this case...

Or it might mean that emulating the swizzle "accurately" (as seen from the game) might not be that hard.. Still I'm having problems figuring out where exactly we should apply it in that case. Need to think more about it..

@unknownbrackets
Copy link
Collaborator

Does this mean it's broken in the software renderer (since it doesn't do the swizzling)? Materializing the right swizzle in VRAM mirrors sounds annoying...

-[Unknown]

Copy link
Collaborator

@unknownbrackets unknownbrackets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, one of my biggest dislikes with compat flags is they tend to make an assumption about the overall game. I wish we could either generalize the detection more or make it more specific, i.e. only when 565ing depth, and only with a high prim count or something. But I guess this game probably uses it throughout...

-[Unknown]

if (!draw2DPipeline565ToDepthDeswizzle_) {
g_scale = renderScaleFactor_;
draw2DPipeline565ToDepthDeswizzle_ = Create2DPipeline(&GenerateDraw2D565ToDepthDeswizzleFs);
linearFilter = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this forced to false only when we're creating? Shouldn't it either be outside this if or just what the caller set?

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly mistake, fixing. I don't think we should try to use any filtering in these at any time.

GPU/Common/DepalettizeCommon.cpp Outdated Show resolved Hide resolved
BlitUsingRaster(src->fbo, 0.0f, 0.0f, src->renderWidth, src->renderHeight, dest->fbo, 0.0f, 0.0f, dest->renderWidth, dest->renderHeight, false, DRAW2D_565_TO_DEPTH, "565_to_depth");

// Really hate to do this, but tracking the depth swizzle state across multiple
// copies is not easy.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could track it as a usage flag and forward it when we blit. Is it that it copies the swizzled depth via 565 (color -> color), and then textures that with the triangle mesh to deswizzle? Poor developer must've not known about the mirrors... or maybe they're slow somehow?

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any way the mirrors are slow, and ignorance would be strange since it uses them earlier in the frame IIRC..

But hm, if we always do the flip when converting depth to color when the bits aren't set... I'll work more on this tomorrow or Monday.

@hrydgard
Copy link
Owner Author

And yes, in the software renderer it's broken exactly the same as this without the swizzle.

@hrydgard
Copy link
Owner Author

I have some new thoughts on avoiding the swizzle compat flag, but will get this in as-is first, so people can start testing it.

@hrydgard hrydgard merged commit 58adf3e into master Aug 21, 2022
@hrydgard hrydgard deleted the depal-depth-565 branch August 21, 2022 17:54
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.

Ratchet & Clank - Light bleeding through walls
2 participants