Title: [282192] trunk
Revision
282192
Author
commit-qu...@webkit.org
Date
2021-09-08 22:27:51 -0700 (Wed, 08 Sep 2021)

Log Message

webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html fails
https://bugs.webkit.org/show_bug.cgi?id=223360
<rdar://problem/75774546>

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2021-09-08
Reviewed by Dean Jackson.

Source/WebCore:

Deleting a buffer will remove the buffer from currently active
vertex array buffer bindings. This worked.
Drawing with a vertex array object that has enabled indexes
but missing buffers for those indexes should fail. This
WebGL specific constraint is checked by ANGLE. However, WebCore
relies on buffer deletion to update the ANGLE VAO. The deletion
does not happen due to the buffers in the test being bound to
multiple VAOs.
Add this check also to WebCore.

Fixed tests:
webgl/1.0.x/conformance/extensions/oes-vertex-array-object.html
webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html

* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::initializeVertexArrayObjects):
(WebCore::WebGL2RenderingContext::drawRangeElements):
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::initializeVertexArrayObjects):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::disableVertexAttribArray):
(WebCore::WebGLRenderingContextBase::validateVertexArrayObject):
(WebCore::WebGLRenderingContextBase::drawArrays):
(WebCore::WebGLRenderingContextBase::drawElements):
(WebCore::WebGLRenderingContextBase::enableVertexAttribArray):
(WebCore::WebGLRenderingContextBase::vertexAttribPointer):
(WebCore::WebGLRenderingContextBase::initVertexAttrib0):
(WebCore::WebGLRenderingContextBase::drawArraysInstanced):
(WebCore::WebGLRenderingContextBase::drawElementsInstanced):
* html/canvas/WebGLRenderingContextBase.h:
* html/canvas/WebGLVertexArrayObjectBase.cpp:
(WebCore::WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase):
(WebCore::WebGLVertexArrayObjectBase::setVertexAttribEnabled):
(WebCore::WebGLVertexArrayObjectBase::setVertexAttribState):
(WebCore::WebGLVertexArrayObjectBase::unbindBuffer):
(WebCore::WebGLVertexArrayObjectBase::updateVertexAttrib0):
(WebCore::WebGLVertexArrayObjectBase::areAllEnabledAttribBuffersBound):
* html/canvas/WebGLVertexArrayObjectBase.h:
(WebCore::WebGLVertexArrayObjectBase::getVertexAttribState):
Make VertexAttribState& a const so that we can maintain confidence
that the cached value of "all enabled attrib buffers are bound"
is maintained, e.g. that the callers cannot modify enabled or bound
buffer status.

LayoutTests:

Test webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html explicitly
until 2.0.y suite is run by default. Same for 1.0.x.

* TestExpectations:
* fast/canvas/webgl/drawElements-empty-vertex-data-expected.txt:
* fast/canvas/webgl/vertexAttribPointer-with-bad-offset-expected.txt:
Add console logs for the added errors.
* platform/ios/TestExpectations:
* platform/mac/TestExpectations:
For consistency, remove all skips for vertex-array-object tests.
They should now work.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282191 => 282192)


--- trunk/LayoutTests/ChangeLog	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/ChangeLog	2021-09-09 05:27:51 UTC (rev 282192)
@@ -1,3 +1,23 @@
+2021-09-08  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html fails
+        https://bugs.webkit.org/show_bug.cgi?id=223360
+        <rdar://problem/75774546>
+
+        Reviewed by Dean Jackson.
+
+        Test webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html explicitly
+        until 2.0.y suite is run by default. Same for 1.0.x.
+
+        * TestExpectations:
+        * fast/canvas/webgl/drawElements-empty-vertex-data-expected.txt:
+        * fast/canvas/webgl/vertexAttribPointer-with-bad-offset-expected.txt:
+        Add console logs for the added errors.
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+        For consistency, remove all skips for vertex-array-object tests.
+        They should now work.
+
 2021-09-08  Arcady Goldmints-Orlov  <agoldmi...@igalia.com>
 
         [GLIB] Unreviewed test gardening. Update some test baselines.

Modified: trunk/LayoutTests/TestExpectations (282191 => 282192)


