Update StructMember{Offset,Size}Attribute to expressions.

This CL updates the StructMember Offset and Size attributes to
store expressions instead of uint32_t values.

Bug: tint:1633
Change-Id: I771b64fbd27a398ffbcb3f8cc2cbb7fa2606983e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101640
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-09-09 14:49:09 +00:00 committed by Dawn LUCI CQ
parent f0209f58ea
commit 93df967003
27 changed files with 157 additions and 95 deletions

View File

@ -25,8 +25,8 @@ namespace tint::ast {
StructMemberOffsetAttribute::StructMemberOffsetAttribute(ProgramID pid,
NodeID nid,
const Source& src,
uint32_t o)
: Base(pid, nid, src), offset(o) {}
const ast::Expression* exp)
: Base(pid, nid, src), expr(exp) {}
StructMemberOffsetAttribute::~StructMemberOffsetAttribute() = default;
@ -37,7 +37,8 @@ std::string StructMemberOffsetAttribute::Name() const {
const StructMemberOffsetAttribute* StructMemberOffsetAttribute::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<StructMemberOffsetAttribute>(src, offset);
auto expr_ = ctx->Clone(expr);
return ctx->dst->create<StructMemberOffsetAttribute>(src, expr_);
}
} // 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 {
@ -37,8 +38,11 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
/// @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 offset the offset value
StructMemberOffsetAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t offset);
/// @param expr the offset expression
StructMemberOffsetAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* expr);
~StructMemberOffsetAttribute() override;
/// @returns the WGSL name for the attribute
@ -50,8 +54,8 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
/// @return the newly cloned node
const StructMemberOffsetAttribute* Clone(CloneContext* ctx) const override;
/// The offset value
const uint32_t offset;
/// The offset expression
const ast::Expression* const expr;
};
} // namespace tint::ast

View File

@ -17,11 +17,13 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using StructMemberOffsetAttributeTest = TestHelper;
TEST_F(StructMemberOffsetAttributeTest, Creation) {
auto* d = create<StructMemberOffsetAttribute>(2u);
EXPECT_EQ(2u, d->offset);
auto* d = MemberOffset(2_u);
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
}
} // namespace

View File

@ -26,8 +26,8 @@ namespace tint::ast {
StructMemberSizeAttribute::StructMemberSizeAttribute(ProgramID pid,
NodeID nid,
const Source& src,
uint32_t sz)
: Base(pid, nid, src), size(sz) {}
const ast::Expression* exp)
: Base(pid, nid, src), expr(exp) {}
StructMemberSizeAttribute::~StructMemberSizeAttribute() = default;
@ -38,7 +38,8 @@ std::string StructMemberSizeAttribute::Name() const {
const StructMemberSizeAttribute* StructMemberSizeAttribute::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<StructMemberSizeAttribute>(src, size);
auto expr_ = ctx->Clone(expr);
return ctx->dst->create<StructMemberSizeAttribute>(src, expr_);
}
} // namespace tint::ast

View File

@ -19,6 +19,7 @@
#include <string>
#include "src/tint/ast/attribute.h"
#include "src/tint/ast/expression.h"
namespace tint::ast {
@ -29,8 +30,11 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
/// @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 size the size value
StructMemberSizeAttribute(ProgramID pid, NodeID nid, const Source& src, uint32_t size);
/// @param expr the size expression
StructMemberSizeAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* expr);
~StructMemberSizeAttribute() override;
/// @returns the WGSL name for the attribute
@ -42,8 +46,8 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
/// @return the newly cloned node
const StructMemberSizeAttribute* Clone(CloneContext* ctx) const override;
/// The size value
const uint32_t size;
/// The size expression
const ast::Expression* const expr;
};
} // namespace tint::ast

View File

@ -19,11 +19,13 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using StructMemberSizeAttributeTest = TestHelper;
TEST_F(StructMemberSizeAttributeTest, Creation) {
auto* d = create<StructMemberSizeAttribute>(2u);
EXPECT_EQ(2u, d->size);
auto* d = MemberSize(2_u);
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
}
} // namespace

View File

