Loading...
Searching...
No Matches
vectorImpl_Boxed.h
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"
13#include "pxr/exec/vdf/vectorDataTyped.h"
14
15#include "pxr/exec/vdf/boxedContainer.h"
17#include "pxr/exec/vdf/forEachCommonType.h"
18#include "pxr/exec/vdf/mask.h"
19
21
22PXR_NAMESPACE_OPEN_SCOPE
23
26template <typename T>
27class VDF_API_TYPE Vdf_VectorImplBoxed final
28 : public Vdf_VectorDataTyped<T>
29{
30public:
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
62 void CloneSubset(
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
94 size_t GetSize() const override {
95 return 1;
96 }
97
102 size_t GetNumStoredElements() const override {
103 return _box.empty() ? 0 : 1;
104 }
105
106 bool IsSharable() const override {
107 return _box.size() >= Vdf_VectorData::_VectorSharingSize;
108 }
109
110 size_t EstimateElementMemory() const override {
111 // This is somewhat tricky to think about. For boxed impls, the
112 // "element" is a Vdf_BoxedContainer<T> that may hold many Ts.
113 size_t elementSize = VdfEstimateSize(_box);
114 if (!_box.empty()) {
115 elementSize +=
116 VdfEstimateSize(_box[0]) * _box.size() +
118 _box.GetRanges().GetNumRanges();
119 }
120 return elementSize;
121 }
122
123 Vdf_VectorData::Info GetInfo() override {
124 return Vdf_VectorData::Info(
125 /* data = */ &_box,
126 /* size = */ 1,
127 /* first = */ 0,
128 /* last = */ 0,
129 /* compressedIndexMapping = */ nullptr,
130 /* layout = */ Vdf_VectorData::Info::Layout::Boxed);
131 }
132
133private:
134
136};
137
138#define VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED(type) \
139 extern template class VDF_API_TYPE Vdf_VectorImplBoxed<type>;
140VDF_FOR_EACH_COMMON_TYPE(VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED)
141#undef VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED
142
143PXR_NAMESPACE_CLOSE_SCOPE
144
145#endif
Fast, compressed bit array which is capable of performing logical operations without first decompress...
size_t GetSize() const
Returns the size of the bit array, ie.
bool AreAllSet() const
Returns true, if all the bits in this bit array are set.
Scoped (i.e.
Definition mallocTag.h:251
This simple container stores multiple values that flow through the network as a single data flow elem...
A range of data elements as denoted by [ begin, end ) indices.
void New(Args &&... args)
Creates an instance.
void Destroy()
Destroys a held instance.
Implements a Vdf_VectorData storage that holds a boxed element.
size_t GetSize() const override
The size of a boxed vector is always 1, since that's the size of the mask used to represent data held...
size_t GetNumStoredElements() const override
The number of elements stored in a boxed vector is eiter 0 (if the box is empty) or 1.
Implements a Vdf_VectorData storage that is always empty.
A VdfMask is placed on connections to specify the data flowing through them.
Definition mask.h:37
size_t VdfEstimateSize(const T &)
Estimate the memory footprint of instance t of type T.