--- trunk/LayoutTests/TestExpectations	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/TestExpectations	2021-09-09 05:27:51 UTC (rev 282192)
@@ -3691,6 +3691,8 @@
 webgl/2.0.y/conformance/textures/misc/texture-corner-case-videos.html [ Pass ]
 webgl/2.0.y/conformance/glsl/misc/fragcolor-fragdata-invariant.html [ Pass ]
 webgl/2.0.y/conformance2/context/constants-and-properties-2.html [ Pass ]
+webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html [ Pass ]
+webgl/1.0.x/conformance/extensions/oes-vertex-array-object.html [ Pass ]
 
 # WebGL 1.0.3 and 2.0.0 tests where behavior is obsolete and WebKit contains implementation
 # and tests for the new behavior. Should be removed once 1.0.3 and 2.0.0 are retired.

Modified: trunk/LayoutTests/fast/canvas/webgl/drawElements-empty-vertex-data-expected.txt (282191 => 282192)


--- trunk/LayoutTests/fast/canvas/webgl/drawElements-empty-vertex-data-expected.txt	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/fast/canvas/webgl/drawElements-empty-vertex-data-expected.txt	2021-09-09 05:27:51 UTC (rev 282192)
@@ -1 +1,2 @@
+CONSOLE MESSAGE: WebGL: INVALID_OPERATION: drawElements: no buffer is bound to enabled attribute
 PASS: Unable to draw with invalid vertexAttribArray0

Modified: trunk/LayoutTests/fast/canvas/webgl/vertexAttribPointer-with-bad-offset-expected.txt (282191 => 282192)


--- trunk/LayoutTests/fast/canvas/webgl/vertexAttribPointer-with-bad-offset-expected.txt	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/fast/canvas/webgl/vertexAttribPointer-with-bad-offset-expected.txt	2021-09-09 05:27:51 UTC (rev 282192)
@@ -1,3 +1,4 @@
 CONSOLE MESSAGE: WebGL: INVALID_VALUE: vertexAttribPointer: bad offset
+CONSOLE MESSAGE: WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute
 PASS: vertexAttribPointer should have an error.
 

Modified: trunk/LayoutTests/fast/canvas/webgl/webgl-drawarrays-crash-2-expected.txt (282191 => 282192)


--- trunk/LayoutTests/fast/canvas/webgl/webgl-drawarrays-crash-2-expected.txt	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/fast/canvas/webgl/webgl-drawarrays-crash-2-expected.txt	2021-09-09 05:27:51 UTC (rev 282192)
@@ -1,2 +1,3 @@
+CONSOLE MESSAGE: WebGL: INVALID_OPERATION: drawArrays: no buffer is bound to enabled attribute
 PASS. You didn't crash.
 

Modified: trunk/LayoutTests/platform/ios/TestExpectations (282191 => 282192)


--- trunk/LayoutTests/platform/ios/TestExpectations	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2021-09-09 05:27:51 UTC (rev 282192)
@@ -3201,7 +3201,6 @@
 webkit.org/b/207858 webgl/webgl-box-shadow.html [ Pass Failure ImageOnlyFailure ]
 webkit.org/b/207858 fast/canvas/webgl/uninitialized-test.html [ Pass Failure ]
 webkit.org/b/207858 fast/canvas/webgl/oes-texture-float-linear.html [ Pass Failure ]