@ -18,10 +18,11 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using StructMemberTest = TestHelper;
TEST_F(StructMemberTest, Creation) {
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4)});
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
EXPECT_EQ(st->symbol, Symbol(1, ID()));
EXPECT_TRUE(st->type->Is<ast::I32>());
EXPECT_EQ(st->attributes.Length(), 1u);
@ -66,7 +67,7 @@ TEST_F(StructMemberTest, Assert_Null_Attribute) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.Member("a", b.ty.i32(), utils::Vector{b.MemberSize(4), nullptr});
b.Member("a", b.ty.i32(), utils::Vector{b.MemberSize(4_a), nullptr});
},
"internal compiler error");
}
@ -76,7 +77,7 @@ TEST_F(StructMemberTest, Assert_DifferentProgramID_Symbol) {
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.Member(b2.Sym("a"), b1.ty.i32(), utils::Vector{b1.MemberSize(4)});
b1.Member(b2.Sym("a"), b1.ty.i32(), utils::Vector{b1.MemberSize(4_a)});
},
"internal compiler error");
}
@ -86,7 +87,7 @@ TEST_F(StructMemberTest, Assert_DifferentProgramID_Attribute) {
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.Member("a", b1.ty.i32(), utils::Vector{b2.MemberSize(4)});
b1.Member("a", b1.ty.i32(), utils::Vector{b2.MemberSize(4_a)});
},
"internal compiler error");
}

View File

