Convert @binding to an expression

This CL updates the binding attribute to store an expression
instead of a single value. The parser always produces an
IntLiteralExpression at the moment.

Bug: tint:1633
Change-Id: I14b2a61b5bcdea66e9e24df7afbb55fb60be785e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100440
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-08-29 21:13:00 +00:00
committed by Dawn LUCI CQ
parent cbe8b36256
commit f9b831c39a
67 changed files with 636 additions and 525 deletions

View File

@@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingAttribute);
namespace tint::ast {
BindingAttribute::BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val)
BindingAttribute::BindingAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* val)
: Base(pid, nid, src), value(val) {}
BindingAttribute::~BindingAttribute() = default;
@@ -34,7 +37,8 @@ std::string BindingAttribute::Name() const {
const BindingAttribute* BindingAttribute::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<BindingAttribute>(src, value);
auto* value_ = ctx->Clone(value);
return ctx->dst->create<BindingAttribute>(src, value_);
}
} // namespace tint::ast

View File

@@ -18,6 +18,7 @@
#include <string>
#include "src/tint/ast/attribute.h"
#include "src/tint/ast/expression.h"
namespace tint::ast {
@@ -28,8 +29,8 @@ class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
/// @param value the binding value
BindingAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value);
/// @param value the binding value expression
BindingAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* value);
~BindingAttribute() override;
/// @returns the WGSL name for the attribute
@@ -41,8 +42,8 @@ class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
/// @return the newly cloned node
const BindingAttribute* Clone(CloneContext* ctx) const override;
/// the binding value
const uint32_t value;
/// the binding value expression
const ast::Expression* const value;
};
} // namespace tint::ast

View File

@@ -17,11 +17,12 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using BindingAttributeTest = TestHelper;
TEST_F(BindingAttributeTest, Creation) {
auto* d = create<BindingAttribute>(2u);
EXPECT_EQ(2u, d->value);
auto* d = Binding(2_a);
EXPECT_TRUE(d->value->Is<IntLiteralExpression>());
}
} // namespace

View File

@@ -143,7 +143,7 @@ const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(ProgramBuil
const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
utils::Vector attrs{
b->create<ast::GroupAttribute>(0u),
b->create<ast::BindingAttribute>(0u),
b->Binding(0_a),
};
switch (texture_kind) {
case ast::builtin::test::TextureKind::kRegular:
@@ -175,10 +175,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b
}
const ast::Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const {
utils::Vector attrs = {
b->create<ast::GroupAttribute>(0u),
b->create<ast::BindingAttribute>(1u),
};
utils::Vector attrs = {b->Group(0u), b->Binding(1_a)};
return b->GlobalVar("sampler", b->ty.sampler(sampler_kind), attrs);
}

View File

@@ -106,7 +106,7 @@ TEST_F(VariableTest, WithAttributes) {
}
TEST_F(VariableTest, HasBindingPoint_BothProvided) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2), Group(1));
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a), Group(1));
EXPECT_TRUE(var->HasBindingPoint());
}
@@ -116,7 +116,7 @@ TEST_F(VariableTest, HasBindingPoint_NeitherProvided) {
}
TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2));
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a));
EXPECT_FALSE(var->HasBindingPoint());
}