Loading...
Searching...
No Matches
controllerBuilder.h
Go to the documentation of this file.
1//
2// Copyright 2026 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_IR_CONTROLLER_BUILDER_H
8#define PXR_EXEC_EXEC_IR_CONTROLLER_BUILDER_H
9
20
21#include "pxr/pxr.h"
22
25
26#include "pxr/exec/exec/builtinComputations.h"
29
30PXR_NAMESPACE_OPEN_SCOPE
31
109public:
110
112 using Callback = ExecIrResult(*)(const VdfContext &);
113
123 EXECIR_API
126 Callback forwardCallback,
127 Callback inverseCallback);
128
134 template <typename ValueType>
135 void
137 const TfToken &attributeName);
138
145 template <typename ValueType>
146 void
148 const TfToken &attributeName);
149
158 template <typename ValueType>
159 void
161 const TfToken &attributeName);
162
171 template <typename ValueType>
172 void
174 const TfToken &attributeName);
175
181 template <typename ValueType>
182 void
184 const TfToken &attributeName);
185
186private:
187 // Returns a private token used to name constant inputs.
188 EXECIR_API
189 static const TfToken &_GetConstantInputName();
190
191private:
193 ExecPrimComputationBuilder _forwardComputeReg;
194 ExecPrimComputationBuilder _inverseComputeReg;
195};
196
197template <typename ValueType>
198void
200 const TfToken &attributeName)
201{
202 using namespace exec_registration;
203
204 // All input attributes (invertible or not) are inputs to the forward
205 // computation.
206 _forwardComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
207}
208
209template <typename ValueType>
210void
212 const TfToken &attributeName)
213{
214 using namespace exec_registration;
215
216 // All input attributes (invertible or not) are inputs to the forward
217 // computation.
218 _forwardComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
219
220 // Non-invertible input attributes are inputs to the inverse computation.
221 _inverseComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
222}
223
224template <typename ValueType>
225void
227 const TfToken &attributeName)
228{
229 using namespace exec_registration;
230
231 // All outputs (invertible or not) are inputs to the inverse computation.
232 //
233 // TODO: We pull on the resolved value because otherwise, for invertible
234 // outputs, we get the computed value from the forward computation. But what
235 // we really want here is the "desired value," i.e., the value the inversion
236 // is trying to satisfy. For now, we use the authored value as the way the
237 // desired value is specified.
238 _inverseComputeReg.Inputs(
239 Attribute(attributeName)
240 .Computation<ValueType>(ExecBuiltinComputations->computeResolvedValue)
241 .InputName(attributeName));
242
243 // Register an expression on the invertible output that pulls its value
244 // from the forward computation result map.
245 _self.AttributeExpression(attributeName)
246 .Callback(+[](const VdfContext &ctx) -> ValueType {
247 const TfToken &attributeName =
248 ctx.GetInputValue<TfToken>(_GetConstantInputName());
249 const ExecIrResult &resultMap =
250 ctx.GetInputValue<ExecIrResult>(ExecIrTokens->forwardCompute);
251 const auto it = resultMap.find(attributeName);
252 if (it != resultMap.end()) {
253 return it->second.Get<ValueType>();
254 }
255
257 "Failed to find a result value for output attribute '%s' "
258 "when computing %s",
259 attributeName.GetText(),
260 ctx.GetNodeDebugName().c_str());
262 .GetFallback<ValueType>();
263 })
264 .Inputs(
265 Prim().Computation<ExecIrResult>(ExecIrTokens->forwardCompute),
266 Constant(attributeName).InputName(_GetConstantInputName()));
267}
268
269template <typename ValueType>
270void
272 const TfToken &attributeName)
273{
274 using namespace exec_registration;
275
276 // Switch attributes are inputs to the forward and inverse computations.
277 _forwardComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
278 _inverseComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
279}
280
281template <typename ValueType>
282void
284 const TfToken &attributeName)
285{
286 using namespace exec_registration;
287
288 // Passthrough attributes are inputs to the forward and inverse
289 // computations.
290 _forwardComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
291 _inverseComputeReg.Inputs(AttributeValue<ValueType>(attributeName));
292}
293
294PXR_NAMESPACE_CLOSE_SCOPE
295
296#endif
The top-level builder object (aka, the self variable generated by EXEC_REGISTER_COMPUTATIONS_FOR_SCHE...
Builder class used to register invertible controller computations.
void SwitchAttribute(const TfToken &attributeName)
Registers a switch attribute.
EXECIR_API ExecIrControllerBuilder(ExecComputationBuilder &self, Callback forwardCallback, Callback inverseCallback)
Constructs a builder that is used to register computations that implement an invertible controller.
ExecIrResult(*)(const VdfContext &) Callback
The type for forward and inverse controller computation calbacks.
void InvertibleOutputAttribute(const TfToken &attributeName)
Registers an invertible output attribute; the output is inverible if invertible is true.
void PassthroughAttribute(const TfToken &attributeName)
Registers a passthrough attribute.
void NonInvertibleInputAttribute(const TfToken &attributeName)
Registers a non-invertible input attribute.
void InvertibleInputAttribute(const TfToken &attributeName)
Registers an invertible input attribute.
Class used to build prim computation definitions.
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
Definition: denseHashMap.h:41
iterator find(const key_type &k)
Finds the element with key k.
Definition: denseHashMap.h:368
iterator end()
Returns an const_iterator pointing to the end of the map.
Definition: denseHashMap.h:350
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
char const * GetText() const
Return the text that this token represents.
Definition: token.h:179
A context is the parameter bundle passed to callbacks of computations.
Definition: context.h:40
VdfByValueOrConstRef< T > GetInputValue(const TfToken &name) const
Returns a value from the input named name of type T.
Definition: context.h:300
VDF_API std::string GetNodeDebugName() const
Returns the debug name for the node for this context.
const T & GetFallback() const
Returns the registered fallback value for T from the registry.
static VDF_API VdfExecutionTypeRegistry & GetInstance()
Returns the VdfExecutionTypeRegistry singleton instance.
This is a public header, but many of the symbols have private names because they are not intended for...
TfDenseHashMap< TfToken, VtValue, TfToken::HashFunctor > ExecIrResult
Map used to return results from controller forward and inverse computations.
Definition: types.h:25
ExecPrimComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for a prim computation.
EXEC_API ExecAttributeExpressionBuilder AttributeExpression(const TfToken &attributeName)
Registers an attribute expression for attributes named attributeName.
ValueSpecifier Computation(const TfToken &computationName)
See Computation().
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68
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.