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>
517 "VtArray is not a supported result type");
519 return _GetMetadataValueSpecifier<allowed>(
521 _GetLocalTraversal(),
529template <Exec_ComputationBuilderProv
iderTypes allowed>
540template <Exec_ComputationBuilderProv
iderTypes allowed>
549 using ValueSpecifier =
550 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
557 template <
typename ResultType>
561 return ValueSpecifier(
564 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
565 ExecProviderResolution::DynamicTraversal::
566 ConnectionTargetedObjects});
576template <Exec_ComputationBuilderProv
iderTypes allowed>
585 using ValueSpecifier =
586 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
621 template <
typename ResultType>
625 return ValueSpecifier(
628 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
629 ExecProviderResolution::DynamicTraversal::
630 RelationshipTargetedObjects});
640namespace exec_registration {
646 Exec_ComputationBuilderProviderTypes::Prim>
676 SdfPath::ReflexiveRelativePath().AppendProperty(attributeName))
687 Exec_ComputationBuilderProviderTypes::Prim>
701 SdfPath::ReflexiveRelativePath().AppendProperty(
713 Exec_ComputationBuilderProviderTypes::Attribute>
748 Exec_ComputationBuilderProviderTypes::Attribute>
752 Exec_ComputationBuilderProviderTypes::Attribute>(
758 Exec_ComputationBuilderProviderTypes::Attribute>
762 Exec_ComputationBuilderProviderTypes::Attribute>(
772 template <
typename ValueType>
777 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
778 .InputName(attributeName);
788 Exec_ComputationBuilderProviderTypes::Any>
832template <
typename ResultType>
834 :
public Exec_ComputationBuilderComputationValueSpecifier<
835 Exec_ComputationBuilderProviderTypes::Any>
865 : Exec_ComputationBuilderComputationValueSpecifier<
869 CheckForRegistration<ResultType>(),
879template <
typename ValueType>
881 :
public Exec_ComputationBuilderComputationValueSpecifier<
882 Exec_ComputationBuilderProviderTypes::Any>
907 : Exec_ComputationBuilderComputationValueSpecifier<
909 _GetMetadataValueSpecifier<allowedProviders>(
911 .CheckForRegistration<ValueType>(),
912 SdfPath::ReflexiveRelativePath(),
916 "VtArray is not a supported result type");
925template <
typename ValueType>
927 :
public Exec_ComputationBuilderConstantAccessorBase
1019 ValueType &&constantValue)
1020 : Exec_ComputationBuilderConstantAccessorBase(
1023 CheckForRegistration<ValueType>())
1026 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1027 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1028 "Must use std::string to represent string literal types.");
1030 VtIsHashable<ValueType>(),
1031 "Types used to provide constant input values must be hashable.");
1035 const ValueType &constantValue)
1036 : Exec_ComputationBuilderConstantAccessorBase(
1039 CheckForRegistration<ValueType>())
1042 !std::is_same_v<std::decay_t<ValueType>,
char*> &&
1043 !std::is_same_v<std::decay_t<ValueType>,
const char*>,
1044 "Must use std::string to represent string literal types.");
1046 VtIsHashable<ValueType>(),
1047 "Types used to provide constant input values must be hashable.");
1055Constant(
const char *) -> Constant<std::string>;
1056Constant(
char *) -> Constant<std::string>;
1064template <
typename ResultType>
1065struct NamespaceAncestor final
1066 :
public Exec_ComputationBuilderComputationValueSpecifier<
1067 Exec_ComputationBuilderProviderTypes::Prim>
1100 : Exec_ComputationBuilderComputationValueSpecifier<
1104 CheckForRegistration<ResultType>(),
1158template <
typename ValueType>
1163 .
Computation<ValueType>(ExecBuiltinComputations->computeValue)
1164 .InputName(attributeName);
1204template <
typename ResultType>
1208 return Exec_ComputationBuilderComputationValueSpecifier<
1209 Exec_ComputationBuilderProviderTypes::Attribute>(
1213 ExecProviderResolution::DynamicTraversal::
1214 ConnectionTargetedObjects});
1245 struct ConstructionAccess {
1247 Construct(
TfType schemaType) {
1292 const TfToken &computationName);
1343 template <
class... DispatchedOntoSchemaTypes>
1346 const TfToken &computationName,
1347 DispatchedOntoSchemaTypes &&...schemaTypes);
1353 const TfToken &computationName,
1388 template <
class... DispatchedOntoSchemaTypes>
1391 const TfToken &computationName,
1392 DispatchedOntoSchemaTypes &&...schemaTypes);
1398 const TfToken &computationName,
1410class Exec_ComputationBuilderBase
1414 Exec_ComputationBuilderBase(
1417 const TfToken &computationName,
1421 ~Exec_ComputationBuilderBase();
1430 template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1431 static void _ValidateInputs();
1440 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1445 std::unique_ptr<ExecDispatchesOntoSchemas>
1446 _GetDispatchesOntoSchemas();
1455 const std::unique_ptr<_Data> _data;
1460template <
typename Derived>
1461class Exec_ComputationBuilderCRTPBase :
public Exec_ComputationBuilderBase
1464 struct _UnspecifiedType {};
1468 Exec_ComputationBuilderCRTPBase(
1471 const TfToken &computationName,
1476 ~Exec_ComputationBuilderCRTPBase();
1526 typename ResultType = _UnspecifiedType,
1527 typename ReturnType = _UnspecifiedType>
1535 :
public Exec_ComputationBuilderCRTPBase<Exec_PrimComputationBuilder>
1543 const TfToken &computationName,
1544 bool dispatched =
false,
1573 template <
typename... Args>
1575 Inputs(Args && ... args);
1581 :
public Exec_ComputationBuilderCRTPBase<Exec_AttributeComputationBuilder>
1590 const TfToken &computationName,
1591 bool dispatched =
false,
1621 template <
typename... Args>
1623 Inputs(Args && ... args);
1630template <Exec_ComputationBuilderProv
iderTypes allowed,
typename T>
1632Exec_ComputationBuilderBase::_ValidateInputs() {
1633 using regType = std::decay_t<T>;
1635 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1636 "Accessor can't provide an input value.");
1638 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1639 "Constant(value) must be followed by .InputName(inputNameToken)");
1641 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1642 "Invalid type used as an input registration.");
1644 regType::allowedProviders & allowed,
1645 "Input is not allowed on a provider of this type.");
1652template <
typename Derived>
1653template <
typename InputResultType,
typename ReturnType>
1665 std::is_same_v<InputResultType, _UnspecifiedType>,
1670 !std::is_void_v<ResultType> ||
1671 std::is_convertible_v<ReturnType, ResultType>,
1672 "Callback return type must be convertible to the computation result "
1675 !std::is_reference_v<ResultType>,
1676 "Callback functions must return by value");
1679 "VtArray is not a supported result type");
1681 const TfType resultType =
1687 if constexpr (std::is_void_v<ReturnType>) {
1688 _AddCallback(callback, resultType);
1692 ctx.
SetOutput<ResultType>(callback(ctx));
1697 return *
static_cast<Derived*
>(
this);
1704template <
typename... Args>
1711 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
1714 (_AddInputKey(&args), ...);
1723template <
typename... Args>
1730 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1733 (_AddInputKey(&args), ...);
1742template <
class... DispatchedOntoSchemaTypes>
1745 const TfToken &computationName,
1746 DispatchedOntoSchemaTypes &&...schemaTypes)
1750 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1754 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1757template <
class... DispatchedOntoSchemaTypes>
1760 const TfToken &computationName,
1761 DispatchedOntoSchemaTypes &&...schemaTypes)
1765 std::decay_t<DispatchedOntoSchemaTypes>,
TfType> && ...));
1769 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1772PXR_NAMESPACE_CLOSE_SCOPE
Class used to build attribute computation 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_PrimComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for a prim computation.
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.
auto ConnectionTargetedObjects(const TfToken &computationName)
As a direct input to an attribute computation or after an Attribute() accessor, requests input values...
ValueSpecifier Metadata(const TfToken &metadataKey)
See Metadata().
ValueSpecifier ConnectionTargetedObjects(const TfToken &computationName)
See ConnectionTargetedObjects().
Metadata(const TfToken &metadataKey)
Requests an input value from the metadata field indicated by metadataKey, of type ResultType.
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...
ValueSpecifier TargetedObjects(const TfToken &computationName)
After a Relationship() accessor, requests input values from the computation computationName of type R...
Computation(const TfToken &computationName)
Requests an input value from the computation computationName of type ResultType.
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...