[Feat] (MG_Backend/DirectVulkan): Present frame in eglSwapBuffers.

This commit is contained in:
BZLZHH
2026-02-08 14:58:42 +08:00
parent 55020a1e86
commit 3b2c2028b9
3 changed files with 24 additions and 1 deletions
@@ -183,7 +183,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
CreateFrameResources();
}
// Wait fence & Acquire image & Record commands & Submit & Present
// Wait fence & Acquire image & Record commands & Submit
void VulkanRenderer::RenderFrame() {
if (!Ctx) MOBILEGL_ASSERT(false, "Renderer not initialized");
FrameContext& frame = *Frames[CurrentFrame];
@@ -222,9 +222,26 @@ namespace MobileGL::MG_Backend::DirectVulkan {
si.pSignalSemaphores = signalSemaphores;
MOBILEGL_ASSERT_VK(vkQueueSubmit(Ctx->GetGraphicsQueue(), 1, &si, frame.InFlightFence), "vkQueueSubmit");
}
void VulkanRenderer::Present() {
if (!Ctx) MOBILEGL_ASSERT(false, "Renderer not initialized");
FrameContext& frame = *Frames[CurrentFrame];
// Acquire image
uint32_t imageIndex = 0;
VkResult res = vkAcquireNextImageKHR(Ctx->GetDevice(), Swapchain->GetSwapchain(), UINT64_MAX,
frame.ImageAvailable, VK_NULL_HANDLE, &imageIndex);
if (res == VK_ERROR_OUT_OF_DATE_KHR) {
MGLOG_D("vkAcquireNextImageKHR: OUT_OF_DATE -> recreate");
RecreateSwapchainIfNeeded();
return;
}
MOBILEGL_ASSERT_VK(res, "vkAcquireNextImageKHR");
// Present
VkPresentInfoKHR pi{VK_STRUCTURE_TYPE_PRESENT_INFO_KHR};
VkSemaphore signalSemaphores[] = {frame.RenderFinished};
pi.waitSemaphoreCount = 1;
pi.pWaitSemaphores = signalSemaphores;
VkSwapchainKHR scs[] = {Swapchain->GetSwapchain()};
@@ -31,6 +31,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
void Shutdown();
void RenderFrame();
void Present();
void RegisterRenderCallback(const std::string& name, RenderCallback cb);
void UnregisterRenderCallback(const std::string& name);
@@ -102,6 +102,11 @@ namespace MobileGL {
}
EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface draw) {
if (!MG_Backend::DirectVulkan::pVulkanRenderer) {
MGLOG_E("EGLForVulkan::SwapBuffers called but VulkanRenderer is null");
return EGL_FALSE;
}
MG_Backend::DirectVulkan::pVulkanRenderer->Present();
return EGL_TRUE;
}