-webkit.org/b/207858 fast/canvas/webgl/oes-vertex-array-object.html [ Pass Failure ]
 webkit.org/b/207858 fast/canvas/webgl/tex-image-and-sub-image-2d-with-video.html [ Pass Failure ]
 webkit.org/b/207858 webgl/1.0.3/conformance/context/context-lost-restored.html [ Pass Failure ]
 webkit.org/b/207858 webgl/1.0.3/conformance/glsl/misc/shader-struct-scope.html [ Pass Failure ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (282191 => 282192)


--- trunk/LayoutTests/platform/mac/TestExpectations	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2021-09-09 05:27:51 UTC (rev 282192)
@@ -406,9 +406,6 @@
 # Sending the mouse down event to the scrollbar starts a nested run loop which causes a hang.
 fast/events/mousedown-in-subframe-scrollbar.html [ Skip ]
 
-webkit.org/b/96828 fast/canvas/webgl/oes-vertex-array-object.html [ Skip ]
-webkit.org/b/96828 webgl/1.0.3/conformance/extensions/oes-vertex-array-object.html [ Skip ]
-
 http/tests/misc/willCacheResponse-delegate-callback.html [ Failure ]
 http/tests/xmlhttprequest/basic-auth-nopassword.html [ Failure ]
 

Modified: trunk/Source/WebCore/ChangeLog (282191 => 282192)


--- trunk/Source/WebCore/ChangeLog	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/ChangeLog	2021-09-09 05:27:51 UTC (rev 282192)
@@ -1,3 +1,55 @@
+2021-09-08  Kimmo Kinnunen  <kkinnu...@apple.com>
+
+        webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html fails
+        https://bugs.webkit.org/show_bug.cgi?id=223360
+        <rdar://problem/75774546>
+
+        Reviewed by Dean Jackson.
+
+        Deleting a buffer will remove the buffer from currently active
+        vertex array buffer bindings. This worked.
+        Drawing with a vertex array object that has enabled indexes
+        but missing buffers for those indexes should fail. This
+        WebGL specific constraint is checked by ANGLE. However, WebCore
+        relies on buffer deletion to update the ANGLE VAO. The deletion
+        does not happen due to the buffers in the test being bound to
+        multiple VAOs.
+        Add this check also to WebCore.
+
+        Fixed tests:
+        webgl/1.0.x/conformance/extensions/oes-vertex-array-object.html
+        webgl/2.0.y/conformance2/vertex_arrays/vertex-array-object.html
+
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::initializeVertexArrayObjects):
+        (WebCore::WebGL2RenderingContext::drawRangeElements):
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::initializeVertexArrayObjects):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::disableVertexAttribArray):
+        (WebCore::WebGLRenderingContextBase::validateVertexArrayObject):
+        (WebCore::WebGLRenderingContextBase::drawArrays):
+        (WebCore::WebGLRenderingContextBase::drawElements):
+        (WebCore::WebGLRenderingContextBase::enableVertexAttribArray):
+        (WebCore::WebGLRenderingContextBase::vertexAttribPointer):
+        (WebCore::WebGLRenderingContextBase::initVertexAttrib0):
+        (WebCore::WebGLRenderingContextBase::drawArraysInstanced):
+        (WebCore::WebGLRenderingContextBase::drawElementsInstanced):
+        * html/canvas/WebGLRenderingContextBase.h:
+        * html/canvas/WebGLVertexArrayObjectBase.cpp:
+        (WebCore::WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase):
+        (WebCore::WebGLVertexArrayObjectBase::setVertexAttribEnabled):
+        (WebCore::WebGLVertexArrayObjectBase::setVertexAttribState):
+        (WebCore::WebGLVertexArrayObjectBase::unbindBuffer):
+        (WebCore::WebGLVertexArrayObjectBase::updateVertexAttrib0):
+        (WebCore::WebGLVertexArrayObjectBase::areAllEnabledAttribBuffersBound):
+        * html/canvas/WebGLVertexArrayObjectBase.h:
+        (WebCore::WebGLVertexArrayObjectBase::getVertexAttribState):
+        Make VertexAttribState& a const so that we can maintain confidence
+        that the cached value of "all enabled attrib buffers are bound"
+        is maintained, e.g. that the callers cannot modify enabled or bound
+        buffer status.
+
 2021-09-08  Ryosuke Niwa  <rn...@webkit.org>
 
         Deploy CheckedRef on FocusController

Modified: trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2021-09-09 05:27:51 UTC (rev 282192)
@@ -223,6 +223,10 @@
 
 void WebGL2RenderingContext::initializeVertexArrayObjects()
 {
+#if !USE(ANGLE)
+    if (!isGLES2Compliant())
+        initVertexAttrib0();
+#endif
     m_defaultVertexArrayObject = WebGLVertexArrayObject::create(*this, WebGLVertexArrayObject::Type::Default);
     addContextObject(*m_defaultVertexArrayObject);
 #if USE(OPENGL_ES)
@@ -230,10 +234,7 @@
 #else
     bindVertexArray(nullptr); // The default VAO was removed in OpenGL 3.3 but not from WebGL 2; bind the default for WebGL to use.
 #endif
-#if !USE(ANGLE)
-    if (!isGLES2Compliant())
-        initVertexAttrib0();
-#endif
+
 }
 
 void WebGL2RenderingContext::initializeShaderExtensions()
