From ec18be01e9afc35dd2530dd4ac21f3d7f5e5889d Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:23:20 +0300 Subject: [PATCH 1/8] Fixing crash on MacOS --- source/blender/render/hydra/engine.cc | 4 +++- source/blender/render/hydra/render_task_delegate.cc | 11 +++++++++-- source/blender/render/hydra/viewport_engine.cc | 8 ++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 0089783710f1..97cbcfb3eec1 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -56,7 +56,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { - render_task_delegate_ = std::make_unique( +// render_task_delegate_ = std::make_unique( +// render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); + render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); } else { diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index d0733d450965..14be7d5b1ec7 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -120,7 +120,7 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) binding.aovName = aov_key; binding.renderBufferId = buf_id; binding.aovSettings = aov_desc.aovSettings; - binding.clearValue = pxr::VtValue(pxr::GfVec4f(0)); + binding.clearValue = aov_desc.clearValue; task_params_.aovBindings.push_back(binding); render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams); @@ -199,10 +199,17 @@ void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport) void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) { + RenderTaskDelegate::add_aov(aov_key); + eGPUTextureFormat format; GPUTexture **tex; if (aov_key == pxr::HdAovTokens->color) { - format = GPU_RGBA32F; + if (buffer_descriptors_[buffer_id(aov_key)].format == pxr::HdFormat::HdFormatFloat16Vec4) { + format = GPU_RGBA16F; + } + else { + format = GPU_RGBA32F; + } tex = &tex_color_; } else if (aov_key == pxr::HdAovTokens->depth) { diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 10fc69862c52..99d229fb4ba1 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -183,7 +183,7 @@ void DrawTexture::write_data(int width, int height, const void *data) width, height, 1, - GPU_RGBA32F, + GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, (float *)data); } @@ -240,9 +240,9 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { - if (scene->r.alphamode != R_ALPHAPREMUL) { - tasks.push_back(light_tasks_delegate_->skydome_task()); - } +// if (scene->r.alphamode != R_ALPHAPREMUL) { +// tasks.push_back(light_tasks_delegate_->skydome_task()); +// } tasks.push_back(light_tasks_delegate_->simple_task()); } tasks.push_back(render_task_delegate_->task()); -- 2.30.2 From e1fe0b9cd348adb069b6d5832a1d8ca57176f105 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:25:46 +0300 Subject: [PATCH 2/8] Code cleanup --- source/blender/render/hydra/engine.cc | 9 ++++++--- source/blender/render/hydra/python.cc | 11 +++++------ source/blender/render/hydra/render_task_delegate.cc | 2 -- source/blender/render/hydra/viewport_engine.cc | 8 +++++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 97cbcfb3eec1..ca5826504a77 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -55,16 +55,19 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) free_camera_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); +#ifdef __APPLE__ + render_task_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); +#else if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { -// render_task_delegate_ = std::make_unique( -// render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); - render_task_delegate_ = std::make_unique( + render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); } else { render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); } +#endif render_task_delegate_->set_camera(free_camera_delegate_->GetCameraId()); if (render_delegate_name_ == "HdStormRendererPlugin") { diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index fe2a9295452c..eba6901ac3bd 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -36,7 +36,8 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) } RenderEngine *bl_engine = pyrna_to_pointer(pyengine, &RNA_RenderEngine); - + + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %s", engine_type); Engine *engine = nullptr; try { if (STREQ(engine_type, "VIEWPORT")) { @@ -52,10 +53,8 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) catch (std::runtime_error &e) { CLOG_ERROR(LOG_RENDER_HYDRA, "%s", e.what()); } - - if (engine) { - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p %s", engine, engine_type); - } + + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); return PyLong_FromVoidPtr(engine); } @@ -67,9 +66,9 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args) } Engine *engine = static_cast(PyLong_AsVoidPtr(pyengine)); + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); delete engine; - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); Py_RETURN_NONE; } diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 14be7d5b1ec7..aa3d2b0de663 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -199,8 +199,6 @@ void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport) void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) { - RenderTaskDelegate::add_aov(aov_key); - eGPUTextureFormat format; GPUTexture **tex; if (aov_key == pxr::HdAovTokens->color) { diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 99d229fb4ba1..5606f4101e62 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -240,9 +240,11 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { -// if (scene->r.alphamode != R_ALPHAPREMUL) { -// tasks.push_back(light_tasks_delegate_->skydome_task()); -// } +#ifndef __APPLE__ + if (scene->r.alphamode != R_ALPHAPREMUL) { + tasks.push_back(light_tasks_delegate_->skydome_task()); + } +#endif tasks.push_back(light_tasks_delegate_->simple_task()); } tasks.push_back(render_task_delegate_->task()); -- 2.30.2 From 88b67e1f8a1b58179d9bac4a28fd0db70bf17932 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:36:36 +0300 Subject: [PATCH 3/8] Reverting back some changes --- source/blender/render/hydra/render_task_delegate.cc | 7 +------ source/blender/render/hydra/viewport_engine.cc | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index aa3d2b0de663..e2f4507e4f3e 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -202,12 +202,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) eGPUTextureFormat format; GPUTexture **tex; if (aov_key == pxr::HdAovTokens->color) { - if (buffer_descriptors_[buffer_id(aov_key)].format == pxr::HdFormat::HdFormatFloat16Vec4) { - format = GPU_RGBA16F; - } - else { - format = GPU_RGBA32F; - } + format = GPU_RGBA32F; tex = &tex_color_; } else if (aov_key == pxr::HdAovTokens->depth) { diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 5606f4101e62..02c10089524c 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -183,7 +183,7 @@ void DrawTexture::write_data(int width, int height, const void *data) width, height, 1, - GPU_RGBA16F, + GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, (float *)data); } -- 2.30.2 From 008cdd2e52de12e0e710b347b5ba529fa0ed4ab1 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Mon, 31 Jul 2023 22:09:10 +0300 Subject: [PATCH 4/8] Fix final render --- source/blender/render/hydra/final_engine.cc | 2 ++ source/blender/render/hydra/viewport_engine.cc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 26355bed245b..9d211a3d90e1 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -69,7 +69,9 @@ void FinalEngine::render(Depsgraph *depsgraph) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { if (scene->r.alphamode != R_ALPHAPREMUL) { +#ifndef __APPLE__ tasks.push_back(light_tasks_delegate_->skydome_task()); +#endif } tasks.push_back(light_tasks_delegate_->simple_task()); } diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 02c10089524c..d057e84363c0 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -240,11 +240,11 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { -#ifndef __APPLE__ if (scene->r.alphamode != R_ALPHAPREMUL) { +#ifndef __APPLE__ tasks.push_back(light_tasks_delegate_->skydome_task()); - } #endif + } tasks.push_back(light_tasks_delegate_->simple_task()); } tasks.push_back(render_task_delegate_->task()); -- 2.30.2 From e6a5bd73516c9aace6cd4fbb24ce9fd1984b922d Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:47:51 +0300 Subject: [PATCH 5/8] Fixed Final render --- source/blender/render/hydra/CMakeLists.txt | 1 + .../render/hydra/render_task_delegate.cc | 30 ++++++++++++------- .../render/hydra/render_task_delegate.h | 4 +-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 5994b1cfbfc4..41180e6604b0 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -62,6 +62,7 @@ set(INC_SYS ${BOOST_INCLUDE_DIR} ${TBB_INCLUDE_DIR} ${GFLAGS_INCLUDE_DIRS} + ${EIGEN3_INCLUDE_DIRS} ) set(LIB diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index e2f4507e4f3e..57a34e936971 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -13,8 +13,9 @@ #include "MEM_guardedalloc.h" +#include "Eigen/Core" + #include "engine.h" -#include "render_task_delegate.h" namespace blender::render::hydra { @@ -127,18 +128,28 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText()); } -void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) +void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) { pxr::HdRenderBuffer *buffer = static_cast( GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, buffer_id(aov_key))); if (!buffer) { return; } - void *buf_data = buffer->Map(); - memcpy(data, - buf_data, - buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat())); - buffer->Unmap(); + + pxr::HdFormat format = buffer->GetFormat(); + size_t len = buffer->GetWidth() * buffer->GetHeight() * pxr::HdGetComponentCount(format); + if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat32) { + float *buf_data = (float *)buffer->Map(); + memcpy(data, buf_data, len * sizeof(float)); + buffer->Unmap(); + } + else if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat16) { + Eigen::half *buf_data = (Eigen::half *)buffer->Map(); + for (size_t i = 0; i < len; ++i) { + data[i] = buf_data[i]; + } + buffer->Unmap(); + } } void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) @@ -228,7 +239,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText()); } -void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) +void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) { GPUTexture *tex = nullptr; int c; @@ -253,14 +264,11 @@ void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) { GPUTexture *tex = nullptr; - int c; if (aov_key == pxr::HdAovTokens->color) { tex = tex_color_; - c = 4; } else if (aov_key == pxr::HdAovTokens->depth) { tex = tex_depth_; - c = 1; } if (!tex) { return; diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index 0092fc73c40a..11bcbb28f738 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -34,7 +34,7 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { virtual bool is_converged(); virtual void set_viewport(pxr::GfVec4d const &viewport); virtual void add_aov(pxr::TfToken const &aov_key); - virtual void read_aov(pxr::TfToken const &aov_key, void *data); + virtual void read_aov(pxr::TfToken const &aov_key, float *data); virtual void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture); virtual void bind(); virtual void unbind(); @@ -56,7 +56,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate { void set_viewport(pxr::GfVec4d const &viewport) override; void add_aov(pxr::TfToken const &aov_key) override; - void read_aov(pxr::TfToken const &aov_key, void *data) override; + void read_aov(pxr::TfToken const &aov_key, float *data) override; void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override; void bind() override; void unbind() override; -- 2.30.2 From 9c225e097a195dfd8bb117e88cda6899d9575849 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:43:56 +0300 Subject: [PATCH 6/8] More correct usage of GPURenderTaskDelegate. Applied `make format` to whole code. --- doc/python_api/examples/bpy.types.HydraRenderEngine.py | 3 +++ scripts/modules/bpy_hydra.py | 1 + source/blender/render/hydra/engine.cc | 7 +------ source/blender/render/hydra/python.cc | 4 ++-- source/blender/render/hydra/render_task_delegate.cc | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/python_api/examples/bpy.types.HydraRenderEngine.py b/doc/python_api/examples/bpy.types.HydraRenderEngine.py index 4f3a051220f6..172b6a6c86c2 100644 --- a/doc/python_api/examples/bpy.types.HydraRenderEngine.py +++ b/doc/python_api/examples/bpy.types.HydraRenderEngine.py @@ -7,6 +7,7 @@ USD Hydra Based Renderer import bpy + class CustomHydraRenderEngine(bpy.types.HydraRenderEngine): # Identifier and name in the user interface. bl_idname = "CUSTOM_HYDRA_RENDERER" @@ -53,8 +54,10 @@ class CustomHydraRenderEngine(bpy.types.HydraRenderEngine): def register(): bpy.utils.register_class(CustomHydraRenderEngine) + def unregister(): bpy.utils.unregister_class(CustomHydraRenderEngine) + if __name__ == "__main__": register() diff --git a/scripts/modules/bpy_hydra.py b/scripts/modules/bpy_hydra.py index 56fe6664f165..cb40f75ffd60 100644 --- a/scripts/modules/bpy_hydra.py +++ b/scripts/modules/bpy_hydra.py @@ -4,6 +4,7 @@ __all__ = ( "export_mtlx", ) + def export_mtlx(material): """ Exports material to .mtlx file. It is called from Blender source code. """ try: diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index ca5826504a77..e0d7d79af04d 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -55,11 +55,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) free_camera_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); -#ifdef __APPLE__ - render_task_delegate_ = std::make_unique( - render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); -#else - if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { + if (bl_engine->type->flag & RE_USE_GPU_CONTEXT && GPU_backend_get_type() == GPU_BACKEND_OPENGL) { render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); } @@ -67,7 +63,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); } -#endif render_task_delegate_->set_camera(free_camera_delegate_->GetCameraId()); if (render_delegate_name_ == "HdStormRendererPlugin") { diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index eba6901ac3bd..b262b87686e7 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -36,7 +36,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) } RenderEngine *bl_engine = pyrna_to_pointer(pyengine, &RNA_RenderEngine); - + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %s", engine_type); Engine *engine = nullptr; try { @@ -53,7 +53,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) catch (std::runtime_error &e) { CLOG_ERROR(LOG_RENDER_HYDRA, "%s", e.what()); } - + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); return PyLong_FromVoidPtr(engine); } diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 57a34e936971..a14db3b0ba14 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -135,7 +135,7 @@ void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) if (!buffer) { return; } - + pxr::HdFormat format = buffer->GetFormat(); size_t len = buffer->GetWidth() * buffer->GetHeight() * pxr::HdGetComponentCount(format); if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat32) { -- 2.30.2 From c948b91feee74b7111b60e0c9386a92138020593 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 2 Aug 2023 04:37:18 +0300 Subject: [PATCH 7/8] Fixes after merge, fixing review comments. Added AOV warnings. --- source/blender/render/hydra/engine.cc | 18 +++++++++++++++ source/blender/render/hydra/engine.h | 5 +++- source/blender/render/hydra/final_engine.cc | 14 ++--------- source/blender/render/hydra/python.cc | 2 +- .../render/hydra/render_task_delegate.cc | 23 +++++++++++++++---- .../render/hydra/render_task_delegate.h | 4 ++-- .../blender/render/hydra/viewport_engine.cc | 17 ++++---------- 7 files changed, 50 insertions(+), 33 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 45f5dd8529f3..c878f433e814 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -133,4 +133,22 @@ float Engine::renderer_percent_done() return (float)it->second.UncheckedGet(); } +pxr::HdTaskSharedPtrVector Engine::tasks() +{ + pxr::HdTaskSharedPtrVector res; + if (light_tasks_delegate_) { + if (scene_->r.alphamode != R_ALPHAPREMUL) { +#ifndef __APPLE__ + /* TODO: Temporary disable skydome task for MacOS due to crash with error: + Failed to created pipeline state, error depthAttachmentPixelFormat is not valid + and shader writes to depth */ + res.push_back(light_tasks_delegate_->skydome_task()); +#endif + } + res.push_back(light_tasks_delegate_->simple_task()); + } + res.push_back(render_task_delegate_->task()); + return res; +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 7fe68c81d9f7..f3558e3ffeeb 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -64,7 +64,10 @@ class Engine { protected: float renderer_percent_done(); - virtual void notify_status(float progress, const std::string &title, const std::string &info) = 0; + pxr::HdTaskSharedPtrVector tasks(); + virtual void notify_status(float progress, + const std::string &title, + const std::string &info) = 0; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 9ce1e485791f..e12b24608c1e 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -66,20 +66,10 @@ void FinalEngine::render() render_task_delegate_->add_aov(pxr::HdAovTokens->depth); } - pxr::HdTaskSharedPtrVector tasks; - if (light_tasks_delegate_) { - if (scene_->r.alphamode != R_ALPHAPREMUL) { -#ifndef __APPLE__ - tasks.push_back(light_tasks_delegate_->skydome_task()); -#endif - } - tasks.push_back(light_tasks_delegate_->simple_task()); - } - tasks.push_back(render_task_delegate_->task()); - render_task_delegate_->bind(); - engine_->Execute(render_index_.get(), &tasks); + auto t = tasks(); + engine_->Execute(render_index_.get(), &t); char elapsed_time[32]; double time_begin = PIL_check_seconds_timer(); diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index b42472cb92a2..be1aa2632252 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -37,7 +37,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) RenderEngine *bl_engine = pyrna_to_pointer(pyengine, &RNA_RenderEngine); - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %s", engine_type); + CLOG_INFO(LOG_HYDRA_RENDER, 1, "Engine %s", engine_type); Engine *engine = nullptr; try { if (STREQ(engine_type, "VIEWPORT")) { diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index dc1a92c6556f..6010d866ee55 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -108,6 +108,16 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) aov_key); if (aov_desc.format == pxr::HdFormatInvalid) { + CLOG_ERROR(LOG_HYDRA_RENDER, "Invalid AOV: %s", aov_key.GetText()); + return; + } + if (!ELEM( + pxr::HdGetComponentFormat(aov_desc.format), pxr::HdFormatFloat32, pxr::HdFormatFloat16)) + { + CLOG_WARN(LOG_HYDRA_RENDER, + "Unsupported data format %s for AOV %s", + pxr::TfEnum::GetName(aov_desc.format).c_str(), + aov_key.GetText()); return; } @@ -128,7 +138,7 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) CLOG_INFO(LOG_HYDRA_RENDER, 1, "%s", aov_key.GetText()); } -void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) +void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) { pxr::HdRenderBuffer *buffer = static_cast( GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, buffer_id(aov_key))); @@ -139,17 +149,21 @@ void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) pxr::HdFormat format = buffer->GetFormat(); size_t len = buffer->GetWidth() * buffer->GetHeight() * pxr::HdGetComponentCount(format); if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat32) { - float *buf_data = (float *)buffer->Map(); + void *buf_data = buffer->Map(); memcpy(data, buf_data, len * sizeof(float)); buffer->Unmap(); } else if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat16) { Eigen::half *buf_data = (Eigen::half *)buffer->Map(); + float *fdata = (float *)data; for (size_t i = 0; i < len; ++i) { - data[i] = buf_data[i]; + fdata[i] = buf_data[i]; } buffer->Unmap(); } + else { + BLI_assert_unreachable(); + } } void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) @@ -221,6 +235,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) tex = &tex_depth_; } else { + CLOG_ERROR(LOG_HYDRA_RENDER, "Invalid AOV: %s", aov_key.GetText()); return; } @@ -239,7 +254,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key) CLOG_INFO(LOG_HYDRA_RENDER, 1, "%s", aov_key.GetText()); } -void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data) +void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) { GPUTexture *tex = nullptr; int c; diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index 7b8cb5e049fb..36e7b56b0f45 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -34,7 +34,7 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { bool is_converged(); virtual void set_viewport(pxr::GfVec4d const &viewport); virtual void add_aov(pxr::TfToken const &aov_key); - virtual void read_aov(pxr::TfToken const &aov_key, float *data); + virtual void read_aov(pxr::TfToken const &aov_key, void *data); virtual void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture); virtual void bind(); virtual void unbind(); @@ -56,7 +56,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate { void set_viewport(pxr::GfVec4d const &viewport) override; void add_aov(pxr::TfToken const &aov_key) override; - void read_aov(pxr::TfToken const &aov_key, float *data) override; + void read_aov(pxr::TfToken const &aov_key, void *data) override; void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override; void bind() override; void unbind() override; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 8b2db59f346c..be78e6ab437d 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -232,21 +232,11 @@ void ViewportEngine::render() render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->depth); - pxr::HdTaskSharedPtrVector tasks; - if (light_tasks_delegate_) { - if (scene_->r.alphamode != R_ALPHAPREMUL) { -#ifndef __APPLE__ - tasks.push_back(light_tasks_delegate_->skydome_task()); -#endif - } - tasks.push_back(light_tasks_delegate_->simple_task()); - } - tasks.push_back(render_task_delegate_->task()); - GPUFrameBuffer *view_framebuffer = GPU_framebuffer_active_get(); render_task_delegate_->bind(); - engine_->Execute(render_index_.get(), &tasks); + auto t = tasks(); + engine_->Execute(render_index_.get(), &t); render_task_delegate_->unbind(); @@ -295,7 +285,8 @@ void ViewportEngine::render(bContext *context) render(); } -void ViewportEngine::notify_status(float /*progress*/, const std::string &info, +void ViewportEngine::notify_status(float /*progress*/, + const std::string &info, const std::string &status) { RE_engine_update_stats(bl_engine_, status.c_str(), info.c_str()); -- 2.30.2 From f870bff953a7e47000b761bc31156af0b927521d Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak <33626169+bnagirniak@users.noreply.github.com> Date: Wed, 2 Aug 2023 10:28:55 +0300 Subject: [PATCH 8/8] comment fix --- source/blender/render/hydra/engine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index c878f433e814..d8ced6fb2bfd 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -140,8 +140,8 @@ pxr::HdTaskSharedPtrVector Engine::tasks() if (scene_->r.alphamode != R_ALPHAPREMUL) { #ifndef __APPLE__ /* TODO: Temporary disable skydome task for MacOS due to crash with error: - Failed to created pipeline state, error depthAttachmentPixelFormat is not valid - and shader writes to depth */ + * Failed to created pipeline state, error depthAttachmentPixelFormat is not valid + * and shader writes to depth */ res.push_back(light_tasks_delegate_->skydome_task()); #endif } -- 2.30.2