Support more AOVs #78

Merged
Bogdan Nagirniak merged 11 commits from DagerD/blender:BLEN-462_3 into hydra-render 2023-07-29 14:45:16 +02:00
5 changed files with 102 additions and 43 deletions
Showing only changes of commit 05d7e0651d - Show all commits

View File

@ -14,6 +14,10 @@
#include "camera.h"
#include "final_engine.h"
PXR_NAMESPACE_OPEN_SCOPE
TF_DEFINE_PRIVATE_TOKENS(tokens_, (worldCoordinate));
PXR_NAMESPACE_CLOSE_SCOPE
namespace blender::render::hydra {
/* FinalEngine implementation */
@ -47,8 +51,19 @@ void FinalEngine::render(Depsgraph *depsgraph)
light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
}
DagerD marked this conversation as resolved Outdated

aovs_map should be moved to Engine::RenderSettings and should be set via set_render_setting

`aovs_map` should be moved to `Engine::RenderSettings` and should be set via `set_render_setting`
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
aovs_map_.add_new("Combined", pxr::HdAovTokens->color);
aovs_map_.add_new("Depth", pxr::HdAovTokens->depth);
aovs_map_.add_new("Normal", pxr::HdAovTokens->normal);
aovs_map_.add_new("Position", pxr::tokens_->worldCoordinate);
RenderResult *result = RE_engine_get_result(bl_engine_);
RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
pxr::TfToken *aov_token = aovs_map_.lookup_ptr(pass->name);
if (aov_token) {
render_task_delegate_->add_aov(*aov_token);
DagerD marked this conversation as resolved Outdated

With GPU context, depth AOV should be added anyway.

With GPU context, depth AOV should be added anyway.
}
}
render_task_delegate_->bind();
@ -59,7 +74,10 @@ void FinalEngine::render(Depsgraph *depsgraph)
}
tasks.push_back(light_tasks_delegate_->simple_task());
}
tasks.push_back(render_task_delegate_->task());
if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
tasks.push_back(static_cast<GPURenderTaskDelegate *>(render_task_delegate_.get())->aov_task());
}
tasks.push_back(render_task_delegate_->render_task());
engine_->Execute(render_index_.get(), &tasks);
char elapsed_time[32];
@ -79,7 +97,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged()) {
if (render_task_delegate_->is_converged(render_task_delegate_->render_task())) {
break;
}
@ -104,14 +122,10 @@ void FinalEngine::update_render_result()
/* TODO: only for the first render layer */
RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
pxr::TfToken aov_key;
if (STREQ(pass->name, "Combined")) {
aov_key = pxr::HdAovTokens->color;
pxr::TfToken *aov_token = aovs_map_.lookup_ptr(pass->name);
if (aov_token) {
render_task_delegate_->read_aov(*aov_token, pass->ibuf->float_buffer.data);
}
else if (STREQ(pass->name, "Depth")) {
aov_key = pxr::HdAovTokens->depth;
}
render_task_delegate_->read_aov(aov_key, pass->ibuf->float_buffer.data);
}
RE_engine_end_result(bl_engine_, result, false, false, false);

View File

@ -20,6 +20,9 @@ class FinalEngine : public Engine {
std::string scene_name_;
std::string layer_name_;
pxr::GfVec2i resolution_;
/* Map supported Blender AOV to corresponded Hydra AOV token */
Map<std::string, pxr::TfToken> aovs_map_;
};
} // namespace blender::render::hydra

View File

