7#ifndef PXR_EXEC_VDF_NETWORK_H
8#define PXR_EXEC_VDF_NETWORK_H
14#include "pxr/exec/vdf/api.h"
18#include "pxr/base/tf/hashset.h"
22#include "tbb/concurrent_queue.h"
23#include "tbb/concurrent_unordered_map.h"
24#include "tbb/concurrent_vector.h"
31#include <unordered_map>
33PXR_NAMESPACE_OPEN_SCOPE
46class VdfPoolChainIndexer;
48class Vdf_InputAndOutputSpecsRegistry;
49class Vdf_ScheduleInvalidator;
51typedef TfHashSet<const VdfOutput *, TfHash> VdfOutputPtrSet;
88 return _outputCapacity.load(std::memory_order_acquire);
100 return _nodes.size() - _freeNodeIds.unsafe_size();
106 return i < _nodes.size() ? _nodes[i] :
nullptr;
112 return i < _nodes.size() ? _nodes[i] :
nullptr;
260 return _version.load(std::memory_order_acquire);
298 void _RegisterNodeDebugName(
305 void _UnregisterNodeDebugName(
const VdfNode &node);
317 void _DeleteNode(
VdfNode *node);
333 void _RemoveNode(
VdfNode *node);
337 void _DidChangeAffectsMask(
VdfOutput &output);
341 size_t _AcquireOutputId();
345 void _ReleaseOutputId(
const VdfId id);
349 void _IncrementVersion();
366 void _RegisterSchedule(
VdfSchedule *schedule)
const;
370 void _UnregisterSchedule(
VdfSchedule *schedule)
const;
374 Vdf_ScheduleInvalidator* _GetScheduleInvalidator()
const {
375 return _scheduleInvalidator.get();
382 Vdf_InputAndOutputSpecsRegistry &_GetInputOutputSpecsRegistry() {
383 return *_specsRegistry;
387 tbb::concurrent_vector<VdfNode *> _nodes;
390 tbb::concurrent_queue<VdfId> _freeNodeIds;
396 std::atomic<uint32_t> _outputCapacity;
399 tbb::concurrent_queue<VdfId> _freeOutputIds;
403 _EditMonitorVector _monitors;
406 std::unique_ptr<Vdf_ScheduleInvalidator> _scheduleInvalidator;
409 std::unique_ptr<VdfPoolChainIndexer> _poolChainIndexer;
412 std::unique_ptr<Vdf_InputAndOutputSpecsRegistry> _specsRegistry;
415 std::atomic<size_t> _version;
418 using _NodeDebugNamesMap = tbb::concurrent_unordered_map<
420 std::unique_ptr<Vdf_ExecNodeDebugName>,
423 _NodeDebugNamesMap _nodeDebugNames;
428PXR_NAMESPACE_CLOSE_SCOPE
A user-extensible hashing mechanism for use with runtime hash tables.
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Represents a range of contiguous elements.
Token for efficient comparison, assignment, and hashing of known strings.
Stores all necessary information to lazily construct a node debug name.
A class that fully represents a connection between two VdfNodes.
A VdfIsolatedSubnetwork builds a collection of VdfNodes and VdfConnections that are disconnected from...
A VdfMask is placed on connections to specify the data flowing through them.
Class to hold on to an externally owned output and a mask.
An abstract class to monitor network edit operations.
virtual void DidConnect(const VdfConnection *connection)=0
Will be called after a connection has been made.
virtual void WillDelete(const VdfNode *node)=0
Will be called before node is deleted.
virtual void WillClear()=0
Will be called before a network is to be cleared out.
virtual void WillDelete(const VdfConnection *connection)=0
Will be called before a connection is deleted.
virtual void DidAddNode(const VdfNode *node)=0
Will be called after a node has been added to the network.
A VdfNetwork is a collection of VdfNodes and their connections.
VDF_API const std::string GetNodeDebugName(const VdfNode *node) const
Retrieves a debug name for a given node.
VDF_API bool DisconnectAndDelete(VdfNode *node)
Disconnects and deletes node.
VDF_API void UnregisterEditMonitor(EditMonitor *monitor)
Unregisters an edit monitor for this network.
VDF_API VdfConnection * Connect(const VdfMaskedOutput &maskedOutput, VdfNode *inputNode, const TfToken &inputName, int atIndex=AppendConnection)
Connects the maskedOutput to the given inputNode's input inputName.
VDF_API VdfNode * GetNodeById(const VdfId nodeId)
Returns the non-const node with id nodeId, if it exists.
VDF_API void ReorderInputConnections(VdfInput *input, const TfSpan< const VdfConnectionVector::size_type > &newToOldIndices)
Reorders all input connections for input according to the mapping defined by newToOldIndices.
VDF_API VdfPoolChainIndex GetPoolChainIndex(const VdfOutput &output) const
Returns the pool chain index from the pool chain indexer.
VDF_API size_t DumpStats(std::ostream &os) const
Prints useful statistics about the network to os.
VDF_API bool Delete(VdfNode *node)
Deletes node from the network.
static const int AppendConnection
Constant for connection API to indicate to place the connection at the end.
size_t GetNumOwnedNodes() const
Returns the number of nodes that are currently owned by the network.
VDF_API VdfConnection * Connect(VdfOutput *output, VdfNode *inputNode, const TfToken &inputName, const VdfMask &mask, int atIndex=AppendConnection)
Connects the output to the given inputNode's input inputName with mask.
size_t GetNodeCapacity() const
Returns the number of entries currently available for nodes and for which it is valid to call GetNode...
VdfNode * GetNode(size_t i)
Returns the non-const node at index i.
VDF_API ~VdfNetwork()
Destructs the network and the nodes managed by it.
VDF_API const VdfNode * GetNodeById(const VdfId nodeId) const
Returns the node with id nodeId, if it exists.
VDF_API void RegisterEditMonitor(EditMonitor *monitor)
Registers an edit monitor for this network.
VDF_API void Disconnect(VdfConnection *connection)
Deletes connection from the network.
size_t GetVersion() const
Returns the current edit version of the network.
VDF_API VdfNetwork()
Constructs an empty network.
VDF_API void Clear()
Clears all nodes from the network.
const VdfNode * GetNode(size_t i) const
Returns the node at index i.
uint32_t GetOutputCapacity() const
Returns the number of indices currently available for outputs.
This is the base class for all nodes in a VdfNetwork.
An universal class to represent pointers to various Vdf types.
A VdfOutput represents an output on a node.
Opaque pool chain index type.
Contains a specification of how to execute a particular VdfNetwork.
std::function< std::string()> VdfNodeDebugNameCallback
Type of callback for building a node debug name.
uint64_t VdfId
The unique identifier type for Vdf objects.
uint32_t VdfIndex
The index type for Vdf objects.
uint32_t VdfVersion
The version type for Vdf objects.