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

Vulkan: Clip clamped depth in geometry shader #16165

Merged
merged 4 commits into from
Oct 6, 2022

Conversation

unknownbrackets
Copy link
Collaborator

Well, I know I said I hate clipping maths (and I do), but I decided to give it a shot anyway. It seems to work on NVIDIA, and with no noticeable slowdown there compared to not using the geometry shader and using clip distance/etc. Not sure how this'll perform on mobile, since the shader does get a bit more complicated.

Test frame dump:
#11216_UCUS98703_pursuit_force_clamp.zip

Which should look like this:
#11216_UCUS98703_pursuit_force_clamp

Note that this is an especially nice test frame dump, because it requires curves and non-curves to be clipped against minz/maxz for proper rendering.

This corrects deformed geometry on Mali devices which don't support user-space clipping but do support depth clamp. I'm not really aware of any other devices this will help, even Apple supports shader clip distance.

With this change, people with Mali GPUs (which are fairly common) ought to avoid most already-solved depth related issues. Apple users still need to turn off hardware transform.

-[Unknown]

This corrects deformed geometry on Mali devices which don't support
user-space clipping but do support depth clamp.
In the geometry shader, if used, we need to output the clip distance from
the clamped Z clip or it gets lost.
We only need to write one clip distance to clip clamped depth, since we
don't clamp when it needs clipping on both sides.
@hrydgard
Copy link
Owner

hrydgard commented Oct 6, 2022

Renders perfectly on S20 with Mali. nice!

Really nice work!

@hrydgard hrydgard merged commit 87d00f7 into hrydgard:master Oct 6, 2022
@unknownbrackets unknownbrackets deleted the geo-shader branch October 6, 2022 07:18
@ghost
Copy link

ghost commented Oct 6, 2022

This might fix #14146 (comment)?

@unknownbrackets
Copy link
Collaborator Author

unknownbrackets commented Oct 6, 2022

Well, #16162 would already fix that for devices capable of geometry shaders. That just needs negative Z clip to render properly, it's not related to depth clamp I think.

It still doesn't quite "fix" it, we'd need to clip in software transform and either force software transform or accept that hardware transform will render wrong for people without shader clip distance or geometry shaders.

We probably also could adjust the vertex range culling to clip negative Z even on Apple devices. I'll just do that, I meant to before, I'll just expand the cases a bit.

-[Unknown]

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.

2 participants