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.
9 changed files with 114 additions and 9 deletions
Showing only changes of commit c7c7d5cfb1 - Show all commits

View File

@ -59,6 +59,8 @@ set(SRC
renderTaskDelegate.cc
renderTaskDelegate.h
simpleLightTaskDelegate.cc
simpleLightTaskDelegate.h
sceneDelegate/blenderSceneDelegate.h
sceneDelegate/blenderSceneDelegate.cc

View File

@ -2,6 +2,7 @@
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hd/rendererPluginRegistry.h>
#include <pxr/imaging/hdSt/renderDelegate.h>
#include <pxr/imaging/hgi/tokens.h>
#include <pxr/base/plug/plugin.h>
#include <pxr/base/plug/registry.h>
@ -38,6 +39,10 @@ Engine::Engine(BL::RenderEngine &b_engine, const std::string &delegateId)
renderIndex.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
renderTaskDelegate = std::make_unique<RenderTaskDelegate>(
renderIndex.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
if (renderDelegate->GetRendererDisplayName() == "GL") {
simpleLightTaskDelegate = std::make_unique<SimpleLightTaskDelegate>(
renderIndex.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
}
engine = std::make_unique<HdEngine>();
}
@ -47,6 +52,7 @@ Engine::~Engine()
sceneDelegate = nullptr;
renderTaskDelegate = nullptr;
freeCameraDelegate = nullptr;
simpleLightTaskDelegate = nullptr;
renderIndex = nullptr;
BogdanNagirniak marked this conversation as resolved Outdated

Setting to null here seems unnecessary? If it's to guarantee a particular order of destruction, the order of these members in the class should already specify that.

Setting to null here seems unnecessary? If it's to guarantee a particular order of destruction, the order of these members in the class should already specify that.

We did that because we need order of destruction. We'll change it to order of members in the class

We did that because we need order of destruction. We'll change it to order of members in the class
renderDelegate = nullptr;
engine = nullptr;

View File

@ -18,6 +18,7 @@
#include "sceneDelegate/blenderSceneDelegate.h"
#include "renderTaskDelegate.h"
#include "simpleLightTaskDelegate.h"
namespace blender::render::hydra {
@ -39,6 +40,7 @@ protected:
std::unique_ptr<BlenderSceneDelegate> sceneDelegate;
std::unique_ptr<RenderTaskDelegate> renderTaskDelegate;
std::unique_ptr<HdxFreeCameraSceneDelegate> freeCameraDelegate;
std::unique_ptr<SimpleLightTaskDelegate> simpleLightTaskDelegate;
std::unique_ptr<HdEngine> engine;
HgiUniquePtr hgi;

View File

@ -48,8 +48,15 @@ void FinalEngine::render(BL::Depsgraph &b_depsgraph)
freeCameraDelegate->SetCamera(gfCamera);
renderTaskDelegate->SetCameraAndViewport(freeCameraDelegate->GetCameraId(), GfVec4d(0, 0, buffer_res[0], buffer_res[1]));
renderTaskDelegate->SetRendererAov(HdAovTokens->color);
HdTaskSharedPtrVector tasks = renderTaskDelegate->GetTasks();
if (simpleLightTaskDelegate) {
simpleLightTaskDelegate->SetCameraPath(freeCameraDelegate->GetCameraId());
}
HdTaskSharedPtrVector tasks;
if (simpleLightTaskDelegate) {
tasks.push_back(simpleLightTaskDelegate->GetTask());
}
tasks.push_back(renderTaskDelegate->GetTask());
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent;
chrono::milliseconds elapsedTime;
@ -132,8 +139,17 @@ void FinalEngineGL::render(BL::Depsgraph &b_depsgraph)
GfCamera gfCamera = CameraData((Object *)b_scene.camera().ptr.data, res, GfVec4f(0, 0, 1, 1)).gf_camera();
freeCameraDelegate->SetCamera(gfCamera);
renderTaskDelegate->SetCameraAndViewport(freeCameraDelegate->GetCameraId(), GfVec4d(0, 0, res[0], res[1]));
if (simpleLightTaskDelegate) {
simpleLightTaskDelegate->SetCameraPath(freeCameraDelegate->GetCameraId());
}
HdTaskSharedPtrVector tasks = renderTaskDelegate->GetTasks();
HdTaskSharedPtrVector tasks;
if (simpleLightTaskDelegate) {
/* TODO: Uncomment this and fix GL error:
invalid operation, reported from void __cdecl pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
// tasks.push_back(simpleLightTaskDelegate->GetTask());
}
tasks.push_back(renderTaskDelegate->GetTask());
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent;
chrono::milliseconds elapsedTime;

View File

@ -20,6 +20,9 @@ RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex* parentIndex, SdfPath const
GetRenderIndex().InsertTask<HdxRenderTask>(this, renderTaskId);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyCollection);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyRenderTags);
taskParams.enableLighting = true;
taskParams.alphaThreshold = 0.1f;
}
SdfPath RenderTaskDelegate::GetTaskID() const
@ -103,10 +106,9 @@ void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data)
buffer->Unmap();
}
HdTaskSharedPtrVector RenderTaskDelegate::GetTasks()
HdTaskSharedPtr RenderTaskDelegate::GetTask()
{
HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
return { renderTask };
return GetRenderIndex().GetTask(GetTaskID());
}
void RenderTaskDelegate::SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport)

View File

@ -28,7 +28,7 @@ public:
HdRenderBuffer *GetRendererAov(TfToken const &id);
void GetRendererAovData(TfToken const &id, void *buf);
HdTaskSharedPtrVector GetTasks();
HdTaskSharedPtr GetTask();
void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport);
private:

View File

@ -0,0 +1,41 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hdx/simpleLightTask.h>
#include "simpleLightTaskDelegate.h"
namespace blender::render::hydra {
SimpleLightTaskDelegate::SimpleLightTaskDelegate(HdRenderIndex *parentIndex,
SdfPath const &delegateID)
: HdSceneDelegate(parentIndex, delegateID)
{
SdfPath taskId = GetTaskID();
GetRenderIndex().InsertTask<HdxSimpleLightTask>(this, taskId);
}
SdfPath SimpleLightTaskDelegate::GetTaskID() const
{
return GetDelegateID().AppendElementString("task");
}
HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
{
return GetRenderIndex().GetTask(GetTaskID());
}
void SimpleLightTaskDelegate::SetCameraPath(SdfPath const &cameraPath)
{
taskParams.cameraPath = cameraPath;
}
VtValue SimpleLightTaskDelegate::Get(SdfPath const &id, TfToken const &key)
{
if (key == HdTokens->params) {
return VtValue(taskParams);
}
return VtValue();
}
} // namespace blender::render::hydra

View File

@ -0,0 +1,29 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#pragma once
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/simpleLightTask.h>
using namespace pxr;
namespace blender::render::hydra {
class SimpleLightTaskDelegate : public HdSceneDelegate {
public:
SimpleLightTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID);
~SimpleLightTaskDelegate() override = default;
SdfPath GetTaskID() const;
HdTaskSharedPtr GetTask();
void SetCameraPath(SdfPath const &);
VtValue Get(SdfPath const &id, TfToken const &key) override;
private:
HdxSimpleLightTaskParams taskParams;
};
} // namespace blender::render::hydra

View File

@ -266,12 +266,13 @@ void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context
freeCameraDelegate->SetCamera(gfCamera);
renderTaskDelegate->SetCameraAndViewport(freeCameraDelegate->GetCameraId(),
GfVec4d(viewSettings.border[0], viewSettings.border[1], viewSettings.border[2], viewSettings.border[3]));
if (simpleLightTaskDelegate) {
simpleLightTaskDelegate->SetCameraPath(freeCameraDelegate->GetCameraId());
}
if (!b_engine.bl_use_gpu_context()) {
renderTaskDelegate->SetRendererAov(HdAovTokens->color);
}
HdTaskSharedPtrVector tasks = renderTaskDelegate->GetTasks();
if (getRendererPercentDone() == 0.0f) {
timeBegin = chrono::steady_clock::now();
@ -279,6 +280,12 @@ void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context
b_engine.bind_display_space_shader(b_scene);
HdTaskSharedPtrVector tasks;
if (simpleLightTaskDelegate) {
tasks.push_back(simpleLightTaskDelegate->GetTask());
}
tasks.push_back(renderTaskDelegate->GetTask());
{
// Release the GIL before calling into hydra, in case any hydra plugins call into python.
TF_PY_ALLOW_THREADS_IN_SCOPE();