Loading...
Searching...
No Matches
inputVector.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_INPUT_VECTOR_H
8#define PXR_EXEC_VDF_INPUT_VECTOR_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
15#include "pxr/exec/vdf/node.h"
16#include "pxr/exec/vdf/tokens.h"
18
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class TfType;
24
26
27class VDF_API_TYPE Vdf_InputVectorBase : public VdfNode
28{
29public:
30
33 size_t GetSize() const {
34 return _values.GetSize();
35 }
36
40 VDF_API
41 void Compute(const VdfContext &context) const override final;
42
45 VDF_API
46 size_t GetMemoryUsage() const override final;
47
48protected:
49 VDF_API
50 Vdf_InputVectorBase(
51 VdfNetwork *network,
52 const VdfOutputSpecs &outputSpecs,
53 VdfVector &&values);
54
55 VDF_API
56 ~Vdf_InputVectorBase() override;
57
58protected:
59
60 // The values stored in this input vector.
61 VdfVector _values;
62};
63
64template<typename T>
65class VDF_API_TYPE VdfInputVector final : public Vdf_InputVectorBase
66{
67public:
68
71 VdfInputVector(VdfNetwork *network, size_t n) :
72 Vdf_InputVectorBase(
73 network,
75 .Connector<T>(VdfTokens->out),
76 VdfTypedVector<T>::CreateWithSize(n))
77 {
78 }
79
82 void SetValue(size_t index, const T &val)
83 {
84 if (!TF_VERIFY(index >= 0 && index < _values.GetSize()))
85 return;
86
87 VdfVector::ReadWriteAccessor<T> a = _values.GetReadWriteAccessor<T>();
88 a[index] = val;
89 }
90
93 bool IsValueEqual(size_t index, const T &val) const
94 {
95 if (const T *v = GetValue(index))
96 return *v == val;
97
98 return false;
99 }
100
104 const T *GetValue(size_t index) const
105 {
106 if (!TF_VERIFY(index >= 0 && index < _values.GetSize()))
107 return nullptr;
108
109 const VdfVector::ReadAccessor<T> a = _values.GetReadAccessor<T>();
110 return &a[index];
111 }
112
113protected:
114
115 // Protected destructor. Only the network is allowed to delete nodes.
116 //
117 ~VdfInputVector() override;
118
119 typedef VdfInputVector<T> This;
120
121 // Implements IsEqual() API of VdfNode
122 bool _IsDerivedEqual(const VdfNode &rhs) const override
123 {
124 if (const This *other = dynamic_cast<const This *>(&rhs))
125 return _ValuesAreEqual(other);
126
127 return false;
128 }
129
130private:
131
132 // Helper method to compare if two VdfInputVector are the same. Note that
133 // this is factored out in order to prevent a performance regression due
134 // to code generation.
135 //
136 bool _ValuesAreEqual(const This *rhs) const
137 {
138 const size_t size = _values.GetSize();
139 if (size == rhs->_values.GetSize()) {
141 _values.GetReadAccessor<T>();
142 const VdfVector &rhsValues = rhs->_values;
144 rhsValues.GetReadAccessor<T>();
145 for (size_t i = 0; i < size; ++i) {
146 if (a[i] != b[i]) {
147 return false;
148 }
149 }
150 return true;
151 }
152 return false;
153 }
154};
155
157class VDF_API_TYPE VdfEmptyInputVector final : public Vdf_InputVectorBase
158{
159public:
160
163 VDF_API
164 VdfEmptyInputVector(VdfNetwork *network, const TfType &type);
165
166protected:
167
168 // Protected destructor. Only the network is allowed to delete nodes.
169 //
170 VDF_API
171 ~VdfEmptyInputVector() override;
172
173 // Implements IsEqual() API of VdfNode
174 //
175 VDF_API
176 bool _IsDerivedEqual(const VdfNode &rhs) const override;
177};
178
180
181template <typename T>
182VdfInputVector<T>::~VdfInputVector() = default;
183
184PXR_NAMESPACE_CLOSE_SCOPE
185
186#endif
Low-level utilities for informing users of various internal and external diagnostic conditions.
TfType represents a dynamic runtime type.
Definition: type.h:48
A context is the parameter bundle passed to callbacks of computations.
Definition: context.h:40
An empty, typed input vector.
Definition: inputVector.h:158
VDF_API VdfEmptyInputVector(VdfNetwork *network, const TfType &type)
Creates an empty input vector of type type.
VDF_API bool _IsDerivedEqual(const VdfNode &rhs) const override
Can be overridden by derived classes to facilitate equality comparision.
A VdfNetwork is a collection of VdfNodes and their connections.
Definition: network.h:60
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
virtual VDF_API bool _IsDerivedEqual(const VdfNode &rhs) const
Can be overridden by derived classes to facilitate equality comparision.
virtual VDF_API size_t GetMemoryUsage() const
Returns the amount of memory used by the node in bytes.
virtual void Compute(const VdfContext &context) const =0
This is the method called to perform computation.
VdfOutputSpecs is a container for VdfOutputSpec objects.
A VdfTypedVector implements a VdfVector with a specific type.
Definition: typedVector.h:23
A read-only accessor for low-level acces to the contents of the VdfVector.
Definition: vector.h:469
A read/write accessor for low-level access to the contents of the VdfVector.
Definition: vector.h:403
This class is used to abstract away knowledge of the cache data used for each node.
Definition: vector.h:56
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:266