HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
system.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_USD_SYSTEM_H
8 #define PXR_EXEC_EXEC_USD_SYSTEM_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/execUsd/api.h"
16 
18 #include "pxr/exec/exec/request.h"
19 #include "pxr/exec/exec/system.h"
20 
21 #include <memory>
22 #include <vector>
23 
25 
27 
28 class ExecUsdCacheView;
29 class ExecUsdRequest;
30 class ExecUsdValueKey;
31 class UsdTimeCode;
32 
33 /// The implementation of a system to procedurally compute values based on USD
34 /// scene description and computation definitions.
35 ///
36 /// ExecUsdSystem specializes the base ExecSystem class and owns USD-specific
37 /// structures and logic necessary to compile, schedule and evaluate requested
38 /// computation values.
39 ///
40 /// The ExecUsdSystem extends the lifetime of the UsdStage it is constructed
41 /// with, although it is atypical for an ExecUsdSystem to outlive its stage in
42 /// practice. As a rule of thumb, the ExecUsdSystem lives right alongside the
43 /// UsdStage in most use-cases.
44 ///
45 class ExecUsdSystem : public ExecSystem
46 {
47 public:
49  explicit ExecUsdSystem(const UsdStageConstRefPtr &stage);
50 
51  // Systems are non-copyable and non-movable to simplify management of
52  // back-pointers.
53  //
54  ExecUsdSystem(const ExecUsdSystem &) = delete;
55  ExecUsdSystem& operator=(const ExecUsdSystem &) = delete;
56 
59 
60  /// Changes the \p time at which values are computed.
61  ///
62  /// Calling this method re-resolves time-dependent inputs from the scene
63  /// graph at the new \p time, and determines which of these inputs are
64  /// *actually* changing between the old and new time. Computed values that
65  /// are dependent on the changing inputs are then invalidated, and requests
66  /// are notified of the time change.
67  ///
68  /// \note
69  /// When computing multiple requests over multiple times, it is much more
70  /// efficient to compute all requests at the same time, before moving on to
71  /// the next time. Doing so, allows time-dependent intermediate results to
72  /// remain cached and be re-used across the multiple calls to Compute().
73  ///
76 
77  /// Builds a request for the given \p valueKeys.
78  ///
79  /// The optionally provided \p valueCallback will be invoked when
80  /// previously computed value keys become invalid as a result of authored
81  /// value changes or structural invalidation of the scene. If multiple
82  /// value keys become invalid at the same time, they may be batched into a
83  /// single invocation of the callback.
84  ///
85  /// \note
86  /// The \p valueCallback is only guaranteed to be invoked at least once per
87  /// invalid value key and invalid time interval combination, and only after
88  /// Compute() has been called. If clients want to be notified of future
89  /// invalidation, they must call Compute() again to renew their interest in
90  /// the computed value keys.
91  ///
92  /// The optionally provided \p timeCallback will be invoked when
93  /// previously computed value keys become invalid as a result of time
94  /// changing. The invalid value keys are the set of time-dependent value
95  /// keys in this request, further filtered to only include the value keys
96  /// where input dependencies are *actually* changing between the old time
97  /// and new time.
98  ///
99  /// \note
100  /// The client must not call into execution (including, but not limited to
101  /// Compute() or value extraction) from within the \p valueCallback, as well
102  /// as the \p timeCallback.
103  ///
106  std::vector<ExecUsdValueKey> &&valueKeys,
111 
112  /// Prepares a given \p request for execution.
113  ///
114  /// This ensures the exec network is compiled and scheduled for the value
115  /// keys in the request. Compute() will implicitly prepare the request
116  /// if needed, but calling PrepareRequest() separately enables clients to
117  /// front-load compilation and scheduling cost.
118  ///
120  void PrepareRequest(const ExecUsdRequest &request);
121 
122  /// Executes the given \p request and returns a cache view for extracting
123  /// the computed values.
124  ///
125  /// This implicitly calls PrepareRequest(), though clients may choose to
126  /// call PrepareRequest() ahead of time and front-load the associated
127  /// compilation and scheduling cost.
128  ///
130  ExecUsdCacheView Compute(const ExecUsdRequest &request);
131 
132  /// Executes the given \p request in the presence of \p valueOverrides, and
133  /// returns a cache view for extracting the computed values.
134  ///
135  /// If a value in \p request depends on a computed value contained in
136  /// \p valueOverrides, then \p valueOverrides provides the result of that
137  /// computation. The overrides only apply for a single invocation of
138  /// ComputeWithOverrides, and do not affect subsequent calls to Compute or
139  /// ComputeWithOverrides.
140  ///
141  /// \warning
142  /// If an override value is provided, it must have the same type as the
143  /// computed value. For example, if a computation would normally produce
144  /// an int, then the overridden value must also be an int. Otherwise, a
145  /// coding error is emitted.
146  ///
147  /// This implicitly calls PrepareRequest(), though clients may choose to
148  /// call PrepareRequest() ahead of time and front-load the associated
149  /// compilation and scheduling cost.
150  ///
153  const ExecUsdRequest &request,
154  ExecUsdValueOverrideVector &&valueOverrides);
155 
156 private:
157  // This object to subscribes to scene changes on the UsdStage and delivers
158  // those changes to the base ExecSystem.
159  class _NoticeListener;
160  std::unique_ptr<_NoticeListener> _noticeListener;
161 };
162 
164 
165 #endif
std::vector< ExecUsdValueOverride > ExecUsdValueOverrideVector
Definition: valueOverride.h:36
EXECUSD_API ExecUsdCacheView ComputeWithOverrides(const ExecUsdRequest &request, ExecUsdValueOverrideVector &&valueOverrides)
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
EXECUSD_API void ChangeTime(UsdTimeCode time)
EXECUSD_API ExecUsdCacheView Compute(const ExecUsdRequest &request)
ExecUsdSystem & operator=(const ExecUsdSystem &)=delete
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_REF_PTRS(UsdStage)
EXECUSD_API void PrepareRequest(const ExecUsdRequest &request)
std::function< void(const ExecRequestIndexSet &)> ExecRequestTimeChangeInvalidationCallback
Definition: request.h:41
#define EXECUSD_API
Definition: api.h:25
EXECUSD_API ExecUsdRequest BuildRequest(std::vector< ExecUsdValueKey > &&valueKeys, ExecRequestComputedValueInvalidationCallback &&valueCallback=ExecRequestComputedValueInvalidationCallback(), ExecRequestTimeChangeInvalidationCallback &&timeCallback=ExecRequestTimeChangeInvalidationCallback())
EXECUSD_API ExecUsdSystem(const UsdStageConstRefPtr &stage)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
EXECUSD_API ~ExecUsdSystem()
std::function< void(const ExecRequestIndexSet &, const class EfTimeInterval &)> ExecRequestComputedValueInvalidationCallback
Definition: request.h:31