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
1031 ValueType &&constantValue)
1032 : Exec_ComputationBuilderConstantAccessorBase(
1035 CheckForRegistration<ValueType>())
1038 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1039 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1040 "Must use std::string to represent string literal types.");
1042 VtIsHashable<ValueType>(),
1043 "Types used to provide constant input values must be hashable.");
1047 const ValueType &constantValue)
1048 : Exec_ComputationBuilderConstantAccessorBase(
1051 CheckForRegistration<ValueType>())
1054 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1055 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1056 "Must use std::string to represent string literal types.");
1058 VtIsHashable<ValueType>(),
1059 "Types used to provide constant input values must be hashable.");
1067Constant(
const char *) -> Constant<std::string>;
1068Constant(
char *) -> Constant<std::string>;
1076template <
typename ResultType>
1077struct NamespaceAncestor final
1078 :
public Exec_ComputationBuilderComputationValueSpecifier<
1079 Exec_ComputationBuilderProviderTypes::Prim>
1112 : Exec_ComputationBuilderComputationValueSpecifier<
1116 CheckForRegistration<ResultType>(),
1170template <
typename ValueType>
1175 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
1176 .InputName(attributeName);
1223template <
typename ResultType>
1227 return Exec_ComputationBuilderComputationValueSpecifier<
1228 Exec_ComputationBuilderProviderTypes::Attribute>(
1232 ExecProviderResolution::DynamicTraversal::
1233 ConnectionTargetedObjects});
1274template <
typename ResultType>
1278 return Exec_ComputationBuilderComputationValueSpecifier<
1279 Exec_ComputationBuilderProviderTypes::Any>(
1283 ExecProviderResolution::DynamicTraversal::
1284 IncomingConnectionOwningAttributes});
1316 struct ConstructionAccess {
1318 Construct(
TfType schemaType) {
1363 const TfToken &computationName);
1459 template <
class... DispatchedOntoSchemaTypes>
1462 const TfToken &computationName,
1463 DispatchedOntoSchemaTypes &&...schemaTypes);
1469 const TfToken &computationName,
1504 template <
class... DispatchedOntoSchemaTypes>
1507 const TfToken &computationName,
1508 DispatchedOntoSchemaTypes &&...schemaTypes);
1514 const TfToken &computationName,
1526class Exec_ComputationBuilderBase
1530 Exec_ComputationBuilderBase(
1533 const TfToken &computationName,
1537 ~Exec_ComputationBuilderBase();
1546 template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1547 static void _ValidateInputs();
1556 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1561 std::unique_ptr<ExecDispatchesOntoSchemas>
1562 _GetDispatchesOntoSchemas();
1571 const std::unique_ptr<_Data> _data;
1576template <
typename Derived>
1577class Exec_ComputationBuilderCRTPBase :
public Exec_ComputationBuilderBase
1580 struct _UnspecifiedType {};
1584 Exec_ComputationBuilderCRTPBase(
1587 const TfToken &computationName,
1592 ~Exec_ComputationBuilderCRTPBase();
1642 typename ResultType = _UnspecifiedType,
1643 typename ReturnType = _UnspecifiedType>
1651 :
public Exec_ComputationBuilderCRTPBase<Exec_PrimComputationBuilder>
1659 const TfToken &computationName,
1660 bool dispatched =
false,
1689 template <
typename... Args>
1691 Inputs(Args && ... args);
1697 :
public Exec_ComputationBuilderCRTPBase<Exec_AttributeComputationBuilder>
1706 const TfToken &computationName,
1707 bool dispatched =
false,
1740 template <
typename... Args>
1742 Inputs(Args && ... args);
1747 :
public Exec_ComputationBuilderCRTPBase<Exec_AttributeExpressionBuilder>
1786 template <
typename... Args>
1788 Inputs(Args && ... args);
1796template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1798Exec_ComputationBuilderBase::_ValidateInputs() {
1799 using regType = std::decay_t<T>;
1801 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1802 "Accessor can't provide an input value.");
1804 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1805 "Constant(value) must be followed by .InputName(inputNameToken)");
1807 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1808 "Invalid type used as an input registration.");
1810 regType::allowedProviders & allowed,
1811 "Input is not allowed on a provider of this type.");
1818template <
typename Derived>
1819template <
typename InputResultType,
typename ReturnType>
1831 std::is_same_v<InputResultType, _UnspecifiedType>,
1836 !std::is_void_v<ResultType> ||
1837 std::is_convertible_v<ReturnType, ResultType>,
1838 "Callback return type must be convertible to the computation result "
1841 !std::is_reference_v<ResultType>,
1842 "Callback functions must return by value");
1845 "VtArray is not a supported result type");
1847 const TfType resultType =
1853 if constexpr (std::is_void_v<ReturnType>) {
1854 _AddCallback(callback, resultType);
1858 ctx.
SetOutput<ResultType>(callback(ctx));
1863 return *
static_cast<Derived*
>(
this);
1870template <
typename... Args>
1877 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
1880 (_AddInputKey(&args), ...);
1889template <
typename... Args>
1896 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1899 (_AddInputKey(&args), ...);
1908template <
typename... Args>
1915 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1918 (_AddInputKey(&args), ...);
1927template <
class... DispatchedOntoSchemaTypes>
1930 const TfToken &computationName,
1931 DispatchedOntoSchemaTypes &&...schemaTypes)
1935 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1939 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1942template <
class... DispatchedOntoSchemaTypes>
1945 const TfToken &computationName,
1946 DispatchedOntoSchemaTypes &&...schemaTypes)
1950 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1954 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1957PXR_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_SC...
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().
EXEC_API Exec_AttributeComputationBuilder AttributeComputation(const TfToken &attributeName, const TfToken &computationName)
Registers an attribute computation named computationName on attributes named attributeName.
Derived & Callback(ReturnType(*callback)(const VdfContext &))
Registers a callback function that implements the evaluation logic for a computation.
EXEC_API Exec_PrimComputationBuilder PrimComputation(const TfToken &computationName)
Registers a prim computation named computationName.
Exec_AttributeComputationBuilder DispatchedAttributeComputation(const TfToken &computationName, DispatchedOntoSchemaTypes &&...schemaTypes)
Registers a dispatched attribute computation named computationName.
EXEC_API Exec_AttributeExpressionBuilder AttributeExpression(const TfToken &attributeName)
Registers an attribute expression for attributes named attributeName.
Exec_PrimComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for a prim computation.
Exec_AttributeExpressionBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for an attribute expres...
Exec_AttributeComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for an attribute comput...
Exec_PrimComputationBuilder DispatchedPrimComputation(const TfToken &computationName, DispatchedOntoSchemaTypes &&...schemaTypes)
Registers a dispatched 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...