mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Convert @group to an expression
This CL updates the group attribute to store an expression instead of a single value. The parser always produces an IntLiteralExpression at the moment. Bug: tint:1633 Change-Id: Ice05c26d652c7f5c21825f745f270e96e3d88e08 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100441 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:
committed by
Dawn LUCI CQ
parent
f9b831c39a
commit
be4c9f48aa
@@ -142,7 +142,7 @@ const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(ProgramBuil
|
||||
|
||||
const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
|
||||
utils::Vector attrs{
|
||||
b->create<ast::GroupAttribute>(0u),
|
||||
b->Group(0_u),
|
||||
b->Binding(0_a),
|
||||
};
|
||||
switch (texture_kind) {
|
||||
@@ -175,7 +175,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b
|
||||
}
|
||||
|
||||
const ast::Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const {
|
||||
utils::Vector attrs = {b->Group(0u), b->Binding(1_a)};
|
||||
utils::Vector attrs = {b->Group(0_a), b->Binding(1_a)};
|
||||
return b->GlobalVar("sampler", b->ty.sampler(sampler_kind), attrs);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupAttribute);
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
GroupAttribute::GroupAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t val)
|
||||
GroupAttribute::GroupAttribute(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
const ast::Expression* val)
|
||||
: Base(pid, nid, src), value(val) {}
|
||||
|
||||
GroupAttribute::~GroupAttribute() = default;
|
||||
@@ -34,7 +37,8 @@ std::string GroupAttribute::Name() const {
|
||||
const GroupAttribute* GroupAttribute::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<GroupAttribute>(src, value);
|
||||
auto* value_ = ctx->Clone(value);
|
||||
return ctx->dst->create<GroupAttribute>(src, value_);
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -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 GroupAttribute final : public Castable<GroupAttribute, 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 group value
|
||||
GroupAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t value);
|
||||
/// @param value the group value expression
|
||||
GroupAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* value);
|
||||
~GroupAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
@@ -41,8 +42,8 @@ class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
|
||||
/// @return the newly cloned node
|
||||
const GroupAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The group value
|
||||
const uint32_t value;
|
||||
/// The group value expression
|
||||
const ast::Expression* const value;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
namespace tint::ast {
|
||||
namespace {
|
||||
|
||||
using namespace tint::number_suffixes; // NOLINT
|
||||
using GroupAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(GroupAttributeTest, Creation) {
|
||||
auto* d = create<GroupAttribute>(2u);
|
||||
EXPECT_EQ(2u, d->value);
|
||||
auto* d = Group(2_a);
|
||||
EXPECT_TRUE(d->value->Is<IntLiteralExpression>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -106,7 +106,7 @@ TEST_F(VariableTest, WithAttributes) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, HasBindingPoint_BothProvided) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a), Group(1));
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a), Group(1_a));
|
||||
EXPECT_TRUE(var->HasBindingPoint());
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, HasBindingPoint_MissingBindingAttribute) {
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Group(1));
|
||||
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Group(1_a));
|
||||
EXPECT_FALSE(var->HasBindingPoint());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user