diff --git a/demos/optical_bench/src/optix_pass.cpp b/demos/optical_bench/src/optix_pass.cpp index c2d4e7f89abc7003a66d658ea806d47cf10b8206..053a352ae5040c2abd30712d2ccccde559b0a350 100644 --- a/demos/optical_bench/src/optix_pass.cpp +++ b/demos/optical_bench/src/optix_pass.cpp @@ -23,6 +23,8 @@ #include "optix_pass.hpp" #include "opticalBenchConfig.h" +#include "time_helper.hpp" + #include <cassert> #include <iostream> #include <memory> @@ -147,10 +149,13 @@ void OptixPass::Initialize() { } void OptixPass::Execute() { + auto start = TimeHelper::Start(); optix_context_manager_->UpdateCamera(render_target_right_); + optix_context_manager_->Launch(dims.x, dims.y); - CopyBuffersAndRenderInOpenGL(render_target_right_); + CopyBuffersAndRenderInOpenGL(render_target_right_); + TimeHelper::PrintAveraged(start); if (IsHMDRendering()) { dims = render_target_left_->GetDimensions(); optix_context_manager_->UpdateCamera(render_target_left_); diff --git a/demos/optical_bench/src/time_helper.hpp b/demos/optical_bench/src/time_helper.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6c334c6949a9700dcabdcf44510d0516b1d111b7 --- /dev/null +++ b/demos/optical_bench/src/time_helper.hpp @@ -0,0 +1,32 @@ +#ifndef OPTICAL_BENCH_TIME_HELPER_HPP_ +#define OPTICAL_BENCH_TIME_HELPER_HPP_ + +#include <chrono> + +class TimeHelper { + public: + static std::chrono::time_point<std::chrono::steady_clock> Start() { + return std::chrono::high_resolution_clock::now(); + } + + static long long GetMicroSecondsSinceStart( + std::chrono::time_point<std::chrono::steady_clock> start) { + return std::chrono::duration_cast<std::chrono::microseconds>( + std::chrono::high_resolution_clock::now() - start) + .count(); + } + + static void PrintAveraged( + std::chrono::time_point<std::chrono::steady_clock> start) { + static long long time = 0; + static int counter = 0; + time += GetMicroSecondsSinceStart(start); + counter++; + if (counter >= 50) { + printf("Time: %d microsec\n", (int)(time / counter)); + counter = 0; + time = 0; + } + } +}; +#endif // OPTICAL_BENCH_TIME_HELPER_HPP_