Loading...
Searching...
No Matches
dataManagerHashTable.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_HASH_TABLE_H
8#define PXR_EXEC_VDF_DATA_MANAGER_HASH_TABLE_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
19#include "pxr/exec/vdf/types.h"
20
21#include "pxr/base/tf/hash.h"
22#include "pxr/base/tf/stl.h"
23
24#include <memory>
25#include <unordered_map>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
30class VdfOutput;
31class VdfNetwork;
32
39template<>
41
44 struct OutputData {
45 OutputData() :
46 invalidationTimestamp(
47 VdfExecutorInvalidationData::InitialInvalidationTimestamp),
48 touched(false)
49 {}
50
51 VdfExecutorBufferData bufferData;
52 VdfExecutorInvalidationData invalidationData;
53 VdfInvalidationTimestamp invalidationTimestamp;
54 std::unique_ptr<VdfSMBLData> smblData;
55 bool touched;
56 };
57
61 typedef OutputData * DataHandle;
62
63};
64
73 public VdfExecutorDataManager<VdfDataManagerHashTable>
74{
75
76 // The output data stored at each entry.
77 typedef
79 VdfDataManagerHashTable>::OutputData
80 _OutputData;
81
82 // Data type for map from outputs to their executor data.
83 using _DataMap = std::unordered_map<VdfId, _OutputData, TfHash>;
84
85public:
86
89 typedef
92
95 typedef
99
103 VDF_API
104 void Resize(const VdfNetwork &network);
105
112 bool IsValidDataHandle(const DataHandle handle) const {
113 return handle != nullptr;
114 }
115
121 DataHandle GetOrCreateDataHandle(const VdfId outputId) const {
122 _DataMap::iterator it = _outputData.find(outputId);
123 if (it == _outputData.end()) {
124 it = _outputData.emplace(
125 std::piecewise_construct,
126 std::forward_as_tuple(outputId),
127 std::forward_as_tuple())
128 .first;
129 }
130 return &it->second;
131 }
132
137 DataHandle GetDataHandle(const VdfId outputId) const {
138 return TfMapLookupPtr(_outputData, outputId);
139 }
140
147 return &handle->bufferData;
148 }
149
156 VdfExecutorInvalidationData * GetInvalidationData(
157 const DataHandle handle) const {
158 return &handle->invalidationData;
159 }
160
164
172 const DataHandle handle) const {
173 return handle->invalidationTimestamp;
174 }
175
182 const DataHandle handle,
183 VdfInvalidationTimestamp timestamp) {
184 handle->invalidationTimestamp = timestamp;
185 }
186
194 VdfSMBLData * GetSMBLData(const DataHandle handle) const {
195 return handle->smblData.get();
196 }
197
205 if (!handle->smblData) {
206 handle->smblData.reset(new VdfSMBLData());
207 }
208 return handle->smblData.get();
209 }
210
217 bool IsTouched(const DataHandle handle) const {
218 return handle->touched;
219 }
220
227 void Touch(const DataHandle handle) const {
228 handle->touched = true;
229 }
230
237 bool Untouch(const DataHandle handle) {
238 const bool wasTouched = handle->touched;
239 handle->touched = false;
240 return wasTouched;
241 }
242
245 void ClearDataForOutput(const VdfId outputId) {
246 _outputData.erase(outputId);
247 }
248
251 void Clear() {
252 TfReset(_outputData);
253 }
254
257 bool IsEmpty() const {
258 return _outputData.empty();
259 }
260
261
262private:
263
264 // Map from outputs to their executor data.
265 mutable _DataMap _outputData;
266
267};
268
270
271PXR_NAMESPACE_CLOSE_SCOPE
272
273#endif
This is a data manager for executors that uses data stored in an external hash table.
bool IsTouched(const DataHandle handle) const
Returns true if the data at the given handle has been touched by evaluation.
VDF_API void Resize(const VdfNetwork &network)
Resize the data manager to accommodate all the outputs in the given network.
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.
Vdf_ExecutorDataManagerTraits< VdfDataManagerHashTable >::DataHandle DataHandle
The data handle type from the type traits class.
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.
VdfExecutorDataManager< VdfDataManagerHashTable > Base
The base class type.
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.
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.
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.
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
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
Container::mapped_type * TfMapLookupPtr(Container &map, Key const &key)
Checks if an item exists in a map or TfHashMap, without copying it.
Definition: stl.h:124
void TfReset(T &obj)
Reset obj to be an empty, space-optimized object.
Definition: stl.h:170
Forward definition of the traits class, which will be specialized by the derived data manager impleme...