7#ifndef PXR_EXEC_VDF_EXECUTION_TYPE_REGISTRY_H
8#define PXR_EXEC_VDF_EXECUTION_TYPE_REGISTRY_H
14#include "pxr/exec/vdf/api.h"
18#include "pxr/base/tf/anyUniquePtr.h"
21#include "pxr/base/tf/type.h"
23#include <tbb/spin_rw_mutex.h>
28PXR_NAMESPACE_OPEN_SCOPE
70 template <
typename T,
typename B>
117 template <
typename T>
118 void _Define(
const T &fallback,
TfType scalarType);
128 std::pair<const _Value &, bool> _InsertRegistration(
129 TfType type, _Value &&fallback);
135 const _Value &_GetFallback(
TfType type)
const;
138 template <
typename T>
139 struct _CreateEmptyVector {
146 template <
typename T>
149 const _Value &fallback,
size_t numElements,
VdfVector *vector);
159 std::map<TfType, _Value> _fallbackMap;
160 mutable tbb::spin_rw_mutex _fallbackMapMutex;
173class VdfExecutionTypeRegistry::_Value
176 template <
typename T>
177 explicit _Value(
const T &fallback)
186 template <
typename T>
187 const T & UncheckedGet()
const {
188 return *
static_cast<const T*
>(_ptr.Get());
194 template <
typename T>
195 bool Equals(
const T &rhs)
const {
196 if constexpr (VdfIsEqualityComparable<T>) {
197 return UncheckedGet<T>() == rhs;
214 TfType scalarType = TfType::Find<T>();
217 "Type '%s' was declared but not defined",
220 scalarType = TfType::Define<T>();
227template <
typename T,
typename B>
233 TfType scalarType = TfType::Find<T>();
236 "Type '%s' was declared but not defined",
239 scalarType = TfType::Define<T, B>();
248VdfExecutionTypeRegistry::_Define(
const T &fallback,
TfType scalarType)
253 if (
const auto [registeredFallback, inserted] = _InsertRegistration(
254 scalarType, _Value(fallback)); !inserted) {
256 registeredFallback.Equals(fallback),
257 "Type %s registered more than once with different fallback "
263 VdfOutputSpec::_RegisterType<T>();
272 const _Value &fallback = _GetFallback(TfType::Find<T>());
273 return fallback.UncheckedGet<T>();
278VdfExecutionTypeRegistry::_FillVector<T>::Call(
279 const _Value &fallback,
283 const T &fallbackValue = fallback.UncheckedGet<T>();
285 vector->
Resize<T>(numElements);
288 for (
size_t i = 0; i < numElements; ++i) {
289 accessor[i] = fallbackValue;
295PXR_NAMESPACE_CLOSE_SCOPE
A simple type-erased container that provides only destruction, moves and immutable,...
Manage a single instance of an object (see.
TfType represents a dynamic runtime type.
TF_API const std::string & GetTypeName() const
Return the machine-independent name for this type.
TF_API const std::type_info & GetTypeid() const
Return a C++ RTTI type_info for this type.
bool IsUnknown() const
Return true if this is the unknown type, representing a type unknown to the TfType system.
Manages low-level value type functionality used within execution.
static VDF_API void FillVector(TfType type, size_t numElements, VdfVector *vector)
Fills vector with the fallback value registered for the given type.
static TfType Define(const T &fallback)
Registers T with execution's runtime type dispatch system.
const T & GetFallback() const
Returns the registered fallback value for T from the registry.
static VDF_API TfType CheckForRegistration(const std::type_info &typeInfo)
Checks if ti is defined as an execution value type.
static TfType CheckForRegistration()
Checks if T is defined as an execution value type.
static VDF_API VdfVector CreateEmptyVector(TfType type)
Create an empty VdfVector holding empty data of the given TfType.
static VDF_API VdfExecutionTypeRegistry & GetInstance()
Returns the VdfExecutionTypeRegistry singleton instance.
Dispatches calls to template instantiations based on a TfType that is determined at runtime.
bool RegisterType()
Register an additional type with the type dispatch table.
A VdfTypedVector implements a VdfVector with a specific type.
A read/write accessor for low-level access to the contents of the VdfVector.
This class is used to abstract away knowledge of the cache data used for each node.
void Resize(size_t size)
Allocates space for size number of elements.
ReadWriteAccessor< TYPE > GetReadWriteAccessor() const
GetReadWriteAccessor() allows low level access to the content of the VdfVector via the Vdf_VectorData...
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Manage a single instance of an object.