7#ifndef PXR_EXEC_EXEC_COMPUTATION_BUILDERS_H
8#define PXR_EXEC_EXEC_COMPUTATION_BUILDERS_H
21#include "pxr/exec/exec/api.h"
22#include "pxr/exec/exec/builtinComputations.h"
28#include "pxr/base/tf/type.h"
30#include "pxr/base/vt/value.h"
33#include "pxr/usd/sdf/path.h"
40PXR_NAMESPACE_OPEN_SCOPE
206constexpr bool operator&(
210 return static_cast<unsigned char>(a) &
static_cast<unsigned char>(b);
213template <Exec_ComputationBuilderProv
iderTypes allowed>
214struct Exec_ComputationBuilderComputationValueSpecifier;
217class Exec_ComputationBuilderCommonBase
221 template <Exec_ComputationBuilderProv
iderTypes allowed>
223 static Exec_ComputationBuilderComputationValueSpecifier<allowed>
224 _GetMetadataValueSpecifier(
235class Exec_ComputationBuilderValueSpecifierBase
236 :
public Exec_ComputationBuilderCommonBase
240 Exec_ComputationBuilderValueSpecifierBase(
241 const TfToken &computationName,
245 const TfToken &disambiguatingId);
248 Exec_ComputationBuilderValueSpecifierBase(
249 const Exec_ComputationBuilderValueSpecifierBase&);
252 ~Exec_ComputationBuilderValueSpecifierBase();
256 void _SetInputName(
const TfToken &inputName);
259 void _SetOptional (
const bool optional);
262 void _SetFallsBackToDispatched(
bool fallsBackToDispatched);
266 friend class Exec_ComputationBuilderBase;
269 void _GetInputKey(Exec_InputKey *inputKey)
const;
275 const std::unique_ptr<_Data> _data;
281struct Exec_ComputationBuilderConstantValueSpecifier final
282 :
public Exec_ComputationBuilderValueSpecifierBase
285 Exec_ComputationBuilderProviderTypes::Any;
288 Exec_ComputationBuilderConstantValueSpecifier(
300template <Exec_ComputationBuilderProv
iderTypes allowed>
301struct Exec_ComputationBuilderComputationValueSpecifier
302 :
public Exec_ComputationBuilderValueSpecifierBase
304 Exec_ComputationBuilderComputationValueSpecifier(
305 const TfToken &computationName,
309 : Exec_ComputationBuilderValueSpecifierBase(
310 computationName, resultType,
311 std::move(providerResolution),
317 using This = Exec_ComputationBuilderComputationValueSpecifier<allowed>;
349 _SetInputName(inputName);
417 _SetFallsBackToDispatched(
true);
426struct Exec_ComputationBuilderAccessorBase
427 :
public Exec_ComputationBuilderCommonBase
430 Exec_ComputationBuilderAccessorBase(
const SdfPath &localTraversal)
431 : _localTraversal(localTraversal)
436 const SdfPath &_GetLocalTraversal()
const {
437 return _localTraversal;
448struct Exec_ComputationBuilderConstantAccessorBase
449 :
public Exec_ComputationBuilderAccessorBase
455 Exec_ComputationBuilderConstantValueSpecifier
456 InputName(
const TfToken &inputName) &&
458 return Exec_ComputationBuilderConstantValueSpecifier(
460 _GetLocalTraversal(),
462 std::move(_constantValue));
467 Exec_ComputationBuilderConstantAccessorBase(
482template <Exec_ComputationBuilderProv
iderTypes allowed>
484 :
public Exec_ComputationBuilderAccessorBase
487 : Exec_ComputationBuilderAccessorBase(localTraversal)
491 using ValueSpecifier =
492 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
498 template <
typename ResultType>
503 "VtArray is not a supported result type.");
505 return ValueSpecifier(
508 {_GetLocalTraversal(),
513 template <
typename ResultType>
517 return ValueSpecifier(
520 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
521 ExecProviderResolution::DynamicTraversal::
522 IncomingConnectionOwningAttributes});
526 template <
typename ResultType>
531 "VtArray is not a supported result type.");
533 return _GetMetadataValueSpecifier<allowed>(
535 _GetLocalTraversal(),
543template <Exec_ComputationBuilderProv
iderTypes allowed>
554template <Exec_ComputationBuilderProv
iderTypes allowed>
563 using ValueSpecifier =
564 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
570 template <
typename ResultType>
574 return ValueSpecifier(
577 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
578 ExecProviderResolution::DynamicTraversal::
579 ConnectionTargetedObjects});
589template <Exec_ComputationBuilderProv
iderTypes allowed>
598 using ValueSpecifier =
599 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
634 template <
typename ResultType>
638 return ValueSpecifier(
641 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
642 ExecProviderResolution::DynamicTraversal::
643 RelationshipTargetedObjects});
653namespace exec_registration {
659 Exec_ComputationBuilderProviderTypes::Prim>
689 SdfPath::ReflexiveRelativePath().AppendProperty(attributeName))
700 Exec_ComputationBuilderProviderTypes::Prim>
714 SdfPath::ReflexiveRelativePath().AppendProperty(
726 Exec_ComputationBuilderProviderTypes::Attribute>
761 Exec_ComputationBuilderProviderTypes::Attribute>
765 Exec_ComputationBuilderProviderTypes::Attribute>(
771 Exec_ComputationBuilderProviderTypes::Attribute>
775 Exec_ComputationBuilderProviderTypes::Attribute>(
785 template <
typename ValueType>
790 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
791 .InputName(attributeName);
801 Exec_ComputationBuilderProviderTypes::Any>
845template <
typename ResultType>
847 :
public Exec_ComputationBuilderComputationValueSpecifier<
848 Exec_ComputationBuilderProviderTypes::Any>
878 : Exec_ComputationBuilderComputationValueSpecifier<
882 CheckForRegistration<ResultType>(),
892template <
typename ValueType>
894 :
public Exec_ComputationBuilderComputationValueSpecifier<
895 Exec_ComputationBuilderProviderTypes::Any>
920 : Exec_ComputationBuilderComputationValueSpecifier<
922 _GetMetadataValueSpecifier<allowedProviders>(
924 .CheckForRegistration<ValueType>(),
925 SdfPath::ReflexiveRelativePath(),
929 "VtArray is not a supported result type.");
938template <
typename ValueType>
940 :
public Exec_ComputationBuilderConstantAccessorBase
1044 ValueType &&constantValue)
1045 : Exec_ComputationBuilderConstantAccessorBase(
1048 CheckForRegistration<ValueType>())
1051 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1052 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1053 "Must use std::string to represent string literal types.");
1056 "Types used to provide constant input values must be hashable.");
1060 const ValueType &constantValue)
1061 : Exec_ComputationBuilderConstantAccessorBase(
1064 CheckForRegistration<ValueType>())
1067 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1068 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1069 "Must use std::string to represent string literal types.");
1072 "Types used to provide constant input values must be hashable.");
1080Constant(
const char *) -> Constant<std::string>;
1081Constant(
char *) -> Constant<std::string>;
1089template <
typename ResultType>
1090struct NamespaceAncestor final
1091 :
public Exec_ComputationBuilderComputationValueSpecifier<
1092 Exec_ComputationBuilderProviderTypes::Prim>
1125 : Exec_ComputationBuilderComputationValueSpecifier<
1129 CheckForRegistration<ResultType>(),
1184template <
typename ValueType>
1189 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
1190 .InputName(attributeName);
1233template <
typename ResultType>
1237 return Exec_ComputationBuilderComputationValueSpecifier<
1238 Exec_ComputationBuilderProviderTypes::Attribute>(
1242 ExecProviderResolution::DynamicTraversal::
1243 ConnectionTargetedObjects});
1284template <
typename ResultType>
1288 return Exec_ComputationBuilderComputationValueSpecifier<
1289 Exec_ComputationBuilderProviderTypes::Any>(
1293 ExecProviderResolution::DynamicTraversal::
1294 IncomingConnectionOwningAttributes});
1326 struct ConstructionAccess {
1329 Construct(
const std::string &schemaTypeName);
1372 const TfToken &computationName);
1468 template <
class... DispatchedOntoSchemaTypes>
1471 const TfToken &computationName,
1472 DispatchedOntoSchemaTypes &&...schemaTypes);
1478 const TfToken &computationName,
1513 template <
class... DispatchedOntoSchemaTypes>
1516 const TfToken &computationName,
1517 DispatchedOntoSchemaTypes &&...schemaTypes);
1523 const TfToken &computationName,
1535class Exec_ComputationBuilderBase
1539 Exec_ComputationBuilderBase(
1542 const TfToken &computationName,
1546 ~Exec_ComputationBuilderBase();
1555 template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1556 static void _ValidateInputs();
1565 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1570 std::unique_ptr<ExecDispatchesOntoSchemas>
1571 _GetDispatchesOntoSchemas();
1580 const std::unique_ptr<_Data> _data;
1585template <
typename Derived>
1586class Exec_ComputationBuilderCRTPBase :
public Exec_ComputationBuilderBase
1589 struct _UnspecifiedType {};
1593 Exec_ComputationBuilderCRTPBase(
1596 const TfToken &computationName,
1601 ~Exec_ComputationBuilderCRTPBase();
1670 typename ResultType = _UnspecifiedType,
1671 typename ReturnType = _UnspecifiedType>
1731 template<
typename ResultType,
typename FuncType>
1739 :
public Exec_ComputationBuilderCRTPBase<ExecPrimComputationBuilder>
1747 const TfToken &computationName,
1748 bool dispatched =
false,
1779 template <
typename... Args>
1781 Inputs(Args && ... args);
1787 :
public Exec_ComputationBuilderCRTPBase<ExecAttributeComputationBuilder>
1796 const TfToken &computationName,
1797 bool dispatched =
false,
1832 template <
typename... Args>
1834 Inputs(Args && ... args);
1839 :
public Exec_ComputationBuilderCRTPBase<ExecAttributeExpressionBuilder>
1880 template <
typename... Args>
1882 Inputs(Args && ... args);
1890template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1892Exec_ComputationBuilderBase::_ValidateInputs() {
1893 using regType = std::decay_t<T>;
1895 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1896 "Accessor can't provide an input value.");
1898 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1899 "Constant(value) must be followed by .InputName(inputNameToken)");
1901 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1902 "Invalid type used as an input registration.");
1904 regType::allowedProviders & allowed,
1905 "This input registration is not allowed on a provider of this type.");
1907 (regType::allowedProviders & allowed) ||
1909 Exec_ComputationBuilderProviderTypes::Attribute),
1910 "This input registration is only allowed on a provider attribute; "
1911 "there may be a missing Attribute(attributeName) registration.");
1913 (regType::allowedProviders & allowed) ||
1915 Exec_ComputationBuilderProviderTypes::Prim),
1916 "This input registration is only allowed on a provider prim; "
1917 "there may be a missing Prim() registration.");
1924template <
typename Derived>
1925template <
typename InputResultType,
typename ReturnType>
1937 std::is_same_v<InputResultType, _UnspecifiedType>,
1942 !std::is_void_v<ResultType> ||
1943 std::is_convertible_v<ReturnType, ResultType>,
1944 "Callback return type must be convertible to the computation result "
1947 !std::is_reference_v<ResultType>,
1948 "Callback functions must return by value.");
1951 "VtArray is not a supported result type.");
1953 const TfType resultType =
1959 if constexpr (std::is_void_v<ReturnType>) {
1960 _AddCallback(callback, resultType);
1964 ctx.
SetOutput<ResultType>(callback(ctx));
1969 return *
static_cast<Derived*
>(
this);
1972template <
typename Derived>
1973template<
typename ResultType,
typename FuncType>
1976 FuncType &&callback)
1982 std::is_invocable_v<
1983 const std::remove_reference_t<FuncType>,
const VdfContext&>,
1984 "Callback function object must have const function call operator.");
1987 !std::is_void_v<ResultType>,
1988 "The ResultType template parameter cannot be void, as this indicates "
1989 "the value type of the result produced by the computation.");
1994 std::is_void_v<std::invoke_result_t<const FuncType, const VdfContext&>>,
1995 "Callback return type must be void. Use VdfContext::SetOutput to "
1996 "set a result value.");
1999 !std::is_reference_v<ResultType>,
2000 "Callback function must return by value.");
2003 "VtArray is not a supported result type.");
2005 const TfType resultType =
2008 _AddCallback(callback, resultType);
2010 return *
static_cast<Derived*
>(
this);
2017template <
typename... Args>
2024 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
2027 (_AddInputKey(&args), ...);
2036template <
typename... Args>
2043 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
2046 (_AddInputKey(&args), ...);
2055template <
typename... Args>
2062 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
2065 (_AddInputKey(&args), ...);
2074template <
class... DispatchedOntoSchemaTypes>
2077 const TfToken &computationName,
2078 DispatchedOntoSchemaTypes &&...schemaTypes)
2082 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
2086 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
2089template <
class... DispatchedOntoSchemaTypes>
2092 const TfToken &computationName,
2093 DispatchedOntoSchemaTypes &&...schemaTypes)
2097 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
2101 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
2104PXR_NAMESPACE_CLOSE_SCOPE
Class used to build attribute computation definitions.
Class used to build attribute expression definitions.
The top-level builder object (aka, the self variable generated by EXEC_REGISTER_COMPUTATIONS_FOR_SCHE...
Class used to build prim computation definitions.
Singleton used to register and access value types used by exec computations.
TfType CheckForRegistration() const
Confirms that ValueType has been registered.
static EXEC_API const ExecTypeRegistry & GetInstance()
Provides access to the singleton instance, first ensuring it is constructed.
A path value used to locate objects in layers or scenegraphs.
static SDF_API const SdfPath & ReflexiveRelativePath()
The relative path representing "self".
SDF_API SdfPath AppendProperty(TfToken const &propName) const
Creates a path by appending an element for propName to this path.
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Token for efficient comparison, assignment, and hashing of known strings.
TfType represents a dynamic runtime type.
A context is the parameter bundle passed to callbacks of computations.
void SetOutput(const TfToken &outputName, const T &value) const
Sets the value of the output named outputName to value.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Exec_ComputationBuilderProviderTypes
An enum that is used as a template parameter to specify which kinds of providers a given input regist...
This file contains definitions for trivial types, including type aliases, so that source files that r...
std::function< void(const class VdfContext &context)> ExecCallbackFn
Function type used for computation callbacks.
Exec_ComputationBuilderRelationshipAccessor< Exec_ComputationBuilderProviderTypes::Attribute > Relationship(const TfToken &relationshipName)
See Relationship().
Stage()
On any computation, provides access to the stage.
Attribute(const TfToken &attributeName)
On a prim computation, provides access to the attribute named attributeName.
Prim()
On an attribute computation, provides access to the owning prim.
Relationship(const TfToken &relationshipName)
On a prim computation, provides access to the relationship named relationshipName.
Exec_ComputationBuilderAttributeAccessor< Exec_ComputationBuilderProviderTypes::Attribute > Attribute(const TfToken &attributeName)
See Attribute().
auto AttributeValue(const TfToken &attributeName)
See AttributeValue().
Derived & Callback(ReturnType(*callback)(const VdfContext &))
Registers a callback function that implements the evaluation logic for a computation.
ExecAttributeExpressionBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for an attribute expres...
ExecPrimComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for a prim computation.
ExecAttributeComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for an attribute comput...
EXEC_API ExecAttributeExpressionBuilder AttributeExpression(const TfToken &attributeName)
Registers an attribute expression for attributes named attributeName.
ExecPrimComputationBuilder DispatchedPrimComputation(const TfToken &computationName, DispatchedOntoSchemaTypes &&...schemaTypes)
Registers a dispatched prim computation named computationName.
EXEC_API ExecAttributeComputationBuilder AttributeComputation(const TfToken &attributeName, const TfToken &computationName)
Registers an attribute computation named computationName on attributes named attributeName.
ExecAttributeComputationBuilder DispatchedAttributeComputation(const TfToken &computationName, DispatchedOntoSchemaTypes &&...schemaTypes)
Registers a dispatched attribute computation named computationName.
EXEC_API ExecPrimComputationBuilder PrimComputation(const TfToken &computationName)
Registers a prim computation named computationName.
ValueSpecifier Metadata(const TfToken &metadataKey)
See Metadata().
Metadata(const TfToken &metadataKey)
Requests an input value from the metadata field indicated by metadataKey, of type ResultType.
ValueSpecifier IncomingConnections(const TfToken &computationName)
See IncomingConnections().
Constant(ValueType &&constantValue)
Requests a constant input value of type ValueType.
NamespaceAncestor(const TfToken &computationName)
On a prim computation, requests an input value from the computation computationName of type ResultTyp...
auto Connections(const TfToken &computationName)
As a direct input to an attribute computation or after an Attribute() accessor, requests input values...
ValueSpecifier TargetedObjects(const TfToken &computationName)
After a Relationship() accessor, requests input values from the computation computationName of type R...
auto IncomingConnections(const TfToken &computationName)
On any provider, requests input values from the computation computationName of type ResultType on the...
Computation(const TfToken &computationName)
Requests an input value from the computation computationName of type ResultType.
ValueSpecifier Connections(const TfToken &computationName)
See Connections().
ValueSpecifier Computation(const TfToken &computationName)
See Computation().
Accessor common to all scene object types that support requesting computations on the object.
Data used to find computation providers during exec compilation.
@ Local
The localTraversal path directly indicates the computation provider.
@ NamespaceAncestor
Find the provider by traversing upward in namespace.
A trait to detect instantiations of VtArray, specialized in array.h.
Attribute accessor, valid for providing input to a prim computation.
Computation value specifier, valid for providing input to any computation.
Prim accessor, valid for providing input to an attribute computation.
Relationship accessor, valid for providing input to a prim computation.
Provides access to the stage, valid for providing input to any computation.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
constexpr bool VtIsHashable()
A constexpr function that returns true if T is hashable via VtHashValue(), false otherwise.