Skip to content

Commit

Permalink
Skip delay when surface is out of date
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-cojocaru committed Nov 29, 2024
1 parent 1ab1334 commit fbde5df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/vulkan/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Context final : public gfx::Context {
void enqueueDeletion(std::function<void(Context&)>&& function);
void submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function) const;

void requestSurfaceUpdate();
void requestSurfaceUpdate(bool useDelay = true);

private:
struct FrameResources {
Expand Down
17 changes: 10 additions & 7 deletions src/mbgl/vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ void Context::submitOneTimeCommand(const std::function<void(const vk::UniqueComm
}
}

void Context::requestSurfaceUpdate() {
void Context::requestSurfaceUpdate(bool useDelay) {
if (surfaceUpdateRequested) {
if (!useDelay) {
surfaceUpdateLatency = 0;
}

return;
}

surfaceUpdateRequested = true;
surfaceUpdateLatency = backend.getMaxFrames() * 3;
surfaceUpdateLatency = useDelay ? backend.getMaxFrames() * 3 : 0;
}

void Context::waitFrame() const {
Expand Down Expand Up @@ -212,7 +216,7 @@ void Context::beginFrame() {
}
}

if (platformSurface && surfaceUpdateRequested && --surfaceUpdateLatency == 0) {
if (platformSurface && surfaceUpdateRequested && --surfaceUpdateLatency <= 0) {
renderableResource.recreateSwapchain();

// we wait for an idle device to recreate the swapchain
Expand Down Expand Up @@ -252,14 +256,13 @@ void Context::beginFrame() {
if (acquireImageResult.result == vk::Result::eSuccess) {
renderableResource.setAcquiredImageIndex(acquireImageResult.value);
} else if (acquireImageResult.result == vk::Result::eSuboptimalKHR) {
renderableResource.setAcquiredImageIndex(acquireImageResult.value);
requestSurfaceUpdate();
beginFrame();
return;
}

} catch (const vk::OutOfDateKHRError& e) {
// request an update and restart frame
requestSurfaceUpdate();
requestSurfaceUpdate(false);
beginFrame();
return;
}
Expand Down Expand Up @@ -319,7 +322,7 @@ void Context::submitFrame() {
requestSurfaceUpdate();
}
} catch (const vk::OutOfDateKHRError& e) {
requestSurfaceUpdate();
requestSurfaceUpdate(false);
}
}

Expand Down

0 comments on commit fbde5df

Please sign in to comment.