diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index b3d0108f010..755f4aeb7fd 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -47,6 +47,8 @@ class RunLoop : public Scheduler, private util::noncopyable { void runOnce(); void stop(); + void updateTime(); + /// Platform integration callback for platforms that do not have full /// run loop integration or don't want to block at the Mapbox GL Native /// loop. It will be called from any thread and is up to the platform diff --git a/include/mbgl/vulkan/renderable_resource.hpp b/include/mbgl/vulkan/renderable_resource.hpp index 1c619d6ceb3..369e53d1e3e 100644 --- a/include/mbgl/vulkan/renderable_resource.hpp +++ b/include/mbgl/vulkan/renderable_resource.hpp @@ -34,12 +34,13 @@ class RenderableResource : public gfx::RenderableResource { class SurfaceRenderableResource : public RenderableResource { protected: - explicit SurfaceRenderableResource(RendererBackend& backend_) - : RenderableResource(backend_) {} + explicit SurfaceRenderableResource(RendererBackend& backend_, vk::PresentModeKHR mode = vk::PresentModeKHR::eFifo) + : RenderableResource(backend_), + presentMode(mode) {} ~SurfaceRenderableResource() override; void initColor(uint32_t w, uint32_t h); - void initSwapchain(uint32_t w, uint32_t h, vk::PresentModeKHR presentMode = vk::PresentModeKHR::eFifo); + void initSwapchain(uint32_t w, uint32_t h); void initDepthStencil(); @@ -73,6 +74,8 @@ class SurfaceRenderableResource : public RenderableResource { protected: vk::UniqueSurfaceKHR surface; vk::UniqueSwapchainKHR swapchain; + vk::PresentModeKHR presentMode; + vk::SurfaceCapabilitiesKHR capabilities; uint32_t acquiredImageIndex{0}; diff --git a/platform/default/src/mbgl/util/run_loop.cpp b/platform/default/src/mbgl/util/run_loop.cpp index 54705e481e4..0076299c655 100644 --- a/platform/default/src/mbgl/util/run_loop.cpp +++ b/platform/default/src/mbgl/util/run_loop.cpp @@ -149,6 +149,12 @@ void RunLoop::stop() { invoke([&] { uv_unref(impl->holderHandle()); }); } +void RunLoop::updateTime() { + MBGL_VERIFY_THREAD(tid); + + uv_update_time(impl->loop); +} + void RunLoop::waitForEmpty([[maybe_unused]] const mbgl::util::SimpleIdentity tag) { while (true) { std::size_t remaining; diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index febb52d3ffe..79ce2c76401 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -1100,6 +1100,10 @@ void GLFWView::run() { } render(); + +#ifndef __APPLE__ + runLoop.updateTime(); +#endif }; // Cap frame rate to 60hz if benchmark mode is disabled diff --git a/platform/glfw/glfw_vulkan_backend.cpp b/platform/glfw/glfw_vulkan_backend.cpp index ad7fd96dd0f..482ca467b03 100644 --- a/platform/glfw/glfw_vulkan_backend.cpp +++ b/platform/glfw/glfw_vulkan_backend.cpp @@ -13,8 +13,9 @@ class GLFWVulkanRenderableResource final : public mbgl::vulkan::SurfaceRenderableResource { public: - explicit GLFWVulkanRenderableResource(GLFWVulkanBackend& backend_) - : SurfaceRenderableResource(backend_) {} + explicit GLFWVulkanRenderableResource(GLFWVulkanBackend& backend_, bool capFrameRate) + : SurfaceRenderableResource(backend_, + capFrameRate ? vk::PresentModeKHR::eFifo : vk::PresentModeKHR::eImmediate) {} std::vector getDeviceExtensions() override { return {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; } @@ -34,7 +35,7 @@ class GLFWVulkanRenderableResource final : public mbgl::vulkan::SurfaceRenderabl void bind() override {} }; -GLFWVulkanBackend::GLFWVulkanBackend(GLFWwindow* window_, const bool) +GLFWVulkanBackend::GLFWVulkanBackend(GLFWwindow* window_, const bool capFrameRate) : mbgl::vulkan::RendererBackend(mbgl::gfx::ContextMode::Unique), mbgl::vulkan::Renderable( [window_] { @@ -43,7 +44,7 @@ GLFWVulkanBackend::GLFWVulkanBackend(GLFWwindow* window_, const bool) glfwGetFramebufferSize(window_, &fbWidth, &fbHeight); return mbgl::Size{static_cast(fbWidth), static_cast(fbHeight)}; }(), - std::make_unique(*this)), + std::make_unique(*this, capFrameRate)), window(window_) { init(); } diff --git a/src/mbgl/vulkan/buffer_resource.cpp b/src/mbgl/vulkan/buffer_resource.cpp index ddcc505900e..2f9ccb4a45b 100644 --- a/src/mbgl/vulkan/buffer_resource.cpp +++ b/src/mbgl/vulkan/buffer_resource.cpp @@ -74,7 +74,7 @@ BufferResource::BufferResource( VmaAllocationCreateInfo allocationInfo = {}; - allocationInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST; + allocationInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; allocationInfo.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; allocationInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT; diff --git a/src/mbgl/vulkan/renderable_resource.cpp b/src/mbgl/vulkan/renderable_resource.cpp index be91db09358..052010f14e9 100644 --- a/src/mbgl/vulkan/renderable_resource.cpp +++ b/src/mbgl/vulkan/renderable_resource.cpp @@ -71,7 +71,7 @@ void SurfaceRenderableResource::initColor(uint32_t w, uint32_t h) { } } -void SurfaceRenderableResource::initSwapchain(uint32_t w, uint32_t h, vk::PresentModeKHR presentMode) { +void SurfaceRenderableResource::initSwapchain(uint32_t w, uint32_t h) { const auto& physicalDevice = backend.getPhysicalDevice(); const auto& device = backend.getDevice(); diff --git a/src/mbgl/vulkan/renderer_backend.cpp b/src/mbgl/vulkan/renderer_backend.cpp index 1dd5d64a131..e2b44708133 100644 --- a/src/mbgl/vulkan/renderer_backend.cpp +++ b/src/mbgl/vulkan/renderer_backend.cpp @@ -97,7 +97,11 @@ std::unique_ptr RendererBackend::createContext() { std::vector RendererBackend::getLayers() { return { #ifdef ENABLE_VULKAN_VALIDATION - "VK_LAYER_KHRONOS_validation" + "VK_LAYER_KHRONOS_validation", +#endif + +#ifdef _WIN32 + "VK_LAYER_LUNARG_monitor", #endif }; } @@ -561,9 +565,9 @@ void RendererBackend::initSwapchain() { auto& renderableResource = renderable.getResource(); const auto& size = renderable.getSize(); - // use triple buffering if rendering to a surface + // buffer resources if rendering to a surface // no buffering when using headless - maxFrames = renderableResource.getPlatformSurface() ? 3 : 1; + maxFrames = renderableResource.getPlatformSurface() ? 2 : 1; renderableResource.init(size.width, size.height);