Loading...
Searching...
No Matches
flatteningSceneIndex.h
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_FLATTENING_SCENE_H
8#define PXR_IMAGING_HD_FLATTENING_SCENE_H
9
10#include "pxr/imaging/hd/api.h"
11
12#include "pxr/imaging/hd/filteringSceneIndex.h"
13
14#include "pxr/usd/sdf/pathTable.h"
15#include <tbb/concurrent_hash_map.h>
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19using HdFlattenedDataSourceProviderSharedPtr =
20 std::shared_ptr<class HdFlattenedDataSourceProvider>;
21using HdFlattenedDataSourceProviderSharedPtrVector =
22 std::vector<HdFlattenedDataSourceProviderSharedPtr>;
23
24namespace HdFlatteningSceneIndex_Impl
25{
26constexpr uint32_t _smallVectorSize = 8;
27using _DataSourceLocatorSetVector =
29}
30
32
46{
47public:
53 static HdFlatteningSceneIndexRefPtr New(
54 HdSceneIndexBaseRefPtr const &inputScene,
55 HdContainerDataSourceHandle const &inputArgs) {
56 return TfCreateRefPtr(
57 new HdFlatteningSceneIndex(inputScene, inputArgs));
58 }
59
60 HD_API
61 ~HdFlatteningSceneIndex() override;
62
63 // satisfying HdSceneIndexBase
64 HD_API
65 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
66
67 HD_API
68 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
69
71 const TfTokenVector &
73 return _dataSourceNames;
74 }
75
77 const HdFlattenedDataSourceProviderSharedPtrVector &
79 return _dataSourceProviders;
80 }
81
82protected:
83
84 HD_API
86 HdSceneIndexBaseRefPtr const &inputScene,
87 HdContainerDataSourceHandle const &inputArgs);
88
89 // satisfying HdSingleInputFilteringSceneIndexBase
90 void _PrimsAdded(
91 const HdSceneIndexBase &sender,
92 const HdSceneIndexObserver::AddedPrimEntries &entries) override;
93
94 void _PrimsRemoved(
95 const HdSceneIndexBase &sender,
96 const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
97
98 void _PrimsDirtied(
99 const HdSceneIndexBase &sender,
100 const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
101
102private:
103 using _DataSourceLocatorSetVector =
105
106 // Consolidate _recentPrims into _prims.
107 void _ConsolidateRecentPrims();
108
109 void _DirtyHierarchy(
110 const SdfPath &primPath,
111 const _DataSourceLocatorSetVector &relativeDirtyLocators,
112 const HdDataSourceLocatorSet &dirtyLocators,
114
115 void _PrimDirtied(
118
119 // _dataSourceNames and _dataSourceProviders run in parallel
120 // and indicate that a data source at locator name in a prim data
121 // source gets flattened by provider.
122 TfTokenVector _dataSourceNames;
123 HdFlattenedDataSourceProviderSharedPtrVector _dataSourceProviders;
124
125 // Stores all data source names - convenient to quickly send out
126 // dirty messages for ancestors of resynced prims.
127 HdDataSourceLocatorSet _dataSourceLocatorSet;
128 // Stores universal set for each name in data source names - convenient
129 // to quickly invalidate all relevant data sourced of ancestors of
130 // resynced prim.
131 _DataSourceLocatorSetVector _relativeDataSourceLocators;
132
133 // members
134 using _PrimTable = SdfPathTable<HdSceneIndexPrim>;
135 _PrimTable _prims;
136
137 struct _PathHashCompare {
138 static bool equal(const SdfPath &a, const SdfPath &b) {
139 return a == b;
140 }
141 static size_t hash(const SdfPath &path) {
142 return hash_value(path);
143 }
144 };
145 using _RecentPrimTable =
146 tbb::concurrent_hash_map<SdfPath, HdSceneIndexPrim, _PathHashCompare>;
147 mutable _RecentPrimTable _recentPrims;
148};
149
150PXR_NAMESPACE_CLOSE_SCOPE
151
152#endif
Represents a set of data source locators closed under descendancy.
A scene index that observes an input scene index and produces a comparable scene in which inherited s...
HD_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource) for the object at primPath.
const HdFlattenedDataSourceProviderSharedPtrVector & GetFlattenedDataSourceProviders() const
Providers in the same order as GetFlattenedDataSourceNames.
static HdFlatteningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputScene, HdContainerDataSourceHandle const &inputArgs)
Creates a new flattening scene index.
const TfTokenVector & GetFlattenedDataSourceNames() const
Data sources under locator name in a prim source get flattened.
HD_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
Abstract interface to scene data.
Definition: sceneIndex.h:48
An abstract base class for a filtering scene index that observes a single input scene index.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:155
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
A notice indicating a prim was invalidated.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition: token.h:437
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440