7 #ifndef PXR_EXEC_VDF_EXECUTION_TYPE_REGISTRY_H
8 #define PXR_EXEC_VDF_EXECUTION_TYPE_REGISTRY_H
19 #include "pxr/base/tf/mallocTag.h"
23 #include <tbb/spin_rw_mutex.h>
70 template <
typename T,
typename B>
91 const char *
const additionalErrorMsg=
nullptr) {
101 const std::type_info &typeInfo,
102 const char *
const additionalErrorMsg);
123 template <
typename T>
124 void _Define(
const T &fallback,
TfType scalarType);
134 std::pair<const _Value &, bool> _InsertRegistration(
144 template <
typename T>
145 struct _CreateEmptyVector {
152 template <
typename T>
155 const _Value &fallback,
size_t numElements,
VdfVector *vector);
165 std::map<TfType, _Value> _fallbackMap;
166 mutable tbb::spin_rw_mutex _fallbackMapMutex;
182 template <
typename T>
192 template <
typename T>
194 return *
static_cast<const T*
>(_ptr.
Get());
200 template <
typename T>
202 if constexpr (VdfIsEqualityComparable<T>) {
203 return UncheckedGet<T>() == rhs;
214 template <
typename T>
218 TfAutoMallocTag mallocTag(
"Vdf",
"VdfExecutionTypeRegistry::Define");
220 TfType scalarType = TfType::Find<T>();
223 "Type '%s' was declared but not defined",
226 scalarType = TfType::Define<T>();
233 template <
typename T,
typename B>
237 TfAutoMallocTag mallocTag(
"Vdf",
"VdfExecutionTypeRegistry::Define");
239 TfType scalarType = TfType::Find<T>();
242 "Type '%s' was declared but not defined",
245 scalarType = TfType::Define<T, B>();
252 template <
typename T>
254 VdfExecutionTypeRegistry::_Define(
const T &fallback,
TfType scalarType)
259 if (
const auto [registeredFallback, inserted] = _InsertRegistration(
260 scalarType, _Value(fallback)); !inserted) {
262 registeredFallback.Equals(fallback),
263 "Type %s registered more than once with different fallback "
269 VdfOutputSpec::_RegisterType<T>();
274 template <
typename T>
278 const _Value &fallback = _GetFallback(TfType::Find<T>());
282 template <
typename T>
284 VdfExecutionTypeRegistry::_FillVector<T>::Call(
285 const _Value &fallback,
289 const T &fallbackValue = fallback.UncheckedGet<
T>();
291 vector->
Resize<
T>(numElements);
294 for (
size_t i = 0; i < numElements; ++i) {
295 accessor[i] = fallbackValue;
ReadWriteAccessor< TYPE > GetReadWriteAccessor() const
#define PXR_NAMESPACE_OPEN_SCOPE
static VDF_API VdfVector CreateEmptyVector(TfType type)
static VDF_API void FillVector(TfType type, size_t numElements, VdfVector *vector)
static TfType Define(const T &fallback)
GLint GLint GLsizei GLint GLenum GLenum type
bool Equals(const T &rhs) const
VDF_API ~VdfExecutionTypeRegistry()
static TfType CheckForRegistration(const char *const additionalErrorMsg=nullptr)
_Value(const T &fallback)
const T & GetFallback() const
const T & UncheckedGet() const
static VDF_API VdfExecutionTypeRegistry & GetInstance()
TF_API const std::string & GetTypeName() const
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API const std::type_info & GetTypeid() const
VdfExecutionTypeRegistry & operator=(const VdfExecutionTypeRegistry &)=delete
void const * Get() const
Return a pointer to the owned object.