@ -17,17 +17,17 @@ RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: pxr::HdSceneDelegate(parent_index, delegate_id)
{
task_id_ = GetDelegateID().AppendElementString("task");
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, task_id_);
render_task_id_ = GetDelegateID().AppendElementString("renderTask");
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, render_task_id_);
task_params_.enableLighting = true;
task_params_.alphaThreshold = 0.1f;
render_task_params_.enableLighting = true;
render_task_params_.alphaThreshold = 0.1f;
}
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key)
{
if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_);
return pxr::VtValue(render_task_params_);
}
if (key == pxr::HdTokens->collection) {
return pxr::VtValue(pxr::HdRprimCollection(
@ -46,33 +46,33 @@ pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr:
return buffer_descriptors_[id];
}
pxr::HdTaskSharedPtr RenderTaskDelegate::task()
pxr::HdTaskSharedPtr RenderTaskDelegate::render_task()
{
return GetRenderIndex().GetTask(task_id_);
return GetRenderIndex().GetTask(render_task_id_);
}
void RenderTaskDelegate::set_camera(pxr::SdfPath const &camera_id)
{
if (task_params_.camera == camera_id) {
if (render_task_params_.camera == camera_id) {
return;
}
task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
render_task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id_, pxr::HdChangeTracker::DirtyParams);
}
bool RenderTaskDelegate::is_converged()
bool RenderTaskDelegate::is_converged(pxr::HdTaskSharedPtr task)
{
return ((pxr::HdxRenderTask *)task().get())->IsConverged();
return ((pxr::HdxRenderTask *)task.get())->IsConverged();
}
void RenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (task_params_.viewport == viewport) {
if (render_task_params_.viewport == viewport) {
return;
}
auto &render_index = GetRenderIndex();
task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
render_task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(render_task_id_, pxr::HdChangeTracker::DirtyParams);
int w = viewport[2] - viewport[0];
int h = viewport[3] - viewport[1];
@ -93,8 +93,12 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
pxr::HdAovDescriptor aov_desc = render_index.GetRenderDelegate()->GetDefaultAovDescriptor(
aov_key);
int w = task_params_.viewport[2] - task_params_.viewport[0];
int h = task_params_.viewport[3] - task_params_.viewport[1];
if (aov_desc.format == pxr::HdFormatInvalid) {
return;
}
int w = render_task_params_.viewport[2] - render_task_params_.viewport[0];
int h = render_task_params_.viewport[3] - render_task_params_.viewport[1];
render_index.InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buf_id);
buffer_descriptors_[buf_id] = pxr::HdRenderBufferDescriptor(
pxr::GfVec3i(w, h, 1), aov_desc.format, aov_desc.multiSampled);
@ -103,8 +107,8 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
binding.aovName = aov_key;
binding.renderBufferId = buf_id;
binding.aovSettings = aov_desc.aovSettings;
task_params_.aovBindings.push_back(binding);
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
render_task_params_.aovBindings.push_back(binding);
render_index.GetChangeTracker().MarkTaskDirty(render_task_id_, pxr::HdChangeTracker::DirtyParams);
}
void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)
@ -142,14 +146,44 @@ pxr::SdfPath RenderTaskDelegate::buffer_id(pxr::TfToken const &aov_key) const
return GetDelegateID().AppendElementString("aov_" + aov_key.GetString());
}
GPURenderTaskDelegate::GPURenderTaskDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: RenderTaskDelegate(parent_index, delegate_id)
{
aov_task_id_ = GetDelegateID().AppendElementString("aovTask");
GetRenderIndex().InsertTask<pxr::HdxVisualizeAovTask>(this, aov_task_id_);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(aov_task_id_,
pxr::HdChangeTracker::DirtyCollection);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(aov_task_id_,
pxr::HdChangeTracker::DirtyRenderTags);
}
pxr::VtValue GPURenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{
if (id == render_task_id_) {
return RenderTaskDelegate::Get(id, key);
}
if (key == pxr::HdTokens->params) {
return pxr::VtValue(aov_task_params_);
}
return pxr::VtValue();
}
pxr::HdTaskSharedPtr GPURenderTaskDelegate::aov_task()
{
return GetRenderIndex().GetTask(aov_task_id_);
}
void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (task_params_.viewport == viewport) {
if (render_task_params_.viewport == viewport) {
return;
}
auto &render_index = GetRenderIndex();
task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
render_task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(render_task_id_, pxr::HdChangeTracker::DirtyParams);
if (tex_color_) {
GPU_texture_free(tex_color_);
@ -172,7 +206,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
tex = &tex_color_;
}
else if (aov_key == pxr::HdAovTokens->depth) {
format = GPU_DEPTH32F_STENCIL8;
format = GPU_DEPTH_COMPONENT32F;
tex = &tex_depth_;
}
else {
@ -184,8 +218,8 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
}
*tex = GPU_texture_create_2d(("tex_render_hydra_" + aov_key.GetString()).c_str(),
task_params_.viewport[2] - task_params_.viewport[0],
task_params_.viewport[3] - task_params_.viewport[1],
render_task_params_.viewport[2] - render_task_params_.viewport[0],
render_task_params_.viewport[3] - render_task_params_.viewport[1],
1,
format,
GPU_TEXTURE_USAGE_GENERAL,

View File

@ -5,6 +5,7 @@
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/renderSetupTask.h>
#include <pxr/imaging/hdx/visualizeAovTask.h>
#include "GPU_framebuffer.h"
#include "GPU_texture.h"
@ -21,8 +22,8 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &id) override;
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
pxr::HdTaskSharedPtr task();
bool is_converged();
pxr::HdTaskSharedPtr render_task();
bool is_converged(pxr::HdTaskSharedPtr task);
DagerD marked this conversation as resolved Outdated

revert task(), set is_converged without parameters

revert `task()`, set `is_converged` without parameters

revert task(), set is_converged virtual and without parameters

> revert `task()`, set `is_converged` virtual and without parameters
void set_camera(pxr::SdfPath const &camera_id);
virtual void set_viewport(pxr::GfVec4d const &viewport);
virtual void add_aov(pxr::TfToken const &aov_key);
@ -34,16 +35,21 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
protected:
pxr::SdfPath buffer_id(pxr::TfToken const &aov_key) const;
pxr::SdfPath task_id_;
pxr::HdxRenderTaskParams task_params_;
pxr::SdfPath render_task_id_;
pxr::HdxRenderTaskParams render_task_params_;
DagerD marked this conversation as resolved Outdated

rename back task_id_, task_params_

rename back `task_id_`, `task_params_`
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
buffer_descriptors_;
};
class GPURenderTaskDelegate : public RenderTaskDelegate {
public:
using RenderTaskDelegate::RenderTaskDelegate;
GPURenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id);
~GPURenderTaskDelegate() override = default;
/* Delegate methods */
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
pxr::HdTaskSharedPtr aov_task();
DagerD marked this conversation as resolved Outdated

Looks like aov_task doesn't need.

Looks like aov_task doesn't need.
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;
@ -52,6 +58,8 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
void unbind() override;
private:
pxr::SdfPath aov_task_id_;
pxr::HdxVisualizeAovTaskParams aov_task_params_;
GPUFrameBuffer *framebuffer_ = nullptr;
GPUTexture *tex_color_ = nullptr;
GPUTexture *tex_depth_ = nullptr;

View File

@ -242,7 +242,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
}
tasks.push_back(light_tasks_delegate_->simple_task());
}
tasks.push_back(render_task_delegate_->task());
tasks.push_back(render_task_delegate_->render_task());
engine_->Execute(render_index_.get(), &tasks);
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
@ -262,7 +262,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_);
if (!render_task_delegate_->is_converged()) {
if (!render_task_delegate_->is_converged(render_task_delegate_->render_task())) {
notify_status(std::string("Time: ") + elapsed_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render");