Fix review comments #27

Merged
Bogdan Nagirniak merged 14 commits from BLEN-392 into hydra-render 2023-04-21 15:02:44 +02:00
6 changed files with 33 additions and 73 deletions
Showing only changes of commit 176406f494 - Show all commits

View File

@ -5,10 +5,11 @@
#include "DEG_depsgraph_query.h"
#include "GPU_framebuffer.h"
#include "GPU_texture.h"
#include "PIL_time.h"
#include "BLI_timecode.h"
#include "camera.h"
#include "final_engine.h"
#include "utils.h"
namespace blender::render::hydra {
@ -63,12 +64,6 @@ void FinalEngine::render(Depsgraph *depsgraph)
}
tasks.push_back(render_task_delegate_->get_task());
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
std::vector<float> &pixels = render_images["Combined"];
@ -79,19 +74,23 @@ void FinalEngine::render(Depsgraph *depsgraph)
engine_->Execute(render_index_.get(), &tasks);
}
char elapsed_time[32];
double time_begin = PIL_check_seconds_timer();
float percent_done = 0.0;
while (true) {
if (RE_engine_test_break(bl_engine_)) {
break;
}
percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
time_begin);
BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsed_time) +
std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged()) {
@ -185,12 +184,6 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
}
tasks.push_back(render_task_delegate_->get_task());
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
std::vector<float> &pixels = render_images["Combined"];
@ -217,19 +210,23 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
engine_->Execute(render_index_.get(), &tasks);
}
char elapsed_time[32];
double time_begin = PIL_check_seconds_timer();
float percent_done = 0.0;
while (true) {
if (RE_engine_test_break(bl_engine_)) {
break;
}
percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current -
time_begin);
BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsed_time) +
std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged()) {

View File

@ -3,8 +3,6 @@
#pragma once
#include <chrono>
#include "engine.h"
namespace blender::render::hydra {

View File

@ -1,9 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <chrono>
#include <filesystem>
#include <sstream>
#include <pxr/base/tf/stringUtils.h>
@ -29,35 +27,6 @@ pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
return ret;
}
std::string format_duration(std::chrono::milliseconds millisecs)
{
std::stringstream ss;
bool neg = millisecs < std::chrono::milliseconds(0);
if (neg) {
millisecs = -millisecs;
}
auto m = std::chrono::duration_cast<std::chrono::minutes>(millisecs);
millisecs -= m;
auto s = std::chrono::duration_cast<std::chrono::seconds>(millisecs);
millisecs -= s;
if (neg) {
ss << "-";
}
if (m < std::chrono::minutes(10)) {
ss << "0";
}
ss << std::to_string(m / std::chrono::minutes(1)) << ":";
if (s < std::chrono::seconds(10)) {
ss << "0";
}
ss << std::to_string(s / std::chrono::seconds(1)) << ":";
if (millisecs < std::chrono::milliseconds(10)) {
ss << "0";
}
ss << std::to_string(millisecs / std::chrono::milliseconds(1) / 10);
return ss.str();
}
std::string cache_image(Main *bmain,
Scene *scene,
Image *image,

View File

@ -3,7 +3,6 @@
#pragma once
#include <chrono>
#include <string>
#include <pxr/base/gf/matrix4d.h>
@ -14,7 +13,6 @@
namespace blender::render::hydra {
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);
std::string format_duration(std::chrono::milliseconds secs);
std::string cache_image(Main *bmain,
Scene *scene,
Image *image,

View File

@ -11,14 +11,16 @@
#include "BKE_camera.h"
#include "BLI_timecode.h"
#include "BLI_math_matrix.h"
#include "DEG_depsgraph_query.h"
#include "GPU_matrix.h"
#include "PIL_time.h"
#include "camera.h"
#include "utils.h"
#include "viewport_engine.h"
namespace blender::render::hydra {
@ -259,10 +261,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
}
if (renderer_percent_done() == 0.0f) {
time_begin_ = std::chrono::steady_clock::now();
}
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader);
@ -285,21 +283,23 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
GPU_shader_unbind();
std::chrono::time_point<std::chrono::steady_clock> time_current =
std::chrono::steady_clock::now();
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(
time_current - time_begin_);
if (renderer_percent_done() == 0.0f) {
time_begin_ = PIL_check_seconds_timer();
}
std::string formatted_time = format_duration(elapsed_time);
char elapsed_time[32];
BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_);
if (!render_task_delegate_->is_converged()) {
notify_status("Time: " + formatted_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
notify_status(std::string("Time: ") + elapsed_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render");
bl_engine_->flag |= RE_ENGINE_DO_DRAW;
}
else {
notify_status(("Time: " + formatted_time).c_str(), "Rendering Done");
notify_status((std::string("Time: ") + elapsed_time).c_str(), "Rendering Done");
}
}

View File

@ -3,8 +3,6 @@
#pragma once
#include <chrono>
#include <pxr/imaging/hd/renderBuffer.h>
#include "GPU_batch.h"
@ -46,7 +44,7 @@ class ViewportEngine : public Engine {
void notify_status(const std::string &title, const std::string &info);
private:
std::chrono::time_point<std::chrono::steady_clock> time_begin_;
double time_begin_;
DrawTexture draw_texture_;
};