⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278295 in webkit


Ignore:
Timestamp:
May 31, 2021, 9:52:51 PM (5 years ago)
Author:
dino@apple.com
Message:

[WebXR] Attach IOSurface to WebXROpaqueFramebuffer
https://bugs.webkit.org/show_bug.cgi?id=225896
<rdar://problem/78128289>

Reviewed by Sam Weinig.

Implement binding of incoming IOSurfaces (via FrameData)
into the WebGL framebuffer that the page will use as
a rendering target.

Currently only single-sample (non-antialiased) buffers
are supported and the canvas context must be WebGL 2.

  • Modules/webxr/WebXROpaqueFramebuffer.cpp:

(WebCore::WebXROpaqueFramebuffer::startFrame): Create a texture if necessary, then
bind its backing store to the incoming IOSurface, then hook it up to the framebuffer.
(WebCore::WebXROpaqueFramebuffer::endFrame): Release the Pbuffer we used in startFrame.
(WebCore::WebXROpaqueFramebuffer::setupFramebuffer): Add Cocoa+ANGLE specific implementation.

  • Modules/webxr/WebXROpaqueFramebuffer.h: Keep a member variable for the Pbuffer.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278294 r278295  
     12021-05-31  Dean Jackson  <dino@apple.com>
     2
     3        [WebXR] Attach IOSurface to WebXROpaqueFramebuffer
     4        https://bugs.webkit.org/show_bug.cgi?id=225896
     5        <rdar://problem/78128289>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Implement binding of incoming IOSurfaces (via FrameData)
     10        into the WebGL framebuffer that the page will use as
     11        a rendering target.
     12
     13        Currently only single-sample (non-antialiased) buffers
     14        are supported and the canvas context must be WebGL 2.
     15
     16        * Modules/webxr/WebXROpaqueFramebuffer.cpp:
     17        (WebCore::WebXROpaqueFramebuffer::startFrame): Create a texture if necessary, then
     18        bind its backing store to the incoming IOSurface, then hook it up to the framebuffer.
     19        (WebCore::WebXROpaqueFramebuffer::endFrame): Release the Pbuffer we used in startFrame.
     20        (WebCore::WebXROpaqueFramebuffer::setupFramebuffer): Add Cocoa+ANGLE specific implementation.
     21        * Modules/webxr/WebXROpaqueFramebuffer.h: Keep a member variable for the Pbuffer.
     22
    1232021-05-31  Alan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp

    r278259 r278295  
    5151#include <wtf/Scope.h>
    5252
     53#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
     54#include "ANGLEHeaders.h"
     55#include "GraphicsContextGLOpenGL.h"
     56#endif
     57
    5358namespace WebCore {
    5459
     
    112117
    113118#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
    114     UNUSED_PARAM(data);
     119    auto gCGL = static_cast<GraphicsContextGLOpenGL*>(m_context.graphicsContextGL());
     120    GCGLenum textureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget();
     121
     122    auto size = data.surface->size();
     123
     124    if (!m_opaqueTexture)
     125        m_opaqueTexture = gCGL->createTexture();
     126
     127    gCGL->bindTexture(textureTarget, m_opaqueTexture);
     128    gCGL->texParameteri(textureTarget, GL::TEXTURE_MAG_FILTER, GL::LINEAR);
     129    gCGL->texParameteri(textureTarget, GL::TEXTURE_MIN_FILTER, GL::LINEAR);
     130    gCGL->texParameteri(textureTarget, GL::TEXTURE_WRAP_S, GL::CLAMP_TO_EDGE);
     131    gCGL->texParameteri(textureTarget, GL::TEXTURE_WRAP_T, GL::CLAMP_TO_EDGE);
     132
     133    // Tell the GraphicsContextGL to use the IOSurface as the backing store for m_opaqueTexture.
     134    m_ioSurfaceTextureHandle = gCGL->createPbufferAndAttachIOSurface(textureTarget, GraphicsContextGLOpenGL::PbufferAttachmentUsage::Write, GL::BGRA, size.width(), size.height(), GL::UNSIGNED_BYTE, data.surface->surface(), 0);
     135    if (!m_ioSurfaceTextureHandle && m_opaqueTexture) {
     136        gCGL->deleteTexture(m_opaqueTexture);
     137        return;
     138    }
     139
     140    // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer.
     141
     142    // Now set up the framebuffer to use the textures/renderbuffers we have created.
     143    gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
     144
     145    if (m_attributes.stencil)
     146        gl.framebufferRenderbuffer(GL::FRAMEBUFFER, GL::STENCIL_ATTACHMENT, GL::RENDERBUFFER, m_depthStencilBuffer);
     147    if (m_attributes.depth)
     148        gl.framebufferRenderbuffer(GL::FRAMEBUFFER, GL::DEPTH_ATTACHMENT, GL::RENDERBUFFER, m_depthStencilBuffer);
     149
     150    // At this point the framebuffer should be "complete".
     151    ASSERT(gl.checkFramebufferStatus(GL::FRAMEBUFFER) == GL::FRAMEBUFFER_COMPLETE);
    115152#else
    116153    m_opaqueTexture = data.opaqueTexture;
    117 #endif
    118154
    119155#if USE(OPENGL_ES)
     
    127163    if (!m_multisampleColorBuffer)
    128164        gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
     165#endif
    129166}
    130167
     
    135172    if (!m_context.graphicsContextGL())
    136173        return;
     174
    137175    auto& gl = *m_context.graphicsContextGL();
     176
     177#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
     178    // FIXME: We have to call finish rather than flush because we only want to disconnect
     179    // the IOSurface and signal the DeviceProxy when we know the content has been rendered.
     180    // It might be possible to set this up so the completion of the rendering triggers
     181    // the endFrame call.
     182    gl.finish();
     183
     184    if (m_ioSurfaceTextureHandle) {
     185        auto gCGL = static_cast<GraphicsContextGLOpenGL*>(&gl);
     186        gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle);
     187    }
     188#else
    138189
    139190    if (m_multisampleColorBuffer) {
     
    163214        gl.blitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL::COLOR_BUFFER_BIT, GL::LINEAR);
    164215    }
    165    
     216
    166217    gl.flush();
     218#endif
    167219}
    168220
     
    185237    // Set up color, depth and stencil formats
    186238    bool useDepthStencil = m_attributes.stencil || m_attributes.depth;
    187     auto colorFormat = m_attributes.alpha ? GraphicsContextGL::RGBA8 : GraphicsContextGL::RGB8;
     239    auto colorFormat = m_attributes.alpha ? GL::RGBA8 : GL::RGB8;
    188240#if USE(OPENGL_ES)
    189241    auto& extensions = reinterpret_cast<ExtensionsGLOpenGLES&>(gl.getExtensions());
     
    192244    auto stencilFormat = GL::STENCIL_INDEX8;
    193245#elif USE(ANGLE)
    194     // FIXME: These values were chosen just to get this to compile successfully.
    195     // Make sure they are correct.
    196     bool supportsPackedDepthStencil = false;
     246    bool supportsPackedDepthStencil = true;
    197247    auto depthFormat = supportsPackedDepthStencil ? GL::DEPTH24_STENCIL8 : GL::DEPTH_COMPONENT;
    198248    auto stencilFormat = GL::STENCIL_INDEX8;
     
    209259        GCGLint maxSampleCount;
    210260#if USE(ANGLE)
    211         // FIXME: This probably is not correct.
    212         maxSampleCount = 0;
     261        gl.getIntegerv(GL::MAX_SAMPLES, makeGCGLSpan(&maxSampleCount, 1));
    213262#else
    214263        gl.getIntegerv(ExtensionsGL::MAX_SAMPLES, makeGCGLSpan(&maxSampleCount, 1));
    215264#endif
    216         // Using more than 4 samples might be overhead.
     265        // Cap the maxiumum multisample count at 4. Any more than this is likely overkill and will impact performance.
    217266        m_sampleCount = std::min(4, maxSampleCount);
    218267    }
     
    252301
    253302    if (m_attributes.antialias && m_context.isWebGL2()) {
    254         // Use an extra FBO for multisample if multisampled_render_to_texture is not supported.
    255303        m_resolvedFBO = gl.createFramebuffer();
    256304        m_multisampleColorBuffer = gl.createRenderbuffer();
  • trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h

    r276962 r278295  
    7878    GCGLint m_sampleCount { 0 };
    7979    PlatformGLObject m_opaqueTexture { 0 };
     80#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
     81    void* m_ioSurfaceTextureHandle { nullptr };
     82#endif
    8083};
    8184
Note: See TracChangeset for help on using the changeset viewer.