Skip to content

Commit

Permalink
Remove (unused) support for hardware fences
Browse files Browse the repository at this point in the history
This code hasn't been used for a while and we should not resurrect it.
  • Loading branch information
pixelflinger committed Aug 15, 2023
1 parent 88337ab commit 3bb52f0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 45 deletions.
6 changes: 1 addition & 5 deletions filament/include/filament/Fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
namespace filament {

/**
* Fence is used to synchronize rendering operations together, with the CPU or with compute.
*
* \note
* Currently Fence only provide client-side synchronization.
*
* Fence is used to synchronize the application main thread with filament's rendering thread.
*/
class UTILS_PUBLIC Fence : public FilamentAPI {
public:
Expand Down
2 changes: 1 addition & 1 deletion filament/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Engine::destroyCameraComponent(utils::Entity entity) noexcept {
}

Fence* Engine::createFence() noexcept {
return downcast(this)->createFence(FFence::Type::SOFT);
return downcast(this)->createFence();
}

SwapChain* Engine::createSwapChain(void* nativeWindow, uint64_t flags) noexcept {
Expand Down
7 changes: 3 additions & 4 deletions filament/src/details/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,7 @@ void FEngine::flushAndWait() {

#else

FFence::waitAndDestroy(
FEngine::createFence(FFence::Type::SOFT), FFence::Mode::FLUSH);
FFence::waitAndDestroy(FEngine::createFence(), FFence::Mode::FLUSH);

#endif

Expand Down Expand Up @@ -762,8 +761,8 @@ FView* FEngine::createView() noexcept {
return p;
}

FFence* FEngine::createFence(FFence::Type type) noexcept {
FFence* p = mHeapAllocator.make<FFence>(*this, type);
FFence* FEngine::createFence() noexcept {
FFence* p = mHeapAllocator.make<FFence>(*this);
if (p) {
std::lock_guard const guard(mFenceListLock);
mFences.insert(p);
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class FEngine : public Engine {

FScene* createScene() noexcept;
FView* createView() noexcept;
FFence* createFence(FFence::Type type) noexcept;
FFence* createFence() noexcept;
FSwapChain* createSwapChain(void* nativeWindow, uint64_t flags) noexcept;
FSwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept;

Expand Down
24 changes: 5 additions & 19 deletions filament/src/details/Fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ static const constexpr uint64_t PUMP_INTERVAL_MILLISECONDS = 1;
using ms = std::chrono::milliseconds;
using ns = std::chrono::nanoseconds;

FFence::FFence(FEngine& engine, Type type)
: mEngine(engine), mFenceSignal(std::make_shared<FenceSignal>(type)) {
FFence::FFence(FEngine& engine)
: mEngine(engine), mFenceSignal(std::make_shared<FenceSignal>()) {
DriverApi& driverApi = engine.getDriverApi();
if (type == Type::HARD) {
mFenceHandle = driverApi.createFence();
}

// we have to first wait for the fence to be signaled by the command stream
auto& fs = mFenceSignal;
Expand All @@ -49,22 +46,15 @@ FFence::FFence(FEngine& engine, Type type)
});
}

void FFence::terminate(FEngine& engine) noexcept {
void FFence::terminate(FEngine&) noexcept {
FenceSignal * const fs = mFenceSignal.get();
fs->signal(FenceSignal::DESTROYED);
if (fs->mType == Type::HARD) {
if (mFenceHandle) {
FEngine::DriverApi& driver = engine.getDriverApi();
driver.destroyFence(mFenceHandle);
mFenceHandle.clear();
}
}
}

UTILS_NOINLINE
FenceStatus FFence::waitAndDestroy(FFence* fence, Mode mode) noexcept {
assert_invariant(fence);
FenceStatus status = fence->wait(mode, FENCE_WAIT_FOR_EVER);
FenceStatus const status = fence->wait(mode, FENCE_WAIT_FOR_EVER);
fence->mEngine.destroy(fence);
return status;
}
Expand Down Expand Up @@ -107,16 +97,12 @@ FenceStatus FFence::wait(Mode mode, uint64_t timeout) noexcept {
return status;
}

if (fs->mType == Type::HARD) {
// note: even if the driver doesn't support h/w fences, mFenceHandle will be valid
status = engine.getDriverApi().wait(mFenceHandle, timeout);
}
return status;
}

UTILS_NOINLINE
void FFence::FenceSignal::signal(State s) noexcept {
std::lock_guard<utils::Mutex> lock(FFence::sLock);
std::lock_guard<utils::Mutex> const lock(FFence::sLock);
mState = s;
FFence::sCondition.notify_all();
}
Expand Down
14 changes: 2 additions & 12 deletions filament/src/details/Fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ class FEngine;

class FFence : public Fence {
public:
// Type of the Fence being created
enum class Type : uint8_t {
SOFT,
HARD
};

FFence(FEngine& engine, Type type);
FFence(FEngine& engine);

void terminate(FEngine& engine) noexcept;

Expand All @@ -54,18 +48,14 @@ class FFence : public Fence {
static utils::Condition sCondition;

struct FenceSignal {
explicit FenceSignal(Type type) noexcept : mType(type) { }
explicit FenceSignal() noexcept = default;
enum State : uint8_t { UNSIGNALED, SIGNALED, DESTROYED };
// we store mType here instead of in FFence, because it allows sizeof(FFence) to be
// much smaller (since it needs to be multiple of 8 on 64 bits architectures)
const Type mType;
State mState = UNSIGNALED;
void signal(State s = SIGNALED) noexcept;
FenceStatus wait(uint64_t timeout) noexcept;
};

FEngine& mEngine;
backend::Handle<backend::HwFence> mFenceHandle;
// TODO: use custom allocator for these small objects
std::shared_ptr<FenceSignal> mFenceSignal;
};
Expand Down
4 changes: 2 additions & 2 deletions filament/src/details/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ void FRenderer::terminate(FEngine& engine) {
// shut down threads if we created any.
DriverApi& driver = engine.getDriverApi();

// before we can destroy this Renderer's resources, we must make sure
// Before we can destroy this Renderer's resources, we must make sure
// that all pending commands have been executed (as they could reference data in this
// instance, e.g. Fences, Callbacks, etc...)
if (UTILS_HAS_THREADING) {
Fence::waitAndDestroy(engine.createFence(FFence::Type::SOFT));
Fence::waitAndDestroy(engine.createFence());
} else {
// In single threaded mode, allow recently-created objects (e.g. no-op fences in Skipper)
// to initialize themselves, otherwise the engine tries to destroy invalid handles.
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void FStream::setDimensions(uint32_t width, uint32_t height) noexcept {
// unfortunately, because this call is synchronous, we must make sure the handle has been
// created first
if (UTILS_UNLIKELY(!mStreamHandle)) {
FFence::waitAndDestroy(mEngine.createFence(FFence::Type::SOFT), Fence::Mode::FLUSH);
FFence::waitAndDestroy(mEngine.createFence(), Fence::Mode::FLUSH);
}
mEngine.getDriverApi().setStreamDimensions(mStreamHandle, mWidth, mHeight);
}
Expand Down

0 comments on commit 3bb52f0

Please sign in to comment.