@@ -224,7 +224,8 @@ class Exec_ComputationBuilderValueSpecifierBase
224224 const TfToken &computationName,
225225 TfType resultType,
226226 ExecProviderResolution &&providerResolution,
227- const TfToken &inputName);
227+ const TfToken &inputName,
228+ bool fallsBackToDispatched);
228229
229230 EXEC_API
230231 Exec_ComputationBuilderValueSpecifierBase (
@@ -240,6 +241,9 @@ class Exec_ComputationBuilderValueSpecifierBase
240241 EXEC_API
241242 void _SetOptional (const bool optional);
242243
244+ EXEC_API
245+ void _SetFallsBackToDispatched (bool fallsBackToDispatched);
246+
243247private:
244248 // Only computation builders can get the input key.
245249 friend class Exec_PrimComputationBuilder ;
@@ -265,12 +269,14 @@ struct Exec_ComputationBuilderComputationValueSpecifier
265269{
266270 Exec_ComputationBuilderComputationValueSpecifier (
267271 const TfToken &computationName,
268- TfType resultType,
269- ExecProviderResolution &&providerResolution)
272+ const TfType resultType,
273+ ExecProviderResolution &&providerResolution,
274+ const bool fallsBackToDispatched = false )
270275 : Exec_ComputationBuilderValueSpecifierBase(
271276 computationName, resultType,
272277 std::move (providerResolution),
273- computationName)
278+ computationName /* inputName */ ,
279+ fallsBackToDispatched)
274280 {
275281 }
276282
@@ -339,6 +345,44 @@ struct Exec_ComputationBuilderComputationValueSpecifier
339345 return *this ;
340346 }
341347
348+ // / Declares the input can find dispatched computations *if* the requested
349+ // / computation name doesn't match a local computation on the provider.
350+ // /
351+ // / \see [DispatchedPrimComputation](#Exec_ComputationBuilder::DispatchedPrimComputation)
352+ // /
353+ // / # Example
354+ // /
355+ // / ```{.cpp}
356+ // / EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(MySchemaType)
357+ // / {
358+ // / // Register a dispatched prim computation.
359+ // / self.DispatchedPrimComputation(_tokens->myDispatchedComputation)
360+ // / .Callback<double>(+[](const VdfContext &) { return 11.0; })
361+ // /
362+ // / // Register a prim computation that requests the above dispatched
363+ // / // computation via uses relationship targets.
364+ // / self.PrimComputation(_tokens->myComputation)
365+ // / .Callback<double>(+[](const VdfContext &ctx) {
366+ // / const double *const valuePtr =
367+ // / ctx.GetInputValuePtr<double>(
368+ // / _tokens->myDispatchedComputation);
369+ // / return valuePtr ? *valuePtr : -1.0;
370+ // / })
371+ // / .Inputs(
372+ // / Relationship(_tokens->myRelationship)
373+ // / .TargetedObjects<double>(
374+ // / _tokens->myDispatchedComputation)
375+ // / .FallsBackToDispatched())
376+ // / }
377+ // / ```
378+ // /
379+ This&
380+ FallsBackToDispatched ()
381+ {
382+ _SetFallsBackToDispatched (true );
383+ return *this ;
384+ }
385+
342386 // / @}
343387};
344388
@@ -829,8 +873,71 @@ class Exec_ComputationBuilder
829873 Exec_PrimComputationBuilder
830874 PrimComputation (const TfToken &computationName);
831875
876+ // / Registers a dispatched prim computation named \p computationName.
877+ // /
878+ // / A dispatched prim computation is only visible to computations on the
879+ // / prim that does the dispatching. I.e., the computation registrations for
880+ // / a schema can include dispatched computations and inputs to computations
881+ // / registered on the same schema can request the dispatched computations,
882+ // / using the input option FallsBackToDispatched(), from *other provider
883+ // / prims* and find them there. *Other schema computation registrations*
884+ // / will not be able to find the dispatched computations, however.
885+ // /
886+ // / Dispatched computations can be restricted as to which prims they can
887+ // / dispatch onto, based on the typed and applied schemas of a given target
888+ // / prim. The second parameter to the DispatchedPrimComputation registration
889+ // / function can be used to specify zero or more schema types (as
890+ // / TfType%s). If any types are given, the dispatched computation will only
891+ // / be found on a target prim if that prim's typed schema type (or one of
892+ // / its base type) is among the given schema types or if the fully expanded
893+ // / list of API schemas applied to the prim includes a schema that is among
894+ // / the given schema types.
895+ // /
896+ // / # Example
897+ // /
898+ // / ```{.cpp}
899+ // / EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(MySchemaType)
900+ // / {
901+ // / // Register a dispatched prim computation that can be found on
902+ // / // scopes.
903+ // / const TfType scopeType = TfType::FindByName("UsdGeomScope");
904+ // / self.DispatchedPrimComputation(_tokens->eleven, scopeType)
905+ // / .Callback<double>(+[](const VdfContext &) { return 11.0; })
906+ // /
907+ // / // Register a prim computation that requests the above dispatched
908+ // / // computation via uses relationship targets.
909+ // / self.PrimComputation(_tokens->myComputation)
910+ // / .Callback<double>(+[](const VdfContext &ctx) {
911+ // / const double *const valuePtr =
912+ // / ctx.GetInputValuePtr<double>(_tokens->eleven);
913+ // / return valuePtr ? *valuePtr : -1.0;
914+ // / })
915+ // / .Inputs(
916+ // /
917+ // / // This input opts-in to finding dispatched computations.
918+ // / Relationship(_tokens->myRelationship)
919+ // / .TargetedObjects<double>(_tokens->eleven)
920+ // / .FallsBackToDispatched())
921+ // / }
922+ // / ```
923+ // /
924+ EXEC_API
925+ Exec_PrimComputationBuilder
926+ DispatchedPrimComputation (
927+ const TfToken &computationName,
928+ ExecDispatchesOntoSchemas &&ontoSchemas);
929+
930+ // Convenience variadic template overload that takes zero or more schema
931+ // types.
932+ template <class ... DispatchedOntoSchemaTypes>
933+ Exec_PrimComputationBuilder
934+ DispatchedPrimComputation (
935+ const TfToken &computationName,
936+ DispatchedOntoSchemaTypes &&...schemaTypes);
937+
832938 // XXX:TODO
833- // AttributeComputation
939+ // - AttributeComputation
940+ // - DispatchedAttributeComputation
834941
835942 // / @}
836943
@@ -849,7 +956,9 @@ class Exec_PrimComputationBuilder
849956 EXEC_API
850957 Exec_PrimComputationBuilder (
851958 TfType schemaType,
852- const TfToken &computationName);
959+ const TfToken &computationName,
960+ bool dispatched = false ,
961+ ExecDispatchesOntoSchemas &&dispatchesOntoSchemas = {});
853962
854963public:
855964 EXEC_API
@@ -1002,6 +1111,21 @@ Exec_PrimComputationBuilder::_ValidateInputs() {
10021111 " Input is not allowed on a provider of this type." );
10031112}
10041113
1114+ template <class ... DispatchedOntoSchemaTypes>
1115+ Exec_PrimComputationBuilder
1116+ Exec_ComputationBuilder::DispatchedPrimComputation (
1117+ const TfToken &computationName,
1118+ DispatchedOntoSchemaTypes &&...schemaTypes)
1119+ {
1120+ static_assert (
1121+ (std::is_same_v<
1122+ std::decay_t <DispatchedOntoSchemaTypes>, TfType> && ...));
1123+
1124+ return DispatchedPrimComputation (
1125+ computationName,
1126+ {std::forward<DispatchedOntoSchemaTypes>(schemaTypes)...});
1127+ }
1128+
10051129PXR_NAMESPACE_CLOSE_SCOPE
10061130
10071131#endif
0 commit comments