@ -2251,25 +2251,37 @@ class ProgramBuilder {
}
/// Creates a ast::StructMemberOffsetAttribute
/// @param val the offset value
/// @param val the offset expression
/// @returns the offset attribute pointer
const ast::StructMemberOffsetAttribute* MemberOffset(uint32_t val) {
return create<ast::StructMemberOffsetAttribute>(source_, val);
template <typename EXPR>
const ast::StructMemberOffsetAttribute* MemberOffset(EXPR&& val) {
return create<ast::StructMemberOffsetAttribute>(source_, Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::StructMemberOffsetAttribute
/// @param source the source information
/// @param val the offset expression
/// @returns the offset attribute pointer
template <typename EXPR>
const ast::StructMemberOffsetAttribute* MemberOffset(const Source& source, EXPR&& val) {
return create<ast::StructMemberOffsetAttribute>(source, Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::StructMemberSizeAttribute
/// @param source the source information
/// @param val the size value
/// @returns the size attribute pointer
const ast::StructMemberSizeAttribute* MemberSize(const Source& source, uint32_t val) {
return create<ast::StructMemberSizeAttribute>(source, val);
template <typename EXPR>
const ast::StructMemberSizeAttribute* MemberSize(const Source& source, EXPR&& val) {
return create<ast::StructMemberSizeAttribute>(source, Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::StructMemberSizeAttribute
/// @param val the size value
/// @returns the size attribute pointer
const ast::StructMemberSizeAttribute* MemberSize(uint32_t val) {
return create<ast::StructMemberSizeAttribute>(source_, val);
template <typename EXPR>
const ast::StructMemberSizeAttribute* MemberSize(EXPR&& val) {
return create<ast::StructMemberSizeAttribute>(source_, Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::StructMemberAlignAttribute
@ -2525,7 +2537,7 @@ class ProgramBuilder {
const ast::StructMember* Member(uint32_t offset, NAME&& name, const ast::Type* type) {
return create<ast::StructMember>(source_, Sym(std::forward<NAME>(name)), type,
utils::Vector<const ast::Attribute*, 1>{
create<ast::StructMemberOffsetAttribute>(offset),
MemberOffset(AInt(offset)),
});
}

View File

@ -464,7 +464,7 @@ ParserImpl::AttributeList ParserImpl::ConvertMemberDecoration(uint32_t struct_ty
return {};
}
return {
create<ast::StructMemberOffsetAttribute>(Source{}, decoration[1]),
builder_.MemberOffset(Source{}, AInt(decoration[1])),
};
case SpvDecorationNonReadable:
// WGSL doesn't have a member decoration for this. Silently drop it.

View File

@ -54,7 +54,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) {
EXPECT_TRUE(result[0]->Is<ast::StructMemberOffsetAttribute>());
auto* offset_deco = result[0]->As<ast::StructMemberOffsetAttribute>();
ASSERT_NE(offset_deco, nullptr);
EXPECT_EQ(offset_deco->offset, 8u);
ASSERT_TRUE(offset_deco->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(offset_deco->expr->As<ast::IntLiteralExpression>()->value, 8u);
EXPECT_TRUE(p->error().empty());
}

View File

@ -3566,7 +3566,7 @@ Maybe<const ast::Attribute*> ParserImpl::attribute() {
}
match(Token::Type::kComma);
return create<ast::StructMemberSizeAttribute>(t.source(), val.value);
return builder_.MemberSize(t.source(), AInt(val.value));
});
}

View File

@ -30,7 +30,8 @@ TEST_F(ParserImplTest, Attribute_Size) {
ASSERT_TRUE(member_attr->Is<ast::StructMemberSizeAttribute>());
auto* o = member_attr->As<ast::StructMemberSizeAttribute>();
EXPECT_EQ(o->size, 4u);
ASSERT_TRUE(o->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(o->expr->As<ast::IntLiteralExpression>()->value, 4u);
}
TEST_F(ParserImplTest, Attribute_Size_TrailingComma) {
@ -46,7 +47,8 @@ TEST_F(ParserImplTest, Attribute_Size_TrailingComma) {
ASSERT_TRUE(member_attr->Is<ast::StructMemberSizeAttribute>());
auto* o = member_attr->As<ast::StructMemberSizeAttribute>();
EXPECT_EQ(o->size, 4u);
ASSERT_TRUE(o->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(o->expr->As<ast::IntLiteralExpression>()->value, 4u);
}
TEST_F(ParserImplTest, Attribute_Size_MissingLeftParen) {

View File

@ -73,8 +73,11 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeAttribute) {
EXPECT_EQ(m->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(m->type->Is<ast::I32>());
EXPECT_EQ(m->attributes.Length(), 1u);
EXPECT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
EXPECT_EQ(m->attributes[0]->As<ast::StructMemberSizeAttribute>()->size, 2u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
auto* s = m->attributes[0]->As<ast::StructMemberSizeAttribute>();
ASSERT_TRUE(s->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(s->expr->As<ast::IntLiteralExpression>()->value, 2u);
EXPECT_EQ(m->source.range, (Source::Range{{1u, 10u}, {1u, 11u}}));
EXPECT_EQ(m->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}}));
@ -95,7 +98,9 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleattributes) {
EXPECT_TRUE(m->type->Is<ast::I32>());
EXPECT_EQ(m->attributes.Length(), 2u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
EXPECT_EQ(m->attributes[0]->As<ast::StructMemberSizeAttribute>()->size, 2u);
auto* size_attr = m->attributes[0]->As<ast::StructMemberSizeAttribute>();
ASSERT_TRUE(size_attr->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(size_attr->expr->As<ast::IntLiteralExpression>()->value, 2u);
ASSERT_TRUE(m->attributes[1]->Is<ast::StructMemberAlignAttribute>());
auto* attr = m->attributes[1]->As<ast::StructMemberAlignAttribute>();

View File

@ -106,9 +106,9 @@ static utils::Vector<const ast::Attribute*, 2> createAttributes(const Source& so
case AttributeKind::kLocation:
return {builder.Location(source, 1_a)};
case AttributeKind::kOffset:
return {builder.create<ast::StructMemberOffsetAttribute>(source, 4u)};
return {builder.MemberOffset(source, 4_a)};
case AttributeKind::kSize:
return {builder.create<ast::StructMemberSizeAttribute>(source, 16u)};
return {builder.MemberSize(source, 16_a)};
case AttributeKind::kStage:
return {builder.Stage(source, ast::PipelineStage::kCompute)};
case AttributeKind::kStride:

View File

@ -2803,11 +2803,22 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
if (auto* o = attr->As<ast::StructMemberOffsetAttribute>()) {
// Offset attributes are not part of the WGSL spec, but are emitted
// by the SPIR-V reader.
if (o->offset < struct_size) {
auto* materialized = Materialize(Expression(o->expr));
if (!materialized) {
return nullptr;
}
auto const_value = materialized->ConstantValue();
if (!const_value) {
AddError("'offset' must be constant expression", o->expr->source);
return nullptr;
}
offset = const_value->As<uint64_t>();
if (offset < struct_size) {
AddError("offsets must be in ascending order", o->source);
return nullptr;
}
offset = o->offset;
align = 1;
has_offset_attr = true;
} else if (auto* a = attr->As<ast::StructMemberAlignAttribute>()) {
@ -2829,13 +2840,24 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
align = const_value->As<u32>();
has_align_attr = true;
} else if (auto* s = attr->As<ast::StructMemberSizeAttribute>()) {
if (s->size < size) {
auto* materialized = Materialize(Expression(s->expr));
if (!materialized) {
return nullptr;
}
auto const_value = materialized->ConstantValue();
if (!const_value) {
AddError("'size' must be constant expression", s->expr->source);
return nullptr;
}
auto value = const_value->As<uint64_t>();
if (value < size) {
AddError("size must be at least as big as the type's size (" +
std::to_string(size) + ")",
s->source);
return nullptr;
}
size = s->size;
size = const_value->As<u32>();
has_size_attr = true;
} else if (auto* l = attr->As<ast::LocationAttribute>()) {
auto* materialize = Materialize(Expression(l->expr));

View File

@ -35,7 +35,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, StorageBuffer_UnalignedMember)
Structure(Source{{12, 34}}, "S",
utils::Vector{
Member("a", ty.f32(), utils::Vector{MemberSize(5)}),
Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_u)}),
});
@ -65,7 +65,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, StorageBuffer_UnalignedMember_S
Structure(Source{{12, 34}}, "S",
utils::Vector{
Member("a", ty.f32(), utils::Vector{MemberSize(5)}),
Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(4_u)}),
});
@ -227,7 +227,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, UniformBuffer_MembersOffsetNotM
Structure(Source{{12, 34}}, "Inner",
utils::Vector{
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5)}),
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5_a)}),
});
Structure(Source{{34, 56}}, "Outer",
@ -279,7 +279,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest,
Member("a", ty.i32()),
Member("b", ty.i32()),
Member("c", ty.i32()),
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5)}),
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5_a)}),
});
Structure(Source{{34, 56}}, "Outer",
@ -327,7 +327,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest,
Structure(Source{{12, 34}}, "Inner",
utils::Vector{
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5)}),
Member("scalar", ty.i32(), utils::Vector{MemberAlign(1_u), MemberSize(5_a)}),
});
Structure(Source{{34, 56}}, "Outer",
@ -550,7 +550,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, PushConstant_UnalignedMember) {
Enable(ast::Extension::kChromiumExperimentalPushConstant);
Structure(
Source{{12, 34}}, "S",
utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5)}),
utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member(Source{{34, 56}}, "b", ty.f32(), utils::Vector{MemberAlign(1_u)})});
GlobalVar(Source{{78, 90}}, "a", ty.type_name("S"), ast::StorageClass::kPushConstant);
@ -575,7 +575,7 @@ TEST_F(ResolverStorageClassLayoutValidationTest, PushConstant_Aligned) {
// };
// var<push_constant> a : S;
Enable(ast::Extension::kChromiumExperimentalPushConstant);
Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5)}),
Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(5_a)}),
Member("b", ty.f32(), utils::Vector{MemberAlign(4_u)})});
GlobalVar("a", ty.type_name("S"), ast::StorageClass::kPushConstant);

