Fix GL Fence signaling status (#2500)

This commit is contained in:
alasram
2024-06-14 07:04:39 -07:00
committed by GitHub
parent 46f2fa1248
commit c509874f80
4 changed files with 37 additions and 7 deletions

View File

@@ -1,12 +1,27 @@
#include <mbgl/gl/fence.hpp>
#include <mbgl/gl/defines.hpp>
#include <cassert>
#include <stdexcept>
#include <string>
namespace mbgl {
namespace gl {
using namespace platform;
namespace {
std::string glErrors() {
std::string error_list = "";
for (auto error = glGetError(); error != GL_NO_ERROR; error = glGetError()) {
error_list += std::to_string(error) + " ";
}
if (error_list.empty()) {
return error_list;
}
return "GL error codes: " + error_list;
}
} // namespace
Fence::Fence() {}
Fence::~Fence() {
@@ -20,12 +35,27 @@ void Fence::insert() noexcept {
fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
}
bool Fence::isSignaled() const noexcept {
bool Fence::isSignaled() const {
if (!fence) {
return false;
}
return glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
GLenum fenceStatus = glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0);
switch (fenceStatus) {
case GL_ALREADY_SIGNALED:
[[fallthrough]];
case GL_CONDITION_SATISFIED:
return true;
case GL_TIMEOUT_EXPIRED:
return false;
case GL_WAIT_FAILED:
throw std::runtime_error("glClientWaitSync failed. " + glErrors());
return false;
default:
assert(false); // unreachable
return false;
}
}
} // namespace gl