Loading...
Searching...
No Matches
dataManagerVector.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_DATA_MANAGER_VECTOR_H
8#define PXR_EXEC_VDF_DATA_MANAGER_VECTOR_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
17#include "pxr/exec/vdf/types.h"
18
19PXR_NAMESPACE_OPEN_SCOPE
20
26{
29 Background = 0,
30
34};
35
37
38template<VdfDataManagerDeallocationMode DeallocationMode>
41class VdfExecutorInvalidationData;
42class VdfNetwork;
43class VdfOutput;
44class VdfSMBLData;
45
52template<VdfDataManagerDeallocationMode Mode>
54
58 typedef Vdf_ExecutorDataVector::DataHandle DataHandle;
59};
60
61
66
67// Allocates an executor data vector for the given \p network.
68VDF_API
71
72// Deallocates the executor data vector \p data that was alloacted with
73// Vdf_DataManagerVectorAllocate, and does so immediately.
74VDF_API
75void
76Vdf_DataManagerVectorDeallocateNow(Vdf_ExecutorDataVector *data);
77
78// Queues up deallocation of the executor data vector \p data that was
79// alloacted with Vdf_DataManagerVectorAllocate. The actually memory
80// will be deallocated at an unspecified time in the future.
81VDF_API
82void
83Vdf_DataManagerVectorDeallocateLater(Vdf_ExecutorDataVector *data);
84
85
93template<VdfDataManagerDeallocationMode DeallocationMode>
95 public VdfExecutorDataManager<VdfDataManagerVector<DeallocationMode> >
96{
97public:
98
101 typedef
104
107 typedef
111
114 VdfDataManagerVector() : _data(nullptr) { }
115
119
122 void Resize(const VdfNetwork &network);
123
130 bool IsValidDataHandle(const DataHandle handle) const {
132 }
133
139 DataHandle GetOrCreateDataHandle(const VdfId outputId) const {
140 return _data->GetOrCreateDataHandle(outputId);
141 }
142
147 DataHandle GetDataHandle(const VdfId outputId) const {
148 return _data
149 ? _data->GetDataHandle(outputId)
151 }
152
159 return _data->GetBufferData(handle);
160 }
161
168 VdfExecutorInvalidationData * GetInvalidationData(
169 const DataHandle handle) const {
170 return _data->GetInvalidationData(handle);
171 }
172
176
184 const DataHandle handle) const {
185 return _data->GetInvalidationTimestamp(handle);
186 }
187
194 const DataHandle handle,
195 VdfInvalidationTimestamp timestamp) {
196 _data->SetInvalidationTimestamp(handle, timestamp);
197 }
198
206 VdfSMBLData * GetSMBLData(const DataHandle handle) const {
207 return _data->GetSMBLData(handle);
208 }
209
217 return _data->GetOrCreateSMBLData(handle);
218 }
219
226 bool IsTouched(const DataHandle handle) const {
227 return _data->IsTouched(handle);
228 }
229
236 void Touch(const DataHandle handle) const {
237 _data->Touch(handle);
238 }
239
246 bool Untouch(const DataHandle handle) {
247 return _data->Untouch(handle);
248 }
249
252 void ClearDataForOutput(const VdfId outputId);
253
256 void Clear();
257
260 bool IsEmpty() const {
261 return !_data || _data->GetNumData() == 0;
262 }
263
264
265private:
266
267 // The Vdf_ExecutorDataVector instance that holds the data.
268 mutable Vdf_ExecutorDataVector *_data;
269
270};
271
273
274template<VdfDataManagerDeallocationMode DeallocationMode>
276{
277 if (DeallocationMode == VdfDataManagerDeallocationMode::Immediate) {
278 Vdf_DataManagerVectorDeallocateNow(_data);
279 } else {
280 Vdf_DataManagerVectorDeallocateLater(_data);
281 }
282}
283
284template<VdfDataManagerDeallocationMode DeallocationMode>
285void
287{
288 // Allocate a new Vdf_ExecutorDataVector if necessary.
289 if (!_data) {
290 _data = Vdf_DataManagerVectorAllocate(network);
291 }
292
293 // Otherwise, make sure to resize our current instance.
294 else {
295 _data->Resize(network);
296 }
297}
298
299template<VdfDataManagerDeallocationMode DeallocationMode>
300void
302 const VdfId outputId)
303{
304 // Clear the data associated with the given output (if it exists).
305 if (_data) {
306 const DataHandle dataHandle = _data->GetDataHandle(outputId);
307 if (IsValidDataHandle(dataHandle)) {
308 _data->Reset(dataHandle, outputId);
309 }
310 }
311}
312
313template<VdfDataManagerDeallocationMode DeallocationMode>
314void
316{
317 // Clear all data.
318 if (_data) {
319 _data->Clear();
320 }
321}
322
323PXR_NAMESPACE_CLOSE_SCOPE
324
325#endif
A vector-like container for executor data used by the VdfDataManagerVector.
size_t GetNumData() const
Returns the number of outputs that have data associated with them.
VdfExecutorBufferData * GetBufferData(const DataHandle handle)
Returns the VdfExecutorBufferData associated with the given handle.
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
Returns the VdfInvalidationTimestamp associated with the given handle.
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle)
Returns the VdfExecutorInvalidationData associated with the given handle.
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle)
Returns an existing VdfSMBLData associated with the given handle or creates a new one of none exists.
size_t DataHandle
The data handle type is an index into the internal data vectors.
static const size_t InvalidHandle
This sentinel index denotes an invalid handle.
VdfSMBLData * GetSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle.
void Touch(const DataHandle handle)
Marks the data at the given handle as having been touched by evaluation.
bool Untouch(const DataHandle handle)
Marks the data at the given handle as not having been touched by evaluation.
DataHandle GetDataHandle(const VdfId outputId) const
Returns an existing data handle for the given output.
void SetInvalidationTimestamp(const DataHandle &handle, VdfInvalidationTimestamp ts)
Sets the invalidation timestamp for the give data handle.
bool IsTouched(const DataHandle handle)
Returns true if the data at the given handle has been touched by evaluation.
DataHandle GetOrCreateDataHandle(const VdfId outputId)
Returns an existing data handle, or creates a new one for the given output.
This is a data manager for executors that uses data stored in a vector indexed by output ids.
bool IsTouched(const DataHandle handle) const
Returns true if the data at the given handle has been touched by evaluation.
Vdf_ExecutorDataManagerTraits< VdfDataManagerVector >::DataHandle DataHandle
The data handle type from the type traits class.
bool IsValidDataHandle(const DataHandle handle) const
Returns true if the given data handle is valid, i.e.
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
Returns the VdfInvalidationTimestamp associated with the given handle.
VdfExecutorBufferData * GetBufferData(const DataHandle handle) const
Returns the VdfExecutorBufferData associated with the given handle.
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle) const
Returns the VdfExecutorInvalidationData associated with the given handle.
void SetInvalidationTimestamp(const DataHandle handle, VdfInvalidationTimestamp timestamp)
Sets the invalidation timestamp for the give data handle.
void ClearDataForOutput(const VdfId outputId)
Clears the executor data for a specific output.
VdfSMBLData * GetSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle.
DataHandle GetOrCreateDataHandle(const VdfId outputId) const
Returns an existing data handle, or creates a new one for the given outputId.
bool IsEmpty() const
Returns true if this data manager is empty.
void Resize(const VdfNetwork &network)
Resize the data manager to accommodate the given network.
DataHandle GetDataHandle(const VdfId outputId) const
Returns an existing data handle for the given outputId.
void Clear()
Clears all the data from this manager.
bool Untouch(const DataHandle handle)
Marks the data at the given handle as not having been touched by evaluation.
VdfDataManagerVector()
Constructor.
VdfExecutorDataManager< VdfDataManagerVector > Base
The base class.
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle or creates a new one of none exists.
void Touch(const DataHandle handle) const
Marks the data at the given handle as having been touched by evaluation.
~VdfDataManagerVector()
Destructor.
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
This class provides functionality to manage the executor specific data associated with each output in...
VdfInvalidationTimestamp GetInvalidationTimestamp() const
Returns the current invalidation timestamp on this executor.
A VdfNetwork is a collection of VdfNodes and their connections.
Definition: network.h:60
A VdfOutput represents an output on a node.
Definition: output.h:32
VdfSMBLData holds per-output data that is meant to be consumed by the executor.
Definition: smblData.h:31
VdfDataManagerDeallocationMode
Enum representing the deallocation strategy for the data manager.
@ Immediate
Deallocate immediately.
@ Background
Deallocate in the background.
VDF_API Vdf_ExecutorDataVector * Vdf_DataManagerVectorAllocate(const VdfNetwork &network)
Private functions for memory management strategies.
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107
unsigned int VdfInvalidationTimestamp
Type of the timestamp that identifies the most recent round of invalidation.
Definition: types.h:74
Forward definition of the traits class, which will be specialized by the derived data manager impleme...