Now Reading
Full display triangle optimization

Full display triangle optimization

2023-03-08 14:25:34

So right here’s a widely known optimization trick that additionally tells you a bit about how GPUs work.

Full display put up processing results are normally drawn as a pair of two massive triangles that cowl the entire display. A fraction shader then processes each pixel. However you may make it a tiny bit sooner by drawing a single giant triangle as an alternative:

That sq. represents the display in clip house. The large triangle on the appropriate covers to entire display identical to the 2 triangles on the left however has a much less shading overhead. The z coordinate doesn’t matter however zero ought to work each in D3D and OpenGL.

Establishing the triangle is handy to do instantly in a vertex shader with no vertex buffer certain. Name glDrawArrays(GL_TRIANGLES, 0, 3) with this vertex shader:

In my microbenchmark the one triangle method was 0.2% sooner than two. We’re undoubtedly deep into micro-optimization territory right here 🙂 I suppose should you learn textures in your shader you’ll see bigger positive factors like occurred within the AMD case examine linked above.

For extra particulars on the mechanics of the automated mip choice, see the part “{Hardware} Partial Derivatives” in this 2021 article by John Hable.

In fact you might use compute shaders right here however you should make sure the memory access patterns play well with no matter format your textures (and the framebuffer?) are saved in. So it’s not an apparent win should you take code complexity under consideration.

See Also

Lastly, should you nonetheless find yourself drawing two triangles, be sure to’re drawing a 4 vertex triangle strip and never a six vertex record. I’m not claiming there’s a velocity distinction – that is just for the nerd cred!


For extra tips like this normally, see Bill Bilodeau’s 2014 GDC talk on the subject (slides).

Because of mankeli for suggestions on a draft of put up.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top