tint: Make sure enable directives go first in ordered_globals
This patch change DependencyAnalysis::SortGlobals() to make sure that
'enable' directive nodes go before any other global declarations in the
sorted global node list, and thus ensure that all extensions will be
registered by reslover before dealing with any other global declarations.
This is necessary because some transforms will add AST nodes before any
other global nodes, and these added nodes should be handled by resolver
after 'enable' nodes are handled.
Bug: tint:1472
Change-Id: Idc2253fc055b0f121cb0cafcaca5275c23ed7b0d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93760
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc
index 7e66899..ed6c88f 100644
--- a/src/tint/resolver/dependency_graph.cc
+++ b/src/tint/resolver/dependency_graph.cc
@@ -569,8 +569,18 @@
return; // This code assumes there are no undeclared identifiers.
}
- std::unordered_set<const Global*> visited;
+ // Make sure all 'enable' directives go before any other global declarations.
for (auto* global : declaration_order_) {
+ if (auto* enable = global->node->As<ast::Enable>()) {
+ sorted_.add(enable);
+ }
+ }
+
+ for (auto* global : declaration_order_) {
+ if (global->node->Is<ast::Enable>()) {
+ // Skip 'enable' directives here, as they are already added.
+ continue;
+ }
utils::UniqueVector<const Global*> stack;
TraverseDependencies(
global,