HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorImpl_Single.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_VECTOR_IMPL_SINGLE_H
8 #define PXR_EXEC_VDF_VECTOR_IMPL_SINGLE_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/api.h"
17 #include "pxr/exec/vdf/mask.h"
20 
21 #include "pxr/base/tf/diagnostic.h"
22 
24 
25 /// \brief Implements a Vdf_VectorData storage that is holds a single element.
26 ///
27 template<typename TYPE>
29  : public Vdf_VectorDataTyped<TYPE>
30 {
31  static_assert(
32  !Vdf_IsBoxedContainer<TYPE>,
33  "Only Vdf_VectorImplBoxed may hold boxed values");
34 
35 public:
36 
37  Vdf_VectorImplSingle() = default;
38 
39  explicit Vdf_VectorImplSingle(const TYPE &value) :
40  _data(value) {
41  }
42 
43  explicit Vdf_VectorImplSingle(TYPE &&value) :
44  _data(std::move(value)) {
45  }
46 
48  _data(rhs._data) {
49  }
50 
52  _data(std::move(rhs._data)) {
53  }
54 
55  ~Vdf_VectorImplSingle() override = default;
56 
57  void MoveInto(Vdf_VectorData::DataHolder *destData) override
58  {
59  destData->Destroy();
60  destData->New< Vdf_VectorImplSingle >(std::move(*this));
61  }
62 
63  void Clone(Vdf_VectorData::DataHolder *destData) const override
64  {
65  // XXX:optimization
66  // Here, since we have destData, we can dynamic_cast it to a
67  // Vdf_SingleElement and if it is, we can assign the element directly
68  // without having to delete and Clone(). So far that hasn't shown up
69  // in any profile.
70  destData->Destroy();
71  destData->New< Vdf_VectorImplSingle >(*this);
72  }
73 
74  void CloneSubset(const VdfMask &mask,
75  Vdf_VectorData::DataHolder *destData) const override
76  {
77  // We only have one element, not much point in looking at the mask.
78  Clone(destData);
79  }
80 
81  void Box(const VdfMask::Bits &bits,
82  Vdf_VectorData::DataHolder *destData) const override
83  {
84  // We should never box single values. Attempting to do so will yield
85  // either a copy of this impl, if the mask is suitable, or an empty
86  // impl. There is no circumstance which will yield a boxed impl.
87  TF_VERIFY(false, "Attempted to box single-element vector");
88 
89  if (bits.GetSize() == 1 && bits.AreAllSet()) {
90  destData->Destroy();
91  destData->New< Vdf_VectorImplSingle >(*this);
92  } else {
93  destData->Destroy();
94  destData->New< Vdf_VectorImplEmpty<TYPE> >(1);
95  }
96  }
97 
98  void Merge(const VdfMask::Bits &bits,
99  Vdf_VectorData::DataHolder *destData) const override
100  {
101  if (bits.AreAllSet()) {
102  Clone(destData);
103  }
104  }
105 
106  size_t GetSize() const override
107  {
108  return 1;
109  }
110 
111  size_t GetNumStoredElements() const override
112  {
113  return 1;
114  }
115 
116  size_t EstimateElementMemory() const override
117  {
118  // Clients of execution may overload VdfEstimateSize to provide a more
119  // accurate estimate based on the held value.
120  return VdfEstimateSize(_data.Get());
121  }
122 
124  {
125  return Vdf_VectorData::Info(
126  /* data = */ &_data.GetMutable(),
127  /* size = */ 1);
128  }
129 
130 private :
131 
133 };
134 
135 #define VDF_DECLARE_EXTERN_VECTOR_IMPL_SINGLE(type) \
136  extern template class VDF_API_TYPE Vdf_VectorImplSingle<type>;
138 #undef VDF_DECLARE_EXTERN_VECTOR_IMPL_SINGLE
139 
141 
142 #endif
Vdf_VectorImplSingle(const TYPE &value)
bool AreAllSet() const
size_t GetNumStoredElements() const override
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define VDF_FOR_EACH_COMMON_TYPE(macro)
VDF_FOR_EACH_COMMON_TYPE expands macro for each common type.
void Merge(const VdfMask::Bits &bits, Vdf_VectorData::DataHolder *destData) const override
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
Vdf_VectorImplSingle(Vdf_VectorImplSingle &&rhs)
void MoveInto(Vdf_VectorData::DataHolder *destData) override
Fast, compressed bit array which is capable of performing logical operations without first decompress...
size_t GetSize() const override
#define VDF_DECLARE_EXTERN_VECTOR_IMPL_SINGLE(type)
void Box(const VdfMask::Bits &bits, Vdf_VectorData::DataHolder *destData) const override
void Clone(Vdf_VectorData::DataHolder *destData) const override
virtual void Clone(DataHolder *destData) const =0
PXR_NAMESPACE_OPEN_SCOPE size_t VdfEstimateSize(const T &)
Definition: estimateSize.h:55
Vdf_VectorImplSingle(const Vdf_VectorImplSingle &rhs)
GLint GLuint mask
Definition: glcorearb.h:124
void CloneSubset(const VdfMask &mask, Vdf_VectorData::DataHolder *destData) const override
size_t GetSize() const
#define VDF_API_TYPE
Definition: api.h:26
Implements a Vdf_VectorData storage that is always empty.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Implements a Vdf_VectorData storage that is holds a single element.
size_t EstimateElementMemory() const override
Vdf_VectorImplSingle(TYPE &&value)
Vdf_VectorData::Info GetInfo() override