Skip to content

Commit

Permalink
Merge pull request #4 from yozhijk/master
Browse files Browse the repository at this point in the history
Add rendering benchmark
  • Loading branch information
yozhijk authored Jun 1, 2017
2 parents 74af1ba + a381dfe commit 58b6c8d
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Baikal/Kernels/CL/scene.cl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Scene_FillDifferentialGeometry(// Scene
float3 dp2 = v1 - v2;
float det = du1 * dv2 - dv1 * du2;

if (det != 0.f)
if (0 && det != 0.f)
{
float invdet = 1.f / det;
diffgeo->dpdu = normalize( (dv2 * dp1 - dv1 * dp2) * invdet );
Expand Down
199 changes: 129 additions & 70 deletions Baikal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ ConfigManager::Mode g_mode = ConfigManager::Mode::kUseSingleGpu;
Baikal::Renderer::OutputType g_ouput_type = Baikal::Renderer::OutputType::kColor;

Baikal::Renderer::BenchmarkStats g_stats;
bool g_benchmarked = false;
bool g_time_benchmarked = false;
bool g_rt_benchmarked = false;
bool g_time_benchmark = false;
float g_time_benchmark_time = 0.f;

decltype(std::chrono::high_resolution_clock::now()) g_time_bench_start_time;



using namespace tinyobj;

Expand Down Expand Up @@ -533,60 +540,65 @@ void Update(bool update_required)
float camroty = 0.f;

const float kMouseSensitivity = 0.001125f;
float2 delta = g_mouse_delta * float2(kMouseSensitivity, kMouseSensitivity);
camrotx = -delta.x;
camroty = -delta.y;

if (std::abs(camroty) > 0.001f)
if (!g_benchmark && !g_time_benchmark)
{
g_camera->Tilt(camroty);
//g_camera->ArcballRotateVertically(float3(0, 0, 0), camroty);
update = true;
}
float2 delta = g_mouse_delta * float2(kMouseSensitivity, kMouseSensitivity);
camrotx = -delta.x;
camroty = -delta.y;

if (std::abs(camrotx) > 0.001f)
{

g_camera->Rotate(camrotx);
//g_camera->ArcballRotateHorizontally(float3(0, 0, 0), camrotx);
update = true;
}
if (std::abs(camroty) > 0.001f)
{
g_camera->Tilt(camroty);
//g_camera->ArcballRotateVertically(float3(0, 0, 0), camroty);
update = true;
}

const float kMovementSpeed = g_cspeed;
if (g_is_fwd_pressed)
{
g_camera->MoveForward((float)dt.count() * kMovementSpeed);
update = true;
}
if (std::abs(camrotx) > 0.001f)
{

if (g_is_back_pressed)
{
g_camera->MoveForward(-(float)dt.count() * kMovementSpeed);
update = true;
}
g_camera->Rotate(camrotx);
//g_camera->ArcballRotateHorizontally(float3(0, 0, 0), camrotx);
update = true;
}

if (g_is_right_pressed)
{
g_camera->MoveRight((float)dt.count() * kMovementSpeed);
update = true;
}
const float kMovementSpeed = g_cspeed;
if (g_is_fwd_pressed)
{
g_camera->MoveForward((float)dt.count() * kMovementSpeed);
update = true;
}

if (g_is_left_pressed)
{
g_camera->MoveRight(-(float)dt.count() * kMovementSpeed);
update = true;
}
if (g_is_back_pressed)
{
g_camera->MoveForward(-(float)dt.count() * kMovementSpeed);
update = true;
}

if (g_is_home_pressed)
{
g_camera->MoveUp((float)dt.count() * kMovementSpeed);
update = true;
}
if (g_is_right_pressed)
{
g_camera->MoveRight((float)dt.count() * kMovementSpeed);
update = true;
}

if (g_is_end_pressed)
{
g_camera->MoveUp(-(float)dt.count() * kMovementSpeed);
update = true;
if (g_is_left_pressed)
{
g_camera->MoveRight(-(float)dt.count() * kMovementSpeed);
update = true;
}

if (g_is_home_pressed)
{
g_camera->MoveUp((float)dt.count() * kMovementSpeed);
update = true;
}

if (g_is_end_pressed)
{
g_camera->MoveUp(-(float)dt.count() * kMovementSpeed);
update = true;
}
}

if (update)
Expand Down Expand Up @@ -753,7 +765,7 @@ void Update(bool update_required)
//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";

g_benchmark = false;
g_benchmarked = true;
g_rt_benchmarked = true;
}
}

Expand Down Expand Up @@ -812,20 +824,31 @@ void OnError(int error, const char* description)
std::cout << description << "\n";
}

