[spirv-reader][ir] Add validation for struct member matrix annotations. Add validation that the struct member annotations for row major and matrix stride are not used. Add a capability to allow them. Bug: 426198644, 426198893 Change-Id: I87cae4efb264b90ece5b6cf6f5fd398db608378f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/249034 Reviewed-by: James Price <jrprice@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/ir/validator.cc b/src/tint/lang/core/ir/validator.cc index 85be9c9..3989869 100644 --- a/src/tint/lang/core/ir/validator.cc +++ b/src/tint/lang/core/ir/validator.cc
@@ -1843,6 +1843,23 @@ return tint::Switch( type, + [&](const core::type::Struct* str) { + if (capabilities_.Contains(Capability::kAllowStructMatrixDecorations)) { + return true; + } + + for (auto* member : str->Members()) { + if (member->RowMajor()) { + diag() << "Row major annotation now allowed on structures"; + return false; + } + if (member->HasMatrixStride()) { + diag() << "Matrix stride annotation not allowed on structures"; + return false; + } + } + return true; + }, [&](const core::type::Reference* ref) { if (ref->StoreType()->Is<core::type::Void>()) { diag() << "references to void are not permitted";
diff --git a/src/tint/lang/core/ir/validator.h b/src/tint/lang/core/ir/validator.h index 36f9ed2..bed083f 100644 --- a/src/tint/lang/core/ir/validator.h +++ b/src/tint/lang/core/ir/validator.h
@@ -79,6 +79,8 @@ kAllowUnannotatedModuleIOVariables, /// Allows non-core types in the IR module kAllowNonCoreTypes, + /// Allows matrix annotations on structure members + kAllowStructMatrixDecorations, }; /// Capabilities is a set of Capability
diff --git a/src/tint/lang/spirv/reader/parser/helper_test.h b/src/tint/lang/spirv/reader/parser/helper_test.h index 6c09bfa..61de210 100644 --- a/src/tint/lang/spirv/reader/parser/helper_test.h +++ b/src/tint/lang/spirv/reader/parser/helper_test.h
@@ -85,6 +85,7 @@ core::ir::Capability::kAllowPhonyInstructions, core::ir::Capability::kAllowVectorElementPointer, core::ir::Capability::kAllowNonCoreTypes, + core::ir::Capability::kAllowStructMatrixDecorations, }); if (validated != Success) { return validated.Failure();