Skip to content

Commit

Permalink
remove backend wait(timeout) API
Browse files Browse the repository at this point in the history
The only use of this API was with a timeout 0 to check the fence
status. Timeouts other than zero could be very dangerous and since we're
not using that feature for now, we just get rid of it.


wait() is replaced with getFenceStatus(). It is currently only used by
the FrameSkipper.

This is not a public API.
  • Loading branch information
pixelflinger committed Aug 15, 2023
1 parent 3bb52f0 commit f1b160d
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion filament/backend/include/private/backend/DriverAPI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ DECL_DRIVER_API_SYNCHRONOUS_N(void, setStreamDimensions, backend::StreamHandle,
DECL_DRIVER_API_SYNCHRONOUS_N(int64_t, getStreamTimestamp, backend::StreamHandle, stream)
DECL_DRIVER_API_SYNCHRONOUS_N(void, updateStreams, backend::DriverApi*, driver)
DECL_DRIVER_API_SYNCHRONOUS_N(void, destroyFence, backend::FenceHandle, fh)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::FenceStatus, wait, backend::FenceHandle, fh, uint64_t, timeout)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::FenceStatus, getFenceStatus, backend::FenceHandle, fh)
DECL_DRIVER_API_SYNCHRONOUS_N(bool, isTextureFormatSupported, backend::TextureFormat, format)
DECL_DRIVER_API_SYNCHRONOUS_0(bool, isTextureSwizzleSupported)
DECL_DRIVER_API_SYNCHRONOUS_N(bool, isTextureFormatMipmappable, backend::TextureFormat, format)
Expand Down
4 changes: 2 additions & 2 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,12 @@
}
}

FenceStatus MetalDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
FenceStatus MetalDriver::getFenceStatus(Handle<HwFence> fh) {
auto* fence = handle_cast<MetalFence>(fh);
if (!fence) {
return FenceStatus::ERROR;
}
return fence->wait(timeout);
return fence->wait(0);
}

bool MetalDriver::isTextureFormatSupported(TextureFormat format) {
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/noop/NoopDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void NoopDriver::updateStreams(CommandStream* driver) {
void NoopDriver::destroyFence(Handle<HwFence> fh) {
}

FenceStatus NoopDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
FenceStatus NoopDriver::getFenceStatus(Handle<HwFence> fh) {
return FenceStatus::CONDITION_SATISFIED;
}

Expand Down
7 changes: 3 additions & 4 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ void OpenGLDriver::destroyFence(Handle<HwFence> fh) {
}
}

FenceStatus OpenGLDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
FenceStatus OpenGLDriver::getFenceStatus(Handle<HwFence> fh) {
if (fh) {
GLFence* f = handle_cast<GLFence*>(fh);
if (mPlatform.canCreateFence() || mContext.isES2()) {
Expand All @@ -1695,14 +1695,13 @@ FenceStatus OpenGLDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
// - wait() was called before the fence was asynchronously created.
return FenceStatus::TIMEOUT_EXPIRED;
}
return mPlatform.waitFence(f->fence, timeout);
return mPlatform.waitFence(f->fence, 0);
}
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
else {
assert_invariant(f->state);
std::unique_lock lock(f->state->lock);
f->state->cond.wait_for(lock,
std::chrono::nanoseconds(timeout), [&state = f->state]() {
f->state->cond.wait_for(lock, std::chrono::nanoseconds(0), [&state = f->state]() {
return state->status != FenceStatus::TIMEOUT_EXPIRED;
});
return f->state->status;
Expand Down
4 changes: 2 additions & 2 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void VulkanDriver::destroyFence(Handle<HwFence> fh) {
mHandleAllocator.destruct<VulkanFence>(fh);
}

FenceStatus VulkanDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
FenceStatus VulkanDriver::getFenceStatus(Handle<HwFence> fh) {
auto& cmdfence = mHandleAllocator.handle_cast<VulkanFence*>(fh)->fence;
if (!cmdfence) {
// If wait is called before a fence actually exists, we return timeout. This matches the
Expand All @@ -684,7 +684,7 @@ FenceStatus VulkanDriver::wait(Handle<HwFence> fh, uint64_t timeout) {
lock.unlock();
}
VkResult result =
vkWaitForFences(mPlatform->getDevice(), 1, &cmdfence->fence, VK_TRUE, timeout);
vkWaitForFences(mPlatform->getDevice(), 1, &cmdfence->fence, VK_TRUE, 0);
return result == VK_SUCCESS ? FenceStatus::CONDITION_SATISFIED : FenceStatus::TIMEOUT_EXPIRED;
}

Expand Down
5 changes: 1 addition & 4 deletions filament/backend/test/BackendTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,10 @@ void BackendTest::executeCommands() {
}
}

void BackendTest::flushAndWait(uint64_t timeout) {
void BackendTest::flushAndWait() {
auto& api = getDriverApi();
auto fence = api.createFence();
api.finish();
executeCommands();
api.wait(fence, timeout);
api.destroyFence(fence);
}

Handle<HwSwapChain> BackendTest::createSwapChain() {
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/test/BackendTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BackendTest : public ::testing::Test {

void initializeDriver();
void executeCommands();
void flushAndWait(uint64_t timeout = 1000);
void flushAndWait();

filament::backend::Handle<filament::backend::HwSwapChain> createSwapChain();

Expand Down
5 changes: 1 addition & 4 deletions filament/backend/test/ComputeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ void ComputeTest::executeCommands() {
}
}

void ComputeTest::flushAndWait(uint64_t timeout) {
void ComputeTest::flushAndWait() {
auto& api = getDriverApi();
auto fence = api.createFence();
api.finish();
executeCommands();
api.wait(fence, timeout);
api.destroyFence(fence);
}
2 changes: 1 addition & 1 deletion filament/backend/test/ComputeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ComputeTest : public ::testing::Test {
void TearDown() override;

void executeCommands();
void flushAndWait(uint64_t timeout = 1000);
void flushAndWait();
filament::backend::DriverApi& getDriverApi() { return *commandStream; }
filament::backend::Driver& getDriver() { return *driver; }

Expand Down
2 changes: 1 addition & 1 deletion filament/src/FrameSkipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool FrameSkipper::beginFrame(DriverApi& driver) noexcept {
auto& fences = mDelayedFences;
auto fence = fences.front();
if (fence) {
auto status = driver.wait(fence, 0);
auto status = driver.getFenceStatus(fence);
if (status == FenceStatus::TIMEOUT_EXPIRED) {
// Sync not ready, skip frame
return false;
Expand Down

0 comments on commit f1b160d

Please sign in to comment.