Skip to content

Commit 192a61a

Browse files
Wait for work of first frame to be done before any presenting
1 parent 6a93e3a commit 192a61a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

filament/backend/src/webgpu/WebGPUDriver.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include <sstream>
5454
#include <utility>
5555

56+
using namespace std::chrono_literals;
57+
5658
namespace filament::backend {
5759

5860
Driver* WebGPUDriver::create(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept {
@@ -923,6 +925,22 @@ void WebGPUDriver::commit(Handle<HwSwapChain> sch) {
923925
assert_invariant(mCommandBuffer);
924926
mCommandEncoder = nullptr;
925927
mQueue.Submit(1, &mCommandBuffer);
928+
929+
static bool firstRender = true;
930+
// For the first frame rendered, we need to make sure the work is done before presenting or we
931+
// get a purple flash
932+
if (firstRender) {
933+
auto f = mQueue.OnSubmittedWorkDone(wgpu::CallbackMode::WaitAnyOnly,
934+
[=](wgpu::QueueWorkDoneStatus) {});
935+
const wgpu::Instance instance = mAdapter.GetInstance();
936+
auto wStatus = instance.WaitAny(f,
937+
std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count());
938+
if (wStatus != wgpu::WaitStatus::Success) {
939+
FWGPU_LOGW << "Waiting for first frame work to finish resulted in an error"
940+
<< static_cast<uint32_t>(wStatus);
941+
}
942+
firstRender = false;
943+
}
926944
mCommandBuffer = nullptr;
927945
mTextureView = nullptr;
928946
assert_invariant(mSwapChain);

0 commit comments

Comments
 (0)