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"
27PXR_NAMESPACE_OPEN_SCOPE
47 template <
typename Iterator>
50 template <
typename IteratorConvertible>
51 IteratorRange(IteratorConvertible begin, IteratorConvertible end) :
52 _begin(begin), _end(end) {}
54 Iterator begin()
const {
return _begin; }
55 Iterator end()
const {
return _end; }
56 bool empty()
const {
return _begin == _end; }
57 size_t size()
const {
return std::distance(_begin, _end); }
99 return _scheduleNodeIndex >= 0 && _secondaryIndex >= 0;
117 return _scheduleNodeIndex == rhs._scheduleNodeIndex &&
118 _secondaryIndex == rhs._secondaryIndex;
121 bool operator!=(
const OutputId &rhs)
const {
122 return !(*
this == rhs);
139 OutputId(
int scheduleNodeIndex,
int secondaryIndex) :
140 _scheduleNodeIndex(scheduleNodeIndex),
141 _secondaryIndex(secondaryIndex)
148 int _scheduleNodeIndex;
174 return _isValid.load(std::memory_order_relaxed);
298 return _nodeInvocations[invocationIndex].requestMask;
309 const VdfMask **affectsMask)
const;
317 const VdfMask **affectsMask)
const {
319 *requestMask = &_nodeInvocations[invocationIndex].requestMask;
320 *affectsMask = &_nodeInvocations[invocationIndex].affectsMask;
338 return _nodeInvocations[invocationIndex].keepMask;
373 return _numUniqueInputDeps;
379 return _computeTasks.size();
385 return _inputsTasks.size();
391 return _numPrepTasks;
397 return _numKeepTasks;
404 int scheduleNodeIndex = _GetScheduleNodeIndex(node);
407 _nodesToComputeTasks[scheduleNodeIndex].taskId,
408 _nodesToComputeTasks[scheduleNodeIndex].taskId +
409 _nodesToComputeTasks[scheduleNodeIndex].taskNum);
417 input.computeOrKeepTaskId,
418 input.computeOrKeepTaskId + input.computeTaskNum);
424 int scheduleNodeIndex = _GetScheduleNodeIndex(node);
425 return scheduleNodeIndex >= 0
426 ? _nodesToKeepTasks[scheduleNodeIndex]
427 : VdfScheduleTaskInvalid;
435 return _computeTasks[index];
443 return _inputsTasks[index];
451 std::vector<VdfScheduleInputDependency>::const_iterator begin =
452 _inputDeps.begin() + task.inputDepIndex;
461 std::vector<VdfScheduleInputDependency>::const_iterator begin =
462 _inputDeps.begin() + task.inputDepIndex + task.prereqsNum;
471 std::vector<VdfScheduleInputDependency>::const_iterator begin =
472 _inputDeps.begin() + task.requiredsIndex;
516 return outputId._scheduleNodeIndex;
577 void _SetIsValidForNetwork(
const VdfNetwork *network);
583 int _GetScheduleNodeIndex(
const VdfNode &node)
const;
588 int _EnsureNodeInSchedule(
const VdfNode &node);
600 std::vector<int> _nodesToIndexMap;
610 std::atomic_bool _isValid;
616 bool _isSmallSchedule;
624 size_t _numUniqueInputDeps;
629 size_t _numKeepTasks;
630 size_t _numPrepTasks;
636 std::vector<VdfScheduleInputDependency> _inputDeps;
640 std::vector<VdfScheduleNodeTasks> _nodesToComputeTasks;
641 std::vector<VdfScheduleTaskIndex> _nodesToKeepTasks;
653#define VDF_FOR_EACH_SCHEDULED_OUTPUT_ID(OUTPUT_ID_NAME,VDF_SCHEDULE,VDF_NODE) \
654 for (VdfSchedule::OutputId __endId = \
655 (VDF_SCHEDULE).GetOutputIdsEnd(VDF_NODE), \
656 OUTPUT_ID_NAME = (VDF_SCHEDULE).GetOutputIdsBegin(VDF_NODE) ; \
657 OUTPUT_ID_NAME != __endId; ++OUTPUT_ID_NAME)
662PXR_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.
IteratorRange< std::vector< VdfScheduleInputDependency >::const_iterator > InputDependencyRange
An iterable range of input dependencies.
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.
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.
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.
IteratorRange< Vdf_CountingIterator< VdfScheduleTaskId > > TaskIdRange
An iterable range of task ids.
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.