HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
loftedOutputSet.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_LOFTED_OUTPUT_SET_H
8 #define PXR_EXEC_EF_LOFTED_OUTPUT_SET_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/ef/api.h"
13 
14 #include "pxr/exec/vdf/types.h"
15 
16 #include <tbb/concurrent_hash_map.h>
17 
18 #include <atomic>
19 #include <cstddef>
20 #include <cstdint>
21 #include <memory>
22 #include <vector>
23 
25 
26 class VdfMaskedOutput;
27 class VdfNetwork;
28 class VdfMask;
29 using VdfMaskedOutputVector = std::vector<VdfMaskedOutput>;
30 class VdfOutput;
31 
32 /// Tracks the set of lofted outputs (outputs whose values were sourced from
33 /// the page cache during evaluation) on behalf of EfPageCacheBasedExecutor.
34 ///
36 {
37 public:
38  EF_API
40 
41  EF_API
43 
44  /// Returns the number of outputs lofted into the page cache.
45  size_t GetSize() const {
46  return _loftedOutputs.size();
47  }
48 
49  /// Allocates storage to accommodate the maximum capacity of the network.
50  ///
51  /// Callers *must* ensure that the set has been sized to the network before
52  /// adding outputs. This is not an optional performance optimization; if
53  /// the network capacity changes, the set must be resized.
54  ///
55  EF_API
56  void Resize(const VdfNetwork &network);
57 
58  /// Adds an output to the set of lofted outputs.
59  ///
60  /// Returns true if this operation succeeds.
61  ///
62  EF_API
63  bool Add(
64  const VdfOutput &output,
65  const VdfMask &mask);
66 
67  /// Removes an output from the set of lofted outputs.
68  EF_API
69  void Remove(
70  const VdfId outputId,
71  const VdfId nodeId,
72  const VdfMask &mask);
73 
74  /// Removes all outputs on node from the set of lofted outputs.
75  EF_API
76  void RemoveAllOutputsForNode(const VdfNode &node);
77 
78  /// Removes all outputs from the set of lofted outputs.
79  EF_API
80  void Clear();
81 
82  /// Inserts any lofted outputs in \p deps into \p processedRequest.
83  EF_API
85  const VdfOutputToMaskMap &deps,
86  VdfMaskedOutputVector *processedRequest) const;
87 
88 private:
89  // A set of outputs, which had their values sourced from the page cache
90  // during evaluation (or getting of output values.) We need to keep track
91  // of these outputs in order to allows us to later properly invalidate them.
92  using _LoftedOutputsMap = tbb::concurrent_hash_map<VdfId, VdfMask>;
93  _LoftedOutputsMap _loftedOutputs;
94 
95  // An array of node references used to accelerate lookups into the
96  // _loftedOutputs map.
97  std::unique_ptr<std::atomic<uint32_t>[]> _loftedNodeRefs;
98 
99  // The size of _loftedNodeRefs, which grows to accommodate the network's
100  // maximum capacity.
101  size_t _numLoftedNodeRefs = 0;
102 };
103 
105 
106 #endif
size_t GetSize() const
Returns the number of outputs lofted into the page cache.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
EF_API bool Add(const VdfOutput &output, const VdfMask &mask)
Definition: node.h:52
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
EF_API void CollectLoftedDependencies(const VdfOutputToMaskMap &deps, VdfMaskedOutputVector *processedRequest) const
Inserts any lofted outputs in deps into processedRequest.
EF_API ~Ef_LoftedOutputSet()
GLint GLuint mask
Definition: glcorearb.h:124
EF_API void RemoveAllOutputsForNode(const VdfNode &node)
Removes all outputs on node from the set of lofted outputs.
std::unordered_map< const VdfOutput *, VdfMask, TfHash > VdfOutputToMaskMap
A map from output pointer to mask.
Definition: types.h:104
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
EF_API void Clear()
Removes all outputs from the set of lofted outputs.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
EF_API void Resize(const VdfNetwork &network)
EF_API Ef_LoftedOutputSet()
EF_API void Remove(const VdfId outputId, const VdfId nodeId, const VdfMask &mask)
Removes an output from the set of lofted outputs.
std::vector< VdfMaskedOutput > VdfMaskedOutputVector
#define EF_API
Definition: api.h:25
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107