24 #ifndef PXR_USD_IMAGING_USD_IMAGING_PRIMVARDESC_CACHE_H 25 #define PXR_USD_IMAGING_USD_IMAGING_PRIMVARDESC_CACHE_H 30 #include "pxr/usdImaging/usdImaging/api.h" 31 #include "pxr/imaging/hd/sceneDelegate.h" 33 #include "pxr/usd/sdf/path.h" 37 #include <tbb/concurrent_unordered_map.h> 38 #include <tbb/concurrent_queue.h> 40 PXR_NAMESPACE_OPEN_SCOPE
66 return _path == rhs._path && _attribute == rhs._attribute;
68 inline bool operator!=(Key
const& rhs)
const {
69 return !(*
this == rhs);
73 inline size_t operator()(Key
const& key)
const {
74 size_t hash = key._path.GetHash();
75 boost::hash_combine(hash, key._attribute.Hash());
81 static Key Primvars(
SdfPath const& path) {
82 static TfToken attr(
"primvars");
83 return Key(path, attr);
92 template <
typename Element>
95 typedef tbb::concurrent_unordered_map<Key, Element, Key::Hash> _MapType;
96 typedef typename _MapType::iterator _MapIt;
97 typedef typename _MapType::const_iterator _MapConstIt;
98 typedef tbb::concurrent_queue<_MapIt> _QueueType;
106 template <
typename T>
107 bool _Find(Key
const& key, T* value)
const {
108 typedef _TypedCache<T> Cache_t;
110 Cache_t *cache =
nullptr;
113 typename Cache_t::_MapConstIt it = cache->_map.find(key);
114 if (it == cache->_map.end()) {
123 template <
typename T>
124 void _Erase(Key
const& key) {
129 typedef _TypedCache<T> Cache_t;
131 Cache_t *cache =
nullptr;
133 cache->_map.unsafe_erase(key);
139 template <
typename T>
140 T& _Get(Key
const& key)
const {
141 typedef _TypedCache<T> Cache_t;
143 Cache_t *cache =
nullptr;
147 std::pair<typename Cache_t::_MapIt, bool> res =
148 cache->_map.insert(std::make_pair(key, T()));
150 return res.first->second;
155 void EnableMutation() { _locked =
false; }
156 void DisableMutation() { _locked =
true; }
160 _Erase<HdPrimvarDescriptorVector>(Key::Primvars(path));
163 HdPrimvarDescriptorVector& GetPrimvars(
SdfPath const& path)
const {
164 return _Get<HdPrimvarDescriptorVector>(Key::Primvars(path));
167 bool FindPrimvars(
SdfPath const& path, HdPrimvarDescriptorVector* value)
const {
168 return _Find(Key::Primvars(path), value);
174 typedef _TypedCache<HdPrimvarDescriptorVector> _PviCache;
175 mutable _PviCache _pviCache;
177 void _GetCache(_PviCache **cache)
const {
183 PXR_NAMESPACE_CLOSE_SCOPE
185 #endif // PXR_USD_IMAGING_USD_IMAGING_PRIMVARDESC_CACHE_H Token for efficient comparison, assignment, and hashing of known strings.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
void Clear(SdfPath const &path)
Clear all data associated with a specific path.
A path value used to locate objects in layers or scenegraphs.
A cache for primvar descriptors.
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...