HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
requiredInputsPredicate.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_REQUIRED_INPUTS_PREDICATE_H
8 #define PXR_EXEC_VDF_REQUIRED_INPUTS_PREDICATE_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/input.h"
15 
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 ///
20 /// \class VdfRequiredInputsPredicate
21 ///
22 /// \brief This predicate determines whether a given input value is needed to
23 /// fulfill the input dependencies required by the node.
24 ///
26 {
27 public:
28  /// All read inputs on \p node are required.
29  ///
31  return VdfRequiredInputsPredicate(_Selector::AllReads, node, nullptr);
32  }
33 
34  /// None of the read inputs on \p node are required.
35  ///
37  return VdfRequiredInputsPredicate(_Selector::NoReads, node, nullptr);
38  }
39 
40  /// One specific read \p input on \p node is required.
41  ///
43  const VdfNode &node,
44  const VdfInput &input) {
45  return VdfRequiredInputsPredicate(_Selector::OneRead, node, &input);
46  }
47 
48  /// Is this input a required read? Note that read/writes as well as
49  /// prerequisite inputs are not required reads.
50  ///
51  bool IsRequiredRead(const VdfInput &input) const {
52  return
53  _selector != _Selector::NoReads &&
54  !input.GetAssociatedOutput() &&
55  !input.GetSpec().IsPrerequisite() &&
56  (_selector == _Selector::AllReads ||
57  (_oneRead == &input && &input.GetNode() == &_node));
58  }
59 
60  /// Are any inputs required?
61  ///
62  bool HasRequiredReads() const {
63  return _selector != _Selector::NoReads;
64  }
65 
66  /// Are all of the inputs required?
67  ///
68  bool RequiresAllReads() const {
69  return _selector == _Selector::AllReads;
70  }
71 
72 private:
73  // Denotes how inputs are selected.
74  enum class _Selector {
75  NoReads,
76  AllReads,
77  OneRead
78  };
79 
80  // Constructor. \p oneRead is only relevant if \p selector equals
81  // _Selector::OneRead. Otherwise \p oneRead may be \c nullptr.
83  _Selector selector,
84  const VdfNode &node,
85  const VdfInput *oneRead) :
86  _selector(selector),
87  _node(node),
88  _oneRead(oneRead)
89  {}
90 
91  // Select inputs based on this choice of selector.
92  _Selector _selector;
93 
94  // The owning node.
95  const VdfNode &_node;
96 
97  // The input, if _selector is OneRead.
98  const VdfInput *_oneRead;
99 };
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 
104 
105 #endif
VDF_API const VdfInputSpec & GetSpec() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
static VdfRequiredInputsPredicate OneRead(const VdfNode &node, const VdfInput &input)
Definition: node.h:52
bool IsPrerequisite() const
Definition: inputSpec.h:96
Definition: input.h:35
bool IsRequiredRead(const VdfInput &input) const
const VdfOutput * GetAssociatedOutput() const
Definition: input.h:82
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
This predicate determines whether a given input value is needed to fulfill the input dependencies req...
static VdfRequiredInputsPredicate NoReads(const VdfNode &node)
static VdfRequiredInputsPredicate AllReads(const VdfNode &node)
const VdfNode & GetNode() const
Definition: input.h:86