tint: Refactor Extensions / Enables.

* Extract ast::Enable::ExtensionKind to ast::Extension.
* Move the parsing out of ast::Enable and next to ast/extension.h
* Change the ast::Enable constructor to take the Extension, instead of
  a std::string. It's the WGSL parser's responsibility to parse, not the
  AST nodes.
* Add ProgramBuilder::Enable() helper.
* Keep ast::Module simple - keep track of the declared AST Enable nodes,
  don't do any deduplicating of the enabled extensions.
* Add the de-duplicated ast::Extensions to the sem::Module.
* Remove the kInternalExtensionForTesting enum value - we have kF16
  now, which can be used instead for testing.
* Rename kNoExtension to kNone.

Bug: tint:1472
Change-Id: I9af635e95d36991ea468e6e0bf6798bb50937edc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90523
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2022-05-18 22:41:48 +00:00
committed by Dawn LUCI CQ
parent 23696b1ba3
commit 7f2b8cd8fc
53 changed files with 455 additions and 492 deletions

View File

@@ -153,11 +153,11 @@ bool Builtin::HasSideEffects() const {
return false;
}
ast::Enable::ExtensionKind Builtin::RequiredExtension() const {
ast::Extension Builtin::RequiredExtension() const {
if (IsDP4a()) {
return ast::Enable::ExtensionKind::kChromiumExperimentalDP4a;
return ast::Extension::kChromiumExperimentalDP4a;
}
return ast::Enable::ExtensionKind::kNoExtension;
return ast::Extension::kNone;
}
} // namespace tint::sem

View File

@@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include "src/tint/ast/extension.h"
#include "src/tint/sem/builtin_type.h"
#include "src/tint/sem/call_target.h"
#include "src/tint/sem/pipeline_stage_set.h"
@@ -144,8 +145,8 @@ class Builtin final : public Castable<Builtin, CallTarget> {
bool HasSideEffects() const;
/// @returns the required extension of this builtin function. Returns
/// ast::Enable::ExtensionKind::kNoExtension if no extension is required.
ast::Enable::ExtensionKind RequiredExtension() const;
/// ast::Extension::kNone if no extension is required.
ast::Extension RequiredExtension() const;
private:
const BuiltinType type_;

View File

@@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Module);
namespace tint::sem {
Module::Module(std::vector<const ast::Node*> dep_ordered_decls)
: dep_ordered_decls_(std::move(dep_ordered_decls)) {}
Module::Module(std::vector<const ast::Node*> dep_ordered_decls, ast::Extensions extensions)
: dep_ordered_decls_(std::move(dep_ordered_decls)), extensions_(std::move(extensions)) {}
Module::~Module() = default;

View File

@@ -17,6 +17,7 @@
#include <vector>
#include "src/tint/ast/extension.h"
#include "src/tint/sem/node.h"
// Forward declarations
@@ -33,7 +34,8 @@ class Module final : public Castable<Module, Node> {
public:
/// Constructor
/// @param dep_ordered_decls the dependency-ordered module-scope declarations
explicit Module(std::vector<const ast::Node*> dep_ordered_decls);
/// @param extensions the list of enabled extensions in the module
Module(std::vector<const ast::Node*> dep_ordered_decls, ast::Extensions extensions);
/// Destructor
~Module() override;
@@ -43,8 +45,12 @@ class Module final : public Castable<Module, Node> {
return dep_ordered_decls_;
}
/// @returns the list of enabled extensions in the module
const ast::Extensions& Extensions() const { return extensions_; }
private:
const std::vector<const ast::Node*> dep_ordered_decls_;
ast::Extensions extensions_;
};
} // namespace tint::sem