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

Use fullscreen tri instead of quad #80311

Merged
merged 2 commits into from
Aug 7, 2023

Conversation

darksylinc
Copy link
Contributor

@darksylinc darksylinc commented Aug 5, 2023

As outlined in godotengine/godot-proposals#7366 a full screen triangle is around 5-10% faster than a fullscreen quad.

The main reason is that the diagonal induces inefficiencies in both how rasterized pixels are assigned to threads and how caches are missed (in the case where there are texture/memory accesses) since the borders are processed at different times.

This trick works optimally as long as the render target resolution is < 16384x16384 due to something called guardband clipping, since most modern GPUs implement a guardband of [-32768; 32767] (note: the paper talks about a guardband of -2048; 2047 because it's from the year 2000). If the guardband is exceeded the GPU must internally split the triangle in 2 quads (which is relatively expensive) and when we rasterize the fullscreen tri we use the range [0; width2] x [0; height2].

Most affected by this is the Mobile renderer, since the Clustered one uses Compute Shaders instead of Pixel Shaders.

However Clustered Forward still uses some fullscreen quads for things like Tonemapping and Sky.

I've only touched the Vulkan renderer. The same optimization could be applied to the GLES3 driver.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great! We already use this optimization in the GL Compatibility renderer, so it makes sense to use it in the RD renderers as well

@clayjohn clayjohn modified the milestones: 4.x, 4.2 Aug 7, 2023
@akien-mga akien-mga merged commit 40ca093 into godotengine:master Aug 7, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

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.

None yet

4 participants