@@ -1797,7 +1798,8 @@
 {
     if (isContextLostOrPending())
         return;
-
+    if (!validateVertexArrayObject("drawRangeElements"))
+        return;
     m_context->drawRangeElements(mode, start, end, count, type, offset);
 }
 

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2021-09-09 05:27:51 UTC (rev 282192)
@@ -124,13 +124,13 @@
 
 void WebGLRenderingContext::initializeVertexArrayObjects()
 {
-    m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(*this, WebGLVertexArrayObjectOES::Type::Default);
-    addContextObject(*m_defaultVertexArrayObject);
-    m_boundVertexArrayObject = m_defaultVertexArrayObject;
 #if !USE(ANGLE)
     if (!isGLES2Compliant())
         initVertexAttrib0();
 #endif
+    m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(*this, WebGLVertexArrayObjectOES::Type::Default);
+    addContextObject(*m_defaultVertexArrayObject);
+    m_boundVertexArrayObject = m_defaultVertexArrayObject;
 }
 
 WebGLExtension* WebGLRenderingContext::getExtension(const String& name)

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-09-09 05:27:51 UTC (rev 282192)
@@ -2337,10 +2337,7 @@
         synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "disableVertexAttribArray", "index out of range");
         return;
     }
-
-    WebGLVertexArrayObjectBase::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(index);
-    state.enabled = false;
-
+    m_boundVertexArrayObject->setVertexAttribEnabled(index, false);
 #if !USE(ANGLE)
     if (index > 0 || isGLES2Compliant())
 #endif
@@ -2359,6 +2356,15 @@
 }
 #endif
 
+bool WebGLRenderingContextBase::validateVertexArrayObject(const char* functionName)
+{
+    if (!m_boundVertexArrayObject->areAllEnabledAttribBuffersBound()) {
+        synthesizeGLError(GraphicsContextGL::INVALID_OPERATION, functionName, "no buffer is bound to enabled attribute");
+        return false;
+    }
+    return true;
+}
+
 bool WebGLRenderingContextBase::validateElementArraySize(GCGLsizei count, GCGLenum type, GCGLintptr offset)
 {
     RefPtr<WebGLBuffer> elementArrayBuffer = m_boundVertexArrayObject->getElementArrayBuffer();
@@ -2700,6 +2706,8 @@
     if (!validateDrawArrays("drawArrays", mode, first, count, 0))
         return;
 #endif
+    if (!validateVertexArrayObject("drawArrays"))
+        return;
 
     if (m_currentProgram && InspectorInstrumentation::isWebGLProgramDisabled(*this, *m_currentProgram))
         return;
@@ -2763,6 +2771,8 @@
     if (!validateDrawElements("drawElements", mode, count, type, offset, numElements, 0))
         return;
 #endif
+    if (!validateVertexArrayObject("drawElements"))
+        return;
 
     if (m_currentProgram && InspectorInstrumentation::isWebGLProgramDisabled(*this, *m_currentProgram))
         return;
@@ -2831,10 +2841,7 @@
         synthesizeGLError(GraphicsContextGL::INVALID_VALUE, "enableVertexAttribArray", "index out of range");
         return;
     }
-
-    WebGLVertexArrayObjectBase::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(index);
-    state.enabled = true;
-
+    m_boundVertexArrayObject->setVertexAttribEnabled(index, true);
     m_context->enableVertexAttribArray(index);
 }
 
@@ -6334,7 +6341,6 @@
         return;
     }
     GCGLsizei bytesPerElement = size * typeSize;
-
     m_boundVertexArrayObject->setVertexAttribState(locker, index, bytesPerElement, size, type, normalized, stride, static_cast<GCGLintptr>(offset), false, m_boundArrayBuffer.get());
     m_context->vertexAttribPointer(index, size, type, normalized, stride, static_cast<GCGLintptr>(offset));
 }
