7#ifndef PXR_IMAGING_HD_RENDER_INDEX_H
8#define PXR_IMAGING_HD_RENDER_INDEX_H
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/changeTracker.h"
14#include "pxr/imaging/hd/dirtyList.h"
15#include "pxr/imaging/hd/perfLog.h"
16#include "pxr/imaging/hd/primTypeIndex.h"
17#include "pxr/imaging/hd/resourceRegistry.h"
18#include "pxr/imaging/hd/sortedIds.h"
19#include "pxr/imaging/hd/tokens.h"
21#include "pxr/imaging/hd/sceneIndex.h"
22#include "pxr/imaging/hd/mergingSceneIndex.h"
23#include "pxr/imaging/hd/legacyPrimSceneIndex.h"
24#include "pxr/imaging/hd/legacyTaskFactory.h"
25#include "pxr/imaging/hd/noticeBatchingSceneIndex.h"
27#include "pxr/imaging/hf/perfLog.h"
29#include "pxr/usd/sdf/path.h"
32#include "pxr/base/tf/hashmap.h"
34#include <tbb/enumerable_thread_specific.h>
37#include <unordered_map>
41PXR_NAMESPACE_OPEN_SCOPE
49class HdRenderDelegate;
55using HdDriverVector = std::vector<HdDriver*>;
56using HdRprimCollectionVector = std::vector<HdRprimCollection>;
57using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
58using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
59using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
60using HdTaskContext = std::unordered_map<
TfToken,
113 typedef std::vector<HdDrawItem const*> HdDrawItemPtrVector;
138 HdRenderDelegate *renderDelegate,
139 HdDriverVector
const& drivers,
140 const std::string &instanceName=std::string(),
141 const std::string &appName=std::string());
154 HdRenderDelegate *renderDelegate,
155 HdDriverVector
const& drivers,
156 HdSceneIndexBaseRefPtr
const &terminalSceneIndex);
205 void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext);
249 return _rprimMap.find(
id) != _rprimMap.end();
305 return _instancerMap.find(
id) != _instancerMap.end();
322 template <
typename T>
341 return _taskMap.find(
id) != _taskMap.end();
413 void InsertSceneIndex(
414 const HdSceneIndexBaseRefPtr &inputScene,
415 SdfPath const& scenePathPrefix,
416 bool needsPrefixing =
true);
419 void RemoveSceneIndex(
420 const HdSceneIndexBaseRefPtr &inputScene);
428 HdSceneIndexBaseRefPtr GetEmulationSceneIndex()
const;
442 HdDriverVector
const& GetDrivers()
const;
484 std::string GetInstanceName()
const;
490 HdRenderDelegate *renderDelegate,
491 HdDriverVector
const& drivers,
492 const std::string &instanceName,
493 const std::string &appName,
494 HdSceneIndexBaseRefPtr
const &terminalSceneIndex =
nullptr,
495 bool createFrontendEmulationOnly =
false);
503 void _CompactPrimIds();
506 void _AllocatePrimId(
HdRprim* prim);
508 using HdTaskCreateFnc =
514 void _InsertSceneDelegateTask(
517 HdLegacyTaskFactorySharedPtr factory);
519 template <
typename T>
520 static inline const TfToken & _GetTypeId();
542 void _InsertRprim(
TfToken const& typeId,
545 void _InsertSprim(
TfToken const& typeId,
548 void _InsertBprim(
TfToken const& typeId,
555 HdTaskSharedPtr
const &task);
557 void _RemoveRprim(
SdfPath const&
id);
560 void _RemoveInstancer(
SdfPath const&
id);
562 void _RemoveRprimSubtree(
const SdfPath &root,
564 void _RemoveInstancerSubtree(
const SdfPath &root,
566 void _RemoveExtComputationSubtree(
const SdfPath &root,
568 void _RemoveTaskSubtree(
const SdfPath &root,
570 void _RemoveTask(
SdfPath const &
id);
581 class _NoticeBatchingContext;
583 HdLegacyPrimSceneIndexRefPtr _emulationSceneIndex;
584 std::unique_ptr<_NoticeBatchingContext> _emulationBatchingCtx;
586 std::unique_ptr<class HdSceneIndexAdapterSceneDelegate> _siSd;
588 HdMergingSceneIndexRefPtr _mergingSceneIndex;
589 std::unique_ptr<_NoticeBatchingContext> _mergingBatchingCtx;
591 HdSceneIndexBaseRefPtr _terminalSceneIndex;
595 HdTaskSharedPtr task;
598 typedef std::unordered_map<SdfPath, _TaskInfo, SdfPath::Hash> _TaskMap;
599 typedef TfHashMap<SdfPath, _RprimInfo, SdfPath::Hash> _RprimMap;
600 typedef std::vector<SdfPath> _RprimPrimIDVector;
602 typedef Hd_PrimTypeIndex<HdSprim> _SprimIndex;
603 typedef Hd_PrimTypeIndex<HdBprim> _BprimIndex;
606 Hd_SortedIds _rprimIds;
611 std::optional<_RprimPrimIDVector> _rprimPrimIdMap;
615 _SprimIndex _sprimIndex;
616 _BprimIndex _bprimIndex;
620 typedef TfHashMap<SdfPath, HdInstancer*, SdfPath::Hash> _InstancerMap;
621 _InstancerMap _instancerMap;
623 HdRenderDelegate *_renderDelegate;
624 HdDriverVector _drivers;
626 HdSceneIndexBaseRefPtr _finalEmulationSceneIndex;
628 std::string _instanceName;
633 HdRprimCollectionVector _collectionsToSync;
637 std::atomic<int> _syncAllDepth;
642 void _InitPrimTypes();
645 bool _CreateFallbackPrims();
648 void _DestroyFallbackPrims();
650 typedef tbb::enumerable_thread_specific<HdDrawItemPtrVector>
651 _ConcurrentDrawItems;
653 void _AppendDrawItems(
const SdfPathVector &rprimIds,
657 _ConcurrentDrawItems* result);
662 static void _ConfigureReprs();
677 _InsertSceneDelegateTask(
678 delegate,
id, HdMakeLegacyTaskFactory<T>());
681PXR_NAMESPACE_CLOSE_SCOPE
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Used for faster iteration of dirty Rprims by the render index.
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
HdDriver represents a device object, commonly a render device, that is owned by the application and p...
Hydra Representation of a Client defined computation.
This class exists to facilitate point cloud style instancing.
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
HD_API void MergingSceneIndexNoticeBatchEnd()
Flushes any queued scene index observer notices from the merging scene index and disables further que...
static HD_API HdRenderIndex * New(HdRenderDelegate *renderDelegate, HdDriverVector const &drivers, const std::string &instanceName=std::string(), const std::string &appName=std::string())
"instanceName" is an optional identifier useful for applications to associate this render index with ...
HD_API HdInstancer * GetInstancer(SdfPath const &id) const
Returns the instancer of id.
HD_API void RemoveRprim(SdfPath const &id)
Remove a rprim from index.
HD_API HdTaskSharedPtr const & GetTask(SdfPath const &id) const
Returns the task for the given id.
HD_API void RemoveInstancer(SdfPath const &id)
Remove an instancer from index.
HD_API SdfPathVector GetBprimSubtree(TfToken const &typeId, SdfPath const &root)
Returns the subtree rooted under the given path for the given bprim type.
HD_API void RemoveTask(SdfPath const &id)
void InsertTask(HdSceneDelegate *delegate, SdfPath const &id)
TfToken UpdateRenderTag(SdfPath const &id, HdDirtyBits bits)
Like GetRenderTag, but updates the render tag if dirty.
HD_API bool IsBprimTypeSupported(TfToken const &typeId) const
Returns whether the bprim type is supported by this render index.
HD_API void EnqueueCollectionToSync(HdRprimCollection const &collection)
Hydra's core currently needs to know the collections used by tasks to aggregate the reprs that need t...
HD_API void InsertBprim(TfToken const &typeId, HdSceneDelegate *delegate, SdfPath const &bprimId)
Insert a bprim into index.
HD_API HdBprim * GetFallbackBprim(TfToken const &typeId) const
Returns the fallback prim for the Bprim of the given type.
HD_API void Clear()
Clear all r (render), s (state) and b (buffer) prims.
HD_API HdSceneDelegate * GetSceneDelegateForRprim(SdfPath const &id) const
Returns the scene delegate for the given rprim.
HD_API void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext)
Syncs input tasks, B & S prims, (external) computations and updates the Rprim dirty list to then sync...
HD_API bool IsRprimTypeSupported(TfToken const &typeId) const
Returns whether the rprim type is supported by this render index.
HD_API HdSceneIndexBaseRefPtr GetTerminalSceneIndex() const
The terminal scene index that is driving what is in the render index through emulation.
bool HasRprim(SdfPath const &id)
Returns true if rprim id exists in index.
HD_API void SceneIndexEmulationNoticeBatchBegin()
An application or legacy scene delegate may prefer for the scene index observer notices generated fro...
HD_API HdSprim * GetFallbackSprim(TfToken const &typeId) const
Returns the fullback prim for the Sprim of the given type.
HD_API void RemoveSubtree(const SdfPath &root, HdSceneDelegate *sceneDelegate)
Clear all entries in the render index under the given root and belong to a specified delegate.
HD_API const SdfPathVector & GetRprimIds()
Returns a sorted list of all Rprims in the render index.
HD_API void SceneIndexEmulationNoticeBatchEnd()
Flushes any queued scene index observer notices and disables further queueing.
HD_API HdDrawItemPtrVector GetDrawItems(HdRprimCollection const &collection, TfTokenVector const &renderTags)
Returns a list of relevant draw items that match the criteria specified.
HD_API void MergingSceneIndexNoticeBatchBegin()
Consolidate notices generated by the merging scene index to vectorized batches.
HD_API HdRprim const * GetRprim(SdfPath const &id) const
Returns the rprim of id.
HD_API TfToken GetRenderTag(SdfPath const &id) const
Returns the render tag for the given rprim.
HD_API void InsertRprim(TfToken const &typeId, HdSceneDelegate *sceneDelegate, SdfPath const &rprimId)
Insert a rprim into index.
HD_API SdfPath GetRprimPathFromPrimId(int primId) const
Given a prim id, returns the path of the corresponding rprim or an empty path if none is found.
HD_API HdResourceRegistrySharedPtr GetResourceRegistry() const
Returns a shared ptr to the resource registry of the current render delegate.
static HdRenderIndex * NewForBackendEmulation(HdRenderDelegate *renderDelegate, HdDriverVector const &drivers, HdSceneIndexBaseRefPtr const &terminalSceneIndex)
Create a render index with the given render delegate that populates itself by observing the given sce...
static HdRenderIndex * NewForFrontendEmulation(HdRenderDelegate *nullRenderDelegate)
Create a render index for "front-end" emulation.
bool HasTask(SdfPath const &id)
bool HasInstancer(SdfPath const &id)
Returns true if instancer id exists in index.
HD_API bool IsSprimTypeSupported(TfToken const &typeId) const
Returns whether the sprim type is supported by this render index.
HD_API SdfPathVector GetRprimSubtree(SdfPath const &root)
Returns the subtree rooted under the given path.
HD_API bool IsSyncAllInProgress() const
Returns true while a thread is invoking SyncAll().
HD_API bool GetSceneDelegateAndInstancerIds(SdfPath const &id, SdfPath *sceneDelegateId, SdfPath *instancerId) const
Query function to return the id's of the scene delegate and instancer associated with the Rprim at th...
HD_API void InsertInstancer(HdSceneDelegate *delegate, SdfPath const &id)
Insert an instancer into index.
HD_API SdfPathVector GetSprimSubtree(TfToken const &typeId, SdfPath const &root)
Returns the subtree rooted under the given path for the given sprim type.
HD_API void InsertSprim(TfToken const &typeId, HdSceneDelegate *delegate, SdfPath const &sprimId)
Insert a sprim into index.
HD_API HdRenderDelegate * GetRenderDelegate() const
Currently, a render index only supports connection to one type of render delegate,...
A named, semantic collection of objects.
The render engine state for a given rprim from the scene graph.
Adapter class providing data exchange with the client scene graph.
Scene delegate which observes notices from an HdSceneIndex and applies them to an HdRenderIndex.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
A path value used to locate objects in layers or scenegraphs.
Token for efficient comparison, assignment, and hashing of known strings.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Functor to use for hash maps from tokens to other things.
std::vector< TfToken > TfTokenVector
Convenience types.