Skip to content

Commit

Permalink
use whenGpuCommandComplete to emulate platform fences
Browse files Browse the repository at this point in the history
This is more appropriate (and simple) than runEveryNowAndThen because 
the later doesn't manage a fence, and therefore is more of a superset.
This will allow us to use a shared context implementation in the future.
  • Loading branch information
pixelflinger committed Aug 15, 2023
1 parent 0935fe3 commit 88337ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
42 changes: 8 additions & 34 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,35 +1344,15 @@ void OpenGLDriver::createFenceR(Handle<HwFence> fh, int) {
}
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
else {
f->sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
std::weak_ptr<GLFence::State> const weak = f->state;
runEveryNowAndThen(
[sync = f->sync, weak]() -> bool {
auto state = weak.lock();
if (state) {
FenceStatus fenceStatus;
GLenum const syncStatus = glClientWaitSync(sync, 0, 0u);
switch (syncStatus) {
case GL_TIMEOUT_EXPIRED:
fenceStatus = FenceStatus::TIMEOUT_EXPIRED;
break;
case GL_ALREADY_SIGNALED:
case GL_CONDITION_SATISFIED:
fenceStatus = FenceStatus::CONDITION_SATISFIED;
break;
default:
fenceStatus = FenceStatus::ERROR;
break;
}
if (fenceStatus != FenceStatus::TIMEOUT_EXPIRED) {
std::lock_guard const lock(state->lock);
state->status = fenceStatus;
state->cond.notify_all();
}
return (fenceStatus != FenceStatus::TIMEOUT_EXPIRED);
}
return true;
});
whenGpuCommandsComplete([weak](){
auto state = weak.lock();
if (state) {
std::lock_guard const lock(state->lock);
state->status = FenceStatus::CONDITION_SATISFIED;
state->cond.notify_all();
}
});
}
#endif
}
Expand Down Expand Up @@ -1698,12 +1678,6 @@ void OpenGLDriver::destroyFence(Handle<HwFence> fh) {
if (mPlatform.canCreateFence() || mContext.isES2()) {
mPlatform.destroyFence(f->fence);
}
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
else {
glDeleteSync(f->sync);
CHECK_GL_ERROR(utils::slog.e)
}
#endif
destruct(fh, f);
}
}
Expand Down
1 change: 0 additions & 1 deletion filament/backend/src/opengl/OpenGLDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class OpenGLDriver final : public DriverBase {
std::condition_variable cond;
FenceStatus status{ FenceStatus::TIMEOUT_EXPIRED };
};
GLsync sync;
std::shared_ptr<State> state{ std::make_shared<GLFence::State>() };
};

Expand Down

0 comments on commit 88337ab

Please sign in to comment.