BLEN-365: Improve creation algorithm of PreviewEngine #21

Merged
Bogdan Nagirniak merged 11 commits from BLEN-365 into hydra-render 2023-04-10 12:44:48 +02:00
4 changed files with 7 additions and 23 deletions
Showing only changes of commit cca11e5b17 - Show all commits

View File

@ -34,13 +34,14 @@ class Engine {
bContext *context, bContext *context,
pxr::HdRenderSettingsMap &render_settings) = 0; pxr::HdRenderSettingsMap &render_settings) = 0;
virtual void render(Depsgraph *depsgraph) = 0; virtual void render(Depsgraph *depsgraph) = 0;
public:
RenderEngine *bl_engine; RenderEngine *bl_engine;
protected: protected:
float renderer_percent_done(); float renderer_percent_done();
protected: protected:
pxr::HdPluginRenderDelegateUniqueHandle render_delegate; pxr::HdPluginRenderDelegateUniqueHandle render_delegate;
std::unique_ptr<pxr::HdRenderIndex> render_index; std::unique_ptr<pxr::HdRenderIndex> render_index;
std::unique_ptr<BlenderSceneDelegate> scene_delegate; std::unique_ptr<BlenderSceneDelegate> scene_delegate;

View File

@ -12,37 +12,22 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
bContext *context, bContext *context,
pxr::HdRenderSettingsMap &render_settings) pxr::HdRenderSettingsMap &render_settings)
{ {
is_synced = false;
scene_delegate->clear_data(); scene_delegate->clear_data();
for (auto &prim : render_index->GetRprimIds()) { for (auto &prim : render_index->GetRprimIds()) {
DagerD marked this conversation as resolved Outdated

Move this to clear()

Move this to clear()
render_index->RemoveRprim(prim); render_index->RemoveRprim(prim);
render_index->RemoveInstancer(prim); render_index->RemoveInstancer(prim);
std::cout << "sync RemoveRprim: " << prim.GetText() << " " << render_index->HasRprim(prim)
<< "\n";
}
for (auto &prim : render_index->GetRprimIds()) {
std::cout << "sync after Remove: " << prim.GetText() << "\n";
} }
scene_delegate->populate(depsgraph, context); scene_delegate->populate(depsgraph, context);
for (auto &prim : render_index->GetRprimIds()) {
std::cout << "sync populate: " << prim.GetText() << "\n";
}
for (auto const &setting : render_settings) { for (auto const &setting : render_settings) {
render_delegate->SetRenderSetting(setting.first, setting.second); render_delegate->SetRenderSetting(setting.first, setting.second);
} }
is_synced = true;
} }
void PreviewEngine::render(Depsgraph *depsgraph) void PreviewEngine::render(Depsgraph *depsgraph)
{ {
//if (!is_synced) {
// return;
//}
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
@ -53,7 +38,6 @@ void PreviewEngine::render(Depsgraph *depsgraph)
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1)); CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
free_camera_delegate->SetCamera(camera); free_camera_delegate->SetCamera(camera);
//render_task_delegate->clear_renderer_aovs();
render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(),
pxr::GfVec4d(0, 0, res[0], res[1])); pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color);

View File

@ -16,8 +16,6 @@ class PreviewEngine : public FinalEngine {
void render(Depsgraph *depsgraph) override; void render(Depsgraph *depsgraph) override;
void stop_renderer(); void stop_renderer();
bool is_synced = false;
protected: protected:
void update_render_result(const std::string &layer_name, void update_render_result(const std::string &layer_name,
int width, int width,

View File

@ -23,7 +23,7 @@ namespace blender::render::hydra {
static double preview_engine_lifetime = 60.0; static double preview_engine_lifetime = 60.0;
DagerD marked this conversation as resolved Outdated

move to PreviewEngine class as static

move to PreviewEngine class as static
static PreviewEngine *preview_engine; static PreviewEngine *preview_engine;
DagerD marked this conversation as resolved Outdated

Use unique_ptr

Use unique_ptr
double timer_func(uintptr_t uuid, void *user_data) double delete_preview_engine(uintptr_t uuid, void *user_data)
{ {
if (preview_engine) { if (preview_engine) {
preview_engine->stop_renderer(); preview_engine->stop_renderer();
DagerD marked this conversation as resolved Outdated

add logging

add logging

Do not stop render, check if it is in render process, then return preview_engine_lifetime.

Do not stop render, check if it is in render process, then return preview_engine_lifetime.
@ -164,7 +164,8 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
if (preview_engine) { if (preview_engine) {
BLI_timer_register(1, timer_func, nullptr, nullptr, preview_engine_lifetime, true); BLI_timer_register(1, delete_preview_engine, nullptr, nullptr, preview_engine_lifetime, true);
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }