Skip to content

Commit 7cfcd2d

Browse files
committed
Implement Tqueries
1 parent 83967fd commit 7cfcd2d

File tree

6 files changed

+503
-467
lines changed

6 files changed

+503
-467
lines changed

filament/backend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ if (FILAMENT_SUPPORTS_WEBGPU)
262262
src/webgpu/WebGPUSwapChain.cpp
263263
src/webgpu/WebGPUSwapChain.h
264264
src/webgpu/WGPUProgram.cpp
265+
src/webgpu/WGPUTimerQuery.cpp
265266
)
266267
if (WIN32)
267268
list(APPEND SRCS src/webgpu/platform/WebGPUPlatformWindows.cpp)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
#include "WebGPUHandles.h"
19+
20+
#include <chrono>
21+
22+
23+
namespace filament::backend {
24+
25+
void WGPUTimerQuery::beginTimeElapsedQuery(WGPUTimerQuery* query) {
26+
query->status->elapsed = 0;
27+
query->status->available.store(false);
28+
29+
// Capture the timer query status via a weak_ptr because the MetalTimerQuery could be destroyed
30+
// before the block executes.
31+
std::weak_ptr<WGPUTimerQuery::Status> status = query->status;
32+
33+
if (auto s = status.lock()) {
34+
s->elapsed = std::chrono::steady_clock::now().time_since_epoch().count();
35+
}
36+
37+
;
38+
}
39+
40+
void WGPUTimerQuery::endTimeElapsedQuery(WGPUTimerQuery* query) {
41+
// Capture the timer query status via a weak_ptr because the WGPUTimerQuery could be destroyed
42+
// before the block executes.
43+
std::weak_ptr<WGPUTimerQuery::Status> status = query->status;
44+
if (auto s = status.lock()) {
45+
s->elapsed = std::chrono::steady_clock::now().time_since_epoch().count() - s->elapsed;
46+
s->available.store(true);
47+
}
48+
}
49+
50+
bool WGPUTimerQuery::getQueryResult(WGPUTimerQuery* query, uint64_t* outElapsedTime) {
51+
if (!query->status->available.load()) {
52+
return false;
53+
}
54+
if (outElapsedTime) {
55+
*outElapsedTime = query->status->elapsed;
56+
}
57+
return true;
58+
}
59+
60+
}// namespace filament::backend

0 commit comments

Comments
 (0)