Title: [284650] trunk/Source/WebCore
Revision
284650
Author
d...@apple.com
Date
2021-10-21 15:35:59 -0700 (Thu, 21 Oct 2021)

Log Message

[WebXR] WebXR on Cocoa doesn't work with multisampled contexts
https://bugs.webkit.org/show_bug.cgi?id=226687
<rdar://problem/78910868>

Reviewed by Tim Horton.

If the WebXR session requested an anti-aliased context, we'd
end up with an incomplete framebuffer because we were never
initialising the multisample buffers. This would assert on
debug builds and produce no output on release builds.

Fix this by initialising the multisample buffers, ensuring
we're targeting them in startFrame, and do the resolution
in endFrame.

* Modules/webxr/WebXROpaqueFramebuffer.cpp:
(WebCore::WebXROpaqueFramebuffer::startFrame):
(WebCore::WebXROpaqueFramebuffer::endFrame): While here, use NEAREST
sampling on the multisample resolution, the way we do in WebGL.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (284649 => 284650)


--- trunk/Source/WebCore/ChangeLog	2021-10-21 22:28:30 UTC (rev 284649)
+++ trunk/Source/WebCore/ChangeLog	2021-10-21 22:35:59 UTC (rev 284650)
@@ -1,3 +1,25 @@
+2021-10-21  Dean Jackson  <d...@apple.com>
+
+        [WebXR] WebXR on Cocoa doesn't work with multisampled contexts
+        https://bugs.webkit.org/show_bug.cgi?id=226687
+        <rdar://problem/78910868>
+
+        Reviewed by Tim Horton.
+
+        If the WebXR session requested an anti-aliased context, we'd
+        end up with an incomplete framebuffer because we were never
+        initialising the multisample buffers. This would assert on
+        debug builds and produce no output on release builds.
+
+        Fix this by initialising the multisample buffers, ensuring
+        we're targeting them in startFrame, and do the resolution
+        in endFrame.
+
+        * Modules/webxr/WebXROpaqueFramebuffer.cpp:
+        (WebCore::WebXROpaqueFramebuffer::startFrame):
+        (WebCore::WebXROpaqueFramebuffer::endFrame): While here, use NEAREST
+        sampling on the multisample resolution, the way we do in WebGL.
+
 2021-10-21  Rob Buis  <rb...@igalia.com>
 
         [css-contain] Support contain:style for counters

Modified: trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp (284649 => 284650)


--- trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp	2021-10-21 22:28:30 UTC (rev 284649)
+++ trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp	2021-10-21 22:35:59 UTC (rev 284650)
@@ -125,7 +125,6 @@
     auto gCGL = static_cast<GraphicsContextGLOpenGL*>(m_context.graphicsContextGL());
     GCGLenum textureTarget = gCGL->drawingBufferTextureTarget();
 
-
     if (!m_opaqueTexture)
         m_opaqueTexture = gCGL->createTexture();
 
@@ -157,14 +156,15 @@
         return;
     }
 
-    // Now set up the framebuffer to use the texture that points to the IOSurface. The depth and
-    // stencil buffers were attached by startFrame.
-    gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
+    // If we're not multisampling, set up the framebuffer to use the texture that points to the IOSurface. The depth and
+    // stencil buffers were attached by setupFramebuffer. If we are multisampling, the framebuffer was initialized in setupFramebuffer,
+    // and we'll resolve into the m_opaqueTexture in endFrame.
+    if (!m_multisampleColorBuffer)
+        gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
 
-    // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer.
-
     // At this point the framebuffer should be "complete".
     ASSERT(gl.checkFramebufferStatus(GL::FRAMEBUFFER) == GL::FRAMEBUFFER_COMPLETE);
+
 #else
     m_opaqueTexture = data.opaqueTexture;
 
@@ -190,28 +190,6 @@
 
     auto& gl = *m_context.graphicsContextGL();
 
-#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
-    // FIXME: We have to call finish rather than flush because we only want to disconnect
-    // the IOSurface and signal the DeviceProxy when we know the content has been rendered.
-    // It might be possible to set this up so the completion of the rendering triggers
-    // the endFrame call.
-    gl.finish();
-
-    if (m_ioSurfaceTextureHandle) {
-        auto gCGL = static_cast<GraphicsContextGLOpenGL*>(&gl);
-        if (m_ioSurfaceTextureHandleIsShared) {
-#if !PLATFORM(IOS_FAMILY_SIMULATOR)
-            gCGL->detachIOSurfaceFromSharedTexture(m_ioSurfaceTextureHandle);
-#else
-            ASSERT_NOT_REACHED();
-#endif
-        } else
-            gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle);
-        m_ioSurfaceTextureHandle = nullptr;
-        m_ioSurfaceTextureHandleIsShared = false;
-    }
-#else
-
     if (m_multisampleColorBuffer) {
 #if !USE(ANGLE)
         // FIXME: These may be needed when using ANGLE, but it didn't compile in the initial implementation.
@@ -234,13 +212,31 @@
         gl.bindFramebuffer(GL::DRAW_FRAMEBUFFER, m_resolvedFBO);
         gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
 
-        // Resolve multisample framebuffer
         gl.bindFramebuffer(GL::READ_FRAMEBUFFER, m_framebuffer->object());
-        gl.blitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL::COLOR_BUFFER_BIT, GL::LINEAR);
+        gl.blitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL::COLOR_BUFFER_BIT, GL::NEAREST);
     }
 
-    gl.flush();
+    // FIXME: We have to call finish rather than flush because we only want to disconnect
+    // the IOSurface and signal the DeviceProxy when we know the content has been rendered.
+    // It might be possible to set this up so the completion of the rendering triggers
+    // the endFrame call.
+    gl.finish();
+
+#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
+    if (m_ioSurfaceTextureHandle) {
+        auto gCGL = static_cast<GraphicsContextGLOpenGL*>(&gl);
+        if (m_ioSurfaceTextureHandleIsShared) {
+#if !PLATFORM(IOS_FAMILY_SIMULATOR)
+            gCGL->detachIOSurfaceFromSharedTexture(m_ioSurfaceTextureHandle);
+#else
+            ASSERT_NOT_REACHED();
 #endif
+        } else
+            gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle);
+        m_ioSurfaceTextureHandle = nullptr;
+        m_ioSurfaceTextureHandleIsShared = false;
+    }
+#endif
 }
 
 bool WebXROpaqueFramebuffer::setupFramebuffer()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to