Loading...
Searching...
No Matches
leafNodeIndexer.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_EF_LEAF_NODE_INDEXER_H
8#define PXR_EXEC_EF_LEAF_NODE_INDEXER_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/node.h"
15#include "pxr/exec/vdf/types.h"
16
17#include <tbb/concurrent_queue.h>
18#include <tbb/concurrent_unordered_map.h>
19#include <tbb/concurrent_vector.h>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class VdfConnection;
24class VdfMask;
25class VdfOutput;
26
35{
36public:
39 using Index = uint32_t;
40
43 static constexpr Index InvalidIndex = Index(-1);
44
48 size_t GetCapacity() const {
49 return _nodes.size();
50 }
51
55 Index GetIndex(const VdfNode &node) const;
56
60 const VdfNode *GetNode(Index index) const {
61 return index < _nodes.size() ? _nodes[index].node : nullptr;
62 }
63
67 const VdfOutput *GetSourceOutput(Index index) const {
68 return index < _nodes.size() ? _nodes[index].output : nullptr;
69 }
70
74 const VdfMask *GetSourceMask(Index index) const {
75 return index < _nodes.size() ? _nodes[index].mask : nullptr;
76 }
77
80 void Invalidate();
81
86 void DidDisconnect(const VdfConnection &connection);
87
92 void DidConnect(const VdfConnection &connection);
93
94private:
95 // The data tracked for each leaf node.
96 struct _LeafNode {
97 const VdfNode *node;
98 const VdfOutput *output;
99 const VdfMask *mask;
100 };
101
102 // Map from VdfNode index to leaf node index. If a given node does not have
103 // an index, InvalidIndex will be stored at the corresponding location.
104 tbb::concurrent_unordered_map<VdfIndex, Index> _indices;
105
106 // The tightly packed vector of leaf node data. The vector is indexed with
107 // the leaf node index.
108 tbb::concurrent_vector<_LeafNode> _nodes;
109
110 // Free list of leaf node data. New indices are assigned by pulling from
111 // this list first.
112 tbb::concurrent_queue<Index> _freeList;
113};
114
115inline
118{
119 const auto it = _indices.find(VdfNode::GetIndexFromId(node.GetId()));
120 return it != _indices.end() ? it->second : InvalidIndex;
121}
122
123PXR_NAMESPACE_CLOSE_SCOPE
124
125#endif
The leaf node indexer tracks leaf nodes added and removed from the network, and associates each leaf ...
const VdfOutput * GetSourceOutput(Index index) const
Returns the output a given leaf node index is sourcing data from.
const VdfMask * GetSourceMask(Index index) const
Returns the mask at the output a given leaf node index is sourcing data from.
void DidDisconnect(const VdfConnection &connection)
Call this to notify the cache of connections that have been deleted.
uint32_t Index
Data type of the index.
void DidConnect(const VdfConnection &connection)
Call this to notify the cache of newly added connections.
Index GetIndex(const VdfNode &node) const
Returns an index for a given leaf node.
static constexpr Index InvalidIndex
Sentinel for an invalid index.
const VdfNode * GetNode(Index index) const
Returns the node for a given index.
void Invalidate()
Invalidate the entire cache.
size_t GetCapacity() const
Returns the capacity of the indexer, i.e.
A class that fully represents a connection between two VdfNodes.
Definition: connection.h:30
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:37
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
static VdfIndex GetIndexFromId(const VdfId id)
Get the node index from the node id.
Definition: node.h:123
VdfId GetId() const
Returns the unique id of this node in its network.
Definition: node.h:116
A VdfOutput represents an output on a node.
Definition: output.h:32