HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorImpl_Boxed.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_BOXED_H
8 #define PXR_EXEC_VDF_VECTOR_IMPL_BOXED_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/api.h"
14 
18 #include "pxr/exec/vdf/mask.h"
19 
20 #include "pxr/base/tf/mallocTag.h"
21 
23 
24 /// \brief Implements a Vdf_VectorData storage that holds a boxed element.
25 ///
26 template <typename T>
28  : public Vdf_VectorDataTyped<T>
29 {
30 public:
31 
33  : _box(box)
34  {}
35 
37  : _box(std::move(box))
38  {}
39 
41  : Vdf_VectorImplBoxed(o._box)
42  {}
43 
45  : Vdf_VectorImplBoxed(std::move(o._box))
46  {}
47 
48  ~Vdf_VectorImplBoxed() override = default;
49 
50  void MoveInto(Vdf_VectorData::DataHolder *destData) override {
51  TfAutoMallocTag tag("Vdf", __ARCH_PRETTY_FUNCTION__);
52  destData->Destroy();
53  destData->New< Vdf_VectorImplBoxed >(std::move(*this));
54  }
55 
56  void Clone(Vdf_VectorData::DataHolder *destData) const override {
57  TfAutoMallocTag tag("Vdf", __ARCH_PRETTY_FUNCTION__);
58  destData->Destroy();
59  destData->New< Vdf_VectorImplBoxed >(*this);
60  }
61 
63  const VdfMask &mask,
64  Vdf_VectorData::DataHolder *destData) const override {
65 
66  // We only have one element, not much point in looking at the mask.
67  Clone(destData);
68  }
69 
70  void Box(
71  const VdfMask::Bits &bits,
72  Vdf_VectorData::DataHolder *destData) const override {
73  TfAutoMallocTag tag("Vdf", __ARCH_PRETTY_FUNCTION__);
74 
75  destData->Destroy();
76  if (bits.GetSize() == 1 && bits.AreAllSet()) {
77  destData->New< Vdf_VectorImplBoxed >(*this);
78  } else {
79  destData->New< Vdf_VectorImplEmpty<T> >(1);
80  }
81  }
82 
83  void Merge(
84  const VdfMask::Bits &bits,
85  Vdf_VectorData::DataHolder *destData) const override {
86 
87  if (bits.AreAllSet()) {
88  Clone(destData);
89  }
90  }
91 
92  size_t GetSize() const override {
93  return 1;
94  }
95 
96  size_t GetNumStoredElements() const override {
97  return 1;
98  }
99 
100  bool IsSharable() const override {
101  return _box.size() >= Vdf_VectorData::_VectorSharingSize;
102  }
103 
104  size_t EstimateElementMemory() const override {
105  // This is somewhat tricky to think about. For boxed impls, the
106  // "element" is a Vdf_BoxedContainer<T> that may hold many Ts.
107  size_t elementSize = VdfEstimateSize(_box);
108  if (!_box.empty()) {
109  elementSize +=
110  VdfEstimateSize(_box[0]) * _box.size() +
112  _box.GetRanges().GetNumRanges();
113  }
114  return elementSize;
115  }
116 
118  return Vdf_VectorData::Info(
119  /* data = */ &_box,
120  /* size = */ 1,
121  /* first = */ 0,
122  /* last = */ 0,
123  /* compressedIndexMapping = */ nullptr,
124  /* layout = */ Vdf_VectorData::Info::Layout::Boxed);
125  }
126 
127 private:
128 
130 };
131 
132 #define VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED(type) \
133  extern template class VDF_API_TYPE Vdf_VectorImplBoxed<type>;
135 #undef VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED
136 
138 
139 #endif
Vdf_VectorImplBoxed(Vdf_BoxedContainer< T > &&box)
bool AreAllSet() const
void Box(const VdfMask::Bits &bits, Vdf_VectorData::DataHolder *destData) const override
size_t GetNumStoredElements() const override
void Merge(const VdfMask::Bits &bits, Vdf_VectorData::DataHolder *destData) const override
#define VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED(type)
void Clone(Vdf_VectorData::DataHolder *destData) const override
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
#define VDF_FOR_EACH_COMMON_TYPE(macro)
VDF_FOR_EACH_COMMON_TYPE expands macro for each common type.
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
Fast, compressed bit array which is capable of performing logical operations without first decompress...
void MoveInto(Vdf_VectorData::DataHolder *destData) override
void CloneSubset(const VdfMask &mask, Vdf_VectorData::DataHolder *destData) const override
bool IsSharable() const override
static constexpr size_t _VectorSharingSize
Definition: vectorData.h:42
size_t GetSize() const override
Vdf_VectorImplBoxed(const Vdf_VectorImplBoxed &o)
virtual void Clone(DataHolder *destData) const =0
#define __ARCH_PRETTY_FUNCTION__
Definition: functionLite.h:29
PXR_NAMESPACE_OPEN_SCOPE size_t VdfEstimateSize(const T &)
Definition: estimateSize.h:55
Vdf_VectorImplBoxed(Vdf_VectorImplBoxed &&o)
GLint GLuint mask
Definition: glcorearb.h:124
Vdf_VectorImplBoxed(const Vdf_BoxedContainer< T > &box)
Implements a Vdf_VectorData storage that holds a boxed element.
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
size_t EstimateElementMemory() const override
Vdf_VectorData::Info GetInfo() override