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"
39PXR_NAMESPACE_OPEN_SCOPE
205constexpr bool operator&(
209 return static_cast<unsigned char>(a) &
static_cast<unsigned char>(b);
212template <Exec_ComputationBuilderProv
iderTypes allowed>
213struct Exec_ComputationBuilderComputationValueSpecifier;
216class Exec_ComputationBuilderCommonBase
220 template <Exec_ComputationBuilderProv
iderTypes allowed>
222 static Exec_ComputationBuilderComputationValueSpecifier<allowed>
223 _GetMetadataValueSpecifier(
234class Exec_ComputationBuilderValueSpecifierBase
235 :
public Exec_ComputationBuilderCommonBase
239 Exec_ComputationBuilderValueSpecifierBase(
240 const TfToken &computationName,
244 const TfToken &disambiguatingId);
247 Exec_ComputationBuilderValueSpecifierBase(
248 const Exec_ComputationBuilderValueSpecifierBase&);
251 ~Exec_ComputationBuilderValueSpecifierBase();
255 void _SetInputName(
const TfToken &inputName);
258 void _SetOptional (
const bool optional);
261 void _SetFallsBackToDispatched(
bool fallsBackToDispatched);
265 friend class Exec_ComputationBuilderBase;
268 void _GetInputKey(Exec_InputKey *inputKey)
const;
274 const std::unique_ptr<_Data> _data;
280struct Exec_ComputationBuilderConstantValueSpecifier final
281 :
public Exec_ComputationBuilderValueSpecifierBase
284 Exec_ComputationBuilderProviderTypes::Any;
287 Exec_ComputationBuilderConstantValueSpecifier(
299template <Exec_ComputationBuilderProv
iderTypes allowed>
300struct Exec_ComputationBuilderComputationValueSpecifier
301 :
public Exec_ComputationBuilderValueSpecifierBase
303 Exec_ComputationBuilderComputationValueSpecifier(
304 const TfToken &computationName,
308 : Exec_ComputationBuilderValueSpecifierBase(
309 computationName, resultType,
310 std::move(providerResolution),
316 using This = Exec_ComputationBuilderComputationValueSpecifier<allowed>;
348 _SetInputName(inputName);
416 _SetFallsBackToDispatched(
true);
425struct Exec_ComputationBuilderAccessorBase
426 :
public Exec_ComputationBuilderCommonBase
429 Exec_ComputationBuilderAccessorBase(
const SdfPath &localTraversal)
430 : _localTraversal(localTraversal)
435 const SdfPath &_GetLocalTraversal()
const {
436 return _localTraversal;
447struct Exec_ComputationBuilderConstantAccessorBase
448 :
public Exec_ComputationBuilderAccessorBase
454 Exec_ComputationBuilderConstantValueSpecifier
455 InputName(
const TfToken &inputName) &&
457 return Exec_ComputationBuilderConstantValueSpecifier(
459 _GetLocalTraversal(),
461 std::move(_constantValue));
466 Exec_ComputationBuilderConstantAccessorBase(
481template <Exec_ComputationBuilderProv
iderTypes allowed>
483 :
public Exec_ComputationBuilderAccessorBase
486 : Exec_ComputationBuilderAccessorBase(localTraversal)
490 using ValueSpecifier =
491 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
497 template <
typename ResultType>
502 "VtArray is not a supported result type");
504 return ValueSpecifier(
507 {_GetLocalTraversal(),
512 template <
typename ResultType>
516 return ValueSpecifier(
519 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
520 ExecProviderResolution::DynamicTraversal::
521 IncomingConnectionOwningAttributes});
525 template <
typename ResultType>
530 "VtArray is not a supported result type");
532 return _GetMetadataValueSpecifier<allowed>(
534 _GetLocalTraversal(),
542template <Exec_ComputationBuilderProv
iderTypes allowed>
553template <Exec_ComputationBuilderProv
iderTypes allowed>
562 using ValueSpecifier =
563 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
569 template <
typename ResultType>
573 return ValueSpecifier(
576 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
577 ExecProviderResolution::DynamicTraversal::
578 ConnectionTargetedObjects});
588template <Exec_ComputationBuilderProv
iderTypes allowed>
597 using ValueSpecifier =
598 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
633 template <
typename ResultType>
637 return ValueSpecifier(
640 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
641 ExecProviderResolution::DynamicTraversal::
642 RelationshipTargetedObjects});
652namespace exec_registration {
658 Exec_ComputationBuilderProviderTypes::Prim>
688 SdfPath::ReflexiveRelativePath().AppendProperty(attributeName))
699 Exec_ComputationBuilderProviderTypes::Prim>
713 SdfPath::ReflexiveRelativePath().AppendProperty(
725 Exec_ComputationBuilderProviderTypes::Attribute>
760 Exec_ComputationBuilderProviderTypes::Attribute>
764 Exec_ComputationBuilderProviderTypes::Attribute>(
770 Exec_ComputationBuilderProviderTypes::Attribute>
774 Exec_ComputationBuilderProviderTypes::Attribute>(
784 template <
typename ValueType>
789 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
790 .InputName(attributeName);
800 Exec_ComputationBuilderProviderTypes::Any>
844template <
typename ResultType>
846 :
public Exec_ComputationBuilderComputationValueSpecifier<
847 Exec_ComputationBuilderProviderTypes::Any>
877 : Exec_ComputationBuilderComputationValueSpecifier<
881 CheckForRegistration<ResultType>(),
891template <
typename ValueType>
893 :
public Exec_ComputationBuilderComputationValueSpecifier<
894 Exec_ComputationBuilderProviderTypes::Any>
919 : Exec_ComputationBuilderComputationValueSpecifier<
921 _GetMetadataValueSpecifier<allowedProviders>(
923 .CheckForRegistration<ValueType>(),
924 SdfPath::ReflexiveRelativePath(),
928 "VtArray is not a supported result type");
937template <
typename ValueType>
939 :
public Exec_ComputationBuilderConstantAccessorBase
1043 ValueType &&constantValue)
1044 : Exec_ComputationBuilderConstantAccessorBase(
1047 CheckForRegistration<ValueType>())
1050 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1051 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1052 "Must use std::string to represent string literal types.");
1054 VtIsHashable<ValueType>(),
1055 "Types used to provide constant input values must be hashable.");
1059 const ValueType &constantValue)
1060 : Exec_ComputationBuilderConstantAccessorBase(
1063 CheckForRegistration<ValueType>())
1066 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1067 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1068 "Must use std::string to represent string literal types.");
1070 VtIsHashable<ValueType>(),
1071 "Types used to provide constant input values must be hashable.");
1079Constant(
const char *) -> Constant<std::string>;
1080Constant(
char *) -> Constant<std::string>;
1088template <
typename ResultType>
1089struct NamespaceAncestor final
1090 :
public Exec_ComputationBuilderComputationValueSpecifier<
1091 Exec_ComputationBuilderProviderTypes::Prim>
1124 : Exec_ComputationBuilderComputationValueSpecifier<
1128 CheckForRegistration<ResultType>(),
1182template <
typename ValueType>
1187 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
1188 .InputName(attributeName);
1235template <
typename ResultType>
1239 return Exec_ComputationBuilderComputationValueSpecifier<
1240 Exec_ComputationBuilderProviderTypes::Attribute>(
1244 ExecProviderResolution::DynamicTraversal::
1245 ConnectionTargetedObjects});
1286template <
typename ResultType>
1290 return Exec_ComputationBuilderComputationValueSpecifier<
1291 Exec_ComputationBuilderProviderTypes::Any>(
1295 ExecProviderResolution::DynamicTraversal::
1296 IncomingConnectionOwningAttributes});
1328 struct ConstructionAccess {
1330 Construct(
TfType schemaType) {
1375 const TfToken &computationName);
1471 template <
class... DispatchedOntoSchemaTypes>
1474 const TfToken &computationName,
1475 DispatchedOntoSchemaTypes &&...schemaTypes);
1481 const TfToken &computationName,
1516 template <
class... DispatchedOntoSchemaTypes>
1519 const TfToken &computationName,
1520 DispatchedOntoSchemaTypes &&...schemaTypes);
1526 const TfToken &computationName,
1538class Exec_ComputationBuilderBase
1542 Exec_ComputationBuilderBase(
1545 const TfToken &computationName,
1549 ~Exec_ComputationBuilderBase();
1558 template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1559 static void _ValidateInputs();
1568 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1573 std::unique_ptr<ExecDispatchesOntoSchemas>
1574 _GetDispatchesOntoSchemas();
1583 const std::unique_ptr<_Data> _data;
1588template <
typename Derived>
1589class Exec_ComputationBuilderCRTPBase :
public Exec_ComputationBuilderBase
1592 struct _UnspecifiedType {};
1596 Exec_ComputationBuilderCRTPBase(
1599 const TfToken &computationName,
1604 ~Exec_ComputationBuilderCRTPBase();
1662 typename ResultType = _UnspecifiedType,
1663 typename ReturnType = _UnspecifiedType>
1671 :
public Exec_ComputationBuilderCRTPBase<ExecPrimComputationBuilder>
1679 const TfToken &computationName,
1680 bool dispatched =
false,
1709 template <
typename... Args>
1711 Inputs(Args && ... args);
1717 :
public Exec_ComputationBuilderCRTPBase<ExecAttributeComputationBuilder>
1726 const TfToken &computationName,
1727 bool dispatched =
false,
1760 template <
typename... Args>
1762 Inputs(Args && ... args);
1767 :
public Exec_ComputationBuilderCRTPBase<ExecAttributeExpressionBuilder>
1806 template <
typename... Args>
1808 Inputs(Args && ... args);
1816template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1818Exec_ComputationBuilderBase::_ValidateInputs() {
1819 using regType = std::decay_t<T>;
1821 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1822 "Accessor can't provide an input value.");
1824 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1825 "Constant(value) must be followed by .InputName(inputNameToken)");
1827 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1828 "Invalid type used as an input registration.");
1830 regType::allowedProviders & allowed,
1831 "Input is not allowed on a provider of this type.");
1838template <
typename Derived>
1839template <
typename InputResultType,
typename ReturnType>
1851 std::is_same_v<InputResultType, _UnspecifiedType>,
1856 !std::is_void_v<ResultType> ||
1857 std::is_convertible_v<ReturnType, ResultType>,
1858 "Callback return type must be convertible to the computation result "
1861 !std::is_reference_v<ResultType>,
1862 "Callback functions must return by value");
1865 "VtArray is not a supported result type");
1867 const TfType resultType =
1873 if constexpr (std::is_void_v<ReturnType>) {
1874 _AddCallback(callback, resultType);
1878 ctx.
SetOutput<ResultType>(callback(ctx));
1883 return *
static_cast<Derived*
>(
this);
1890template <
typename... Args>
1897 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
1900 (_AddInputKey(&args), ...);
1909template <
typename... Args>
1916 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1919 (_AddInputKey(&args), ...);
1928template <
typename... Args>
1935 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1938 (_AddInputKey(&args), ...);
1947template <
class... DispatchedOntoSchemaTypes>
1950 const TfToken &computationName,
1951 DispatchedOntoSchemaTypes &&...schemaTypes)
1955 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1959 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1962template <
class... DispatchedOntoSchemaTypes>
1965 const TfToken &computationName,
1966 DispatchedOntoSchemaTypes &&...schemaTypes)
1970 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1974 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1977PXR_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...