@@ -133,7 +133,14 @@ ConfigManager::Mode g_mode = ConfigManager::Mode::kUseSingleGpu;
133133Baikal::Renderer::OutputType g_ouput_type = Baikal::Renderer::OutputType::kColor ;
134134
135135Baikal::Renderer::BenchmarkStats g_stats;
136- bool g_benchmarked = false ;
136+ bool g_time_benchmarked = false ;
137+ bool g_rt_benchmarked = false ;
138+ bool g_time_benchmark = false ;
139+ float g_time_benchmark_time = 0 .f;
140+
141+ decltype (std::chrono::high_resolution_clock::now()) g_time_bench_start_time;
142+
143+
137144
138145using namespace tinyobj ;
139146
@@ -533,60 +540,65 @@ void Update(bool update_required)
533540 float camroty = 0 .f ;
534541
535542 const float kMouseSensitivity = 0 .001125f ;
536- float2 delta = g_mouse_delta * float2 (kMouseSensitivity , kMouseSensitivity );
537- camrotx = -delta.x ;
538- camroty = -delta.y ;
539543
540- if (std::abs (camroty) > 0 . 001f )
544+ if (!g_benchmark && !g_time_benchmark )
541545 {
542- g_camera->Tilt (camroty);
543- // g_camera->ArcballRotateVertically(float3(0, 0, 0), camroty);
544- update = true ;
545- }
546+ float2 delta = g_mouse_delta * float2 (kMouseSensitivity , kMouseSensitivity );
547+ camrotx = -delta.x ;
548+ camroty = -delta.y ;
546549
547- if (std::abs (camrotx) > 0 .001f )
548- {
549550
550- g_camera->Rotate (camrotx);
551- // g_camera->ArcballRotateHorizontally(float3(0, 0, 0), camrotx);
552- update = true ;
553- }
551+ if (std::abs (camroty) > 0 .001f )
552+ {
553+ g_camera->Tilt (camroty);
554+ // g_camera->ArcballRotateVertically(float3(0, 0, 0), camroty);
555+ update = true ;
556+ }
554557
555- const float kMovementSpeed = g_cspeed;
556- if (g_is_fwd_pressed)
557- {
558- g_camera->MoveForward ((float )dt.count () * kMovementSpeed );
559- update = true ;
560- }
558+ if (std::abs (camrotx) > 0 .001f )
559+ {
561560
562- if (g_is_back_pressed)
563- {
564- g_camera->MoveForward (-(float )dt.count () * kMovementSpeed );
565- update = true ;
566- }
561+ g_camera->Rotate (camrotx);
562+ // g_camera->ArcballRotateHorizontally(float3(0, 0, 0), camrotx);
563+ update = true ;
564+ }
567565
568- if (g_is_right_pressed)
569- {
570- g_camera->MoveRight ((float )dt.count () * kMovementSpeed );
571- update = true ;
572- }
566+ const float kMovementSpeed = g_cspeed;
567+ if (g_is_fwd_pressed)
568+ {
569+ g_camera->MoveForward ((float )dt.count () * kMovementSpeed );
570+ update = true ;
571+ }
573572
574- if (g_is_left_pressed )
575- {
576- g_camera->MoveRight (-(float )dt.count () * kMovementSpeed );
577- update = true ;
578- }
573+ if (g_is_back_pressed )
574+ {
575+ g_camera->MoveForward (-(float )dt.count () * kMovementSpeed );
576+ update = true ;
577+ }
579578
580- if (g_is_home_pressed )
581- {
582- g_camera->MoveUp ((float )dt.count () * kMovementSpeed );
583- update = true ;
584- }
579+ if (g_is_right_pressed )
580+ {
581+ g_camera->MoveRight ((float )dt.count () * kMovementSpeed );
582+ update = true ;
583+ }
585584
586- if (g_is_end_pressed)
587- {
588- g_camera->MoveUp (-(float )dt.count () * kMovementSpeed );
589- update = true ;
585+ if (g_is_left_pressed)
586+ {
587+ g_camera->MoveRight (-(float )dt.count () * kMovementSpeed );
588+ update = true ;
589+ }
590+
591+ if (g_is_home_pressed)
592+ {
593+ g_camera->MoveUp ((float )dt.count () * kMovementSpeed );
594+ update = true ;
595+ }
596+
597+ if (g_is_end_pressed)
598+ {
599+ g_camera->MoveUp (-(float )dt.count () * kMovementSpeed );
600+ update = true ;
601+ }
590602 }
591603
592604 if (update)
@@ -753,7 +765,7 @@ void Update(bool update_required)
753765 // std::cout << "Shadow rays: " << (float)(numrays / (stats.shadow_rays_time_in_ms * 0.001f) * 0.000001f) << "mrays/s ( " << stats.shadow_rays_time_in_ms << "ms )\n";
754766
755767 g_benchmark = false ;
756- g_benchmarked = true ;
768+ g_rt_benchmarked = true ;
757769 }
758770}
759771
@@ -812,20 +824,31 @@ void OnError(int error, const char* description)
812824 std::cout << description << " \n " ;
813825}
814826
815- bool GradeBenchmarkResults (std::string const & scene, int & general, int & rt )
827+ bool GradeTimeBenchmarkResults (std::string const & scene, int time_in_sec, std::string& rating, ImVec4& color )
816828{
817829 if (scene == " classroom.obj" )
818830 {
819- auto num_samples = g_stats.resolution .x * g_stats.resolution .y ;
820- auto primary = (float )(num_samples / (g_stats.primary_rays_time_in_ms * 0 .001f ) * 0 .000001f );
821- auto secondary = (float )(num_samples / (g_stats.secondary_rays_time_in_ms * 0 .001f ) * 0 .000001f );
822- auto shadow = (float )(num_samples / (g_stats.shadow_rays_time_in_ms * 0 .001f ) * 0 .000001f );
823-
824- auto avg = (primary + secondary + shadow) / 3 .f ;
825- auto samples = g_stats.samples_pes_sec ;
831+ if (time_in_sec < 70 )
832+ {
833+ rating = " Excellent" ;
834+ color = ImVec4 (0 .1f , 0 .7f , 0 .1f , 1 .f );
835+ }
836+ else if (time_in_sec < 100 )
837+ {
838+ rating = " Good" ;
839+ color = ImVec4 (0 .1f , 0 .7f , 0 .1f , 1 .f );
840+ }
841+ else if (time_in_sec < 120 )
842+ {
843+ rating = " Average" ;
844+ color = ImVec4 (0 .7f , 0 .7f , 0 .1f , 1 .f );
845+ }
846+ else
847+ {
848+ rating = " Poor" ;
849+ color = ImVec4 (0 .7f , 0 .1f , 0 .1f , 1 .f );
850+ }
826851
827- general = (int )(samples / 60 .f * 100 .f );
828- rt = (int )(100 .f * avg / 300 .f );
829852 return true ;
830853 }
831854
@@ -1092,34 +1115,70 @@ int main(int argc, char * argv[])
10921115 ImGui::Text (" " );
10931116 ImGui::Text (" Frame time %.3f ms/frame (%.1f FPS)" , 1000 .0f / ImGui::GetIO ().Framerate , ImGui::GetIO ().Framerate );
10941117 ImGui::Text (" Renderer performance %.3f Msamples/s" , (ImGui::GetIO ().Framerate * g_window_width * g_window_height) / 1000000 .f );
1095-
10961118 ImGui::Separator ();
10971119
1098- if (!g_benchmark && ImGui::Button ( " Start benchmark " ) )
1120+ if (g_time_benchmark )
10991121 {
1100- g_benchmark = true ;
1122+ ImGui::ProgressBar (g_samplecount / 512 . f ) ;
11011123 }
11021124
1103- if (g_benchmarked )
1125+ if (!g_time_benchmark && !g_benchmark )
11041126 {
1105- ImGui::Text (" " );
1106- ImGui::Text (" Performance index measures general" );
1107- ImGui::Text (" rendering capabilities." );
1108- ImGui::Text (" RT performance index measures system" );
1109- ImGui::Text (" ray tracing capabilities." );
1127+ if (ImGui::Button (" Start benchmark" ) && g_num_samples == -1 )
1128+ {
1129+ g_time_bench_start_time = std::chrono::high_resolution_clock::now ();
1130+ g_time_benchmark = true ;
1131+ update = true ;
1132+ }
1133+
1134+ if (!g_time_benchmark && ImGui::Button (" Start RT benchmark" ))
1135+ {
1136+ g_benchmark = true ;
1137+ }
1138+ }
11101139
1111- int general, rt;
1140+ if (g_time_benchmark && g_samplecount > 511 )
1141+ {
1142+ g_time_benchmark = false ;
1143+ auto delta = std::chrono::duration_cast<std::chrono::milliseconds>
1144+ (std::chrono::high_resolution_clock::now () - g_time_bench_start_time).count ();
1145+ g_time_benchmark_time = delta / 1000 .f ;
1146+ g_time_benchmarked = true ;
1147+ }
11121148
1113- if (GradeBenchmarkResults (g_modelname, general, rt))
1149+ if (g_time_benchmarked)
1150+ {
1151+ auto minutes = (int )(g_time_benchmark_time / 60 .f );
1152+ auto seconds = (int )(g_time_benchmark_time - minutes * 60 );
1153+ ImGui::Separator ();
1154+
1155+ ImVec4 color;
1156+ std::string rating;
1157+ ImGui::Text (" Rendering time: %2dmin:%ds" , minutes, seconds);
1158+ if (GradeTimeBenchmarkResults (g_modelname, minutes * 60 + seconds, rating, color))
11141159 {
1115- ImGui::TextColored (ImVec4 (0 .2f , 1 .f , 0 .2f , 1 .f ), " Performance index: %d (of 100)" , general);
1116- ImGui::TextColored (ImVec4 (0 .2f , 1 .f , 0 .2f , 1 .f ), " RT perf index: %d (of 100)" , rt);
1160+ ImGui::TextColored (color, " Rating: %s" , rating.c_str ());
11171161 }
11181162 else
11191163 {
1120- ImGui::TextColored ( ImVec4 ( 0 . 7f , 0 . 2f , 0 . 2f , 1 . f ), " Perf grades are not available for this scene " );
1164+ ImGui::Text ( " Rating: N/A " );
11211165 }
11221166 }
1167+
1168+ if (g_rt_benchmarked)
1169+ {
1170+ // if (GradeBenchmarkResults(g_modelname, general, rt))
1171+ // {
1172+ auto num_rays = g_stats.resolution .x * g_stats.resolution .y ;
1173+ auto primary = (float )(num_rays / (g_stats.primary_rays_time_in_ms * 0 .001f ) * 0 .000001f );
1174+ auto secondary = (float )(num_rays / (g_stats.secondary_rays_time_in_ms * 0 .001f ) * 0 .000001f );
1175+ auto shadow = (float )(num_rays / (g_stats.shadow_rays_time_in_ms * 0 .001f ) * 0 .000001f );
1176+
1177+ ImGui::Separator ();
1178+ ImGui::Text (" Primary rays: %f Mrays/s" , primary);
1179+ ImGui::Text (" Secondary rays: %f Mrays/s" , secondary);
1180+ ImGui::Text (" Shadow rays: %f Mrays/s" , shadow);
1181+ }
11231182
11241183 ImGui::End ();
11251184
0 commit comments