@@ -7537,13 +7543,10 @@
 #if !USE(ANGLE)
 void WebGLRenderingContextBase::initVertexAttrib0()
 {
-    WebGLVertexArrayObjectBase::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(0);
-    
     m_vertexAttrib0Buffer = createBuffer();
     m_context->bindBuffer(GraphicsContextGL::ARRAY_BUFFER, m_vertexAttrib0Buffer->object());
     m_context->bufferData(GraphicsContextGL::ARRAY_BUFFER, 0, GraphicsContextGL::DYNAMIC_DRAW);
     m_context->vertexAttribPointer(0, 4, GraphicsContextGL::FLOAT, false, 0, 0);
-    state.bufferBinding = m_vertexAttrib0Buffer;
     m_context->bindBuffer(GraphicsContextGL::ARRAY_BUFFER, 0);
     m_context->enableVertexAttribArray(0);
     m_vertexAttrib0BufferSize = 0;
@@ -7936,6 +7939,8 @@
     if (!validateDrawArrays("drawArraysInstanced", mode, first, count, primcount))
         return;
 #endif // !USE(ANGLE)
+    if (!validateVertexArrayObject("drawArraysInstanced"))
+        return;
 
     clearIfComposited(ClearCallerDrawOrClear);
 
@@ -7975,6 +7980,8 @@
     if (!validateDrawElements("drawElementsInstanced", mode, count, type, offset, numElements, primcount))
         return;
 #endif // !USE(ANGLE)
+    if (!validateVertexArrayObject("drawElementsInstanced"))
+        return;
 
     clearIfComposited(ClearCallerDrawOrClear);
 

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2021-09-09 05:27:51 UTC (rev 282192)
@@ -512,6 +512,7 @@
     bool validateDrawElements(const char* functionName, GCGLenum mode, GCGLsizei count, GCGLenum type, long long offset, unsigned& numElements, GCGLsizei primcount);
     bool validateNPOTTextureLevel(GCGLsizei width, GCGLsizei height, GCGLint level, const char* functionName);
 #endif
+    bool validateVertexArrayObject(const char* functionName);
 
     // Adds a compressed texture format.
     void addCompressedTextureFormat(GCGLenum);

Modified: trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.cpp (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.cpp	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.cpp	2021-09-09 05:27:51 UTC (rev 282192)
@@ -39,6 +39,9 @@
     , m_type(type)
 {
     m_vertexAttribState.resize(context.getMaxVertexAttribs());
+#if !USE(ANGLE)
+    updateVertexAttrib0();
+#endif
 }
 
 void WebGLVertexArrayObjectBase::setElementArrayBuffer(const AbstractLocker& locker, WebGLBuffer* buffer)
@@ -50,24 +53,36 @@
     m_boundElementArrayBuffer = buffer;
     
 }
+void WebGLVertexArrayObjectBase::setVertexAttribEnabled(int index, bool flag)
+{
+    auto& state = m_vertexAttribState[index];
+    if (state.enabled == flag)
+        return;
+    state.enabled = flag;
+    if (!state.validateBinding())
+        m_allEnabledAttribBuffersBoundCache = false;
+    else
+        m_allEnabledAttribBuffersBoundCache.reset();
+}
 
 void WebGLVertexArrayObjectBase::setVertexAttribState(const AbstractLocker& locker, GCGLuint index, GCGLsizei bytesPerElement, GCGLint size, GCGLenum type, GCGLboolean normalized, GCGLsizei stride, GCGLintptr offset, bool isInteger, WebGLBuffer* buffer)
 {
-    GCGLsizei validatedStride = stride ? stride : bytesPerElement;
-    
     auto& state = m_vertexAttribState[index];
-    
+    bool bindingWasValid = state.validateBinding();
     if (buffer)
         buffer->onAttached();
     if (state.bufferBinding)
         state.bufferBinding->onDetached(locker, context()->graphicsContextGL());
-    
     state.bufferBinding = buffer;
+    if (!state.validateBinding())
+        m_allEnabledAttribBuffersBoundCache = false;
+    else if (!bindingWasValid)
+        m_allEnabledAttribBuffersBoundCache.reset();
     state.bytesPerElement = bytesPerElement;
     state.size = size;
     state.type = type;
     state.normalized = normalized;
-    state.stride = validatedStride;
+    state.stride = stride ? stride : bytesPerElement;
     state.originalStride = stride;
     state.offset = offset;
     state.isInteger = isInteger;
@@ -80,28 +95,37 @@
         m_boundElementArrayBuffer = nullptr;
     }
     
-    for (size_t i = 0; i < m_vertexAttribState.size(); ++i) {
-        auto& state = m_vertexAttribState[i];
+    for (auto& state : m_vertexAttribState) {
         if (state.bufferBinding == &buffer) {
             buffer.onDetached(locker, context()->graphicsContextGL());
-            
+            state.bufferBinding = nullptr;
+            if (!state.validateBinding())
+                m_allEnabledAttribBuffersBoundCache = false;
+        }
+    }
 #if !USE(ANGLE)
-            if (!i && !context()->isGLES2Compliant()) {
-                state.bufferBinding = context()->m_vertexAttrib0Buffer;
-                state.bufferBinding->onAttached();
-                state.bytesPerElement = 0;
-                state.size = 4;
-                state.type = GraphicsContextGL::FLOAT;
-                state.normalized = false;
-                state.stride = 16;
-                state.originalStride = 0;
-                state.offset = 0;
-            } else
+    updateVertexAttrib0();
 #endif
-                state.bufferBinding = nullptr;
-        }
+}
+
+#if !USE(ANGLE)
+void WebGLVertexArrayObjectBase::updateVertexAttrib0()
+{
+    auto& state = m_vertexAttribState[0];
+    if (!state.bufferBinding && !context()->isGLES2Compliant()) {
+        state.bufferBinding = context()->m_vertexAttrib0Buffer;
+        state.bufferBinding->onAttached();
+        state.bytesPerElement = 0;
+        state.size = 4;
+        state.type = GraphicsContextGL::FLOAT;
+        state.normalized = false;
+        state.stride = 16;
+        state.originalStride = 0;
+        state.offset = 0;
+        m_allEnabledAttribBuffersBoundCache.reset();
     }
 }
