Hydra tasks refactor #73

Merged
Bogdan Nagirniak merged 8 commits from hydra-tasks-refactor into hydra-render 2023-07-25 22:13:33 +02:00
5 changed files with 110 additions and 93 deletions
Showing only changes of commit 35bc8deb9c - Show all commits

View File

@ -107,9 +107,10 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
render_task_delegate_->set_camera(free_camera_delegate_->GetCameraId());
render_task_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
if (light_tasks_delegate_) {
light_tasks_delegate_->set_camera_and_viewport(
free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
tasks_ = light_tasks_delegate_->get_tasks();
light_tasks_delegate_->set_camera(free_camera_delegate_->GetCameraId());
light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
tasks_.push_back(light_tasks_delegate_->skydome_task());
tasks_.push_back(light_tasks_delegate_->simple_task());
}
tasks_.push_back(render_task_delegate_->task());

View File

@ -1,9 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hdx/simpleLightTask.h>
#include <pxr/imaging/hdx/skydomeTask.h>
#include "light_tasks_delegate.h"
namespace blender::render::hydra {
@ -12,34 +9,10 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: pxr::HdSceneDelegate(parent_index, delegate_id)
{
skydome_task_id_ = GetDelegateID().AppendElementString("simpleLightTask");
simple_task_id_ = GetDelegateID().AppendElementString("skydomeTask");
GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_);
simple_task_id_ = GetDelegateID().AppendElementString("simpleTask");
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_);
}
pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks()
{
/*Note that this task is intended to be the first "Render Task",
so that the AOV's are properly cleared, however it
does not spawn a HdRenderPass.*/
return {GetRenderIndex().GetTask(skydome_task_id_), GetRenderIndex().GetTask(simple_task_id_)};
}
void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,
pxr::GfVec4d const &viewport)
{
if (simple_task_params_.cameraPath != camera_id) {
simple_task_params_.cameraPath = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(simple_task_id_,
pxr::HdChangeTracker::DirtyParams);
}
if (skydome_task_params_.viewport != viewport || skydome_task_params_.camera != camera_id) {
skydome_task_params_.viewport = viewport;
skydome_task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_,
pxr::HdChangeTracker::DirtyParams);
}
skydome_task_id_ = GetDelegateID().AppendElementString("skydomeTask");
GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_);
}
pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
@ -55,4 +28,40 @@ pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
return pxr::VtValue();
}
pxr::HdTaskSharedPtr LightTasksDelegate::simple_task()
{
return GetRenderIndex().GetTask(simple_task_id_);
}
pxr::HdTaskSharedPtr LightTasksDelegate::skydome_task()
{
/* Note that this task is intended to be the first "Render Task",
so that the AOV's are properly cleared, however it
does not spawn a HdRenderPass. */
return GetRenderIndex().GetTask(skydome_task_id_);
}
void LightTasksDelegate::set_camera(pxr::SdfPath const &camera_id)
{
if (simple_task_params_.cameraPath == camera_id) {
return;
}
simple_task_params_.cameraPath = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(simple_task_id_,
pxr::HdChangeTracker::DirtyParams);
skydome_task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_,
pxr::HdChangeTracker::DirtyParams);
}
void LightTasksDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (skydome_task_params_.viewport == viewport) {
return;
}
skydome_task_params_.viewport = viewport;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_,
pxr::HdChangeTracker::DirtyParams);
}
} // namespace blender::render::hydra

View File

@ -4,8 +4,8 @@
#pragma once
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/renderSetupTask.h>
#include <pxr/imaging/hdx/simpleLightTask.h>
#include <pxr/imaging/hdx/skydomeTask.h>
namespace blender::render::hydra {
@ -14,12 +14,15 @@ class LightTasksDelegate : public pxr::HdSceneDelegate {
LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id);
~LightTasksDelegate() override = default;
pxr::HdTaskSharedPtrVector get_tasks();
void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport);
/* Delegate methods */
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
pxr::HdTaskSharedPtr simple_task();
pxr::HdTaskSharedPtr skydome_task();
void set_camera(pxr::SdfPath const &camera_id);
void set_viewport(pxr::GfVec4d const &viewport);
private:
pxr::SdfPath simple_task_id_;
pxr::SdfPath skydome_task_id_;

