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

Changeset 284102 in webkit


Ignore:
Timestamp:
Oct 13, 2021, 10:28:28 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

WebGL video texture upload is very slow due to excessive transfer of the video pixel buffer
https://bugs.webkit.org/show_bug.cgi?id=231425

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-10-13
Reviewed by Youenn Fablet.

Typical WebGL content requests the videos to be uploaded to a texture
once per render loop update, even though the video has not changed.
The video pixel buffer is slow to transfer across IPC. It should be transferred
only when it has changed.

MediaPlayerPrivateAVFoundationObjC and MediaPlayerPrivateMediaSourceAVFObjC hold
the last requested pixel buffer ref. They will update it or discard it only
when pixelBufferForCurrentTime() is called.

Cache the pixel buffer to MediaPlayerPrivateRemote (GPUP side proxy)
Cache the pixel buffer to RemoteMediaPlayerProxy (WebP side proxy)

The caches increase the total memory use only during the duration
of the call, since after the ref has been updated, it refers
to the one always held in the original objects (MediaPlayerPrivateAVFoundationObjC
and MediaPlayerPrivateMediaSourceAVFObjC)

No new tests, fixes a perf regression wrt GPUP media.

  • GPUProcess/media/RemoteMediaPlayerProxy.cpp:

(WebKit::RemoteMediaPlayerProxy::invalidate):

  • GPUProcess/media/RemoteMediaPlayerProxy.h:
  • GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
  • GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm:

(WebKit::RemoteMediaPlayerProxy::nativeImageForCurrentTime):
(WebKit::RemoteMediaPlayerProxy::pixelBufferForCurrentTimeIfChanged):
(WebKit::RemoteMediaPlayerProxy::pixelBufferForCurrentTime): Deleted.

  • WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
  • WebProcess/GPU/media/cocoa/MediaPlayerPrivateRemoteCocoa.mm:

