fix wasm build. (#9312)
The new AsyncJobQueue can't work with wasm, which doesn't support threads.
This commit is contained in:
@@ -173,6 +173,12 @@ void FrameInfoManager::endFrame(DriverApi& driver) noexcept {
|
||||
// backend frame end-time
|
||||
front.backendEndFrame = std::chrono::steady_clock::now();
|
||||
|
||||
if (UTILS_UNLIKELY(!jobQueue.isValid())) {
|
||||
front.gpuFrameComplete = {};
|
||||
front.ready.store(true, std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
|
||||
// now launch a job that'll wait for the gpu to complete
|
||||
jobQueue.push([&driver, &front] {
|
||||
FenceStatus const status = driver.fenceWait(front.fence, FENCE_WAIT_FOR_EVER);
|
||||
|
||||
@@ -48,13 +48,17 @@ public:
|
||||
// adds a job to the queue. no-op if drainAndExit() was called.
|
||||
void push(Job&& job);
|
||||
|
||||
bool isValid() const noexcept;
|
||||
|
||||
private:
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
using Container = std::vector<Job>;
|
||||
std::thread mThread;
|
||||
Mutex mLock; // NOLINT(*-include-cleaner)
|
||||
Condition mCondition; // NOLINT(*-include-cleaner)
|
||||
Container mQueue;
|
||||
bool mExitRequested = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
namespace utils {
|
||||
|
||||
AsyncJobQueue::AsyncJobQueue(const char* name, Priority priority) {
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
mQueue.reserve(2);
|
||||
mThread = std::thread([this, name, priority]() {
|
||||
JobSystem::setThreadName(name);
|
||||
@@ -50,13 +51,17 @@ AsyncJobQueue::AsyncJobQueue(const char* name, Priority priority) {
|
||||
}
|
||||
} while (!exitRequested);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
AsyncJobQueue::~AsyncJobQueue() noexcept {
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
assert_invariant(mQueue.empty());
|
||||
#endif
|
||||
}
|
||||
|
||||
void AsyncJobQueue::push(Job&& job) {
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
std::unique_lock lock(mLock);
|
||||
if (UTILS_UNLIKELY(mExitRequested)) {
|
||||
LOG(WARNING) << "AsyncJobQueue::push() called after drainAndExit()";
|
||||
@@ -67,9 +72,20 @@ void AsyncJobQueue::push(Job&& job) {
|
||||
lock.unlock();
|
||||
mCondition.notify_one();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AsyncJobQueue::isValid() const noexcept {
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
return mThread.joinable();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void AsyncJobQueue::drainAndExit() {
|
||||
#if !defined(__EMSCRIPTEN__)
|
||||
std::unique_lock lock(mLock);
|
||||
// we request the service thread to exit, but we're guaranteed that it'll only exit
|
||||
// after all current callbacks are processed. In addition, once mExitRequested is set,
|
||||
@@ -80,6 +96,7 @@ void AsyncJobQueue::drainAndExit() {
|
||||
if (mThread.joinable()) {
|
||||
mThread.join();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user