Hydra render engine #104712

Closed
Bogdan Nagirniak wants to merge 142 commits from BogdanNagirniak/blender:hydra-render into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 21 additions and 11 deletions
Showing only changes of commit a95359896d - Show all commits

View File

@ -25,7 +25,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name_));
BogdanNagirniak marked this conversation as resolved Outdated

This will need an addition for Vulkan support. It seems there is no way to pass a parameter, but this should work:

if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) {
  setenv HGI_ENABLE_VULKAN=1
}

This should be relatively thread safe, as Blender can not switch between OpenGL and Vulkan at runtime, so it should always get set to the same thing.

This will need an addition for Vulkan support. It seems there is no way to pass a parameter, but this should work: ``` if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) { setenv HGI_ENABLE_VULKAN=1 } ``` This should be relatively thread safe, as Blender can not switch between OpenGL and Vulkan at runtime, so it should always get set to the same thing.
/* Current USD (23.02) has limited support for Vulkan. To make it works USD should be built
/* USD has limited support for Vulkan. To make it works USD should be built
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) {
BLI_setenv("HGI_ENABLE_VULKAN", "1");

View File

@ -14,16 +14,16 @@ const double LIFETIME = 180.0;
std::unique_ptr<PreviewEngine> PreviewEngine::instance_;
PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine,
const std::string &render_delegate_id)
const std::string &render_delegate_name)
{
if (!instance_) {
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_id);
instance_ = std::make_unique<PreviewEngine>(bl_engine, render_delegate_name);
}
BogdanNagirniak marked this conversation as resolved Outdated

This is not used anywhere else in Blender internally, only in the Python API. Why is it needed here?

Preview rendering alraedy runs in its own thread as far as I know, it should be fine to run in a blocking loop waiting for the render to be done while the main thread continues.

This is not used anywhere else in Blender internally, only in the Python API. Why is it needed here? Preview rendering alraedy runs in its own thread as far as I know, it should be fine to run in a blocking loop waiting for the render to be done while the main thread continues.
if (BLI_timer_is_registered((uintptr_t)instance_.get())) {
/* Unregister timer while PreviewEngine is working */
BLI_timer_unregister((uintptr_t)instance_.get());
}
instance_->update(bl_engine, render_delegate_id);
instance_->update(bl_engine, render_delegate_name);
return instance_.get();
}
@ -96,10 +96,13 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
return -1;
}
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_id)
void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_name)
{
this->bl_engine_ = bl_engine;
/* TODO: recreate render_delegate when render_delegate_id is changed */
bl_engine_ = bl_engine;
if (render_delegate_name != render_delegate_name_) {
render_delegate_->Stop();
instance_.reset(new PreviewEngine(bl_engine, render_delegate_name));
}
}
void PreviewEngine::update_render_result(std::vector<float> &pixels)

View File

@ -12,7 +12,7 @@ class PreviewEngine : public FinalEngine {
using FinalEngine::FinalEngine;
static PreviewEngine *get_instance(RenderEngine *bl_engine,
const std::string &render_delegate_id);
const std::string &render_delegate_name);
static void schedule_free();
void sync(Depsgraph *depsgraph,
@ -25,7 +25,7 @@ class PreviewEngine : public FinalEngine {
static double free_instance(uintptr_t uuid, void *user_data);
static std::unique_ptr<PreviewEngine> instance_;
void update(RenderEngine *bl_engine, const std::string &render_delegate_id);
void update(RenderEngine *bl_engine, const std::string &render_delegate_name);
void update_render_result(std::vector<float> &pixels);
};

View File

@ -15,7 +15,7 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene");
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id,
BlenderSceneDelegate::EngineType engine_type,
std::string render_delegate_name)
const std::string &render_delegate_name)
: HdSceneDelegate(parent_index, delegate_id),
engine_type(engine_type),
render_delegate_name(render_delegate_name)
@ -187,6 +187,11 @@ void BlenderSceneDelegate::clear()
objects_.clear();
instancers_.clear();
materials_.clear();
depsgraph = nullptr;
context = nullptr;
scene = nullptr;
view3d = nullptr;
}
pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
@ -253,6 +258,8 @@ InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool
{
pxr::SdfPath p_id;
if (child_id) {
/* Getting instancer path id from child Mesh instance (consist with 3 path elements) and
* Light instance (consist with 4 path elements) */
int n = id.GetPathElementCount();
if (n == 3) {
p_id = id.GetParentPath();

View File

@ -30,7 +30,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id,
BlenderSceneDelegate::EngineType engine_type,
std::string render_delegate_name);
const std::string &render_delegate_name);
~BlenderSceneDelegate() override = default;
/* Delegate methods */