Skip to content

Commit

Permalink
Add latency to surface updats
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-cojocaru committed Nov 28, 2024
1 parent 4878005 commit 22acf40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 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() { surfaceUpdateRequested = true; }
void requestSurfaceUpdate();

private:
struct FrameResources {
Expand Down Expand Up @@ -197,6 +197,7 @@ class Context final : public gfx::Context {
uint8_t frameResourceIndex = 0;
std::vector<FrameResources> frameResources;
bool surfaceUpdateRequested{false};
int32_t surfaceUpdateLatency{0};
int32_t currentFrameCount{0};

struct {
Expand Down
11 changes: 10 additions & 1 deletion src/mbgl/vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ void Context::submitOneTimeCommand(const std::function<void(const vk::UniqueComm
}
}

void Context::requestSurfaceUpdate() {
if (surfaceUpdateLatency) {
return;
}

surfaceUpdateRequested = true;
surfaceUpdateLatency = backend.getMaxFrames() * 3;
}

void Context::waitFrame() const {
MLN_TRACE_FUNC();
const auto& device = backend.getDevice();
Expand Down Expand Up @@ -203,7 +212,7 @@ void Context::beginFrame() {
}
}

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

// we wait for an idle device to recreate the swapchain
Expand Down

0 comments on commit 22acf40

Please sign in to comment.