Rasterization: How does hardware disambiguate identical Z values at silhouette edges? I have written a software rasterizer, and have encountered a (literal) edge case.
At the silhouette edge of a typical object, you have two triangles—the front face and the back face.  They are not coplanar, but they of course share that single edge.  Say the pixel center / subpixel sample happens to lie very close to this edge—so close that the depth value computed for both triangles is actually exactly, bit-for-bit, identical.
Without special handling for this case, sometimes the &quot;wrong&quot; fragment will get through.  For example, with the &lt; depth function, if the backface renders first, then the depth test for the frontface will fail and the backface will show through.   If the frontface renders first, then the depth test for the backface will fail and the frontface will show.  The former case produces the wrong image—sometimes quite objectionably so.
I have thought about hacks to fix this like trying to handle the &quot;equals&quot; case explicitly, depending upon the depth function and whether the fragment came from a front face, but it's not clear, especially for the ≤ and ≥ depth functions, what the &quot;right&quot; answer is.  Still, it's about the only thing I can think of trying.
This is basically Z-fighting, but unlike the usual Z-fighting graphics newbies encounter when they don't set the clipping planes right or whatever (and which makes this issue almost ungoogleable), existing hardware definitely does provide some kind of solution to handle this particular case, because this problem does not occur on real GPUs.
So my question is—how is this handled by real GPUs?  If that's unanswerable, then how can it be handled consistently?
If you are taking about this occurring within a single draw call for a single object then you are talking about rasterization not Z fighting.  So the real question is, &quot;how are two triangles rasterized that are right next to each other&quot;. And the answer to that question boils down to rasterization rules. Which must be enforced, on GPU's that happens in hardware, for your software rasterizer you need to pick a rule set, then enforce it in code. Generically a rasterizer can leave no holes, and each pixel is only drawn once. You may want to always add colors when drawing your triangles, start with a color of zero and just add new colors drawn to that pixel, this will make your overdraw stand out like a sore thumb.
The most widely know rule set for handling this is the &quot;top left rule&quot; which states: The center of every pixel must lie completely inside the triangle, (you are computing pixel centers right?) or it center lies exactly on a triangle edge or on multiple edges in the case of corners, and a left edge is a non-horizontal edge that is on the left side of the triangle.
This last bit is directly from Wikipedia.