24 #ifndef PXR_IMAGING_HD_RENDER_INDEX_H
25 #define PXR_IMAGING_HD_RENDER_INDEX_H
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/changeTracker.h"
31 #include "pxr/imaging/hd/perfLog.h"
32 #include "pxr/imaging/hd/primTypeIndex.h"
33 #include "pxr/imaging/hd/resourceRegistry.h"
34 #include "pxr/imaging/hd/sortedIds.h"
35 #include "pxr/imaging/hd/tokens.h"
37 #include "pxr/imaging/hf/perfLog.h"
39 #include "pxr/usd/sdf/path.h"
42 #include "pxr/base/tf/hashmap.h"
44 #include <tbb/enumerable_thread_specific.h>
47 #include <unordered_map>
50 PXR_NAMESPACE_OPEN_SCOPE
58 class HdRenderDelegate;
64 using HdDirtyListSharedPtr = std::shared_ptr<class HdDirtyList>;
66 using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
68 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
69 using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
70 using HdTaskContext = std::unordered_map<
TfToken,
73 using HdDriverVector = std::vector<HdDriver*>;
119 typedef std::vector<HdDrawItem const*> HdDrawItemPtrVector;
131 HdRenderDelegate *renderDelegate,
132 HdDriverVector
const& drivers);
166 HdDirtyListSharedPtr
const &dirtyList,
175 void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext);
216 return _rprimMap.find(
id) != _rprimMap.end();
268 return _instancerMap.find(
id) != _instancerMap.end();
280 template <
typename T>
289 return _taskMap.find(
id) != _taskMap.end();
369 HdDriverVector
const& GetDrivers()
const;
380 HdRenderDelegate *renderDelegate,
381 HdDriverVector
const& drivers);
389 void _CompactPrimIds();
392 void _AllocatePrimId(
HdRprim* prim);
400 HdTaskSharedPtr
const& task);
402 template <
typename T>
403 static inline const TfToken & _GetTypeId();
405 void _RemoveRprimSubtree(
const SdfPath &root,
407 void _RemoveInstancerSubtree(
const SdfPath &root,
409 void _RemoveExtComputationSubtree(
const SdfPath &root,
411 void _RemoveTaskSubtree(
const SdfPath &root,
424 HdTaskSharedPtr task;
427 typedef std::unordered_map<SdfPath, _TaskInfo, SdfPath::Hash> _TaskMap;
428 typedef TfHashMap<SdfPath, _RprimInfo, SdfPath::Hash> _RprimMap;
429 typedef std::vector<SdfPath> _RprimPrimIDVector;
431 typedef Hd_PrimTypeIndex<HdSprim> _SprimIndex;
432 typedef Hd_PrimTypeIndex<HdBprim> _BprimIndex;
435 Hd_SortedIds _rprimIds;
437 _RprimPrimIDVector _rprimPrimIdMap;
441 _SprimIndex _sprimIndex;
442 _BprimIndex _bprimIndex;
446 typedef TfHashMap<SdfPath, HdInstancer*, SdfPath::Hash> _InstancerMap;
447 _InstancerMap _instancerMap;
449 struct _SyncQueueEntry {
450 HdDirtyListSharedPtr dirtyList;
454 typedef std::vector<_SyncQueueEntry> _SyncQueue;
455 _SyncQueue _syncQueue;
469 std::unordered_map<HdDirtyBits, const SdfPathVector> _dirtyRprimIdsMap;
472 const SdfPathVector& _GetDirtyRprimIds(HdDirtyBits mask);
474 HdRenderDelegate *_renderDelegate;
475 HdDriverVector _drivers;
481 unsigned int _renderTagVersion;
484 void _InitPrimTypes();
487 bool _CreateFallbackPrims();
490 void _DestroyFallbackPrims();
492 void _GatherRenderTags(
const HdTaskSharedPtrVector *tasks);
494 typedef tbb::enumerable_thread_specific<HdDrawItemPtrVector>
495 _ConcurrentDrawItems;
497 void _AppendDrawItems(
const SdfPathVector &rprimIds,
501 _ConcurrentDrawItems* result);
506 static void _ConfigureReprs();
517 template <
typename T>
522 HF_MALLOC_TAG_FUNCTION();
524 HdTaskSharedPtr task = std::make_shared<T>(delegate, id);
525 _TrackDelegateTask(delegate,
id, task);
528 PXR_NAMESPACE_CLOSE_SCOPE
530 #endif //PXR_IMAGING_HD_RENDER_INDEX_H
Hydra Representation of a Client defined computation.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
HD_API bool IsSprimTypeSupported(TfToken const &typeId) const
Returns whether the sprim type is supported by this render index.
HD_API bool IsRprimTypeSupported(TfToken const &typeId) const
Returns whether the rprim type is supported by this render index.
HD_API void InsertBprim(TfToken const &typeId, HdSceneDelegate *delegate, SdfPath const &bprimId)
Insert a bprim into index.
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
HD_API HdSceneDelegate * GetSceneDelegateForRprim(SdfPath const &id) const
Returns the scene delegate for the given rprim.
HD_API HdInstancer * GetInstancer(SdfPath const &id) const
Returns the instancer of id.
This class exists to facilitate point cloud style instancing.
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...
Functor to use for hash maps from tokens to other things.
HD_API void InsertInstancer(HdSceneDelegate *delegate, SdfPath const &id)
Insert an instancer into index.
HD_API HdResourceRegistrySharedPtr GetResourceRegistry() const
Returns a shared ptr to the resource registry of the current render delegate.
HD_API TfToken GetRenderTag(SdfPath const &id) const
Returns the render tag for the given rprim.
HD_API void InsertSprim(TfToken const &typeId, HdSceneDelegate *delegate, SdfPath const &sprimId)
Insert a sprim into index.
HD_API void InsertRprim(TfToken const &typeId, HdSceneDelegate *sceneDelegate, SdfPath const &rprimId)
Insert a rprim into index.
HD_API const SdfPathVector & GetRprimIds()
Returns a sorted list of all Rprims in the render index.
HD_API void RemoveRprim(SdfPath const &id)
Remove a rprim from 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...
Token for efficient comparison, assignment, and hashing of known strings.
HdDriver represents a device object, commonly a render device, that is owned by the application and p...
The render engine state for a given rprim from the scene graph.
HD_API void Clear()
Clear all r (render), s (state) and b (buffer) prims.
HD_API void RemoveTask(SdfPath const &id)
Removes the given task from the RenderIndex.
HD_API void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext)
Syncs input tasks, B & S prims, (external) computations and processes all pending dirty lists (which ...
Adapter class providing data exchange with the client scene graph.
bool HasInstancer(SdfPath const &id)
Returns true if instancer id exists in index.
std::vector< TfToken > TfTokenVector
Convenience types.
bool HasTask(SdfPath const &id)
Returns true if a task exists in the index with the given id.
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
HD_API SdfPathVector GetRprimSubtree(SdfPath const &root)
Returns the subtree rooted under the given path.
Used for faster iteration of dirty rprims, filtered by mask.
bool HasRprim(SdfPath const &id)
Returns true if rprim id exists in index.
HD_API SdfPathVector GetBprimSubtree(TfToken const &typeId, SdfPath const &root)
Returns the subtree rooted under the given path for the given bprim type.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
HD_API HdTaskSharedPtr const & GetTask(SdfPath const &id) const
Returns the task for the given id.
HD_API void EnqueuePrimsToSync(HdDirtyListSharedPtr const &dirtyList, HdRprimCollection const &collection)
Adds the dirty list to the sync queue.
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
HD_API HdBprim * GetFallbackBprim(TfToken const &typeId) const
Returns the fallback prim for the Bprim of the given type.
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...
static HD_API HdRenderIndex * New(HdRenderDelegate *renderDelegate, HdDriverVector const &drivers)
Create a render index with the given render delegate.
HD_API HdDrawItemPtrVector GetDrawItems(HdRprimCollection const &collection, TfTokenVector const &renderTags)
Returns a list of relevant draw items that match the criteria specified.
HD_API HdSprim * GetFallbackSprim(TfToken const &typeId) const
Returns the fullback prim for the Sprim of the given type.
HD_API bool IsBprimTypeSupported(TfToken const &typeId) const
Returns whether the bprim type is supported by this render index.
Bprim (buffer prim) is a base class of managing a blob of data that is used to communicate between th...
void InsertTask(HdSceneDelegate *delegate, SdfPath const &id)
Inserts a new task into the render index with an identifier of id.
HD_API void RemoveInstancer(SdfPath const &id)
Remove an instancer from index.
HD_API TfToken GetMaterialTag(SdfPath const &id) const
Return the material tag for the given rprim.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
HD_API HdRprim const * GetRprim(SdfPath const &id) const
Returns the rprim of id.
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 HdRenderDelegate * GetRenderDelegate() const
Currently, a render index only supports connection to one type of render delegate, due to the inserted information and change tracking being specific to that delegate type.