resolver: Allocate IDs for named pipeline constants

Keep track of any constant IDs specified in the shader, and then
allocate IDs for the remaining constants when creating the semantic
info.

Bug: tint:755
Change-Id: I6a76b1193cac459b62582cde7469b092dde51d5d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50841
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-05-13 20:32:32 +00:00
committed by Commit Bot service account
parent 8650247ddb
commit f2f3bfc677
8 changed files with 236 additions and 5 deletions

View File

@@ -26,7 +26,19 @@ namespace sem {
Variable::Variable(const ast::Variable* declaration,
const sem::Type* type,
ast::StorageClass storage_class)
: declaration_(declaration), type_(type), storage_class_(storage_class) {}
: declaration_(declaration),
type_(type),
storage_class_(storage_class),
is_pipeline_constant_(false) {}
Variable::Variable(const ast::Variable* declaration,
const sem::Type* type,
uint16_t constant_id)
: declaration_(declaration),
type_(type),
storage_class_(ast::StorageClass::kNone),
is_pipeline_constant_(true),
constant_id_(constant_id) {}
Variable::~Variable() = default;

View File

@@ -37,7 +37,7 @@ class VariableUser;
/// Variable holds the semantic information for variables.
class Variable : public Castable<Variable, Node> {
public:
/// Constructor
/// Constructor for variables and non-overridable constants
/// @param declaration the AST declaration node
/// @param type the variable type
/// @param storage_class the variable storage class
@@ -45,6 +45,14 @@ class Variable : public Castable<Variable, Node> {
const sem::Type* type,
ast::StorageClass storage_class);
/// Constructor for overridable pipeline constants
/// @param declaration the AST declaration node
/// @param type the variable type
/// @param constant_id the pipeline constant ID
Variable(const ast::Variable* declaration,
const sem::Type* type,
uint16_t constant_id);
/// Destructor
~Variable() override;
@@ -63,11 +71,19 @@ class Variable : public Castable<Variable, Node> {
/// @param user the user to add
void AddUser(const VariableUser* user) { users_.emplace_back(user); }
/// @returns true if this variable is an overridable pipeline constant
bool IsPipelineConstant() const { return is_pipeline_constant_; }
/// @returns the pipeline constant ID associated with the variable
uint32_t ConstantId() const { return constant_id_; }
private:
const ast::Variable* const declaration_;
const sem::Type* const type_;
ast::StorageClass const storage_class_;
std::vector<const VariableUser*> users_;
const bool is_pipeline_constant_;
const uint16_t constant_id_ = 0;
};
/// VariableUser holds the semantic information for an identifier expression