Skip to content

Commit

Permalink
Cherry-pick 9e5c9ba. rdar://problem/113605412
Browse files Browse the repository at this point in the history
    Cherry-pick 80f6e24. rdar://problem/112743547

        Allocating a new IPC::Semaphore for each RemoteImageBufferProxy::flushDrawingContextAsync adds significant overhead.
        https://bugs.webkit.org/show_bug.cgi?id=259433
        <rdar://112743547>

        Reviewed by Dean Jackson.

        Frequently we have an existing pending flush object, where the semaphore has already been signaled.

        This makes the m_signaled bool atomic, so that we can check for completed flush objects without taking
        the lock and blocking. This will still be false if the existing use of the semaphore hasn't yet been signaled,
        or if the waitFor call failed.

        If we find a completed flush objects, then moves the semaphore across into the new one to prevent a new allocation.

        * Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.cpp:
        (WebKit::RemoteImageBufferProxyFlushFence::tryTakeSemaphore):
        (WebKit::RemoteImageBufferProxy::flushDrawingContextAsync):
        (WebKit::RemoteImageBufferProxyFlushFence::WTF_GUARDED_BY_LOCK): Deleted.

        Canonical link: https://commits.webkit.org/266265@main

Identifier: 265870.266@safari-7616-branch
  • Loading branch information
mattwoodrow authored and MyahCobbs committed Aug 9, 2023
1 parent 5d7fe04 commit 7924fb5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,23 @@ class RemoteImageBufferProxyFlushFence : public ThreadSafeRefCounted<RemoteImage
return m_signaled;
}

std::optional<IPC::Semaphore> tryTakeSemaphore()
{
if (!m_signaled)
return std::nullopt;
Locker locker { m_lock };
return WTFMove(m_semaphore);
}

private:
RemoteImageBufferProxyFlushFence(IPC::Semaphore semaphore)
: m_semaphore(WTFMove(semaphore))
{
tracePoint(FlushRemoteImageBufferStart, reinterpret_cast<uintptr_t>(this));
}
Lock m_lock;
bool m_signaled WTF_GUARDED_BY_LOCK(m_lock) { false };
IPC::Semaphore m_semaphore;
std::atomic<bool> m_signaled { false };
IPC::Semaphore WTF_GUARDED_BY_LOCK(m_lock) m_semaphore;
};

namespace {
Expand Down Expand Up @@ -324,9 +332,13 @@ bool RemoteImageBufferProxy::flushDrawingContextAsync()
return m_pendingFlush;

LOG_WITH_STREAM(SharedDisplayLists, stream << "RemoteImageBufferProxy " << m_renderingResourceIdentifier << " flushDrawingContextAsync");
IPC::Semaphore flushSemaphore;
m_remoteDisplayList.flushContext(flushSemaphore);
m_pendingFlush = RemoteImageBufferProxyFlushFence::create(WTFMove(flushSemaphore));
std::optional<IPC::Semaphore> flushSemaphore;
if (m_pendingFlush)
flushSemaphore = m_pendingFlush->tryTakeSemaphore();
if (!flushSemaphore)
flushSemaphore.emplace();
m_remoteDisplayList.flushContext(*flushSemaphore);
m_pendingFlush = RemoteImageBufferProxyFlushFence::create(WTFMove(*flushSemaphore));
m_needsFlush = false;
return true;
}
Expand Down

0 comments on commit 7924fb5

Please sign in to comment.