diff --git a/Hydrogent/interface/Tasks/HnTaskManager.hpp b/Hydrogent/interface/Tasks/HnTaskManager.hpp index e886d6db..7081bf31 100644 --- a/Hydrogent/interface/Tasks/HnTaskManager.hpp +++ b/Hydrogent/interface/Tasks/HnTaskManager.hpp @@ -67,7 +67,7 @@ class HnTaskManager const pxr::SdfPath& GetId() const { return m_ManagerId; } - /// Returns the task list that can be passed to the Hydra engine for execution. + /// Returns the list of tasks that can be passed to the Hydra engine for execution. /// /// \param [in] TaskOrder - Optional task order. If not specified, the default order is used: /// - SetupRendering @@ -78,7 +78,9 @@ class HnTaskManager /// - RenderRprimsTranslucent /// - ReadRprimId /// - PostProcess - /// \return The task list that can be passed to pxr::HdEngine::Execute. + /// \return The list of tasks that can be passed to pxr::HdEngine::Execute. + /// + /// \remarks Only enabled tasks are returned. const pxr::HdTaskSharedPtrVector GetTasks(const std::vector* TaskOrder = nullptr) const; /// Sets new collection for the render tasks. @@ -98,10 +100,12 @@ class HnTaskManager /// \param [in] TaskId - The task ID that will be used to register the task in the render index. /// \param [in] UID - The task UID that will be used to identify the task in the task manager. /// \param [in] Params - The task parameters that will be associated with the task using the task ID. + /// \param [in] Enabled - Whether the task is enabled. template void CreateTask(const pxr::SdfPath& TaskId, TaskUID UID, - TaskParamsType&& Params); + TaskParamsType&& Params, + bool Enabled = true); /// Creates a new render task. /// @@ -110,7 +114,8 @@ class HnTaskManager template void CreateTask(const pxr::TfToken& TaskId, TaskUID UID, - TaskParamsType&& Params); + TaskParamsType&& Params, + bool Enabled = true); template bool SetTaskParams(TaskUID UID, @@ -122,6 +127,9 @@ class HnTaskManager void SetRenderRprimParams(const HnRenderRprimsTaskParams& Params); + void EnableTask(TaskUID UID, bool Enable); + bool IsTaskEnabled(TaskUID UID) const; + pxr::HdTaskSharedPtr GetTask(TaskUID UID) const; void RemoveTask(TaskUID UID); @@ -214,7 +222,12 @@ class HnTaskManager }; TaskParamsDelegate m_ParamsDelegate; - std::unordered_map m_TaskUIDs; + struct TaskInfo + { + pxr::SdfPath Id; + bool Enabled = false; + }; + std::unordered_map m_TaskInfo; std::vector m_DefaultTaskOrder; std::vector m_RenderTaskIds; @@ -229,11 +242,12 @@ void HnTaskManager::SetParameter(const pxr::SdfPath& TaskId, const pxr::TfToken& template void HnTaskManager::CreateTask(const pxr::SdfPath& TaskId, TaskUID UID, - TaskParamsType&& Params) + TaskParamsType&& Params, + bool Enabled) { m_RenderIndex.InsertTask(&m_ParamsDelegate, TaskId); - auto it_inserted = m_TaskUIDs.emplace(UID, TaskId); - VERIFY(it_inserted.second, "Task with UID ", UID, " already exists: ", it_inserted.first->second.GetText()); + auto it_inserted = m_TaskInfo.emplace(UID, TaskInfo{TaskId, Enabled}); + VERIFY(it_inserted.second, "Task with UID ", UID, " already exists: ", it_inserted.first->second.Id.GetText()); m_ParamsDelegate.SetParameter(TaskId, pxr::HdTokens->params, std::forward(Params)); m_DefaultTaskOrder.emplace_back(UID); @@ -242,9 +256,10 @@ void HnTaskManager::CreateTask(const pxr::SdfPath& TaskId, template void HnTaskManager::CreateTask(const pxr::TfToken& TaskId, TaskUID UID, - TaskParamsType&& Params) + TaskParamsType&& Params, + bool Enabled) { - CreateTask(pxr::SdfPath{GetId().AppendChild(TaskId)}, UID, std::forward(Params)); + CreateTask(pxr::SdfPath{GetId().AppendChild(TaskId)}, UID, std::forward(Params), Enabled); } template @@ -265,11 +280,11 @@ template bool HnTaskManager::SetTaskParams(TaskUID UID, TaskParamsType&& Params) { - const auto it = m_TaskUIDs.find(UID); - if (it == m_TaskUIDs.end()) + const auto it = m_TaskInfo.find(UID); + if (it == m_TaskInfo.end()) return false; - return SetTaskParams(it->second, std::forward(Params)); + return SetTaskParams(it->second.Id, std::forward(Params)); } } // namespace USD diff --git a/Hydrogent/src/Tasks/HnTaskManager.cpp b/Hydrogent/src/Tasks/HnTaskManager.cpp index 7a201904..922b8e1d 100644 --- a/Hydrogent/src/Tasks/HnTaskManager.cpp +++ b/Hydrogent/src/Tasks/HnTaskManager.cpp @@ -146,29 +146,29 @@ HnTaskManager::HnTaskManager(pxr::HdRenderIndex& RenderIndex, HnTaskManager::~HnTaskManager() { // Remove all tasks from the render index - for (const auto& it : m_TaskUIDs) + for (const auto& it : m_TaskInfo) { - m_RenderIndex.RemoveTask(it.second); + m_RenderIndex.RemoveTask(it.second.Id); } - m_TaskUIDs.clear(); + m_TaskInfo.clear(); } pxr::HdTaskSharedPtr HnTaskManager::GetTask(TaskUID UID) const { - auto it = m_TaskUIDs.find(UID); - return it != m_TaskUIDs.end() ? - m_RenderIndex.GetTask(it->second) : + auto it = m_TaskInfo.find(UID); + return it != m_TaskInfo.end() ? + m_RenderIndex.GetTask(it->second.Id) : nullptr; } void HnTaskManager::RemoveTask(TaskUID UID) { - auto it = m_TaskUIDs.find(UID); - if (it == m_TaskUIDs.end()) + auto it = m_TaskInfo.find(UID); + if (it == m_TaskInfo.end()) return; - m_RenderIndex.RemoveTask(it->second); - m_TaskUIDs.erase(it); + m_RenderIndex.RemoveTask(it->second.Id); + m_TaskInfo.erase(it); } void HnTaskManager::SetParameter(const pxr::SdfPath& TaskId, const TfToken& ValueKey, pxr::VtValue Value) @@ -247,13 +247,17 @@ const pxr::HdTaskSharedPtrVector HnTaskManager::GetTasks(const std::vectorsize()); for (auto UID : *TaskOrder) { - auto it = m_TaskUIDs.find(UID); - if (it == m_TaskUIDs.end()) + auto it = m_TaskInfo.find(UID); + if (it == m_TaskInfo.end()) continue; - Tasks.push_back(m_RenderIndex.GetTask(it->second)); + if (!it->second.Enabled) + continue; + + Tasks.push_back(m_RenderIndex.GetTask(it->second.Id)); } return Tasks; @@ -309,6 +313,21 @@ const pxr::SdfPath* HnTaskManager::GetSelectedRprimId() const } } +void HnTaskManager::EnableTask(TaskUID UID, bool Enable) +{ + auto it = m_TaskInfo.find(UID); + if (it == m_TaskInfo.end()) + return; + + it->second.Enabled = Enable; +} + +bool HnTaskManager::IsTaskEnabled(TaskUID UID) const +{ + auto it = m_TaskInfo.find(UID); + return it != m_TaskInfo.end() ? it->second.Enabled : false; +} + } // namespace USD } // namespace Diligent