Changeset 279298 in webkit
- Timestamp:
- Jun 25, 2021, 3:06:49 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
-
ChangeLog (modified) (1 diff)
-
Modules/webxr/WebXROpaqueFramebuffer.cpp (modified) (3 diffs)
-
Modules/webxr/WebXROpaqueFramebuffer.h (modified) (1 diff)
-
PAL/ChangeLog (modified) (1 diff)
-
PAL/pal/spi/cocoa/MetalSPI.h (modified) (3 diffs)
-
platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (modified) (2 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGL.h (modified) (1 diff)
-
platform/xr/PlatformXR.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r279296 r279298 1 2021-06-22 Dean Jackson <dino@apple.com> 2 3 Add support for MTLSharedTextures in WebXR 4 https://bugs.webkit.org/show_bug.cgi?id=227245 5 <rdar://problem/79591620> 6 7 Reviewed by Tim Horton. 8 9 Sometimes, the IOSurface passed to WebXR come from a shared MTLTexture. In 10 this case we can't treat the IOSurface data as a regular single-plane 11 image. Instead we should use it to recreate the MTLTexture and then 12 bind that to WebGL's framebuffer. 13 14 * Modules/webxr/WebXROpaqueFramebuffer.cpp: Use some new binding methods on GraphicsContextGLOpenGL 15 if given a shared texture. 16 (WebCore::WebXROpaqueFramebuffer::startFrame): 17 (WebCore::WebXROpaqueFramebuffer::endFrame): 18 * Modules/webxr/WebXROpaqueFramebuffer.h: 19 * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm: New methods to link an 20 IOSurface to a GL texture, going through a MTLSharedTexture. 21 (WebCore::GraphicsContextGLOpenGL::attachIOSurfaceToSharedTexture): 22 (WebCore::GraphicsContextGLOpenGL::detachIOSurfaceFromSharedTexture): 23 * platform/graphics/opengl/GraphicsContextGLOpenGL.h: 24 * platform/xr/PlatformXR.h: Add a new "isShared" member to LayerData 25 to differentiate between normal IOSurfaces and those that came 26 from a shared texture. 27 (PlatformXR::Device::FrameData::LayerData::encode const): 28 (PlatformXR::Device::FrameData::LayerData::decode): 29 1 30 2021-06-25 Alex Christensen <achristensen@webkit.org> 2 31 -
trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp
r278528 r279298 126 126 GCGLenum textureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget(); 127 127 128 auto size = data.surface->size();129 if (!size.width() || !size.height())130 return;131 128 132 129 if (!m_opaqueTexture) … … 140 137 141 138 // Tell the GraphicsContextGL to use the IOSurface as the backing store for m_opaqueTexture. 142 m_ioSurfaceTextureHandle = gCGL->createPbufferAndAttachIOSurface(textureTarget, GraphicsContextGLOpenGL::PbufferAttachmentUsage::Write, GL::BGRA, size.width(), size.height(), GL::UNSIGNED_BYTE, data.surface->surface(), 0); 143 if (!m_ioSurfaceTextureHandle && m_opaqueTexture) { 139 if (data.isShared) { 140 m_ioSurfaceTextureHandle = gCGL->attachIOSurfaceToSharedTexture(textureTarget, data.surface.get()); 141 m_ioSurfaceTextureHandleIsShared = true; 142 } else { 143 auto size = data.surface->size(); 144 if (!size.width() || !size.height()) 145 return; 146 m_ioSurfaceTextureHandle = gCGL->createPbufferAndAttachIOSurface(textureTarget, GraphicsContextGLOpenGL::PbufferAttachmentUsage::Write, GL::BGRA, size.width(), size.height(), GL::UNSIGNED_BYTE, data.surface->surface(), 0); 147 m_ioSurfaceTextureHandleIsShared = false; 148 } 149 150 if (!m_ioSurfaceTextureHandle) { 144 151 gCGL->deleteTexture(m_opaqueTexture); 152 m_opaqueTexture = 0; 145 153 return; 146 154 } 147 148 // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer.149 155 150 156 // Now set up the framebuffer to use the texture that points to the IOSurface. The depth and 151 157 // stencil buffers were attached by startFrame. 152 158 gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0); 159 160 // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer. 153 161 154 162 // At this point the framebuffer should be "complete". … … 188 196 if (m_ioSurfaceTextureHandle) { 189 197 auto gCGL = static_cast<GraphicsContextGLOpenGL*>(&gl); 190 gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle); 198 if (m_ioSurfaceTextureHandleIsShared) 199 gCGL->detachIOSurfaceFromSharedTexture(m_ioSurfaceTextureHandle); 200 else 201 gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle); 202 m_ioSurfaceTextureHandle = nullptr; 203 m_ioSurfaceTextureHandleIsShared = false; 191 204 } 192 205 #else -
trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h
r278295 r279298 80 80 #if USE(IOSURFACE_FOR_XR_LAYER_DATA) 81 81 void* m_ioSurfaceTextureHandle { nullptr }; 82 bool m_ioSurfaceTextureHandleIsShared { false }; 82 83 #endif 83 84 }; -
trunk/Source/WebCore/PAL/ChangeLog
r279290 r279298 1 2021-06-22 Dean Jackson <dino@apple.com> 2 3 Add support for MTLSharedTextures in WebXR 4 https://bugs.webkit.org/show_bug.cgi?id=227245 5 <rdar://problem/79591620> 6 7 Reviewed by Tim Horton. 8 9 Define MTLSharedTextureHandle's initWithIOSurface. 10 11 * pal/spi/cocoa/MetalSPI.h: 12 1 13 2021-06-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 14 -
trunk/Source/WebCore/PAL/pal/spi/cocoa/MetalSPI.h
r275403 r279298 26 26 #if USE(APPLE_INTERNAL_SDK) 27 27 28 #import <Metal/MTLTexture_Private.h> 28 29 #import <Metal/MetalPrivate.h> 29 30 … … 31 32 32 33 #import <Foundation/NSObject.h> 34 35 typedef struct __IOSurface *IOSurfaceRef; 33 36 34 37 @protocol MTLDeviceSPI <MTLDevice> … … 42 45 @end 43 46 47 @interface MTLSharedTextureHandle(Private) 48 - (instancetype)initWithIOSurface:(IOSurfaceRef)ioSurface label:(NSString*)label; 49 @end 50 44 51 #endif -
trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm
r279172 r279298 38 38 #import <CoreGraphics/CGBitmapContext.h> 39 39 #import <Metal/Metal.h> 40 #import <pal/spi/cocoa/MetalSPI.h> 40 41 #import <wtf/BlockObjCExceptions.h> 41 42 #import <wtf/darwin/WeakLinking.h> … … 685 686 } 686 687 688 void* GraphicsContextGLOpenGL::attachIOSurfaceToSharedTexture(GCGLenum target, IOSurface* surface) 689 { 690 constexpr EGLint emptyAttributes[] = { EGL_NONE }; 691 692 // Create a MTLTexture out of the IOSurface. 693 // FIXME: We need to use the same device that ANGLE is using, which might not be the default. 694 695 RetainPtr<MTLSharedTextureHandle> handle = adoptNS([[MTLSharedTextureHandle alloc] initWithIOSurface:surface->surface() label:@"WebXR"]); 696 if (!handle) { 697 LOG(WebGL, "Unable to create a MTLSharedTextureHandle from the IOSurface in attachIOSurfaceToTexture."); 698 return nullptr; 699 } 700 701 if (!handle.get().device) { 702 LOG(WebGL, "MTLSharedTextureHandle does not have a Metal device in attachIOSurfaceToTexture."); 703 return nullptr; 704 } 705 706 auto texture = adoptNS([handle.get().device newSharedTextureWithHandle:handle.get()]); 707 if (!texture) { 708 LOG(WebGL, "Unable to create a MTLSharedTexture from the texture handle in attachIOSurfaceToTexture."); 709 return nullptr; 710 } 711 712 // FIXME: Does the texture have the correct usage mode? 713 714 // Create an EGLImage out of the MTLTexture 715 auto display = platformDisplay(); 716 auto eglImage = EGL_CreateImageKHR(display, EGL_NO_CONTEXT, EGL_METAL_TEXTURE_ANGLE, reinterpret_cast<EGLClientBuffer>(texture.get()), emptyAttributes); 717 if (!eglImage) { 718 LOG(WebGL, "Unable to create an EGLImage from the Metal handle in attachIOSurfaceToTexture."); 719 return nullptr; 720 } 721 722 // Tell the currently bound texture to use the EGLImage. 723 gl::EGLImageTargetTexture2DOES(target, eglImage); 724 725 return eglImage; 726 } 727 728 void GraphicsContextGLOpenGL::detachIOSurfaceFromSharedTexture(void* handle) 729 { 730 auto display = platformDisplay(); 731 EGL_DestroyImageKHR(display, handle); 732 } 687 733 688 734 bool GraphicsContextGLOpenGL::isGLES2Compliant() const -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r279172 r279298 537 537 void* createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef, GCGLuint plane); 538 538 void destroyPbufferAndDetachIOSurface(void* handle); 539 void* attachIOSurfaceToSharedTexture(GCGLenum target, IOSurface*); 540 void detachIOSurfaceFromSharedTexture(void* handle); 539 541 #endif 540 542 -
trunk/Source/WebCore/platform/xr/PlatformXR.h
r278789 r279298 174 174 #if USE(IOSURFACE_FOR_XR_LAYER_DATA) 175 175 std::unique_ptr<WebCore::IOSurface> surface; 176 bool isShared { false }; 176 177 #else 177 178 PlatformGLObject opaqueTexture { 0 }; … … 443 444 WTF::MachSendRight surfaceSendRight = surface ? surface->createSendRight() : WTF::MachSendRight(); 444 445 encoder << surfaceSendRight; 446 encoder << isShared; 445 447 #else 446 448 encoder << opaqueTexture; … … 457 459 return std::nullopt; 458 460 layerData.surface = WebCore::IOSurface::createFromSendRight(WTFMove(surfaceSendRight), WebCore::DestinationColorSpace::SRGB()); 461 if (!decoder.decode(layerData.isShared)) 462 return std::nullopt; 459 463 #else 460 464 if (!decoder.decode(layerData.opaqueTexture))
Note:
See TracChangeset
for help on using the changeset viewer.