+#endif
 
 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GCGLuint index, GCGLuint divisor)
 {
@@ -115,6 +139,20 @@
         visitor.addOpaqueRoot(state.bufferBinding.get());
 }
 
+bool WebGLVertexArrayObjectBase::areAllEnabledAttribBuffersBound()
+{
+    if (!m_allEnabledAttribBuffersBoundCache) {
+        m_allEnabledAttribBuffersBoundCache = [&] {
+            for (auto const& state : m_vertexAttribState) {
+                if (!state.validateBinding())
+                    return false;
+            }
+            return true;
+        }();
+    }
+    return *m_allEnabledAttribBuffersBoundCache;
 }
 
+}
+
 #endif // ENABLE(WEBGL)

Modified: trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.h (282191 => 282192)


--- trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.h	2021-09-09 04:37:45 UTC (rev 282191)
+++ trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.h	2021-09-09 05:27:51 UTC (rev 282192)
@@ -30,6 +30,7 @@
 #include "GraphicsContextGL.h"
 #include "WebGLBuffer.h"
 #include "WebGLContextObject.h"
+#include <optional>
 
 namespace JSC {
 class AbstractSlotVisitor;
@@ -71,7 +72,8 @@
     WebGLBuffer* getElementArrayBuffer() const { return m_boundElementArrayBuffer.get(); }
     void setElementArrayBuffer(const WTF::AbstractLocker&, WebGLBuffer*);
 
-    VertexAttribState& getVertexAttribState(int index) { return m_vertexAttribState[index]; }
+    void setVertexAttribEnabled(int index, bool flag);
+    const VertexAttribState& getVertexAttribState(int index) { return m_vertexAttribState[index]; }
     void setVertexAttribState(const WTF::AbstractLocker&, GCGLuint, GCGLsizei, GCGLint, GCGLenum, GCGLboolean, GCGLsizei, GCGLintptr, bool, WebGLBuffer*);
     void unbindBuffer(const WTF::AbstractLocker&, WebGLBuffer&);
 
@@ -79,14 +81,19 @@
 
     void addMembersToOpaqueRoots(const WTF::AbstractLocker&, JSC::AbstractSlotVisitor&);
 
+    bool areAllEnabledAttribBuffersBound();
 protected:
     WebGLVertexArrayObjectBase(WebGLRenderingContextBase&, Type);
     void deleteObjectImpl(const WTF::AbstractLocker&, GraphicsContextGL*, PlatformGLObject) override = 0;
+#if !USE(ANGLE)
+    void updateVertexAttrib0();
+#endif
 
     Type m_type;
     bool m_hasEverBeenBound { false };
     RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
     Vector<VertexAttribState> m_vertexAttribState;
+    std::optional<bool> m_allEnabledAttribBuffersBoundCache;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to