[HN Gopher] Full screen triangle optimization
___________________________________________________________________
Full screen triangle optimization
Author : rck
Score : 36 points
Date : 2023-03-08 20:25 UTC (2 hours ago)
(HTM) web link (30fps.net)
(TXT) w3m dump (30fps.net)
| obl wrote:
| In actual hardware shading is done 32 or 64 pixels at a time, not
| four. The problem above just got worse.
|
| While it's true that there are "wasted" execution in 2x2 quads
| for derivative computation, it's absolutely not the case that all
| lanes of a hardware thread (warp / wavefront) have to come from
| the same triangle. That would be insanely inefficient.
|
| I dont think that it's publicly documented how the "packing" of
| quads into lanes is done in the rasterizer for modern GPUs. I'd
| guess something opportunistic (maybe per tile) taking advantage
| of the general spatial coherency of triangles in mesh order.
| delusional wrote:
| The linked AMD guide seems to suggest the author is correct
|
| >Because the quad is rendered using two separate triangles,
| separate wavefronts are generated for the pixel work associated
| with each of those triangles. Some of the pixels near the
| boundary separating those triangles end up being organized into
| partial wavefronts
| ttoinou wrote:
| Why didn't they ever implemented a rectangle primitive to be
| drawn instead of a triangle ? Anyway, here the perf impact is
| negligible
| Jasper_ wrote:
| Do you mean a bounding rectangle? That exists on a lot of GPUs,
| where you draw a triangle and the entire bounding box
| surrounding the triangle is covered. However, the details
| differ greatly between different GPUs, meaning it's hard to
| standardize. Full-screen triangles are just fine.
| st_goliath wrote:
| Triangles in 3D euclidean space have the advantage of being
| uniquely defined by 3 vertices that have the nice property of
| always sitting on a single plane. There's no linear
| transformation you could apply that results in something other
| than a well-defined, planar triangle. The worst that might
| happen is collapsing it into a line or a point.
|
| The same cannot be said for quads. If you e.g. have 4 vertices
| where 3 are sitting on the same plane, but the 4th isn't, there
| are 2 possible ways to subdivide this into triangles. In
| addition to all he possible non-linear surfaces one might image
| occupying that space.
|
| Old OpenGL and Direct3D versions _did have_ quad and arbitrary
| polygon rendering support. IIRC from vague memory, the above
| scenario was something you were supposed to avoid and results
| varied between graphics card vendors.
|
| On a side note: If we are talking purely _2D_. Some old 2D
| software rendering systems often used _trapezoids_ as basic
| primitives, defined by their top and bottom edges. For
| instance, the X11 XRender API explicitly supports drawing
| trapezoids. They are easy to rasterize, interpolate across and
| quite flexible. Many other 2D shapes can be conveniently
| composed from them, including screen space triangles, if you
| were to implement a software rasterizer.
| jra101 wrote:
| NVIDIA has an OpenGL extension that does just that [1].
|
| [1]
| https://registry.khronos.org/OpenGL/extensions/NV/NV_fill_re...
| delusional wrote:
| A triangle is the simpleste polygon. As soon as you start doing
| quads the complexity skyrockets: what if it self intersects?
| What if it's concave? What does a winding order mean when the
| verts can be all out of order?
| jbverschoor wrote:
| Triangles are used to render 3d meshes because of that yes.
| However, the article is about "Full screen post processing
| effects", which is easier done in a rectangle
| ladon86 wrote:
| Would this still be true on a tiled rendering GPU, i.e. mobile?
|
| If not, is there any possibility that dividing a fullscreen quad
| into _more_ triangles would actually end up faster?
| pixelpoet wrote:
| Even desktop GPUs use tiled rendering since Maxwell generation
| on Nvidia, and I forget which gen for AMD. I don't see how it's
| possible for many triangles to be faster than one for
| fullscreen rendering.
| teucris wrote:
| > In my microbenchmark1 the single triangle approach was 0.2%
| faster than two. We are definitely deep into micro-optimization
| territory here :)
|
| In the 3D graphics space, this kind of knuckle-shaving is deeply
| revered!
___________________________________________________________________
(page generated 2023-03-08 23:00 UTC)