Print FPS for sample Animometer

Change-Id: I21ae60077638944258436c4cab14cc1d98e7f169
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125881
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Peng Huang <penghuang@chromium.org>
This commit is contained in:
Peng Huang 2023-03-31 16:44:51 +00:00 committed by Dawn LUCI CQ
parent d8f0f44b54
commit 3f76570d9a
1 changed files with 9 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/ScopedAutoreleasePool.h" #include "dawn/utils/ScopedAutoreleasePool.h"
#include "dawn/utils/SystemUtils.h" #include "dawn/utils/SystemUtils.h"
#include "dawn/utils/Timer.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
wgpu::Device device; wgpu::Device device;
@ -145,13 +146,12 @@ void init() {
bindGroup = utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}}); bindGroup = utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}});
} }
int frameCount = 0;
void frame() { void frame() {
wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView(); wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView();
static int f = 0;
f++;
for (auto& data : shaderData) { for (auto& data : shaderData) {
data.time = f / 60.0f; data.time = frameCount / 60.0f;
} }
queue.WriteBuffer(ubo, 0, shaderData.data(), kNumTriangles * sizeof(ShaderData)); queue.WriteBuffer(ubo, 0, shaderData.data(), kNumTriangles * sizeof(ShaderData));
@ -174,7 +174,6 @@ void frame() {
queue.Submit(1, &commands); queue.Submit(1, &commands);
swapchain.Present(); swapchain.Present();
DoFlush(); DoFlush();
fprintf(stderr, "frame %i\n", f);
} }
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
@ -183,9 +182,14 @@ int main(int argc, const char* argv[]) {
} }
init(); init();
utils::Timer* timer = utils::CreateTimer();
timer->Start();
while (!ShouldQuit()) { while (!ShouldQuit()) {
utils::ScopedAutoreleasePool pool; utils::ScopedAutoreleasePool pool;
frameCount++;
frame(); frame();
utils::USleep(16000); if (frameCount % 60 == 0) {
printf("FPS: %lf\n", static_cast<double>(frameCount) / timer->GetElapsedTime());
}
} }
} }