Bug 218185 - WebGL2 clearBuffer results are lost if drawing buffer is pending a clear in certain cases
Summary: WebGL2 clearBuffer results are lost if drawing buffer is pending a clear in c...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on: 241765
Blocks:
  Show dependency treegraph
 
Reported: 2020-10-26 06:30 PDT by Kimmo Kinnunen
Modified: 2022-06-20 12:23 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2020-10-26 06:30:55 PDT
WebGL2 clearBuffer results are lost if drawing buffer is pending a clear in certain cases

1) Drawing buffer is prepared for display
2) clearBuffer is called
3) ..before drawing buffer is cleared
4) ..while having clip
5) will just run the clearBuffer

Instead, the pending clear should be flushed and then the clearBuffer should be done.
Comment 1 Radar WebKit Bug Importer 2020-11-02 05:31:16 PST
<rdar://problem/70946707>
Comment 2 Kenneth Russell 2020-11-18 12:10:08 PST
Thanks for reporting Kimmo. Do you have a test case for this? (Which clip do you mean? Scissor rectangle set?)
Comment 3 Kimmo Kinnunen 2020-11-18 23:51:51 PST
Yeah, scissor enable.

void WebGL2RenderingContext::clearBufferiv(GCGLenum buffer, GCGLint drawbuffer, Int32List&& values, GCGLuint srcOffset)
{
    if (isContextLostOrPending() || !validateClearBuffer("clearBufferiv", buffer, values.length(), srcOffset))
        return;

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



void WebGL2RenderingContext::updateBuffersToAutoClear(ClearBufferCaller caller, GCGLenum buffer, GCGLint drawbuffer)
{
    // This method makes sure that we don't auto-clear any buffers which the
    // user has manually cleared using the new ES 3.0 clearBuffer* APIs.

    // If the user has a framebuffer bound, don't update the auto-clear
    // state of the built-in back buffer.
    if (m_framebufferBinding)
        return;

    // If the scissor test is on, assume that we can't short-circuit
    // these clears.
    if (m_scissorEnabled)
        return;
Comment 4 Kenneth Russell 2020-11-20 16:55:20 PST
Thanks. Yes, it looks like there's a problem as you describe.

Would you be willing to try writing a test case for this? It could be modeled after https://github.com/KhronosGroup/WebGL/blob/master/sdk/tests/conformance2/rendering/rasterizer-discard-and-implicit-clear.html . Suggestion:

- Use setupQuad to set up a small quad (maybe scale 0.1)

In requestAnimationFrame:
- Enable scissor test (but have the scissor rect cover the entire canvas)
- Use clearBufferiv to clear the color buffer to green
- Draw the scaled quad in green
- Assert the canvas is fully green (with the bug, the surrounding region of the quad will be black)