From 8025107d2885c33e99c72a1117f1438265ee721c Mon Sep 17 00:00:00 2001 From: Ada Chan Date: Fri, 22 Mar 2024 15:28:54 -0700 Subject: [PATCH] Add tracepoints around WebXR frame rendering https://bugs.webkit.org/show_bug.cgi?id=271474 rdar://125215811 Reviewed by Kimmo Kinnunen. * Source/WTF/wtf/SystemTracing.h: * Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp: (WebCore::WebXROpaqueFramebuffer::startFrame): (WebCore::WebXROpaqueFramebuffer::endFrame): * Source/WebCore/Modules/webxr/WebXRSession.cpp: (WebCore::WebXRSession::onFrame): * Source/WebKit/Resources/Signposts/SystemTracePoints.plist: Canonical link: https://commits.webkit.org/276571@main --- Source/WTF/wtf/SystemTracing.h | 12 ++++ .../Modules/webxr/WebXROpaqueFramebuffer.cpp | 11 +++ Source/WebCore/Modules/webxr/WebXRSession.cpp | 4 ++ .../Signposts/SystemTracePoints.plist | 72 +++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/Source/WTF/wtf/SystemTracing.h b/Source/WTF/wtf/SystemTracing.h index 25206bcc6814..5fa61b1a6422 100644 --- a/Source/WTF/wtf/SystemTracing.h +++ b/Source/WTF/wtf/SystemTracing.h @@ -109,6 +109,12 @@ enum TracePointCode { RenderTreeLayoutEnd, PerformOpportunisticallyScheduledTasksStart, PerformOpportunisticallyScheduledTasksEnd, + WebXRLayerStartFrameStart, + WebXRLayerStartFrameEnd, + WebXRLayerEndFrameStart, + WebXRLayerEndFrameEnd, + WebXRSessionFrameCallbacksStart, + WebXRSessionFrameCallbacksEnd, WebKitRange = 10000, WebHTMLViewPaintStart, @@ -151,6 +157,12 @@ enum TracePointCode { ProcessLaunchEnd, InitializeSandboxStart, InitializeSandboxEnd, + WebXRCPFrameWaitStart, + WebXRCPFrameWaitEnd, + WebXRCPFrameStartSubmissionStart, + WebXRCPFrameStartSubmissionEnd, + WebXRCPFrameEndSubmissionStart, + WebXRCPFrameEndSubmissionEnd, GPUProcessRange = 16000, WakeUpAndApplyDisplayListStart, diff --git a/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp b/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp index cd56ab5a177d..e9a79654bd0b 100644 --- a/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp +++ b/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp @@ -36,6 +36,7 @@ #include "WebGLRenderingContextBase.h" #include "WebGLUtilities.h" #include +#include #if PLATFORM(COCOA) #include "GraphicsContextGLCocoa.h" @@ -134,6 +135,11 @@ void WebXROpaqueFramebuffer::startFrame(const PlatformXR::FrameData::LayerData& if (!gl) return; + tracePoint(WebXRLayerStartFrameStart); + auto scopeExit = makeScopeExit([&]() { + tracePoint(WebXRLayerStartFrameEnd); + }); + auto [textureTarget, textureTargetBinding] = gl->externalImageTextureBindingPoint(); ScopedWebGLRestoreFramebuffer restoreFramebuffer { m_context }; @@ -206,6 +212,11 @@ void WebXROpaqueFramebuffer::endFrame() if (!gl) return; + tracePoint(WebXRLayerEndFrameStart); + auto scopeExit = makeScopeExit([&]() { + tracePoint(WebXRLayerEndFrameEnd); + }); + if (m_multisampleColorBuffer) { ScopedWebGLRestoreFramebuffer restoreFramebuffer { m_context }; diff --git a/Source/WebCore/Modules/webxr/WebXRSession.cpp b/Source/WebCore/Modules/webxr/WebXRSession.cpp index 155f6905c76b..f114e147b7cd 100644 --- a/Source/WebCore/Modules/webxr/WebXRSession.cpp +++ b/Source/WebCore/Modules/webxr/WebXRSession.cpp @@ -44,6 +44,7 @@ #include "XRSessionEvent.h" #include #include +#include namespace WebCore { @@ -600,6 +601,7 @@ void WebXRSession::onFrame(PlatformXR::FrameData&& frameData) if (m_inputInitialized) m_inputSources->update(now, m_frameData.inputSources); + tracePoint(WebXRSessionFrameCallbacksStart); // 6.5.For each entry in session’s list of currently running animation frame callbacks, in order: for (auto& callback : callbacks) { // 6.6.If the entry’s cancelled boolean is true, continue to the next entry. @@ -611,6 +613,8 @@ void WebXRSession::onFrame(PlatformXR::FrameData&& frameData) // 6.8.If an exception is thrown, report the exception. } + tracePoint(WebXRSessionFrameCallbacksEnd); + // 6.9.Set session’s list of currently running animation frame callbacks to the empty list. m_callbacks.removeAllMatching([](auto& callback) { return callback->isFiredOrCancelled(); diff --git a/Source/WebKit/Resources/Signposts/SystemTracePoints.plist b/Source/WebKit/Resources/Signposts/SystemTracePoints.plist index dfa02745df8a..7b7eceff1abc 100644 --- a/Source/WebKit/Resources/Signposts/SystemTracePoints.plist +++ b/Source/WebKit/Resources/Signposts/SystemTracePoints.plist @@ -488,6 +488,42 @@ UInt64 + + Name + WebXR layer start frame + Type + Interval + Component + 47 + CodeBegin + 5049 + CodeEnd + 5050 + + + Name + WebXR layer end frame + Type + Interval + Component + 47 + CodeBegin + 5051 + CodeEnd + 5052 + + + Name + WebXR frame render callbacks + Type + Interval + Component + 47 + CodeBegin + 5053 + CodeEnd + 5054 + Name Paint WebHTMLView @@ -811,6 +847,42 @@ CodeEnd 14006 + + Name + WebXR Compositor wait for frame + Type + Interval + Component + 47 + CodeBegin + 14007 + CodeEnd + 14008 + + + Name + WebXR Compositor start submission for frame + Type + Interval + Component + 47 + CodeBegin + 14009 + CodeEnd + 14010 + + + Name + WebXR Compositor end submission for frame + Type + Interval + Component + 47 + CodeBegin + 14011 + CodeEnd + 14012 + Name Wake up and apply display list