(WebKit::MediaPlayerPrivateRemote::pixelBufferForCurrentTime):

Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r284099 r284102  
     12021-10-13  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        WebGL video texture upload is very slow due to excessive transfer of the video pixel buffer
     4        https://bugs.webkit.org/show_bug.cgi?id=231425
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Typical WebGL content requests the videos to be uploaded to a texture
     9        once per render loop update, even though the video has not changed.
     10        The video pixel buffer is slow to transfer across IPC. It should be transferred
     11        only when it has changed.
     12
     13        MediaPlayerPrivateAVFoundationObjC and MediaPlayerPrivateMediaSourceAVFObjC hold
     14        the last requested pixel buffer ref. They will update it or discard it only
     15        when pixelBufferForCurrentTime() is called.
     16
     17        Cache the pixel buffer to MediaPlayerPrivateRemote (GPUP side proxy)
     18        Cache the pixel buffer to RemoteMediaPlayerProxy (WebP side proxy)
     19
     20        The caches increase the total memory use only during the duration
     21        of the call, since after the ref has been updated, it refers
     22        to the one always held in the original objects (MediaPlayerPrivateAVFoundationObjC
     23        and MediaPlayerPrivateMediaSourceAVFObjC)
     24
     25        No new tests, fixes a perf regression wrt GPUP media.
     26
     27        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
     28        (WebKit::RemoteMediaPlayerProxy::invalidate):
     29        * GPUProcess/media/RemoteMediaPlayerProxy.h:
     30        * GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
     31        * GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm:
     32        (WebKit::RemoteMediaPlayerProxy::nativeImageForCurrentTime):
     33        (WebKit::RemoteMediaPlayerProxy::pixelBufferForCurrentTimeIfChanged):
     34        (WebKit::RemoteMediaPlayerProxy::pixelBufferForCurrentTime): Deleted.
     35        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
     36        * WebProcess/GPU/media/cocoa/MediaPlayerPrivateRemoteCocoa.mm:
     37        (WebKit::MediaPlayerPrivateRemote::pixelBufferForCurrentTime):
     38
    1392021-10-13  Per Arne Vollan <pvollan@apple.com>
    240
  • trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp

    r284080 r284102  
    107107    }
    108108    m_renderingResourcesRequest = { };
     109#if USE(AVFOUNDATION)
     110    m_pixelBufferForCurrentTime = nullptr;
     111#endif
    109112}
    110113
  • trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h

    r283333 r284102  
    315315#endif
    316316#if USE(AVFOUNDATION)
    317     void pixelBufferForCurrentTime(CompletionHandler<void(RetainPtr<CVPixelBufferRef>&&)>&&);
     317    void pixelBufferForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RetainPtr<CVPixelBufferRef>>&&)>&&);
    318318#endif
    319319
     
    370370
    371371    bool m_observingTimeChanges { false };
    372 
     372#if USE(AVFOUNDATION)
     373    RetainPtr<CVPixelBufferRef> m_pixelBufferForCurrentTime;
     374#endif
    373375#if !RELEASE_LOG_DISABLED
    374376    const Logger& m_logger;
  • trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in

    r281227 r284102  
    127127#endif
    128128#if USE(AVFOUNDATION)
    129     PixelBufferForCurrentTime() -> (RetainPtr<CVPixelBufferRef> pixelBuffer) Synchronous
     129    PixelBufferForCurrentTimeIfChanged() -> (std::optional<RetainPtr<CVPixelBufferRef>> pixelBuffer) Synchronous
    130130#endif
    131131
  • trunk/Source/WebKit/GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm

    r280776 r284102  
    112112}
    113113
    114 void RemoteMediaPlayerProxy::pixelBufferForCurrentTime(CompletionHandler<void(RetainPtr<CVPixelBufferRef>&&)>&& completionHandler)
     114#if USE(AVFOUNDATION)
     115void RemoteMediaPlayerProxy::pixelBufferForCurrentTimeIfChanged(CompletionHandler<void(std::optional<RetainPtr<CVPixelBufferRef>>&&)>&& completionHandler)
    115116{
    116     RetainPtr<CVPixelBufferRef> result;
     117    std::optional<RetainPtr<CVPixelBufferRef>> result;
     118    RetainPtr<CVPixelBufferRef> pixelBuffer;
    117119    if (m_player)
    118         result = m_player->pixelBufferForCurrentTime();
     120        pixelBuffer = m_player->pixelBufferForCurrentTime();
     121    if (m_pixelBufferForCurrentTime != pixelBuffer) {
     122        result = pixelBuffer;
     123        m_pixelBufferForCurrentTime = WTFMove(pixelBuffer);
     124    }
    119125    completionHandler(WTFMove(result));
    120126}
     127#endif
    121128
    122129} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h

    r282789 r284102  
    446446    bool m_timeIsProgressing { false };
    447447    bool m_renderingCanBeAccelerated { false };
     448#if USE(AVFOUNDATION)
     449    RetainPtr<CVPixelBufferRef> m_pixelBufferForCurrentTime;
     450#endif
    448451};
    449452
  • trunk/Source/WebKit/WebProcess/GPU/media/cocoa/MediaPlayerPrivateRemoteCocoa.mm

    r281157 r284102  
    6767}
    6868
     69#if USE(AVFOUNDATION)
    6970RetainPtr<CVPixelBufferRef> MediaPlayerPrivateRemote::pixelBufferForCurrentTime()
    7071{
    71 
    72     RetainPtr<CVPixelBufferRef> result;
    73     if (!connection().sendSync(Messages::RemoteMediaPlayerProxy::PixelBufferForCurrentTime(), Messages::RemoteMediaPlayerProxy::PixelBufferForCurrentTime::Reply(result), m_id))
     72    std::optional<RetainPtr<CVPixelBufferRef>> result;
     73    if (!connection().sendSync(Messages::RemoteMediaPlayerProxy::PixelBufferForCurrentTimeIfChanged(), Messages::RemoteMediaPlayerProxy::PixelBufferForCurrentTimeIfChanged::Reply(result), m_id))
    7474        return nullptr;
    75     return result;
     75    if (result)
     76        m_pixelBufferForCurrentTime = WTFMove(*result);
     77    return m_pixelBufferForCurrentTime;
    7678}
     79#endif
    7780
    7881} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.