View File

@ -20,23 +20,67 @@ RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
task_params_.alphaThreshold = 0.1f;
}
pxr::SdfPath RenderTaskDelegate::buffer_id(pxr::TfToken const &aov) const
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key)
{
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_);
}
if (key == pxr::HdTokens->collection) {
return pxr::VtValue(pxr::HdRprimCollection(
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull)));
}
return pxr::VtValue();
}
bool RenderTaskDelegate::is_converged()
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const & /*id*/)
{
return ((pxr::HdxRenderTask *)task().get())->IsConverged();
return {pxr::HdRenderTagTokens->geometry};
}
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
{
return buffer_descriptors_[id];
}
pxr::HdTaskSharedPtr RenderTaskDelegate::task()
{
return GetRenderIndex().GetTask(task_id_);
}
void RenderTaskDelegate::set_camera(pxr::SdfPath const &camera_id)
{
if (task_params_.camera == camera_id) {
return;
}
task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
}
void RenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (task_params_.viewport == viewport) {
return;
}
auto &render_index = GetRenderIndex();
task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
int w = viewport[2] - viewport[0];
int h = viewport[3] - viewport[1];
for (auto &it : buffer_descriptors_) {
it.second.dimensions = pxr::GfVec3i(w, h, 1);
render_index.GetChangeTracker().MarkBprimDirty(it.first,
pxr::HdRenderBuffer::DirtyDescription);
}
}
void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
{
auto &render_index = GetRenderIndex();
pxr::SdfPath buf_id = buffer_id(aov_key);
if (buffer_descriptors_.find(buf_id) != buffer_descriptors_.end()) {
return;
}
auto &render_index = GetRenderIndex();
pxr::HdAovDescriptor aov_desc = render_index.GetRenderDelegate()->GetDefaultAovDescriptor(
aov_key);
@ -72,55 +116,14 @@ void RenderTaskDelegate::get_aov_data(pxr::TfToken const &aov, void *data)
buffer->Unmap();
}
pxr::HdTaskSharedPtr RenderTaskDelegate::task()
bool RenderTaskDelegate::is_converged()
{
return GetRenderIndex().GetTask(task_id_);
return ((pxr::HdxRenderTask *)task().get())->IsConverged();
}
void RenderTaskDelegate::set_camera(pxr::SdfPath const &camera_id)
pxr::SdfPath RenderTaskDelegate::buffer_id(pxr::TfToken const &aov) const
{
task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
}
void RenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (task_params_.viewport == viewport) {
return;
}
auto &render_index = GetRenderIndex();
task_params_.viewport = viewport;
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
int w = viewport[2] - viewport[0];
int h = viewport[3] - viewport[1];
for (auto &it : buffer_descriptors_) {
it.second.dimensions = pxr::GfVec3i(w, h, 1);
render_index.GetChangeTracker().MarkBprimDirty(it.first,
pxr::HdRenderBuffer::DirtyDescription);
}
}
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key)
{
if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_);
}
if (key == pxr::HdTokens->collection) {
return pxr::VtValue(pxr::HdRprimCollection(
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull)));
}
return pxr::VtValue();
}
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
{
return buffer_descriptors_[id];
}
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const & /*id*/)
{
return {pxr::HdRenderTagTokens->geometry};
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
}
} // namespace blender::render::hydra

View File

@ -238,11 +238,11 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
view_settings.border[3]));
if (light_tasks_delegate_) {
light_tasks_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(),
pxr::GfVec4d(view_settings.border[0],
view_settings.border[1],
view_settings.border[2],
view_settings.border[3]));
light_tasks_delegate_->set_camera(free_camera_delegate_->GetCameraId());
light_tasks_delegate_->set_viewport(pxr::GfVec4d(view_settings.border[0],
view_settings.border[1],
view_settings.border[2],
view_settings.border[3]));
}
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
@ -254,7 +254,8 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) {
tasks = light_tasks_delegate_->get_tasks();
tasks.push_back(light_tasks_delegate_->skydome_task());
tasks.push_back(light_tasks_delegate_->simple_task());
}
tasks.push_back(render_task_delegate_->task());