7#ifndef PXR_USD_IMAGING_USD_IMAGING_PRIMVARDESC_CACHE_H
8#define PXR_USD_IMAGING_USD_IMAGING_PRIMVARDESC_CACHE_H
13#include "pxr/usdImaging/usdImaging/api.h"
14#include "pxr/imaging/hd/sceneDelegate.h"
16#include "pxr/usd/sdf/path.h"
21#include <tbb/concurrent_unordered_map.h>
22#include <tbb/concurrent_queue.h>
24PXR_NAMESPACE_OPEN_SCOPE
49 inline bool operator==(Key
const& rhs)
const {
50 return _path == rhs._path && _attribute == rhs._attribute;
52 inline bool operator!=(Key
const& rhs)
const {
53 return !(*
this == rhs);
57 inline size_t operator()(Key
const& key)
const {
59 key._attribute.Hash());
64 static Key Primvars(
SdfPath const& path) {
65 static TfToken attr(
"primvars");
66 return Key(path, attr);
75 template <
typename Element>
78 typedef tbb::concurrent_unordered_map<Key, Element, Key::Hash> _MapType;
79 typedef typename _MapType::iterator _MapIt;
80 typedef typename _MapType::const_iterator _MapConstIt;
81 typedef tbb::concurrent_queue<_MapIt> _QueueType;
90 bool _Find(Key
const& key, T* value)
const {
91 typedef _TypedCache<T> Cache_t;
93 Cache_t *cache =
nullptr;
96 typename Cache_t::_MapConstIt it = cache->_map.find(key);
97 if (it == cache->_map.end()) {
106 template <
typename T>
107 void _Erase(Key
const& key) {
112 typedef _TypedCache<T> Cache_t;
114 Cache_t *cache =
nullptr;
116 cache->_map.unsafe_erase(key);
122 template <
typename T>
123 T& _Get(Key
const& key)
const {
124 typedef _TypedCache<T> Cache_t;
126 Cache_t *cache =
nullptr;
130 std::pair<typename Cache_t::_MapIt, bool> res =
131 cache->_map.insert(std::make_pair(key, T()));
133 return res.first->second;
138 void EnableMutation() { _locked =
false; }
139 void DisableMutation() { _locked =
true; }
143 _Erase<HdPrimvarDescriptorVector>(Key::Primvars(path));
146 HdPrimvarDescriptorVector& GetPrimvars(
SdfPath const& path)
const {
147 return _Get<HdPrimvarDescriptorVector>(Key::Primvars(path));
150 bool FindPrimvars(
SdfPath const& path, HdPrimvarDescriptorVector* value)
const {
151 return _Find(Key::Primvars(path), value);
157 typedef _TypedCache<HdPrimvarDescriptorVector> _PviCache;
158 mutable _PviCache _pviCache;
160 void _GetCache(_PviCache **cache)
const {
166PXR_NAMESPACE_CLOSE_SCOPE
A path value used to locate objects in layers or scenegraphs.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Token for efficient comparison, assignment, and hashing of known strings.
A cache for primvar descriptors.
void Clear(SdfPath const &path)
Clear all data associated with a specific path.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...