1
\$\begingroup\$

Suppose I issue a draw command that draws 3 overlapping triangles (T1, T2, T3). Fragment shader assigns Depth = 3 to T1 fragments, 2 to T2 and 1 to T3 fragments. Depth Buffer is cleared to 0 before draw call. GL Test is set to GL_Less.

Now, when pixels for triangle 2 are depth tested by the hardware, is it guaranteed that hardware will read the latest written values i.e 3 (by T1 fragments)?

\$\endgroup\$
  • \$\begingroup\$ When Fragments are checked against depth to keep or discard the value is written immediately. Any reason you have doubts? \$\endgroup\$ – Sidar Jun 10 '18 at 15:38
  • \$\begingroup\$ I know this is guaranteed across draw calls and think that same must be applicable with in a single draw call. if different fragments map to same pixel, then fragment's depth test must be done in the order of primitives generating these pixels and last updated depth value must be for depth testing. \$\endgroup\$ – harish jangra Jun 11 '18 at 13:05
1
\$\begingroup\$

OpenGL doesn't have a "memory model", that's implementation-dependent (i.e. up to the driver).

However, the specification states (page 9):

Commands are always processed in the order in which they are received...

Therefore if you issue three draw calls, the three draw calls are processed in the order in which you issue them.

Furthermore, individual vertices in each single draw call are also processed in the same order they appear in your source buffers, again from the specification but this time page 8:

Data such as positional coordinates, colors, normals, texture coordinates, etc. are associated with a vertex and each vertex is processed independently, in order, and in the same way.

Note that some drivers may be a little "creative" about this, and behave as if commands or vertices were processed in order; typically this would be a performance optimization (e.g. for parallel processing) and anything you may do that depends on them actually being in order might disable that optimization. How much of a factor that is would vary from application-to-application and from driver-to-driver so general guidance can't really exist.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.