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_SYSTEM_H
8 #define PXR_EXEC_EXEC_SYSTEM_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/exec/api.h"
14 
15 #include "pxr/exec/esf/stage.h"
16 
17 #include <memory>
18 #include <utility>
19 #include <vector>
20 
22 
23 class EfTime;
24 class Exec_Program;
25 class Exec_RequestImpl;
26 class Exec_RequestTracker;
27 class Exec_Runtime;
28 class ExecValueKey;
29 class SdfPath;
30 class TfToken;
31 template <typename> class TfFunctionRef;
32 template <typename> class TfSpan;
34 class VdfMaskedOutput;
35 class VdfRequest;
36 class VdfSchedule;
37 
38 /// Base implementation of a system to procedurally compute values based on
39 /// scene description and computation definitions.
40 ///
41 /// ExecSystem owns all the structures necessary to compile, schedule and
42 /// evaluate requested computation values. Derived classes are responsible
43 /// for interfacing with the underlying scene description.
44 ///
46 {
47 public:
48  /// Diagnostic utility class.
49  class Diagnostics;
50 
51 protected:
52  /// Construct an exec system for computing values on \p stage.
53  EXEC_API
54  explicit ExecSystem(EsfStage &&stage);
55 
56  ExecSystem(const ExecSystem &) = delete;
57  ExecSystem& operator=(const ExecSystem &) = delete;
58 
59  EXEC_API
60  ~ExecSystem();
61 
62  /// Changes time on the system.
63  ///
64  /// This stores the new time value in the time input node output,
65  /// invalidates all time dependent computed values, and notifies requests of
66  /// the change in time.
67  ///
68  EXEC_API
69  void _ChangeTime(const EfTime &time);
70 
71  /// Computes the values in the \p computeRequest using the provided
72  /// \p schedule.
73  ///
74  EXEC_API
75  void _Compute(
76  const VdfSchedule &schedule,
77  const VdfRequest &computeRequest);
78 
79  /// Computes the values in the \p computeRequest using the provided
80  /// \p schedule in the presence of \p valueOverrides.
81  ///
82  EXEC_API
83  std::unique_ptr<VdfExecutorInterface> _ComputeWithOverrides(
84  const VdfSchedule &schedule,
85  const VdfRequest &computeRequest,
86  ExecValueOverrideVector &&valueOverrides);
87 
88  /// Invoke \p f on each outstanding exec request.
89  ///
90  /// \p f is executed with the request tracker mutex held so it must not
91  /// re-enter the request tracker. This method may execute \p f for
92  /// multiple requests concurrently.
93  ///
94  EXEC_API
96  TfFunctionRef<void(Exec_RequestImpl&)> f) const;
97 
98  /// Derived systems instantiate this class to deliver scene changes to exec.
100 
101 private:
102  // Requires access to _Compute, _Compile, and _HasPendingRecompilation.
103  friend class Exec_RequestImpl;
104  std::vector<VdfMaskedOutput> _Compile(TfSpan<const ExecValueKey> valueKeys);
105 
106  // Returns true if the program has inputs requiring recompilation.
107  EXEC_API
108  bool _HasPendingRecompilation() const;
109 
110  // Discards all internal state, and constructs new internal data structures
111  // leaving the system in the same state as if it was newly constructed.
112  //
113  EXEC_API
114  void _InvalidateAll();
115 
116  // Notifies the system of invalidation due to uncompilation.
117  EXEC_API
118  void _InvalidateDisconnectedInputs();
119 
120  // Notifies the system of attribute value invalidation.
121  EXEC_API
122  void _InvalidateAttributeValues(TfSpan<const SdfPath> invalidAttributes);
123 
124  // Notifies the system of metadata value invalidation.
125  EXEC_API
126  void _InvalidateMetadataValues(
127  TfSpan<const std::pair<SdfPath, TfToken>> invalidObjects);
128 
129  // Notifies the system to invalidate value keys that don't have a compiled
130  // leaf node.
131  //
132  EXEC_API
133  void _InvalidateUnknownValues();
134 
135 private:
136  EsfStage _stage;
137 
138  std::unique_ptr<Exec_Program> _program;
139  std::unique_ptr<Exec_Runtime> _runtime;
140 
141  std::unique_ptr<Exec_RequestTracker> _requestTracker;
142 };
143 
145 
146 #endif
GT_API const UT_StringHolder time
ExecSystem & operator=(const ExecSystem &)=delete
EXEC_API void _Compile(TfSpan< const ExecValueKey > valueKeys)
Compiles outputs for the value keys in the request.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
EXEC_API std::unique_ptr< VdfExecutorInterface > _ComputeWithOverrides(const VdfSchedule &schedule, const VdfRequest &computeRequest, ExecValueOverrideVector &&valueOverrides)
Definition: time.h:36
GLfloat f
Definition: glcorearb.h:1926
Definition: token.h:70
Contains a specification of how to execute a particular VdfNetwork.
Definition: schedule.h:40
Definition: span.h:70
Utility class with various diagnostic functions for ExecSystem.
#define EXEC_API
Definition: api.h:25
Definition: path.h:280
EXEC_API void _Compute(const VdfSchedule &schedule, const VdfRequest &computeRequest)
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
EXEC_API void _ParallelForEachRequest(TfFunctionRef< void(Exec_RequestImpl &)> f) const
EXEC_API ExecSystem(EsfStage &&stage)
Construct an exec system for computing values on stage.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
EXEC_API void _ChangeTime(const EfTime &time)
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values...
EXEC_API ~ExecSystem()
std::vector< ExecValueOverride > ExecValueOverrideVector
Definition: valueOverride.h:36