Loading...
Searching...
No Matches
computationBuilders.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_EXEC_COMPUTATION_BUILDERS_H
8#define PXR_EXEC_EXEC_COMPUTATION_BUILDERS_H
9
18
19#include "pxr/pxr.h"
20
21#include "pxr/exec/exec/api.h"
22#include "pxr/exec/exec/builtinComputations.h"
25#include "pxr/exec/exec/types.h"
26
27#include "pxr/base/tf/token.h"
28#include "pxr/base/tf/type.h"
29#include "pxr/base/vt/traits.h"
30#include "pxr/base/vt/value.h"
32#include "pxr/exec/vdf/traits.h"
33#include "pxr/usd/sdf/path.h"
34
35#include <memory>
36#include <type_traits>
37#include <utility>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
41struct Exec_InputKey;
42
43
113
122
143
160
174
184
193
194
199{
200 Prim = 1 << 0,
201 Attribute = 1 << 1,
202 Any = 0xff
203};
204
205constexpr bool operator&(
208{
209 return static_cast<unsigned char>(a) & static_cast<unsigned char>(b);
210}
211
212template <Exec_ComputationBuilderProviderTypes allowed>
213struct Exec_ComputationBuilderComputationValueSpecifier;
214
215// Common base class for value specifiers and object accessors.
216class Exec_ComputationBuilderCommonBase
217{
218protected:
219 // Returns a value specifier for computing a metadata value.
220 template <Exec_ComputationBuilderProviderTypes allowed>
221 EXEC_API
222 static Exec_ComputationBuilderComputationValueSpecifier<allowed>
223 _GetMetadataValueSpecifier(
224 const TfType resultType,
225 const SdfPath &localTraversal,
226 const TfToken &metadataKey);
227};
228
229// Untemplated value specifier base class.
230//
231// This class builds up an Exec_InputKey that specifies how to source an input
232// value at exec compilation time.
233//
234class Exec_ComputationBuilderValueSpecifierBase
235 : public Exec_ComputationBuilderCommonBase
236{
237public:
238 EXEC_API
239 Exec_ComputationBuilderValueSpecifierBase(
240 const TfToken &computationName,
241 TfType resultType,
242 ExecProviderResolution &&providerResolution,
243 const TfToken &inputName,
244 const TfToken &disambiguatingId);
245
246 EXEC_API
247 Exec_ComputationBuilderValueSpecifierBase(
248 const Exec_ComputationBuilderValueSpecifierBase&);
249
250 EXEC_API
251 ~Exec_ComputationBuilderValueSpecifierBase();
252
253protected:
254 EXEC_API
255 void _SetInputName(const TfToken &inputName);
256
257 EXEC_API
258 void _SetOptional (const bool optional);
259
260 EXEC_API
261 void _SetFallsBackToDispatched(bool fallsBackToDispatched);
262
263private:
264 // Only computation builders can get the input key.
265 friend class Exec_ComputationBuilderBase;
266
267 EXEC_API
268 void _GetInputKey(Exec_InputKey *inputKey) const;
269
270private:
271 // We PIMPL the data for this class to avoid exposing more private details
272 // in this public header.
273 struct _Data;
274 const std::unique_ptr<_Data> _data;
275};
276
277// A value specifier that requests a constant value, valid on a prim or
278// attribute computation
279//
280struct Exec_ComputationBuilderConstantValueSpecifier final
281 : public Exec_ComputationBuilderValueSpecifierBase
282{
283 static constexpr Exec_ComputationBuilderProviderTypes allowedProviders =
284 Exec_ComputationBuilderProviderTypes::Any;
285
286 EXEC_API
287 Exec_ComputationBuilderConstantValueSpecifier(
288 const TfType resultType,
289 const SdfPath &localTraversal,
290 const TfToken &inputName,
291 VtValue &&constantValue);
292};
293
294// A value specifier that requests the value of a computation.
295//
296// The template parameter determines which types of providers the input
297// registration is allowed to be used on.
298//
299template <Exec_ComputationBuilderProviderTypes allowed>
300struct Exec_ComputationBuilderComputationValueSpecifier
301 : public Exec_ComputationBuilderValueSpecifierBase
302{
303 Exec_ComputationBuilderComputationValueSpecifier(
304 const TfToken &computationName,
305 const TfType resultType,
306 ExecProviderResolution &&providerResolution,
307 const TfToken &disambiguatingId = TfToken())
308 : Exec_ComputationBuilderValueSpecifierBase(
309 computationName, resultType,
310 std::move(providerResolution),
311 computationName /* inputName */,
312 disambiguatingId)
313 {
314 }
315
316 using This = Exec_ComputationBuilderComputationValueSpecifier<allowed>;
317
318 static constexpr Exec_ComputationBuilderProviderTypes allowedProviders =
319 allowed;
320
323
345 This&
346 InputName(const TfToken &inputName)
347 {
348 _SetInputName(inputName);
349 return *this;
350 }
351
374 This&
376 {
377 _SetOptional(false);
378 return *this;
379 }
380
413 This&
415 {
416 _SetFallsBackToDispatched(true);
417 return *this;
418 }
419
421};
422
423
424// Untemplated object accessor base class.
425struct Exec_ComputationBuilderAccessorBase
426 : public Exec_ComputationBuilderCommonBase
427{
428
429 Exec_ComputationBuilderAccessorBase(const SdfPath &localTraversal)
430 : _localTraversal(localTraversal)
431 {
432 }
433
434protected:
435 const SdfPath &_GetLocalTraversal() const {
436 return _localTraversal;
437 }
438
439private:
440 // The relative path used for the first phase of provider resolution.
441 SdfPath _localTraversal;
442};
443
444// Untemplated base class for accessors used to provide constant values as
445// computation inputs.
446//
447struct Exec_ComputationBuilderConstantAccessorBase
448 : public Exec_ComputationBuilderAccessorBase
449{
450 // We specialize the InputName() accessor because it is required for
451 // constant values. I.e., Constant() returns an accessor, and the
452 // InputName() option must be used to generate a value specifier.
453 //
454 Exec_ComputationBuilderConstantValueSpecifier
455 InputName(const TfToken &inputName) &&
456 {
457 return Exec_ComputationBuilderConstantValueSpecifier(
458 _valueType,
459 _GetLocalTraversal(),
460 inputName,
461 std::move(_constantValue));
462 }
463
464protected:
465 EXEC_API
466 Exec_ComputationBuilderConstantAccessorBase(
467 VtValue &&constantValue,
468 TfType valueType);
469
470private:
471 VtValue _constantValue;
472 const TfType _valueType;
473};
474
481template <Exec_ComputationBuilderProviderTypes allowed>
483 : public Exec_ComputationBuilderAccessorBase
484{
485 Exec_ComputationBuilderAccessor(const SdfPath &localTraversal)
486 : Exec_ComputationBuilderAccessorBase(localTraversal)
487 {
488 }
489
490 using ValueSpecifier =
491 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
492
495
497 template <typename ResultType>
498 ValueSpecifier
499 Computation(const TfToken &computationName)
500 {
501 static_assert(!VtIsArray<ResultType>::value,
502 "VtArray is not a supported result type");
503
504 return ValueSpecifier(
505 computationName,
506 ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>(),
507 {_GetLocalTraversal(),
509 }
510
512 template <typename ResultType>
513 ValueSpecifier
514 IncomingConnections(const TfToken &computationName)
515 {
516 return ValueSpecifier(
517 computationName,
518 ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>(),
519 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
520 ExecProviderResolution::DynamicTraversal::
521 IncomingConnectionOwningAttributes});
522 }
523
525 template <typename ResultType>
526 ValueSpecifier
527 Metadata(const TfToken &metadataKey)
528 {
529 static_assert(!VtIsArray<ResultType>::value,
530 "VtArray is not a supported result type");
531
532 return _GetMetadataValueSpecifier<allowed>(
533 ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>(),
534 _GetLocalTraversal(),
535 metadataKey);
536 }
537
539};
540
542template <Exec_ComputationBuilderProviderTypes allowed>
544 : public Exec_ComputationBuilderAccessor<allowed>
545{
548 {
549 }
550};
551
553template <Exec_ComputationBuilderProviderTypes allowed>
556{
559 {
560 }
561
562 using ValueSpecifier =
563 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
564
567
569 template <typename ResultType>
570 ValueSpecifier
571 Connections(const TfToken &computationName)
572 {
573 return ValueSpecifier(
574 computationName,
575 ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>(),
576 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
577 ExecProviderResolution::DynamicTraversal::
578 ConnectionTargetedObjects});
579 }
580
582
583 // XXX:TODO
584 // Accessors for AnimSpline, etc.
585};
586
588template <Exec_ComputationBuilderProviderTypes allowed>
591{
594 {
595 }
596
597 using ValueSpecifier =
598 Exec_ComputationBuilderComputationValueSpecifier<allowed>;
599
602
633 template <typename ResultType>
634 ValueSpecifier
635 TargetedObjects(const TfToken &computationName)
636 {
637 return ValueSpecifier(
638 computationName,
639 ExecTypeRegistry::GetInstance().CheckForRegistration<ResultType>(),
640 {Exec_ComputationBuilderAccessorBase::_GetLocalTraversal(),
641 ExecProviderResolution::DynamicTraversal::
642 RelationshipTargetedObjects});
643 }
644
646};
647
648
649// The following registrations are in the exec_registration namespace so that
650// the registration macro can make them available (without the namespace) as
651// arguments to registrations methods (i.e., Inputs()).
652namespace exec_registration {
653
654
656struct Attribute final
658 Exec_ComputationBuilderProviderTypes::Prim>
659{
662
685 Attribute(const TfToken &attributeName)
688 SdfPath::ReflexiveRelativePath().AppendProperty(attributeName))
689 {
690 }
691
693};
694
695
697struct Relationship final
699 Exec_ComputationBuilderProviderTypes::Prim>
700{
703
710 Relationship(const TfToken &relationshipName)
713 SdfPath::ReflexiveRelativePath().AppendProperty(
714 relationshipName))
715 {
716 }
717
719};
720
721
723struct Prim final
725 Exec_ComputationBuilderProviderTypes::Attribute>
726{
729
754 SdfPath(".."))
755 {
756 }
757
760 Exec_ComputationBuilderProviderTypes::Attribute>
761 Attribute(const TfToken &attributeName)
762 {
764 Exec_ComputationBuilderProviderTypes::Attribute>(
765 SdfPath("..").AppendProperty(attributeName));
766 }
767
770 Exec_ComputationBuilderProviderTypes::Attribute>
771 Relationship(const TfToken &relationshipName)
772 {
774 Exec_ComputationBuilderProviderTypes::Attribute>(
775 SdfPath("..").AppendProperty(relationshipName));
776 }
777
779
782
784 template <typename ValueType>
785 auto
786 AttributeValue(const TfToken &attributeName)
787 {
788 return Attribute(attributeName)
789 .Computation<ValueType>(ExecBuiltinComputations->computeValue)
790 .InputName(attributeName);
791 }
792
794};
795
796
798struct Stage final
800 Exec_ComputationBuilderProviderTypes::Any>
801{
804
832 SdfPath::AbsoluteRootPath())
833 {
834 }
835
837};
838
839// XXX:TODO
840// Property, NamespaceParent, NamespaceChildren, etc.
841
842
844template <typename ResultType>
845struct Computation final
846 : public Exec_ComputationBuilderComputationValueSpecifier<
847 Exec_ComputationBuilderProviderTypes::Any>
848{
851
876 Computation(const TfToken &computationName)
877 : Exec_ComputationBuilderComputationValueSpecifier<
879 computationName,
880 ExecTypeRegistry::GetInstance().
881 CheckForRegistration<ResultType>(),
884 {
885 }
886
888};
889
891template <typename ValueType>
892struct Metadata final
893 : public Exec_ComputationBuilderComputationValueSpecifier<
894 Exec_ComputationBuilderProviderTypes::Any>
895{
898
918 Metadata(const TfToken &metadataKey)
919 : Exec_ComputationBuilderComputationValueSpecifier<
921 _GetMetadataValueSpecifier<allowedProviders>(
922 ExecTypeRegistry::GetInstance()
923 .CheckForRegistration<ValueType>(),
924 SdfPath::ReflexiveRelativePath(),
925 metadataKey))
926 {
927 static_assert(!VtIsArray<ValueType>::value,
928 "VtArray is not a supported result type");
929
930 InputName(metadataKey);
931 }
932
934};
935
936// Constant accessor
937template <typename ValueType>
938struct Constant final
939 : public Exec_ComputationBuilderConstantAccessorBase
940{
943
1031 ValueType &&constantValue)
1032 : Exec_ComputationBuilderConstantAccessorBase(
1033 VtValue(std::move(constantValue)),
1034 ExecTypeRegistry::GetInstance().
1035 CheckForRegistration<ValueType>())
1036 {
1037 static_assert(
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.");
1041 static_assert(
1042 VtIsHashable<ValueType>(),
1043 "Types used to provide constant input values must be hashable.");
1044 }
1045
1046 Constant(
1047 const ValueType &constantValue)
1048 : Exec_ComputationBuilderConstantAccessorBase(
1049 VtValue(constantValue),
1050 ExecTypeRegistry::GetInstance().
1051 CheckForRegistration<ValueType>())
1052 {
1053 static_assert(
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.");
1057 static_assert(
1058 VtIsHashable<ValueType>(),
1059 "Types used to provide constant input values must be hashable.");
1060 }
1061
1063};
1064
1065// Deduction guides that ensure std::string is the value type used to store
1066// character string literals.
1067Constant(const char *) -> Constant<std::string>;
1068Constant(char *) -> Constant<std::string>;
1069
1070
1071// XXX:TODO
1072// This should be implemented as an alias for an accessor that takes a predicate
1073// plus .Compute(), but that requires implementing predicates plus having a way
1074// to express the computation name and result type as computation parameters.
1075// Therefore, for now, this is implemented as a value specifier.
1076template <typename ResultType>
1077struct NamespaceAncestor final
1078 : public Exec_ComputationBuilderComputationValueSpecifier<
1079 Exec_ComputationBuilderProviderTypes::Prim>
1080{
1083
1111 NamespaceAncestor(const TfToken &computationName)
1112 : Exec_ComputationBuilderComputationValueSpecifier<
1114 computationName,
1115 ExecTypeRegistry::GetInstance().
1116 CheckForRegistration<ResultType>(),
1119 {
1120 }
1121
1123};
1124
1125// XXX:TODO
1126// AnimSpline
1127
1128
1131
1132// Note:
1133// Aliases are implemented as generator functions, rather than as structs,
1134// because that way they can simply be expressed as registrations.
1135
1170template <typename ValueType>
1171auto
1172AttributeValue(const TfToken &attributeName)
1173{
1174 return Attribute(attributeName)
1175 .Computation<ValueType>(ExecBuiltinComputations->computeValue)
1176 .InputName(attributeName);
1177}
1178
1180
1183
1223template <typename ResultType>
1224auto
1225Connections(const TfToken &computationName)
1226{
1227 return Exec_ComputationBuilderComputationValueSpecifier<
1228 Exec_ComputationBuilderProviderTypes::Attribute>(
1229 computationName,
1232 ExecProviderResolution::DynamicTraversal::
1233 ConnectionTargetedObjects});
1234}
1235
1274template <typename ResultType>
1275auto
1276IncomingConnections(const TfToken &computationName)
1277{
1278 return Exec_ComputationBuilderComputationValueSpecifier<
1279 Exec_ComputationBuilderProviderTypes::Any>(
1280 computationName,
1283 ExecProviderResolution::DynamicTraversal::
1284 IncomingConnectionOwningAttributes});
1285}
1286
1288
1289} // namespace exec_registration
1290
1291
1292// We forward declare these classes so the generated documentation for
1293// PrimComputation(), AttributeComputation(), and AttributeExpression() comes
1294// before the Callback() and Inputs() docs.
1295//
1299
1304{
1305 EXEC_API
1306 Exec_ComputationBuilder(TfType schemaType);
1307
1308public:
1309 EXEC_API
1311
1312 // Allows access to the constructor.
1313 //
1314 // Only schema computation registration functions should create computation
1315 // builders.
1316 struct ConstructionAccess {
1318 Construct(TfType schemaType) {
1319 return Exec_ComputationBuilder(schemaType);
1320 }
1321 };
1322
1325
1339 EXEC_API
1341 PrimComputation(const TfToken &computationName);
1342
1359 EXEC_API
1362 const TfToken &attributeName,
1363 const TfToken &computationName);
1364
1406 EXEC_API
1408 AttributeExpression(const TfToken &attributeName);
1409
1459 template <class... DispatchedOntoSchemaTypes>
1462 const TfToken &computationName,
1463 DispatchedOntoSchemaTypes &&...schemaTypes);
1464
1465 // overload that takes a vector of TfTypes
1466 EXEC_API
1469 const TfToken &computationName,
1470 ExecDispatchesOntoSchemas &&ontoSchemas);
1471
1504 template <class... DispatchedOntoSchemaTypes>
1507 const TfToken &computationName,
1508 DispatchedOntoSchemaTypes &&...schemaTypes);
1509
1510 // overload that takes a vector of TfTypes
1511 EXEC_API
1514 const TfToken &computationName,
1515 ExecDispatchesOntoSchemas &&ontoSchemas);
1516
1518
1519private:
1520 // The type of the schema for which this builder defines computations.
1521 TfType _schemaType;
1522};
1523
1524
1525// Untemplated base class for classes used to build computation definitions.
1526class Exec_ComputationBuilderBase
1527{
1528protected:
1529 EXEC_API
1530 Exec_ComputationBuilderBase(
1531 const TfToken &attributeName,
1532 TfType schemaType,
1533 const TfToken &computationName,
1534 bool dispatched,
1535 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas);
1536
1537 ~Exec_ComputationBuilderBase();
1538
1539 // Adds the callback with result type.
1540 EXEC_API
1541 void _AddCallback(ExecCallbackFn &&calback, TfType resultType);
1542
1543 // Validates that all inputs are allowed to be registered on computations of
1544 // the \p allowed provider types.
1545 //
1546 template <Exec_ComputationBuilderProviderTypes allowed, typename T>
1547 static void _ValidateInputs();
1548
1549 // Adds an input key from the given value specifier.
1550 //
1551 // This extra level of indirection helps keep Exec_InputKey out of the
1552 // header so that type can remain private.
1553 //
1554 EXEC_API
1555 void _AddInputKey(
1556 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1557
1558 // Returns a pointer to the dispatches-onto schemas if the computation is
1559 // dispatched, or a null pointer, otherwise.
1560 //
1561 std::unique_ptr<ExecDispatchesOntoSchemas>
1562 _GetDispatchesOntoSchemas();
1563
1564 // We PIMPL the data for this class to avoid exposing more private details
1565 // in this public header.
1566 //
1567 struct _Data;
1568 _Data &_GetData();
1569
1570private:
1571 const std::unique_ptr<_Data> _data;
1572};
1573
1574
1575// CRTP base class for classes used to build computation definitions.
1576template <typename Derived>
1577class Exec_ComputationBuilderCRTPBase : public Exec_ComputationBuilderBase
1578{
1579 // Type used as a default template parameter type for metaprogramming.
1580 struct _UnspecifiedType {};
1581
1582protected:
1583 EXEC_API
1584 Exec_ComputationBuilderCRTPBase(
1585 const TfToken &attributeName,
1586 TfType schemaType,
1587 const TfToken &computationName,
1588 bool dispatched,
1589 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas);
1590
1591 EXEC_API
1592 ~Exec_ComputationBuilderCRTPBase();
1593
1594public:
1641 template<
1642 typename ResultType = _UnspecifiedType,
1643 typename ReturnType = _UnspecifiedType>
1644 Derived&
1645 Callback(ReturnType (*callback)(const VdfContext &));
1646};
1647
1648
1651 : public Exec_ComputationBuilderCRTPBase<Exec_PrimComputationBuilder>
1652{
1653 // Only Exec_ComputationBuilder can create instances.
1654 friend class Exec_ComputationBuilder;
1655
1656 EXEC_API
1658 TfType schemaType,
1659 const TfToken &computationName,
1660 bool dispatched = false,
1661 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas = {});
1662
1663public:
1664 EXEC_API
1666
1689 template <typename... Args>
1691 Inputs(Args && ... args);
1692};
1693
1694
1697 : public Exec_ComputationBuilderCRTPBase<Exec_AttributeComputationBuilder>
1698{
1699 // Only Exec_ComputationBuilder can create instances.
1700 friend class Exec_ComputationBuilder;
1701
1702 EXEC_API
1704 const TfToken &attributeName,
1705 TfType schemaType,
1706 const TfToken &computationName,
1707 bool dispatched = false,
1708 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas = {});
1709
1710public:
1711 EXEC_API
1713
1740 template <typename... Args>
1742 Inputs(Args && ... args);
1743};
1744
1747 : public Exec_ComputationBuilderCRTPBase<Exec_AttributeExpressionBuilder>
1748{
1749 // Only Exec_ComputationBuilder can create instances.
1750 friend class Exec_ComputationBuilder;
1751
1752 EXEC_API
1754 const TfToken &attributeName,
1755 TfType schemaType);
1756
1757public:
1758 EXEC_API
1760
1786 template <typename... Args>
1788 Inputs(Args && ... args);
1789};
1790
1791
1792//
1793// Exec_ComputationBuilderBase
1794//
1795
1796template <Exec_ComputationBuilderProviderTypes allowed, typename T>
1797void
1798Exec_ComputationBuilderBase::_ValidateInputs() {
1799 using regType = std::decay_t<T>;
1800 static_assert(
1801 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1802 "Accessor can't provide an input value.");
1803 static_assert(
1804 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1805 "Constant(value) must be followed by .InputName(inputNameToken)");
1806 static_assert(
1807 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1808 "Invalid type used as an input registration.");
1809 static_assert(
1810 regType::allowedProviders & allowed,
1811 "Input is not allowed on a provider of this type.");
1812}
1813
1814//
1815// Exec_ComputationBuilderCRTPBase
1816//
1817
1818template <typename Derived>
1819template <typename InputResultType, typename ReturnType>
1820Derived&
1822 ReturnType (*callback)(const VdfContext &))
1823{
1824 // In order to allow the return type of the callback to be different from
1825 // the computation result type in some cases AND be able to deduce the
1826 // result type from the return type in others, we have to default both
1827 // template parameters to _UnspecifiedType and use metaprogramming to get
1828 // the actual result type.
1829 using ResultType =
1830 std::conditional_t<
1831 std::is_same_v<InputResultType, _UnspecifiedType>,
1832 ReturnType,
1833 InputResultType>;
1834
1835 static_assert(
1836 !std::is_void_v<ResultType> ||
1837 std::is_convertible_v<ReturnType, ResultType>,
1838 "Callback return type must be convertible to the computation result "
1839 "type");
1840 static_assert(
1841 !std::is_reference_v<ResultType>,
1842 "Callback functions must return by value");
1843 static_assert(
1845 "VtArray is not a supported result type");
1846
1847 const TfType resultType =
1849
1850 // If the return type is void, the callback is on the hook to call
1851 // VdfContext::SetOutput; otherwise, we wrap it in a lambda that passes
1852 // the callback return value to SetOutput.
1853 if constexpr (std::is_void_v<ReturnType>) {
1854 _AddCallback(callback, resultType);
1855 } else {
1856 _AddCallback(
1857 [callback](const VdfContext& ctx) {
1858 ctx.SetOutput<ResultType>(callback(ctx));
1859 },
1860 resultType);
1861 }
1862
1863 return *static_cast<Derived*>(this);
1864}
1865
1866//
1867// Exec_PrimComputationBuilder
1868//
1869
1870template <typename... Args>
1873 Args && ... args)
1874{
1875 // Validate inputs
1876 (_ValidateInputs<
1877 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
1878
1879 // Add inputs
1880 (_AddInputKey(&args), ...);
1881
1882 return *this;
1883}
1884
1885//
1886// Exec_AttributeComputationBuilder
1887//
1888
1889template <typename... Args>
1892 Args && ... args)
1893{
1894 // Validate inputs
1895 (_ValidateInputs<
1896 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1897
1898 // Add inputs
1899 (_AddInputKey(&args), ...);
1900
1901 return *this;
1902}
1903
1904//
1905// Exec_AttributeExpressionBuilder
1906//
1907
1908template <typename... Args>
1911 Args && ... args)
1912{
1913 // Validate inputs
1914 (_ValidateInputs<
1915 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1916
1917 // Add inputs
1918 (_AddInputKey(&args), ...);
1919
1920 return *this;
1921}
1922
1923//
1924// Exec_ComputationBuilder
1925//
1926
1927template <class... DispatchedOntoSchemaTypes>
1930 const TfToken &computationName,
1931 DispatchedOntoSchemaTypes &&...schemaTypes)
1932{
1933 static_assert(
1934 (std::is_same_v<
1935 std::decay_t<DispatchedOntoSchemaTypes>, TfType> && ...));
1936
1938 computationName,
1939 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1940}
1941
1942template <class... DispatchedOntoSchemaTypes>
1945 const TfToken &computationName,
1946 DispatchedOntoSchemaTypes &&...schemaTypes)
1947{
1948 static_assert(
1949 (std::is_same_v<
1950 std::decay_t<DispatchedOntoSchemaTypes>, TfType> && ...));
1951
1953 computationName,
1954 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1955}
1956
1957PXR_NAMESPACE_CLOSE_SCOPE
1958
1959#endif
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.
Definition: typeRegistry.h:46
TfType CheckForRegistration() const
Confirms that ValueType has been registered.
Definition: typeRegistry.h:94
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.
Definition: path.h:281
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 ...
Definition: smallVector.h:157
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
A context is the parameter bundle passed to callbacks of computations.
Definition: context.h:40
void SetOutput(const TfToken &outputName, const T &value) const
Sets the value of the output named outputName to value.
Definition: context.h:394
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
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.
Definition: types.h:28
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.
This & InputName(const TfToken &inputName)
Overrides the default input name, setting it to inputName.
This & FallsBackToDispatched()
Declares the input can find dispatched computations if the requested computation name doesn't match a...
This & Required()
Declares the input is required, i.e., that the computation expects an input value always to be provid...
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().
STL namespace.
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.
Definition: traits.h:22
Attribute accessor, valid for providing input to a prim computation.
Computation value specifier, valid for providing input to any computation.
Metadata value specifier, valid on a prim or attribute 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...