Skip to content
Permalink
Browse files
Apply implicit clears and clearBuffer commands in proper order
https://bugs.webkit.org/show_bug.cgi?id=241765

Patch by Alexey Knyazev <3479527+lexaknyazev@users.noreply.github.com> on 2022-06-21
Reviewed by Kimmo Kinnunen.

Merging clearBuffer comamnds with implicit clears was producing
incorrect results, especially with enabled scissor test.

To resolve that, treat clearBuffer commands as draw calls,
i.e., apply implicit clears before them and notify the canvas
after, if needed.

It may be possible to reintroduce merged and/or skipped clears
provided that such an optimization does not break any tests.

See conformance2/rendering/clearbuffer-and-draw.html

* Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::clearBufferiv):
(WebCore::WebGL2RenderingContext::clearBufferuiv):
(WebCore::WebGL2RenderingContext::clearBufferfv):
(WebCore::WebGL2RenderingContext::clearBufferfi):

Canonical link: https://commits.webkit.org/251689@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295684 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
lexaknyazev authored and webkit-commit-queue committed Jun 21, 2022
1 parent 7d7f9b9 commit 11f2fe2
Showing 1 changed file with 20 additions and 12 deletions.
@@ -1680,8 +1680,11 @@ void WebGL2RenderingContext::clearBufferiv(GCGLenum buffer, GCGLint drawbuffer,
if (!data)
return;

// Flush any pending implicit clears. This cannot be done after the
// user-requested clearBuffer call because of scissor test side effects.
clearIfComposited(CallerTypeDrawOrClear);

m_context->clearBufferiv(buffer, drawbuffer, data.value());
updateBuffersToAutoClear(ClearBufferCaller::ClearBufferiv, buffer, drawbuffer);
}

void WebGL2RenderingContext::clearBufferuiv(GCGLenum buffer, GCGLint drawbuffer, Uint32List&& values, GCGLuint srcOffset)
@@ -1691,8 +1694,11 @@ void WebGL2RenderingContext::clearBufferuiv(GCGLenum buffer, GCGLint drawbuffer,
auto data = validateClearBuffer("clearBufferuiv", buffer, values, srcOffset);
if (!data)
return;

// This call is not applicable to the default framebuffer attachments
// as they cannot have UINT type. Ignore any pending implicit clears.

m_context->clearBufferuiv(buffer, drawbuffer, data.value());
updateBuffersToAutoClear(ClearBufferCaller::ClearBufferuiv, buffer, drawbuffer);
}

void WebGL2RenderingContext::clearBufferfv(GCGLenum buffer, GCGLint drawbuffer, Float32List&& values, GCGLuint srcOffset)
@@ -1703,25 +1709,27 @@ void WebGL2RenderingContext::clearBufferfv(GCGLenum buffer, GCGLint drawbuffer,
if (!data)
return;

// Flush any pending implicit clears. This cannot be done after the
// user-requested clearBuffer call because of scissor test side effects.
clearIfComposited(CallerTypeDrawOrClear);

m_context->clearBufferfv(buffer, drawbuffer, data.value());
// clearBufferiv and clearBufferuiv will currently generate an error
// if they're called against the default back buffer. If support for
// extended canvas color spaces is added, this call might need to be
// added to the other versions.
markContextChanged();
updateBuffersToAutoClear(ClearBufferCaller::ClearBufferfv, buffer, drawbuffer);

// This might have been used to clear the color buffer of the default
// back buffer. Notification is required to update the canvas.
markContextChangedAndNotifyCanvasObserver();
}

void WebGL2RenderingContext::clearBufferfi(GCGLenum buffer, GCGLint drawbuffer, GCGLfloat depth, GCGLint stencil)
{
if (isContextLostOrPending())
return;

// Flush any pending implicit clears. This cannot be done after the
// user-requested clearBuffer call because of scissor test side effects.
clearIfComposited(CallerTypeDrawOrClear);

m_context->clearBufferfi(buffer, drawbuffer, depth, stencil);
// This might have been used to clear the depth and stencil buffers
// of the default back buffer.
markContextChanged();
updateBuffersToAutoClear(ClearBufferCaller::ClearBufferfi, buffer, drawbuffer);
}

RefPtr<WebGLQuery> WebGL2RenderingContext::createQuery()

0 comments on commit 11f2fe2

Please sign in to comment.