1

If not, then why discard interrupted earlyZ? Imagine that there is an object A in front of B, A has a discard operation in fs.Assume that the pixel of A at screen coordinates (100, 100) pass the Early z test,then it is discarded in the fragment shader,so A has no chance to write depth.Now render B!Obviously A will not have any effect on B at (100,100). If this is the case, then why does A’s EarlyZ need to be interrupted?

Marsir
  • 105
  • 1
  • 2
  • 8
  • I did not quite get your question, but from what it sounds like, there is also something called **transparency**, that affects how pixels and depth will be discarded / rendered. – Dstarred Jul 31 '21 at 13:32
  • 1
    @SnipingPoodle No sorry, but the "transparency" has no effect on the depth of a fragment. The transparency comes into play when you use [Blending](https://www.khronos.org/opengl/wiki/Blending), but it has nothing to do with the [Depth Test](https://www.khronos.org/opengl/wiki/Depth_Test). – Rabbid76 Jul 31 '21 at 13:37
  • Whoops, sorry about that. – Dstarred Jul 31 '21 at 13:40
  • @SnipingPoodle I just want to know if early-z is write depth to buffer before FS. – Marsir Jul 31 '21 at 14:04

1 Answers1

3

Yes, the depth write is (as far as the hardware is concerned) part of the depth test. This is a atomic, ordered read/modify/write operation, so the hardware implements it that way.

Therefore, fragment testing before the fragment shader also means writing those fragment values before the fragment shader. So even if the FS discards the fragment, part of its components have already been written and cannot be unwritten.

So if an FS has a discard statement in it, the GPU will not use early tests unless the FS specifies that it must do so. And if it does specify that, then the discard will only partially discard the fragment.

Note that this also includes things like occlusion query counts and stencil tests/writes.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982