From 6d4acd86961404ee09ca38c237c1a44b7870c9c2 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Mon, 29 May 2023 16:52:43 +0300 Subject: [PATCH 1/4] removed timer --- source/blender/render/hydra/preview_engine.cc | 49 ------------------- source/blender/render/hydra/preview_engine.h | 7 --- source/blender/render/hydra/python.cc | 10 +--- 3 files changed, 2 insertions(+), 64 deletions(-) diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 93dcd8dea492..0fd0afd96af4 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -3,48 +3,11 @@ #include "DEG_depsgraph_query.h" -#include "BLI_timer.h" #include "camera.h" #include "preview_engine.h" namespace blender::render::hydra { -const double LIFETIME = 180.0; - -std::unique_ptr PreviewEngine::instance_; - -PreviewEngine *PreviewEngine::create(RenderEngine *bl_engine, - const std::string &render_delegate_name) -{ - if (!instance_) { - instance_ = std::make_unique(bl_engine, render_delegate_name); - } - else if (instance_->render_delegate_name != render_delegate_name) { - instance_->render_delegate_->Stop(); - instance_ = std::make_unique(bl_engine, render_delegate_name); - } - else { - instance_->bl_engine_ = bl_engine; - } - - instance_->scene_delegate_->clear(); - - if (BLI_timer_is_registered((uintptr_t)&instance_)) { - /* Unregister timer while PreviewEngine is working */ - BLI_timer_unregister((uintptr_t)&instance_); - } - - return instance_.get(); -} - -void PreviewEngine::free() -{ - instance_->render_delegate_->Stop(); - - /* Register timer for schedule free PreviewEngine instance */ - BLI_timer_register((uintptr_t)&instance_, free_instance, nullptr, nullptr, LIFETIME, true); -} - void PreviewEngine::render(Depsgraph *depsgraph) { prepare_for_render(depsgraph); @@ -74,18 +37,6 @@ void PreviewEngine::render(Depsgraph *depsgraph) update_render_result(pixels); } -double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) -{ - if (!instance_->render_task_delegate_->is_converged()) { - /* Restart timer if render isn't completed */ - return LIFETIME; - } - - CLOG_INFO(LOG_RENDER_HYDRA, 2, ""); - instance_ = nullptr; - return -1; -} - void PreviewEngine::update_render_result(std::vector &pixels) { RenderResult *result = RE_engine_begin_result( diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 986f88f69e83..5714f0205ac1 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -9,19 +9,12 @@ namespace blender::render::hydra { class PreviewEngine : public FinalEngine { public: - static PreviewEngine *create(RenderEngine *bl_engine, const std::string &render_delegate_name); - static void free(); - void render(Depsgraph *depsgraph) override; private: using FinalEngine::FinalEngine; - static double free_instance(uintptr_t uuid, void *user_data); - void update_render_result(std::vector &pixels); - /* Singleton class instance */ - static std::unique_ptr instance_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 335bbd283730..9ef8f00b3478 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -111,7 +111,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) engine = new ViewportEngine(bl_engine, render_delegate_id); } else if (STREQ(engine_type, "PREVIEW")) { - engine = PreviewEngine::create(bl_engine, render_delegate_id); + engine = new PreviewEngine(bl_engine, render_delegate_id); } else { if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { @@ -134,13 +134,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args) } Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); - PreviewEngine *preview_engine = dynamic_cast(engine); - if (preview_engine) { - PreviewEngine::free(); - } - else { - delete engine; - } + delete engine; CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); Py_RETURN_NONE; -- 2.30.2 From 710a223f7f1a3497975f05b6180ed00888fabd6b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 30 May 2023 12:35:01 +0300 Subject: [PATCH 2/4] Moved using to public --- source/blender/render/hydra/preview_engine.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 5714f0205ac1..89b53a95c33a 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -9,10 +9,11 @@ namespace blender::render::hydra { class PreviewEngine : public FinalEngine { public: + using FinalEngine::FinalEngine; + void render(Depsgraph *depsgraph) override; private: - using FinalEngine::FinalEngine; void update_render_result(std::vector &pixels); }; -- 2.30.2 From 57d041d03c43c7590843c9f7cef9fbf31504fe28 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 30 May 2023 12:37:33 +0300 Subject: [PATCH 3/4] make format --- source/blender/render/hydra/preview_engine.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 89b53a95c33a..4dfc88d80028 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -15,7 +15,6 @@ class PreviewEngine : public FinalEngine { private: void update_render_result(std::vector &pixels); - }; } // namespace blender::render::hydra -- 2.30.2 From 1a25464620ae43a4229e93560951db56dab0792a Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 31 May 2023 12:44:58 +0300 Subject: [PATCH 4/4] Removed unused includes, code improvement --- source/blender/render/hydra/preview_engine.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 0fd0afd96af4..955147f497fd 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include "DEG_depsgraph_query.h" - -#include "camera.h" #include "preview_engine.h" namespace blender::render::hydra { @@ -12,14 +9,13 @@ void PreviewEngine::render(Depsgraph *depsgraph) { prepare_for_render(depsgraph); - std::vector &pixels = render_images_["Combined"]; - { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks_); } + std::vector &pixels = render_images_["Combined"]; while (true) { if (RE_engine_test_break(bl_engine_)) { break; -- 2.30.2