View File

@ -400,7 +400,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferArrayF16_TemporallyBan)
Enable(ast::Extension::kF16);
auto* s = Structure(
"S", utils::Vector{Member("a", ty.f16(Source{{56, 78}}), utils::Vector{MemberSize(16)})});
"S", utils::Vector{Member("a", ty.f16(Source{{56, 78}}), utils::Vector{MemberSize(16_a)})});
auto* a = ty.array(ty.Of(s), 3_u);
GlobalVar("g", a, ast::StorageClass::kUniform, Binding(0_a), Group(0_a));
@ -474,7 +474,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferArrayF32) {
// @size(16) f : f32;
// }
// var<uniform> g : array<S, 3u>;
auto* s = Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16)})});
auto* s = Structure("S", utils::Vector{Member("a", ty.f32(), utils::Vector{MemberSize(16_a)})});
auto* a = ty.array(ty.Of(s), 3_u);
GlobalVar(Source{{56, 78}}, "g", a, ast::StorageClass::kUniform, Binding(0_a), Group(0_a));

View File

@ -460,15 +460,15 @@ TEST_F(ResolverStructLayoutTest, NestedStruct) {
TEST_F(ResolverStructLayoutTest, SizeAttributes) {
auto* inner = Structure("Inner", utils::Vector{
Member("a", ty.f32(), utils::Vector{MemberSize(8)}),
Member("b", ty.f32(), utils::Vector{MemberSize(16)}),
Member("c", ty.f32(), utils::Vector{MemberSize(8)}),
Member("a", ty.f32(), utils::Vector{MemberSize(8_a)}),
Member("b", ty.f32(), utils::Vector{MemberSize(16_a)}),
Member("c", ty.f32(), utils::Vector{MemberSize(8_a)}),
});
auto* s = Structure("S", utils::Vector{
Member("a", ty.f32(), utils::Vector{MemberSize(4)}),
Member("b", ty.u32(), utils::Vector{MemberSize(8)}),
Member("a", ty.f32(), utils::Vector{MemberSize(4_a)}),
Member("b", ty.u32(), utils::Vector{MemberSize(8_a)}),
Member("c", ty.Of(inner)),
Member("d", ty.i32(), utils::Vector{MemberSize(32)}),
Member("d", ty.i32(), utils::Vector{MemberSize(32_a)}),
});
ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@ -1257,7 +1257,7 @@ TEST_F(ResolverValidationTest, ZeroStructMemberAlignAttribute) {
TEST_F(ResolverValidationTest, ZeroStructMemberSizeAttribute) {
Structure("S", utils::Vector{
Member("a", ty.f32(), utils::Vector{MemberSize(Source{{12, 34}}, 0)}),
Member("a", ty.f32(), utils::Vector{MemberSize(Source{{12, 34}}, 0_a)}),
});
EXPECT_FALSE(r()->Resolve());
@ -1267,7 +1267,7 @@ TEST_F(ResolverValidationTest, ZeroStructMemberSizeAttribute) {
TEST_F(ResolverValidationTest, OffsetAndSizeAttribute) {
Structure("S", utils::Vector{
Member(Source{{12, 34}}, "a", ty.f32(),
utils::Vector{MemberOffset(0), MemberSize(4)}),
utils::Vector{MemberOffset(0_a), MemberSize(4_a)}),
});
EXPECT_FALSE(r()->Resolve());
@ -1279,7 +1279,7 @@ TEST_F(ResolverValidationTest, OffsetAndSizeAttribute) {
TEST_F(ResolverValidationTest, OffsetAndAlignAttribute) {
Structure("S", utils::Vector{
Member(Source{{12, 34}}, "a", ty.f32(),
utils::Vector{MemberOffset(0), MemberAlign(4_u)}),
utils::Vector{MemberOffset(0_a), MemberAlign(4_u)}),
});
EXPECT_FALSE(r()->Resolve());
@ -1291,7 +1291,7 @@ TEST_F(ResolverValidationTest, OffsetAndAlignAttribute) {
TEST_F(ResolverValidationTest, OffsetAndAlignAndSizeAttribute) {
Structure("S", utils::Vector{
Member(Source{{12, 34}}, "a", ty.f32(),
utils::Vector{MemberOffset(0), MemberAlign(4_u), MemberSize(4)}),
utils::Vector{MemberOffset(0_a), MemberAlign(4_u), MemberSize(4_a)}),
});
EXPECT_FALSE(r()->Resolve());

View File

@ -73,7 +73,7 @@ void DecomposeStridedArray::Run(CloneContext& ctx, const DataMap&, DataMap&) con
auto* member_ty = ctx.Clone(ast->type);
auto* member = ctx.dst->Member(kMemberName, member_ty,
utils::Vector{
ctx.dst->MemberSize(arr->Stride()),
ctx.dst->MemberSize(AInt(arr->Stride())),
});
ctx.dst->Structure(name, utils::Vector{member});
return name;

View File

@ -71,7 +71,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(16u),
b.MemberOffset(16_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -127,7 +127,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(16u),
b.MemberOffset(16_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -180,7 +180,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(16u),
b.MemberOffset(16_u),
b.create<ast::StrideAttribute>(8u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -233,7 +233,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -290,7 +290,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(16u),
b.MemberOffset(16_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -344,7 +344,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -402,7 +402,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -461,7 +461,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -532,7 +532,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),
@ -585,7 +585,7 @@ TEST_F(DecomposeStridedMatrixTest, WritePrivateMatrix) {
"S", utils::Vector{
b.Member("m", b.ty.mat2x2<f32>(),
utils::Vector{
b.create<ast::StructMemberOffsetAttribute>(8u),
b.MemberOffset(8_u),
b.create<ast::StrideAttribute>(32u),
b.Disable(ast::DisabledValidation::kIgnoreStrideAttribute),
}),

View File

@ -246,9 +246,9 @@ struct Std140::State {
// The matrix was @size() annotated with a larger size than the
// natural size for the matrix. This extra padding needs to be
// applied to the last column vector.
attributes.Push(
b.MemberSize(member->Size() - mat->ColumnType()->Size() *
(num_columns - 1)));
attributes.Push(b.MemberSize(
AInt(member->Size() -
mat->ColumnType()->Size() * (num_columns - 1))));
}
// Build the member

View File

@ -212,8 +212,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct_WithOffsetAttributes) {
auto* s = Structure("S", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberOffset(0)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(8)}),
Member("a", ty.i32(), utils::Vector{MemberOffset(0_a)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(8_a)}),
});
GlobalVar("g", ty.Of(s), ast::StorageClass::kPrivate);

View File

@ -221,8 +221,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_WithOffsetAttributes) {
auto* s = Structure("S", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberOffset(0)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(8)}),
Member("a", ty.i32(), utils::Vector{MemberOffset(0_a)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(8_a)}),
});
GlobalVar("g", ty.Of(s), ast::StorageClass::kPrivate);

View File

@ -254,8 +254,8 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_NonComposites) {
auto* s = Structure(
"S", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberSize(32)}),
Member("b", ty.f32(), utils::Vector{MemberAlign(128_u), MemberSize(128)}),
Member("a", ty.i32(), utils::Vector{MemberSize(32_a)}),
Member("b", ty.f32(), utils::Vector{MemberAlign(128_u), MemberSize(128_a)}),
Member("c", ty.vec2<f32>()),
Member("d", ty.u32()),
Member("e", ty.vec3<f32>()),
@ -376,10 +376,11 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_Structures) {
});
// inner_y: size(516), align(4)
auto* inner_y = Structure("inner_y", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberSize(512)}),
Member("b", ty.f32()),
});
auto* inner_y =
Structure("inner_y", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberSize(512_a)}),
Member("b", ty.f32()),
});
auto* s = Structure("S", utils::Vector{
Member("a", ty.i32()),
@ -595,7 +596,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayVec3DefaultStride) {
TEST_F(MslGeneratorImplTest, AttemptTintPadSymbolCollision) {
auto* s = Structure("S", utils::Vector{
// uses symbols tint_pad_[0..9] and tint_pad_[20..35]
Member("tint_pad_2", ty.i32(), utils::Vector{MemberSize(32)}),
Member("tint_pad_2", ty.i32(), utils::Vector{MemberSize(32_a)}),
Member("tint_pad_20", ty.f32(),
utils::Vector{MemberAlign(128_u), MemberSize(128_u)}),
Member("tint_pad_33", ty.vec2<f32>()),

View File

@ -788,7 +788,11 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out,
return true;
},
[&](const ast::StructMemberSizeAttribute* size) {
out << "size(" << size->size << ")";
out << "size(";
if (!EmitExpression(out, size->expr)) {
return false;
}
out << ")";
return true;
},
[&](const ast::StructMemberAlignAttribute* align) {

View File

@ -178,8 +178,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) {
TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl) {
auto* s = Structure("S", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberOffset(8)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(16)}),
Member("a", ty.i32(), utils::Vector{MemberOffset(8_a)}),
Member("b", ty.f32(), utils::Vector{MemberOffset(16_a)}),
});
GeneratorImpl& gen = Build();
@ -199,8 +199,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl) {
TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl_WithSymbolCollisions) {
auto* s =
Structure("S", utils::Vector{
Member("tint_0_padding", ty.i32(), utils::Vector{MemberOffset(8)}),
Member("tint_2_padding", ty.f32(), utils::Vector{MemberOffset(16)}),
Member("tint_0_padding", ty.i32(), utils::Vector{MemberOffset(8_a)}),
Member("tint_2_padding", ty.f32(), utils::Vector{MemberOffset(16_a)}),
});
GeneratorImpl& gen = Build();
@ -237,8 +237,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructAlignDecl) {
TEST_F(WgslGeneratorImplTest, EmitType_StructSizeDecl) {
auto* s = Structure("S", utils::Vector{
Member("a", ty.i32(), utils::Vector{MemberSize(16)}),
Member("b", ty.f32(), utils::Vector{MemberSize(32)}),
Member("a", ty.i32(), utils::Vector{MemberSize(16_a)}),
Member("b", ty.f32(), utils::Vector{MemberSize(32_a)}),
});
GeneratorImpl& gen = Build();