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

Add support for binding the depth buffer as a color target. Fixes Kurohyo depth sorting #15772

Merged
merged 9 commits into from
Aug 1, 2022

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Aug 1, 2022

Fixes #9576

Kurohyo uses 2d backdrops with 3d characters rendered on top of them, and to fill in the Z buffer to make the characters sort against the background correctly, it writes a depth image directly to the Z buffer.

The PSP doesn't have any special mode for this, instead this game uses 565 color mode, binds the Z buffer as a color buffer, and writes the image as a color image.

I am not introducing a game specific compat flag, hoping for the best, heh (that it won't break something else).

Since such rebinding is entirely impossible on PC, but we can write explicitly to depth, we find the corresponding framebuffer that last touched that depth buffer, bind it normally for rendering, and we use a new rendering mode where:

  • Color writes are masked away (don't happen)
  • Depth writes are enabled in ALWAYS mode (no testing, just writing)
  • The fragment color value is interpreted as a 565 value overlapping a 16-bit depth value, and the computed depth value is written to the depth buffer

Result - the characters should clip correctly!

WIP, only works in Vulkan in straight-through depth mode so far, but the other backends will be fixed too.

@hrydgard hrydgard added the GE emulation Backend-independent GPU issues label Aug 1, 2022
@hrydgard hrydgard added this to the v1.14.0 milestone Aug 1, 2022
@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Hm, still has problems on Vulkan on Adreno, works on OpenGL though.

@dante3732
Copy link

It seems to work fine, I will write if there are problems.

@dante3732
Copy link

dante3732 commented Aug 1, 2022

The character is partially visible through the car.
1
2

@dante3732
Copy link

Same
Снимок экрана (2306)

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Ah interesting, think we might be mistakenly filtering the depth texture. I'll get a fix in soon.

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

I believe that change should take care of it.

(Not a perfect method, it could theoretically have been upscaled in a
normal render pass...)
@dante3732
Copy link

dante3732 commented Aug 1, 2022

I believe that change should take care of it.

1

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Okay, I guess not, but it kinda has to be that, or something very related... Can I have a GE dump or savestate file from that location?

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Also, does it look like that in all backends (Vulkan, D3D etc?)

@dante3732
Copy link

Okay, I guess not, but it kinda has to be that, or something very related... Can I have a GE dump or savestate file from that location?

How make GE dump?

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

@dante3732
Copy link

Also, does it look like that in all backends (Vulkan, D3D etc?)

Only on D3D9 all fine.
324

@dante3732
Copy link

Okay, I guess not, but it kinda has to be that, or something very related... Can I have a GE dump or savestate file from that location?

Savestate https://drive.google.com/file/d/1-o47utQjASHd0EDx3EOaSkEfmXU_y5IU/view?usp=sharing

@dante3732
Copy link

dante3732 commented Aug 1, 2022

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

thanks!

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Yeah there's something weird going on:

source image:

image

resulting z buffer:

image

Then it gets fuzzy because of some blur effect later in the frame, but the depth buffer is wrong right from the beginning. hmm

@hrydgard
Copy link
Owner Author

hrydgard commented Aug 1, 2022

Alright, I think I got it sorted now. Thanks so much for the test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Depth / Z Issue involves depth drawing parameters. GE emulation Backend-independent GPU issues
Projects
None yet
3 participants