7#ifndef PXR_EXEC_VDF_SCHEDULE_H
8#define PXR_EXEC_VDF_SCHEDULE_H
14#include "pxr/exec/vdf/api.h"
15#include "pxr/exec/vdf/countingIterator.h"
22#include "pxr/base/tf/bits.h"
26PXR_NAMESPACE_OPEN_SCOPE
46 template <
typename Iterator>
49 template <
typename IteratorConvertible>
50 IteratorRange(IteratorConvertible begin, IteratorConvertible end) :
51 _begin(begin), _end(end) {}
53 Iterator begin()
const {
return _begin; }
54 Iterator end()
const {
return _end; }
55 bool empty()
const {
return _begin == _end; }
56 size_t size()
const {
return std::distance(_begin, _end); }
98 return _scheduleNodeIndex >= 0 && _secondaryIndex >= 0;
116 return _scheduleNodeIndex == rhs._scheduleNodeIndex &&
117 _secondaryIndex == rhs._secondaryIndex;
120 bool operator!=(
const OutputId &rhs)
const {
121 return !(*
this == rhs);
138 OutputId(
int scheduleNodeIndex,
int secondaryIndex) :
139 _scheduleNodeIndex(scheduleNodeIndex),
140 _secondaryIndex(secondaryIndex)
147 int _scheduleNodeIndex;
297 return _nodeInvocations[invocationIndex].requestMask;
308 const VdfMask **affectsMask)
const;
316 const VdfMask **affectsMask)
const {
318 *requestMask = &_nodeInvocations[invocationIndex].requestMask;
319 *affectsMask = &_nodeInvocations[invocationIndex].affectsMask;
337 return _nodeInvocations[invocationIndex].keepMask;
372 return _numUniqueInputDeps;
378 return _computeTasks.size();
384 return _inputsTasks.size();
390 return _numPrepTasks;
396 return _numKeepTasks;
403 int scheduleNodeIndex = _GetScheduleNodeIndex(node);
406 _nodesToComputeTasks[scheduleNodeIndex].taskId,
407 _nodesToComputeTasks[scheduleNodeIndex].taskId +
408 _nodesToComputeTasks[scheduleNodeIndex].taskNum);
416 input.computeOrKeepTaskId,
417 input.computeOrKeepTaskId + input.computeTaskNum);
423 int scheduleNodeIndex = _GetScheduleNodeIndex(node);
424 return scheduleNodeIndex >= 0
425 ? _nodesToKeepTasks[scheduleNodeIndex]
426 : VdfScheduleTaskInvalid;
434 return _computeTasks[index];
442 return _inputsTasks[index];
450 std::vector<VdfScheduleInputDependency>::const_iterator begin =
451 _inputDeps.begin() + task.inputDepIndex;
460 std::vector<VdfScheduleInputDependency>::const_iterator begin =
461 _inputDeps.begin() + task.inputDepIndex + task.prereqsNum;
470 std::vector<VdfScheduleInputDependency>::const_iterator begin =
471 _inputDeps.begin() + task.requiredsIndex;
515 return outputId._scheduleNodeIndex;
576 void _SetIsValidForNetwork(
const VdfNetwork *network);
582 int _GetScheduleNodeIndex(
const VdfNode &node)
const;
587 int _EnsureNodeInSchedule(
const VdfNode &node);
599 std::vector<int> _nodesToIndexMap;
615 bool _isSmallSchedule;
623 size_t _numUniqueInputDeps;
628 size_t _numKeepTasks;
629 size_t _numPrepTasks;
635 std::vector<VdfScheduleInputDependency> _inputDeps;
639 std::vector<VdfScheduleNodeTasks> _nodesToComputeTasks;
640 std::vector<VdfScheduleTaskIndex> _nodesToKeepTasks;
652#define VDF_FOR_EACH_SCHEDULED_OUTPUT_ID(OUTPUT_ID_NAME,VDF_SCHEDULE,VDF_NODE) \
653 for (VdfSchedule::OutputId __endId = \
654 (VDF_SCHEDULE).GetOutputIdsEnd(VDF_NODE), \
655 OUTPUT_ID_NAME = (VDF_SCHEDULE).GetOutputIdsBegin(VDF_NODE) ; \
656 OUTPUT_ID_NAME != __endId; ++OUTPUT_ID_NAME)
661PXR_NAMESPACE_CLOSE_SCOPE
Fast bit array that keeps track of the number of bits set and can find the next set in a timely manne...
A class that fully represents a connection between two VdfNodes.
A VdfMask is placed on connections to specify the data flowing through them.
A VdfNetwork is a collection of VdfNodes and their connections.
This is the base class for all nodes in a VdfNetwork.
A VdfOutput represents an output on a node.
Minimal iterator range that the schedule returns instances of, in order to facilitate iterating over ...
An OutputId is a small key object that, once obtained for a particular VdfOutput, can be used to quer...
OutputId & operator++()
Increment this OutputId to refer to the next scheduled output on the current output's node.
bool IsValid() const
Returns whether this OutputId can be used to make queries about an output's scheduling.
bool operator==(const OutputId &rhs) const
Equality operator.
Contains a specification of how to execute a particular VdfNetwork.
VDF_API const VdfMask & GetAffectsMask(const OutputId &outputId) const
Returns the affects mask associated with the given OutputId.
const VdfNetwork * GetNetwork() const
Returns the network for this schedule.
void SetHasSMBL(bool enable)
Enables SMBL for this schedule.
InputDependencyRange GetRequiredInputDependencies(const VdfScheduleComputeTask &task) const
Returns an iterable range of required (i.e.
VDF_API OutputId GetOrCreateOutputId(const VdfOutput &output)
Similar to GetOutputId, but creates an OutptuId if none exists, effectively adding the output to the ...
VDF_API void SetPassToOutput(const OutputId &outputId, const VdfOutput *output)
Registers a "pass to" output for the output indicated by outputId.
const VdfMask & GetKeepMask(const VdfScheduleTaskIndex invocationIndex) const
Returns the keep mask for the given node invocation index.
VDF_API VdfSchedule()
Constructs an empty schedule.
VDF_API ~VdfSchedule()
Destructor.
VDF_API void InitializeFromNetwork(const VdfNetwork &network)
Initializes structures based on the size of the network.
VDF_API OutputId GetOutputId(const VdfOutput &output) const
Returns a small, cheap OutputId, which can be passed to other Get* methods in this class to efficient...
VDF_API void SetAffectsMask(const OutputId &outputId, const VdfMask &mask)
Registers an affects mask for the output indicated by outputId.
VDF_API const VdfMask & GetRequestMask(const OutputId &outputId) const
Returns the request mask associated with the given OutputId.
size_t GetNumUniqueInputDependencies() const
Returns the number of unique input dependencies created for the scheduled task graph.
VDF_API OutputId GetOutputIdsBegin(const VdfNode &node) const
Gets an OutputId identifying the first scheduled output for the given node, if any.
InputDependencyRange GetPrereqInputDependencies(const VdfScheduleInputsTask &task) const
Returns an iterable range of prereq input dependencies for the given inputs task.
VDF_API OutputId GetOutputIdsEnd(const VdfNode &node) const
Gets an OutputId identifying the "end" of the scheduled outputs for a node.
VDF_API const VdfOutput * GetFromBufferOutput(const OutputId &outputId) const
Returns the "from buffer's" output associated with the given OutputId.
const VdfScheduleTaskIndex GetKeepTaskIndex(const VdfNode &node) const
Returns an index to the keep task associated with the given node.
const VdfScheduleComputeTask & GetComputeTask(const VdfScheduleTaskIndex index) const
Returns the compute task associated with the given task index.
VDF_API bool IsScheduled(const VdfNode &node) const
Returns whether this schedule includes node in any way.
size_t GetNumKeepTasks() const
Returns the total number of keep tasks in the schedule.
TaskIdRange GetComputeTaskIds(const VdfScheduleInputDependency &input) const
Returns an iterable range of task indices given an input dependency.
VDF_API void DeduplicateInputs()
Consolidates scheduled input entries added by AddInput.
VDF_API void ForEachScheduledOutput(const VdfNode &node, const VdfScheduledOutputCallback &callback) const
Loops over each scheduled output of node and calls callback with the output and request mask in an ef...
VDF_API void SetRequest(const VdfRequest &request)
Sets the request that was used to make up this schedule.
VDF_API InputsRange GetInputs(const VdfNode &node) const
Returns a range of inputs scheduled for the given node.
IteratorRange< std::vector< VdfScheduleInputDependency >::const_iterator > InputDependencyRange
An iterable range of input dependencies.
int GetScheduleNodeIndex(const OutputId &outputId) const
Returns the node index of the schedule node associated with the given outputId.
const VdfRequest & GetRequest() const
Returns the request for this schedule.
VDF_API const VdfMask & GetKeepMask(const OutputId &outputId) const
Returns the keep mask associated with the given OutputId.
VDF_API VdfScheduleInputDependencyUniqueIndex GetUniqueIndex(const OutputId outputId) const
Returns the unique index assigned to the output.
IteratorRange< Vdf_CountingIterator< VdfScheduleTaskId > > TaskIdRange
An iterable range of task ids.
VDF_API void SetRequestMask(const OutputId &outputId, const VdfMask &mask)
Registers a request mask for the output indicated by outputId.
VDF_API void AddInput(const VdfConnection &connection, const VdfMask &mask)
Adds the input targeted by the given connection to the schedule.
VDF_API const VdfOutput * GetPassToOutput(const OutputId &outputId) const
Returns the "pass to" output associated with the given OutputId.
std::vector< VdfScheduleNode > ScheduleNodeVector
The type for the vector of schedule nodes in the schedule.
const TaskIdRange GetComputeTaskIds(const VdfNode &node) const
Returns a range of ids describing compute tasks associated with the given node.
VDF_API void SetKeepMask(const OutputId &outputId, const VdfMask &mask)
Registers a keep mask for the output indicated by outputId.
const VdfScheduleInputsTask & GetInputsTask(const VdfScheduleTaskIndex index) const
Returns the inputs task associated with the given task index.
VDF_API void GetRequestAndAffectsMask(const OutputId &outputId, const VdfMask **requestMask, const VdfMask **affectsMask) const
Returns pointers to the request and affects masks simultaneously, saving on the overhead of making tw...
const VdfMask & GetRequestMask(const VdfScheduleTaskIndex invocationIndex) const
Returns the request mask for the given node invocation.
VDF_API const VdfNode * GetNode(const OutputId &outputId) const
Returns the VdfNode that owns the VdfOutput associated with the given outputId.
VdfSchedule(const VdfSchedule &)=delete
Noncopyable.
const TfBits & GetScheduledNodeBits() const
Returns a set of bits where each set bit's index corresponds to the node index of a node in this sche...
VDF_API const VdfOutput * GetOutputToClear(const VdfNode &node) const
Returns the output whose temporary buffer can be immediately deallocated after node has finished exec...
void GetRequestAndAffectsMask(const VdfScheduleTaskIndex invocationIndex, const VdfMask **requestMask, const VdfMask **affectsMask) const
Returns pointers to the request and affects masks for the given node invocation index.
bool IsValid() const
Returns whether or not this schedule is valid and can be used for execution.
ScheduleNodeVector & GetScheduleNodeVector()
Returns the vector of schedule nodes in this schedule.
size_t GetNumInputsTasks() const
Returns the total number of inputs tasks in the schedule.
VDF_API void Clear()
Clears the schedule.
bool IsSmallSchedule() const
Returns whether this schedule is small enough to avoid overhead incurred by the _nodesToIndexMap mapp...
VDF_API bool IsAffective(const OutputId &outputId) const
Returns true if the output is expected to have an effect on its corresponding input,...
VDF_API const VdfOutput * GetOutput(const OutputId &outputId) const
Returns the scheduled VdfOutput associated with the given OutputId.
size_t GetNumPrepTasks() const
Returns the total number of prep tasks in the schedule.
VDF_API void SetFromBufferOutput(const OutputId &outputId, const VdfOutput *output)
Registers a "from buffer" for the output indicated by outputId.
InputDependencyRange GetOptionalInputDependencies(const VdfScheduleInputsTask &task) const
Returns an iterable range of optional (i.e.
size_t GetNumComputeTasks() const
Returns the total number of compute tasks in the schedule.
bool HasSMBL() const
Returns true if this schedule participates in sparse mung buffer locking.
VDF_API void SetOutputToClear(const VdfNode &node, const VdfOutput *outputToClear)
Registers an output whose temporary buffer can be eagerly cleared as soon as node has finished execut...
Used to make a VdfSchedule.
std::function< void(const VdfOutput *, const VdfMask &)> VdfScheduledOutputCallback
Function type to be used with ForEachScheduledOutput().
std::vector< T, Vdf_DefaultInitAllocator< T > > Vdf_DefaultInitVector
A std::vector which on resize performs default initialization instead of value initialization.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
uint32_t VdfScheduleInputDependencyUniqueIndex
A sequential index assigned to the unique output and mask combination of a VdfScheduleInputDependency...
bool VdfScheduleTaskIsInvalid(uint32_t task)
Returns true if the given task index or id is invalid.
uint32_t VdfScheduleTaskIndex
Type describing a task index.
A VdfScheduleComputeTask represents a unit of computation for the parallel evaluation engine.