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
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
117 Vdf_VectorData::Info GetInfo() override {
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
127private:
128
130};
131
132#define VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED(type) \
133 extern template class VDF_API_TYPE Vdf_VectorImplBoxed<type>;
134VDF_FOR_EACH_COMMON_TYPE(VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED)
135#undef VDF_DECLARE_EXTERN_VECTOR_IMPL_BOXED
136
137PXR_NAMESPACE_CLOSE_SCOPE
138
139#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:249
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.
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.
Definition: estimateSize.h:55