HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
output.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_VDF_OUTPUT_H
8 #define PXR_EXEC_VDF_OUTPUT_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
15 #include "pxr/exec/vdf/types.h"
16 
17 #include <tbb/spin_mutex.h>
18 
20 
21 class TfToken;
22 class VdfInput;
23 class VdfMask;
24 class VdfOutputSpec;
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 ///
28 /// A VdfOutput represents an output on a node. It has a spec and a list of
29 /// nodes currently connected to it.
30 ///
31 class VdfOutput
32 {
33 public:
34 
35  /// Constructor
36  ///
37  VDF_API
38  VdfOutput(VdfNode &owner, int specIndex);
39 
40  /// Destructor
41  ///
42  VDF_API
43  ~VdfOutput();
44 
45  /// Returns a list of connections connected to this output.
46  ///
47  const VdfConnectionVector &GetConnections() const { return _connections; }
48 
49  /// Returns the number of connections for this output.
50  ///
51  size_t GetNumConnections() const {
52  return _connections.size();
53  }
54 
55  /// Returns the owning node for this output.
56  ///
57  const VdfNode &GetNode() const { return _owner; }
58 
59  /// Returns the non-const owning node for this output.
60  ///
61  VdfNode &GetNode() { return _owner; }
62 
63  /// Returns the name of this output.
64  ///
65  VDF_API
66  const TfToken &GetName() const;
67 
68  /// Sets the input associated with this output. If \p input is NULL it
69  /// clears the associated input.
70  ///
71  VDF_API
72  void SetAssociatedInput(const VdfInput *input);
73 
74  /// Returns the in/out connector associated with this output.
75  ///
76  const VdfInput *GetAssociatedInput() const {
77  return _associatedInput;
78  }
79 
80  /// Returns the mask of elements that this output is expected to modify
81  /// from its corresponding input.
82  ///
83  /// Outputs with no corresponding input return a NULL mask.
84  ///
85  const VdfMask *GetAffectsMask() const {
86  return _affectsMask.IsEmpty() ? nullptr : &_affectsMask;
87  }
88 
89  /// Sets the affects mask for this output.
90  ///
91  /// It is a coding error to set this mask on an output that has no
92  /// corresponding input, or to set a mask that is of size 0.
93  ///
94  VDF_API
95  void SetAffectsMask(const VdfMask &mask);
96 
97  /// The unique id of this output. No current, or previously constructed
98  /// output in the same network will share this id.
99  ///
100  VdfId GetId() const {
101  return _id;
102  }
103 
104  /// Get the output index from the output id. The index uniquely identifies
105  /// the output in the current state of the network, but may alias an index
106  /// which existed in a previous state of the network and has since been
107  /// destructed.
108  ///
109  static VdfIndex GetIndexFromId(const VdfId id) {
110  return static_cast<VdfIndex>(id);
111  }
112 
113  /// Get the output version from the output id. Output ids with the same
114  /// index are disambiguated by a version number. Given multiple output ids
115  /// with the same index, only one version will match the current state
116  /// of the network.
117  ///
118  static VdfVersion GetVersionFromId(const VdfId id) {
119  return static_cast<VdfVersion>(id >> 32);
120  }
121 
122  /// Returns the connector specification object for this output.
123  ///
124  VDF_API
125  const VdfOutputSpec &GetSpec() const;
126 
127  /// Returns the debug name for this output.
128  ///
129  /// Creates a debug name that combines the output name with the debug
130  /// name of its owner.
131  ///
132  VDF_API
133  std::string GetDebugName() const;
134 
135  /// Returns the expected number of entries in the data computed at
136  /// this output.
137  ///
138  /// This number is a guess based on what's currently connected to the
139  /// output.
140  ///
141  VDF_API
142  int GetNumDataEntries() const;
143 
144 private:
145 
146  // Only the VdfNetwork and VdfIsolatedSubnetwork should have access to the
147  // connect API.
148  friend class VdfNetwork;
149  friend class VdfIsolatedSubnetwork;
150 
151  // Connects \p node's input named \p inputName to this output with a
152  // given \p mask. If \p atIndex is >= 0 the connection will be placed at
153  // index \p atIndex on the target input. Otherwise the connection will
154  // be appended at the end.
155  //
156  VdfConnection *_Connect(VdfNode *node,
157  const TfToken &inputName,
158  const VdfMask &mask,
159  int atIndex);
160 
161  /// Removes \p connection from this output.
162  void _RemoveConnection(VdfConnection *connection);
163 
164 private:
165 
166  // The node that owns this output.
167  VdfNode &_owner;
168 
169  // The output id.
170  const VdfId _id;
171 
172  // The input (if any) associated with this output.
173  const VdfInput *_associatedInput;
174 
175  // The list of connections connected to this output.
176  VdfConnectionVector _connections;
177 
178  // The mask indicating the elements that this output is expected to modify
179  // from its corresponding input. For outputs with no corresponding input,
180  // the mask will be of size 0.
181  VdfMask _affectsMask;
182 
183  // The index of the connector spec for this output on the owning node.
184  int _specIndex;
185 
186  // Sychronize concurrently connecting to this output.
187  tbb::spin_mutex _connectionsMutex;
188 };
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 
193 
194 #endif
uint32_t VdfVersion
The version type for Vdf objects.
Definition: types.h:113
bool IsEmpty() const
Definition: mask.h:168
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Definition: node.h:52
VdfId GetId() const
Definition: output.h:100
size_type size() const
Definition: smallVector.h:596
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
const VdfNode & GetNode() const
Definition: output.h:57
VDF_API ~VdfOutput()
VDF_API const VdfOutputSpec & GetSpec() const
#define VDF_API
Definition: api.h:25
const VdfInput * GetAssociatedInput() const
Definition: output.h:76
Definition: input.h:35
Definition: token.h:70
const VdfConnectionVector & GetConnections() const
Definition: output.h:47
size_t GetNumConnections() const
Definition: output.h:51
static VdfVersion GetVersionFromId(const VdfId id)
Definition: output.h:118
VDF_API void SetAssociatedInput(const VdfInput *input)
VDF_API const TfToken & GetName() const
GLint GLuint mask
Definition: glcorearb.h:124
GLuint id
Definition: glcorearb.h:655
VDF_API std::string GetDebugName() const
VdfNode & GetNode()
Definition: output.h:61
VDF_API void SetAffectsMask(const VdfMask &mask)
static VdfIndex GetIndexFromId(const VdfId id)
Definition: output.h:109
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const VdfMask * GetAffectsMask() const
Definition: output.h:85
VDF_API VdfOutput(VdfNode &owner, int specIndex)
VDF_API int GetNumDataEntries() const
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107
uint32_t VdfIndex
The index type for Vdf objects.
Definition: types.h:110