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/dirtyList.h"
32#include "pxr/imaging/hd/perfLog.h"
33#include "pxr/imaging/hd/primTypeIndex.h"
34#include "pxr/imaging/hd/resourceRegistry.h"
35#include "pxr/imaging/hd/sortedIds.h"
36#include "pxr/imaging/hd/tokens.h"
38#include "pxr/imaging/hd/sceneIndex.h"
39#include "pxr/imaging/hd/mergingSceneIndex.h"
40#include "pxr/imaging/hd/legacyPrimSceneIndex.h"
41#include "pxr/imaging/hd/noticeBatchingSceneIndex.h"
43#include "pxr/imaging/hf/perfLog.h"
45#include "pxr/usd/sdf/path.h"
48#include "pxr/base/tf/hashmap.h"
50#include <tbb/enumerable_thread_specific.h>
53#include <unordered_map>
56PXR_NAMESPACE_OPEN_SCOPE
64class HdRenderDelegate;
70using HdDriverVector = std::vector<HdDriver*>;
71using HdRprimCollectionVector = std::vector<HdRprimCollection>;
72using HdTaskSharedPtr = std::shared_ptr<class HdTask>;
73using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
74using HdTaskSharedPtrVector = std::vector<HdTaskSharedPtr>;
75using HdTaskContext = std::unordered_map<
TfToken,
123 typedef std::vector<HdDrawItem const*> HdDrawItemPtrVector;
139 HdRenderDelegate *renderDelegate,
140 HdDriverVector
const& drivers,
141 const std::string &instanceName=std::string());
179 void SyncAll(HdTaskSharedPtrVector *tasks, HdTaskContext *taskContext);
220 return _rprimMap.find(
id) != _rprimMap.end();
272 return _instancerMap.find(
id) != _instancerMap.end();
284 template <
typename T>
293 return _taskMap.find(
id) != _taskMap.end();
365 void InsertSceneIndex(
366 const HdSceneIndexBaseRefPtr &inputScene,
367 SdfPath const& scenePathPrefix,
368 bool needsPrefixing =
true);
371 void RemoveSceneIndex(
372 const HdSceneIndexBaseRefPtr &inputScene);
391 HdDriverVector
const& GetDrivers()
const;
423 std::string GetInstanceName()
const;
429 HdRenderDelegate *renderDelegate,
430 HdDriverVector
const& drivers,
431 const std::string &instanceName=std::string());
439 void _CompactPrimIds();
442 void _AllocatePrimId(
HdRprim* prim);
450 HdTaskSharedPtr
const& task);
452 template <
typename T>
453 static inline const TfToken & _GetTypeId();
475 void _InsertRprim(
TfToken const& typeId,
478 void _InsertSprim(
TfToken const& typeId,
481 void _InsertBprim(
TfToken const& typeId,
487 void _RemoveRprim(
SdfPath const&
id);
490 void _RemoveInstancer(
SdfPath const&
id);
492 void _RemoveRprimSubtree(
const SdfPath &root,
494 void _RemoveInstancerSubtree(
const SdfPath &root,
496 void _RemoveExtComputationSubtree(
const SdfPath &root,
498 void _RemoveTaskSubtree(
const SdfPath &root,
510 HdLegacyPrimSceneIndexRefPtr _emulationSceneIndex;
511 HdNoticeBatchingSceneIndexRefPtr _emulationNoticeBatchingSceneIndex;
512 unsigned int _noticeBatchingDepth;
514 std::unique_ptr<class HdSceneIndexAdapterSceneDelegate> _siSd;
516 HdMergingSceneIndexRefPtr _mergingSceneIndex;
517 HdSceneIndexBaseRefPtr _terminalSceneIndex;
521 HdTaskSharedPtr task;
524 typedef std::unordered_map<SdfPath, _TaskInfo, SdfPath::Hash> _TaskMap;
525 typedef TfHashMap<SdfPath, _RprimInfo, SdfPath::Hash> _RprimMap;
526 typedef std::vector<SdfPath> _RprimPrimIDVector;
528 typedef Hd_PrimTypeIndex<HdSprim> _SprimIndex;
529 typedef Hd_PrimTypeIndex<HdBprim> _BprimIndex;
532 Hd_SortedIds _rprimIds;
534 _RprimPrimIDVector _rprimPrimIdMap;
538 _SprimIndex _sprimIndex;
539 _BprimIndex _bprimIndex;
543 typedef TfHashMap<SdfPath, HdInstancer*, SdfPath::Hash> _InstancerMap;
544 _InstancerMap _instancerMap;
546 HdRenderDelegate *_renderDelegate;
547 HdDriverVector _drivers;
550 std::string _instanceName;
555 HdRprimCollectionVector _collectionsToSync;
561 void _InitPrimTypes();
564 bool _CreateFallbackPrims();
567 void _DestroyFallbackPrims();
569 typedef tbb::enumerable_thread_specific<HdDrawItemPtrVector>
570 _ConcurrentDrawItems;
572 void _AppendDrawItems(
const SdfPathVector &rprimIds,
576 _ConcurrentDrawItems* result);
581 static void _ConfigureReprs();
597 HF_MALLOC_TAG_FUNCTION();
599 HdTaskSharedPtr task = std::make_shared<T>(delegate,
id);
600 _TrackDelegateTask(delegate,
id, task);
603PXR_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 Hydra render index is a flattened representation of the client scene graph, which may be composed...
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)
Removes the given task from the RenderIndex.
void InsertTask(HdSceneDelegate *delegate, SdfPath const &id)
Inserts a new task into the render index with an identifier of 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.
static HD_API bool IsSceneIndexEmulationEnabled()
Returns true if scene index features are available This is true by default but can be controlled via ...
HD_API HdDrawItemPtrVector GetDrawItems(HdRprimCollection const &collection, TfTokenVector const &renderTags)
Returns a list of relevant draw items that match the criteria specified.
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.
bool HasTask(SdfPath const &id)
Returns true if a task exists in the index with the given 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 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.
static HD_API HdRenderIndex * New(HdRenderDelegate *renderDelegate, HdDriverVector const &drivers, const std::string &instanceName=std::string())
Create a render index with the given render delegate.
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.