Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,20 @@ Now we implement the core algorithmic logic that analyzes pass dependencies and
// Track which pass produces each resource (write-after-write dependencies)
std::unordered_map<std::string, size_t> resourceWriters;

// Resource Production Registration
// Register every pass's outputs *before* looking at any inputs, in its own pass over
// `passes`. Producers and consumers can appear in any order in the `passes` vector -
// a pass added later might produce a resource a pass added earlier consumes - so
// dependency discovery below must not assume producers come first positionally.
for (size_t i = 0; i < passes.size(); ++i) {
for (const auto& output : passes[i].outputs) {
resourceWriters[output] = i; // Record this pass as producer
}
}

// Dependency Discovery Through Resource Usage Analysis
// Analyze each pass to determine data flow relationships
// Now that every producer is known, analyze each pass's inputs to determine data flow
// relationships, regardless of where the producer sits in the passes vector.
for (size_t i = 0; i < passes.size(); ++i) {
const auto& pass = passes[i];

Expand All @@ -248,11 +260,6 @@ Now we implement the core algorithmic logic that analyzes pass dependencies and
dependents[it->second].push_back(i); // Producer has this as dependent
}
}

// Register output production - subsequent passes may depend on these
for (const auto& output : pass.outputs) {
resourceWriters[output] = i; // Record this pass as producer
}
}

// Topological Sort for Optimal Execution Order
Expand All @@ -272,9 +279,10 @@ Now we implement the core algorithmic logic that analyzes pass dependencies and

inStack[node] = true; // Mark as currently being processed

// Recursively process all dependent passes first (post-order traversal)
for (auto dependent : dependents[node]) {
visit(dependent);
// Recursively process all passes this one depends on first (post-order traversal),
// so a producer is always pushed onto executionOrder before its consumers.
for (auto dependency : dependencies[node]) {
visit(dependency);
}

inStack[node] = false; // Remove from current path
Expand Down
Loading