Skip to content

Commit 4189fbb

Browse files
DjuffinAngle LUCI CQ
authored andcommitted
Implement EGL_ANDROID_presentation_time for Vulkan backend
The implementation leverages the VK_GOOGLE_display_timing Vulkan extension. Bug: chromium:434977616 Bug: angleproject:42261214 Change-Id: I7e6c64eca6c01e7eb79d41dc5ef63311a7792e2b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6799254 Reviewed-by: Shahbaz Youssefi <[email protected]> Reviewed-by: Cody Northrop <[email protected]> Commit-Queue: Shahbaz Youssefi <[email protected]>
1 parent b84c764 commit 4189fbb

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/libANGLE/renderer/vulkan/DisplayVk.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ void DisplayVk::generateExtensions(egl::DisplayExtensions *outExtensions) const
573573

574574
outExtensions->bufferAgeEXT = true;
575575

576+
outExtensions->presentationTime = getFeatures().supportsTimestampSurfaceAttribute.enabled;
576577
outExtensions->protectedContentEXT = (getFeatures().supportsProtectedMemory.enabled &&
577578
getFeatures().supportsSurfaceProtectedSwapchains.enabled);
578579

src/libANGLE/renderer/vulkan/SurfaceVk.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, EGLNativ
10321032
mDepthStencilImageBinding(this, kAnySurfaceImageSubjectIndex),
10331033
mColorImageMSBinding(this, kAnySurfaceImageSubjectIndex),
10341034
mFrameCount(1),
1035+
mPresentID(0),
10351036
mBufferAgeQueryFrameNumber(0)
10361037
{
10371038
// Initialize the color render target with the multisampled targets. If not multisampled, the
@@ -2618,6 +2619,23 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk,
26182619
.image->getAcquireNextImageSemaphore()
26192620
.valid());
26202621

2622+
// EGL_ANDROID_presentation_time: set the desired presentation time for the frame.
2623+
VkPresentTimesInfoGOOGLE presentTimesInfo = {};
2624+
VkPresentTimeGOOGLE presentTime = {};
2625+
if (mDesiredPresentTime.has_value())
2626+
{
2627+
ASSERT(contextVk->getFeatures().supportsTimestampSurfaceAttribute.enabled);
2628+
presentTime.presentID = mPresentID++;
2629+
presentTime.desiredPresentTime = mDesiredPresentTime.value();
2630+
mDesiredPresentTime.reset();
2631+
2632+
presentTimesInfo.sType = VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE;
2633+
presentTimesInfo.swapchainCount = 1;
2634+
presentTimesInfo.pTimes = &presentTime;
2635+
2636+
vk::AddToPNextChain(&presentInfo, &presentTimesInfo);
2637+
}
2638+
26212639
VkResult presentResult =
26222640
renderer->queuePresent(contextVk, contextVk->getPriority(), presentInfo);
26232641

@@ -2835,6 +2853,12 @@ void WindowSurfaceVk::setTimestampsEnabled(bool enabled)
28352853
ASSERT(IsAndroid());
28362854
}
28372855

2856+
egl::Error WindowSurfaceVk::setPresentationTime(EGLnsecsANDROID time)
2857+
{
2858+
mDesiredPresentTime = time;
2859+
return egl::NoError();
2860+
}
2861+
28382862
void WindowSurfaceVk::deferAcquireNextImage()
28392863
{
28402864
ASSERT(mAcquireOperation.state == ImageAcquireState::Ready);

src/libANGLE/renderer/vulkan/SurfaceVk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef LIBANGLE_RENDERER_VULKAN_SURFACEVK_H_
1111
#define LIBANGLE_RENDERER_VULKAN_SURFACEVK_H_
1212

13+
#include <optional>
1314
#include "common/CircularBuffer.h"
1415
#include "common/SimpleMutex.h"
1516
#include "common/vulkan/vk_headers.h"
@@ -368,6 +369,7 @@ class WindowSurfaceVk : public SurfaceVk
368369
bool hasStagedUpdates() const;
369370

370371
void setTimestampsEnabled(bool enabled) override;
372+
egl::Error setPresentationTime(EGLnsecsANDROID time) override;
371373

372374
egl::Error getCompressionRate(const egl::Display *display,
373375
const gl::Context *context,
@@ -549,6 +551,10 @@ class WindowSurfaceVk : public SurfaceVk
549551

550552
// EGL_EXT_buffer_age: Track frame count.
551553
uint64_t mFrameCount;
554+
// EGL_ANDROID_presentation_time: Next frame's id and presentation time
555+
// used for VK_GOOGLE_display_timing.
556+
uint32_t mPresentID;
557+
std::optional<EGLnsecsANDROID> mDesiredPresentTime;
552558

553559
// EGL_KHR_lock_surface3
554560
vk::BufferHelper mLockBufferHelper;

0 commit comments

Comments
 (0)