bool GradeBenchmarkResults(std::string const& scene, int& general, int& rt)
bool GradeTimeBenchmarkResults(std::string const& scene, int time_in_sec, std::string& rating, ImVec4& color)
{
if (scene == "classroom.obj")
{
auto num_samples = g_stats.resolution.x * g_stats.resolution.y;
auto primary = (float)(num_samples / (g_stats.primary_rays_time_in_ms * 0.001f) * 0.000001f);
auto secondary = (float)(num_samples / (g_stats.secondary_rays_time_in_ms * 0.001f) * 0.000001f);
auto shadow = (float)(num_samples / (g_stats.shadow_rays_time_in_ms * 0.001f) * 0.000001f);

auto avg = (primary + secondary + shadow) / 3.f;
auto samples = g_stats.samples_pes_sec;
if (time_in_sec < 70)
{
rating = "Excellent";
color = ImVec4(0.1f, 0.7f, 0.1f, 1.f);
}
else if (time_in_sec < 100)
{
rating = "Good";
color = ImVec4(0.1f, 0.7f, 0.1f, 1.f);
}
else if (time_in_sec < 120)
{
rating = "Average";
color = ImVec4(0.7f, 0.7f, 0.1f, 1.f);
}
else
{
rating = "Poor";
color = ImVec4(0.7f, 0.1f, 0.1f, 1.f);
}

general = (int)(samples / 60.f * 100.f);
rt = (int)(100.f * avg / 300.f);
return true;
}

Expand Down Expand Up @@ -1092,34 +1115,70 @@ int main(int argc, char * argv[])
ImGui::Text(" ");
ImGui::Text("Frame time %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Text("Renderer performance %.3f Msamples/s", (ImGui::GetIO().Framerate * g_window_width * g_window_height) / 1000000.f);

ImGui::Separator();

if (!g_benchmark && ImGui::Button("Start benchmark"))
if (g_time_benchmark)
{
g_benchmark = true;
ImGui::ProgressBar(g_samplecount / 512.f);
}

if (g_benchmarked)
if (!g_time_benchmark && !g_benchmark)
{
ImGui::Text(" ");
ImGui::Text("Performance index measures general");
ImGui::Text("rendering capabilities.");
ImGui::Text("RT performance index measures system");
ImGui::Text("ray tracing capabilities.");
if(ImGui::Button("Start benchmark") && g_num_samples == -1)
{
g_time_bench_start_time = std::chrono::high_resolution_clock::now();
g_time_benchmark = true;
update = true;
}

if (!g_time_benchmark && ImGui::Button("Start RT benchmark"))
{
g_benchmark = true;
}
}

int general, rt;
if (g_time_benchmark && g_samplecount > 511)
{
g_time_benchmark = false;
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::high_resolution_clock::now() - g_time_bench_start_time).count();
g_time_benchmark_time = delta / 1000.f;
g_time_benchmarked = true;
}

if (GradeBenchmarkResults(g_modelname, general, rt))
if (g_time_benchmarked)
{
auto minutes = (int)(g_time_benchmark_time / 60.f);
auto seconds = (int)(g_time_benchmark_time - minutes * 60);
ImGui::Separator();

ImVec4 color;
std::string rating;
ImGui::Text("Rendering time: %2dmin:%ds", minutes, seconds);
if (GradeTimeBenchmarkResults(g_modelname, minutes * 60 + seconds, rating, color))
{
ImGui::TextColored(ImVec4(0.2f, 1.f, 0.2f, 1.f), "Performance index: %d (of 100)", general);
ImGui::TextColored(ImVec4(0.2f, 1.f, 0.2f, 1.f), "RT perf index: %d (of 100)", rt);
ImGui::TextColored(color, "Rating: %s", rating.c_str());
}
else
{
ImGui::TextColored(ImVec4(0.7f, 0.2f, 0.2f, 1.f), "Perf grades are not available for this scene");
ImGui::Text("Rating: N/A");
}
}

if (g_rt_benchmarked)
{
//if (GradeBenchmarkResults(g_modelname, general, rt))
//{
auto num_rays = g_stats.resolution.x * g_stats.resolution.y;
auto primary = (float)(num_rays / (g_stats.primary_rays_time_in_ms * 0.001f) * 0.000001f);
auto secondary = (float)(num_rays / (g_stats.secondary_rays_time_in_ms * 0.001f) * 0.000001f);
auto shadow = (float)(num_rays / (g_stats.shadow_rays_time_in_ms * 0.001f) * 0.000001f);

ImGui::Separator();
ImGui::Text("Primary rays: %f Mrays/s", primary);
ImGui::Text("Secondary rays: %f Mrays/s", secondary);
ImGui::Text("Shadow rays: %f Mrays/s", shadow);
}

ImGui::End();

Expand Down

0 comments on commit 58b6c8d

Please sign in to comment.