excessive glClear()ing #4694

Closed
anholt opened this Issue Oct 6, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@anholt

anholt commented Oct 6, 2016

Looking at an apitrace of Processing's 3.2.1's QuadRendering demo, the handling of clearing is inefficient:

glClearDepth(1)
glClearStencil(0)
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glClearDepth(1)
glClear(GL_DEPTH_BUFFER_BIT)
glClearColor(1,1,1,1)
glClear(GL_COLOR_BUFFER_BIT)

Two problems here:

double clearing depth

On i965, you will actually clear depth twice. Nobody expects an app to emit double clears of the same buffer, and i965 probably won't ever do the tracking necessary to elide your second clear.

Separate clearing of the buffers

On vc4, this resulted in 2 extra flushes of the job (huge memory bandwidth cost). This is common enough that I've now added workarounds for this to vc4 to coalesce the clears together, but you may still be triggering pathological behavior on other tiling renderers.

@codeanticode codeanticode added the opengl label Oct 7, 2016

@codeanticode codeanticode self-assigned this Oct 7, 2016

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 7, 2016

Member

Thanks for pointing it out. The following code should be equivalent and more efficient:

glClearDepth(1)
glClearStencil(0)
glClearColor(1,1,1,1)
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

Would you agree?

Member

codeanticode commented Oct 7, 2016

Thanks for pointing it out. The following code should be equivalent and more efficient:

glClearDepth(1)
glClearStencil(0)
glClearColor(1,1,1,1)
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

Would you agree?

@anholt

This comment has been minimized.

Show comment
Hide comment
@anholt

anholt Oct 7, 2016

Yeah. Even if the clear value setup is redundant with previous calls, those are cheap.

anholt commented Oct 7, 2016

Yeah. Even if the clear value setup is redundant with previous calls, those are cheap.

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 12, 2016

Member

ok, the separate calls were not actually together in the code, but ended happening so because during frame initialization the renderer clears the depth and stencil buffers, and then the color buffer separately (only) when background() is called in draw(). Actually, it is a little trickier to fix properly, as it is not enough to just to clear depth, stencil, and color buffers in background. You would still need to clear depth and stencil buffers in sketches that don't clear the background.

Member

codeanticode commented Oct 12, 2016

ok, the separate calls were not actually together in the code, but ended happening so because during frame initialization the renderer clears the depth and stencil buffers, and then the color buffer separately (only) when background() is called in draw(). Actually, it is a little trickier to fix properly, as it is not enough to just to clear depth, stencil, and color buffers in background. You would still need to clear depth and stencil buffers in sketches that don't clear the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment