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
1043 ValueType &&constantValue)
1044 : Exec_ComputationBuilderConstantAccessorBase(
1045 VtValue(std::move(constantValue)),
1046 ExecTypeRegistry::GetInstance().
1047 CheckForRegistration<ValueType>())
1048 {
1049 static_assert(
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.");
1053 static_assert(
1054 VtIsHashable<ValueType>(),
1055 "Types used to provide constant input values must be hashable.");
1056 }
1057
1058 Constant(
1059 const ValueType &constantValue)
1060 : Exec_ComputationBuilderConstantAccessorBase(
1061 VtValue(constantValue),
1062 ExecTypeRegistry::GetInstance().
1063 CheckForRegistration<ValueType>())
1064 {
1065 static_assert(
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.");
1069 static_assert(
1070 VtIsHashable<ValueType>(),
1071 "Types used to provide constant input values must be hashable.");
1072 }
1073
1075};
1076
1077// Deduction guides that ensure std::string is the value type used to store
1078// character string literals.
1079Constant(const char *) -> Constant<std::string>;
1080Constant(char *) -> Constant<std::string>;
1081
1082
1083// XXX:TODO
1084// This should be implemented as an alias for an accessor that takes a predicate
1085// plus .Compute(), but that requires implementing predicates plus having a way
1086// to express the computation name and result type as computation parameters.
1087// Therefore, for now, this is implemented as a value specifier.
1088template <typename ResultType>
1089struct NamespaceAncestor final
1090 : public Exec_ComputationBuilderComputationValueSpecifier<
1091 Exec_ComputationBuilderProviderTypes::Prim>
1092{
1095
1123 NamespaceAncestor(const TfToken &computationName)
1124 : Exec_ComputationBuilderComputationValueSpecifier<
1126 computationName,
1127 ExecTypeRegistry::GetInstance().
1128 CheckForRegistration<ResultType>(),
1131 {
1132 }
1133
1135};
1136
1137// XXX:TODO
1138// AnimSpline
1139
1140
1143
1144// Note:
1145// Aliases are implemented as generator functions, rather than as structs,
1146// because that way they can simply be expressed as registrations.
1147
1182template <typename ValueType>
1183auto
1184AttributeValue(const TfToken &attributeName)
1185{
1186 return Attribute(attributeName)
1187 .Computation<ValueType>(ExecBuiltinComputations->computeValue)
1188 .InputName(attributeName);
1189}
1190
1192
1195
1235template <typename ResultType>
1236auto
1237Connections(const TfToken &computationName)
1238{
1239 return Exec_ComputationBuilderComputationValueSpecifier<
1240 Exec_ComputationBuilderProviderTypes::Attribute>(
1241 computationName,
1244 ExecProviderResolution::DynamicTraversal::
1245 ConnectionTargetedObjects});
1246}
1247
1286template <typename ResultType>
1287auto
1288IncomingConnections(const TfToken &computationName)
1289{
1290 return Exec_ComputationBuilderComputationValueSpecifier<
1291 Exec_ComputationBuilderProviderTypes::Any>(
1292 computationName,
1295 ExecProviderResolution::DynamicTraversal::
1296 IncomingConnectionOwningAttributes});
1297}
1298
1300
1301} // namespace exec_registration
1302
1303
1304// We forward declare these classes so the generated documentation for
1305// PrimComputation(), AttributeComputation(), and AttributeExpression() comes
1306// before the Callback() and Inputs() docs.
1307//
1311
1316{
1317 EXEC_API
1318 ExecComputationBuilder(TfType schemaType);
1319
1320public:
1321 EXEC_API
1323
1324 // Allows access to the constructor.
1325 //
1326 // Only schema computation registration functions should create computation
1327 // builders.
1328 struct ConstructionAccess {
1330 Construct(TfType schemaType) {
1331 return ExecComputationBuilder(schemaType);
1332 }
1333 };
1334
1337
1351 EXEC_API
1353 PrimComputation(const TfToken &computationName);
1354
1371 EXEC_API
1374 const TfToken &attributeName,
1375 const TfToken &computationName);
1376
1418 EXEC_API
1420 AttributeExpression(const TfToken &attributeName);
1421
1471 template <class... DispatchedOntoSchemaTypes>
1474 const TfToken &computationName,
1475 DispatchedOntoSchemaTypes &&...schemaTypes);
1476
1477 // overload that takes a vector of TfTypes
1478 EXEC_API
1481 const TfToken &computationName,
1482 ExecDispatchesOntoSchemas &&ontoSchemas);
1483
1516 template <class... DispatchedOntoSchemaTypes>
1519 const TfToken &computationName,
1520 DispatchedOntoSchemaTypes &&...schemaTypes);
1521
1522 // overload that takes a vector of TfTypes
1523 EXEC_API
1526 const TfToken &computationName,
1527 ExecDispatchesOntoSchemas &&ontoSchemas);
1528
1530
1531private:
1532 // The type of the schema for which this builder defines computations.
1533 TfType _schemaType;
1534};
1535
1536
1537// Untemplated base class for classes used to build computation definitions.
1538class Exec_ComputationBuilderBase
1539{
1540protected:
1541 EXEC_API
1542 Exec_ComputationBuilderBase(
1543 const TfToken &attributeName,
1544 TfType schemaType,
1545 const TfToken &computationName,
1546 bool dispatched,
1547 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas);
1548
1549 ~Exec_ComputationBuilderBase();
1550
1551 // Adds the callback with result type.
1552 EXEC_API
1553 void _AddCallback(ExecCallbackFn &&calback, TfType resultType);
1554
1555 // Validates that all inputs are allowed to be registered on computations of
1556 // the \p allowed provider types.
1557 //
1558 template <Exec_ComputationBuilderProviderTypes allowed, typename T>
1559 static void _ValidateInputs();
1560
1561 // Adds an input key from the given value specifier.
1562 //
1563 // This extra level of indirection helps keep Exec_InputKey out of the
1564 // header so that type can remain private.
1565 //
1566 EXEC_API
1567 void _AddInputKey(
1568 const Exec_ComputationBuilderValueSpecifierBase *valueSpecifier);
1569
1570 // Returns a pointer to the dispatches-onto schemas if the computation is
1571 // dispatched, or a null pointer, otherwise.
1572 //
1573 std::unique_ptr<ExecDispatchesOntoSchemas>
1574 _GetDispatchesOntoSchemas();
1575
1576 // We PIMPL the data for this class to avoid exposing more private details
1577 // in this public header.
1578 //
1579 struct _Data;
1580 _Data &_GetData();
1581
1582private:
1583 const std::unique_ptr<_Data> _data;
1584};
1585
1586
1587// CRTP base class for classes used to build computation definitions.
1588template <typename Derived>
1589class Exec_ComputationBuilderCRTPBase : public Exec_ComputationBuilderBase
1590{
1591 // Type used as a default template parameter type for metaprogramming.
1592 struct _UnspecifiedType {};
1593
1594protected:
1595 EXEC_API
1596 Exec_ComputationBuilderCRTPBase(
1597 const TfToken &attributeName,
1598 TfType schemaType,
1599 const TfToken &computationName,
1600 bool dispatched,
1601 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas);
1602
1603 EXEC_API
1604 ~Exec_ComputationBuilderCRTPBase();
1605
1606public:
1661 template<
1662 typename ResultType = _UnspecifiedType,
1663 typename ReturnType = _UnspecifiedType>
1664 Derived&
1665 Callback(ReturnType (*callback)(const VdfContext &));
1666};
1667
1668
1671 : public Exec_ComputationBuilderCRTPBase<ExecPrimComputationBuilder>
1672{
1673 // Only ExecComputationBuilder can create instances.
1674 friend class ExecComputationBuilder;
1675
1676 EXEC_API
1678 TfType schemaType,
1679 const TfToken &computationName,
1680 bool dispatched = false,
1681 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas = {});
1682
1683public:
1684 EXEC_API
1686
1709 template <typename... Args>
1711 Inputs(Args && ... args);
1712};
1713
1714
1717 : public Exec_ComputationBuilderCRTPBase<ExecAttributeComputationBuilder>
1718{
1719 // Only ExecComputationBuilder can create instances.
1720 friend class ExecComputationBuilder;
1721
1722 EXEC_API
1724 const TfToken &attributeName,
1725 TfType schemaType,
1726 const TfToken &computationName,
1727 bool dispatched = false,
1728 ExecDispatchesOntoSchemas &&dispatchesOntoSchemas = {});
1729
1730public:
1731 EXEC_API
1733
1760 template <typename... Args>
1762 Inputs(Args && ... args);
1763};
1764
1767 : public Exec_ComputationBuilderCRTPBase<ExecAttributeExpressionBuilder>
1768{
1769 // Only ExecComputationBuilder can create instances.
1770 friend class ExecComputationBuilder;
1771
1772 EXEC_API
1774 const TfToken &attributeName,
1775 TfType schemaType);
1776
1777public:
1778 EXEC_API
1780
1806 template <typename... Args>
1808 Inputs(Args && ... args);
1809};
1810
1811
1812//
1813// Exec_ComputationBuilderBase
1814//
1815
1816template <Exec_ComputationBuilderProviderTypes allowed, typename T>
1817void
1818Exec_ComputationBuilderBase::_ValidateInputs() {
1819 using regType = std::decay_t<T>;
1820 static_assert(
1821 !std::is_base_of_v<Exec_ComputationBuilderAccessorBase, regType>,
1822 "Accessor can't provide an input value.");
1823 static_assert(
1824 !std::is_same_v<Exec_ComputationBuilderConstantAccessorBase, regType>,
1825 "Constant(value) must be followed by .InputName(inputNameToken)");
1826 static_assert(
1827 std::is_base_of_v<Exec_ComputationBuilderValueSpecifierBase, regType>,
1828 "Invalid type used as an input registration.");
1829 static_assert(
1830 regType::allowedProviders & allowed,
1831 "Input is not allowed on a provider of this type.");
1832}
1833
1834//
1835// Exec_ComputationBuilderCRTPBase
1836//
1837
1838template <typename Derived>
1839template <typename InputResultType, typename ReturnType>
1840Derived&
1842 ReturnType (*callback)(const VdfContext &))
1843{
1844 // In order to allow the return type of the callback to be different from
1845 // the computation result type in some cases AND be able to deduce the
1846 // result type from the return type in others, we have to default both
1847 // template parameters to _UnspecifiedType and use metaprogramming to get
1848 // the actual result type.
1849 using ResultType =
1850 std::conditional_t<
1851 std::is_same_v<InputResultType, _UnspecifiedType>,
1852 ReturnType,
1853 InputResultType>;
1854
1855 static_assert(
1856 !std::is_void_v<ResultType> ||
1857 std::is_convertible_v<ReturnType, ResultType>,
1858 "Callback return type must be convertible to the computation result "
1859 "type");
1860 static_assert(
1861 !std::is_reference_v<ResultType>,
1862 "Callback functions must return by value");
1863 static_assert(
1865 "VtArray is not a supported result type");
1866
1867 const TfType resultType =
1869
1870 // If the return type is void, the callback is on the hook to call
1871 // VdfContext::SetOutput; otherwise, we wrap it in a lambda that passes
1872 // the callback return value to SetOutput.
1873 if constexpr (std::is_void_v<ReturnType>) {
1874 _AddCallback(callback, resultType);
1875 } else {
1876 _AddCallback(
1877 [callback](const VdfContext& ctx) {
1878 ctx.SetOutput<ResultType>(callback(ctx));
1879 },
1880 resultType);
1881 }
1882
1883 return *static_cast<Derived*>(this);
1884}
1885
1886//
1887// ExecPrimComputationBuilder
1888//
1889
1890template <typename... Args>
1893 Args && ... args)
1894{
1895 // Validate inputs
1896 (_ValidateInputs<
1897 Exec_ComputationBuilderProviderTypes::Prim, Args>(), ...);
1898
1899 // Add inputs
1900 (_AddInputKey(&args), ...);
1901
1902 return *this;
1903}
1904
1905//
1906// ExecAttributeComputationBuilder
1907//
1908
1909template <typename... Args>
1912 Args && ... args)
1913{
1914 // Validate inputs
1915 (_ValidateInputs<
1916 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1917
1918 // Add inputs
1919 (_AddInputKey(&args), ...);
1920
1921 return *this;
1922}
1923
1924//
1925// ExecAttributeExpressionBuilder
1926//
1927
1928template <typename... Args>
1931 Args && ... args)
1932{
1933 // Validate inputs
1934 (_ValidateInputs<
1935 Exec_ComputationBuilderProviderTypes::Attribute, Args>(), ...);
1936
1937 // Add inputs
1938 (_AddInputKey(&args), ...);
1939
1940 return *this;
1941}
1942
1943//
1944// ExecComputationBuilder
1945//
1946
1947template <class... DispatchedOntoSchemaTypes>
1950 const TfToken &computationName,
1951 DispatchedOntoSchemaTypes &&...schemaTypes)
1952{
1953 static_assert(
1954 (std::is_same_v<
1955 std::decay_t<DispatchedOntoSchemaTypes>, TfType> && ...));
1956
1958 computationName,
1959 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1960}
1961
1962template <class... DispatchedOntoSchemaTypes>
1965 const TfToken &computationName,
1966 DispatchedOntoSchemaTypes &&...schemaTypes)
1967{
1968 static_assert(
1969 (std::is_same_v<
1970 std::decay_t<DispatchedOntoSchemaTypes>, TfType> && ...));
1971
1973 computationName,
1974 {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1975}
1976
1977PXR_NAMESPACE_CLOSE_SCOPE
1978
1979#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_SCHE...
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:120
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().
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.
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...