From 7d80c2783a93878e6b7ceeb5eb28ee49006cf870 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 15 Mar 2021 21:59:42 +0000 Subject: [PATCH] validator_decoration_test: Handle new size / align decorations Bug: tint:626 Change-Id: Ibaaff85d4cd2e0a0bce05006d2bf74ca884a8db0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44783 Auto-Submit: Ben Clayton Commit-Queue: James Price Reviewed-by: James Price --- src/validator/validator_decoration_test.cc | 68 +++++++++++++--------- src/validator/validator_impl.cc | 6 +- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/validator/validator_decoration_test.cc b/src/validator/validator_decoration_test.cc index 58ab2d5576..a9b8de7615 100644 --- a/src/validator/validator_decoration_test.cc +++ b/src/validator/validator_decoration_test.cc @@ -20,7 +20,9 @@ #include "src/ast/location_decoration.h" #include "src/ast/stage_decoration.h" #include "src/ast/struct_block_decoration.h" +#include "src/ast/struct_member_align_decoration.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/ast/struct_member_size_decoration.h" #include "src/ast/workgroup_decoration.h" #include "src/validator/validator_test_helper.h" @@ -29,15 +31,17 @@ namespace { enum class DecorationKind { kAccess, + kAlign, kBinding, kBuiltin, kConstantId, kGroup, kLocation, + kOffset, + kSize, kStage, kStride, kStructBlock, - kStructMemberOffset, kWorkgroup, }; struct DecorationTestParams { @@ -54,26 +58,30 @@ ast::Decoration* createDecoration(ProgramBuilder& builder, case DecorationKind::kAccess: return builder.create( ast::AccessControl::kReadOnly); - case DecorationKind::kLocation: - return builder.create(1); + case DecorationKind::kAlign: + return builder.create(4u); case DecorationKind::kBinding: return builder.create(1); - case DecorationKind::kGroup: - return builder.create(1u); case DecorationKind::kBuiltin: return builder.create(ast::Builtin::kPosition); - case DecorationKind::kWorkgroup: - return builder.create(1u, 1u, 1u); - case DecorationKind::kStage: - return builder.create(ast::PipelineStage::kCompute); - case DecorationKind::kStructBlock: - return builder.create(); - case DecorationKind::kStride: - return builder.create(4u); - case DecorationKind::kStructMemberOffset: - return builder.create(4u); case DecorationKind::kConstantId: return builder.create(0u); + case DecorationKind::kGroup: + return builder.create(1u); + case DecorationKind::kLocation: + return builder.create(1); + case DecorationKind::kOffset: + return builder.create(4u); + case DecorationKind::kSize: + return builder.create(4u); + case DecorationKind::kStage: + return builder.create(ast::PipelineStage::kCompute); + case DecorationKind::kStride: + return builder.create(4u); + case DecorationKind::kStructBlock: + return builder.create(); + case DecorationKind::kWorkgroup: + return builder.create(1u, 1u, 1u); } return nullptr; } @@ -103,16 +111,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, ArrayDecorationTest, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, false}, DecorationTestParams{DecorationKind::kBinding, false}, DecorationTestParams{DecorationKind::kBuiltin, false}, DecorationTestParams{DecorationKind::kConstantId, false}, DecorationTestParams{DecorationKind::kGroup, false}, DecorationTestParams{DecorationKind::kLocation, false}, + DecorationTestParams{DecorationKind::kOffset, false}, + DecorationTestParams{DecorationKind::kSize, false}, DecorationTestParams{DecorationKind::kStage, false}, DecorationTestParams{DecorationKind::kStride, true}, DecorationTestParams{DecorationKind::kStructBlock, false}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - false}, DecorationTestParams{DecorationKind::kWorkgroup, false})); using FunctionDecorationTest = ValidatorDecorationsTestWithParams; @@ -137,16 +146,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, FunctionDecorationTest, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, false}, DecorationTestParams{DecorationKind::kBinding, false}, DecorationTestParams{DecorationKind::kBuiltin, false}, DecorationTestParams{DecorationKind::kConstantId, false}, DecorationTestParams{DecorationKind::kGroup, false}, DecorationTestParams{DecorationKind::kLocation, false}, + DecorationTestParams{DecorationKind::kOffset, false}, + DecorationTestParams{DecorationKind::kSize, false}, // Skip kStage as we always apply it in this test DecorationTestParams{DecorationKind::kStride, false}, DecorationTestParams{DecorationKind::kStructBlock, false}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - false}, DecorationTestParams{DecorationKind::kWorkgroup, true})); using FunctionReturnTypeDecorationTest = ValidatorDecorationsTestWithParams; @@ -172,16 +182,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, FunctionReturnTypeDecorationTest, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, false}, DecorationTestParams{DecorationKind::kBinding, false}, DecorationTestParams{DecorationKind::kBuiltin, true}, DecorationTestParams{DecorationKind::kConstantId, false}, DecorationTestParams{DecorationKind::kGroup, false}, DecorationTestParams{DecorationKind::kLocation, true}, + DecorationTestParams{DecorationKind::kOffset, false}, + DecorationTestParams{DecorationKind::kSize, false}, DecorationTestParams{DecorationKind::kStage, false}, DecorationTestParams{DecorationKind::kStride, false}, DecorationTestParams{DecorationKind::kStructBlock, false}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - false}, DecorationTestParams{DecorationKind::kWorkgroup, false})); using StructDecorationTest = ValidatorDecorationsTestWithParams; @@ -206,16 +217,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, StructDecorationTest, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, false}, DecorationTestParams{DecorationKind::kBinding, false}, DecorationTestParams{DecorationKind::kBuiltin, false}, DecorationTestParams{DecorationKind::kConstantId, false}, DecorationTestParams{DecorationKind::kGroup, false}, DecorationTestParams{DecorationKind::kLocation, false}, + DecorationTestParams{DecorationKind::kOffset, false}, + DecorationTestParams{DecorationKind::kSize, false}, DecorationTestParams{DecorationKind::kStage, false}, DecorationTestParams{DecorationKind::kStride, false}, DecorationTestParams{DecorationKind::kStructBlock, true}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - false}, DecorationTestParams{DecorationKind::kWorkgroup, false})); using StructMemberDecorations = ValidatorDecorationsTestWithParams; @@ -241,16 +253,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, StructMemberDecorations, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, true}, DecorationTestParams{DecorationKind::kBinding, false}, DecorationTestParams{DecorationKind::kBuiltin, true}, DecorationTestParams{DecorationKind::kConstantId, false}, DecorationTestParams{DecorationKind::kGroup, false}, DecorationTestParams{DecorationKind::kLocation, true}, + DecorationTestParams{DecorationKind::kOffset, true}, + DecorationTestParams{DecorationKind::kSize, true}, DecorationTestParams{DecorationKind::kStage, false}, DecorationTestParams{DecorationKind::kStride, false}, DecorationTestParams{DecorationKind::kStructBlock, false}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - true}, DecorationTestParams{DecorationKind::kWorkgroup, false})); using VariableDecorationTest = ValidatorDecorationsTestWithParams; @@ -273,16 +286,17 @@ INSTANTIATE_TEST_SUITE_P( ValidatorTest, VariableDecorationTest, testing::Values(DecorationTestParams{DecorationKind::kAccess, false}, + DecorationTestParams{DecorationKind::kAlign, false}, DecorationTestParams{DecorationKind::kBinding, true}, DecorationTestParams{DecorationKind::kBuiltin, true}, DecorationTestParams{DecorationKind::kConstantId, true}, DecorationTestParams{DecorationKind::kGroup, true}, DecorationTestParams{DecorationKind::kLocation, true}, + DecorationTestParams{DecorationKind::kOffset, false}, + DecorationTestParams{DecorationKind::kSize, false}, DecorationTestParams{DecorationKind::kStage, false}, DecorationTestParams{DecorationKind::kStride, false}, DecorationTestParams{DecorationKind::kStructBlock, false}, - DecorationTestParams{DecorationKind::kStructMemberOffset, - false}, DecorationTestParams{DecorationKind::kWorkgroup, false})); } // namespace diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index 1b18e68cf1..3a957d4ee8 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -23,7 +23,9 @@ #include "src/ast/stage_decoration.h" #include "src/ast/stride_decoration.h" #include "src/ast/struct_block_decoration.h" +#include "src/ast/struct_member_align_decoration.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/ast/struct_member_size_decoration.h" #include "src/ast/uint_literal.h" #include "src/ast/workgroup_decoration.h" #include "src/semantic/call.h" @@ -127,7 +129,9 @@ bool ValidatorImpl::ValidateConstructedType(const type::Type* type) { for (auto* deco : member->decorations()) { if (!(deco->Is() || deco->Is() || - deco->Is())) { + deco->Is() || + deco->Is() || + deco->Is())) { add_error(deco->source(), "decoration is not valid for structure members"); return false;