validation: structure containing a RTA cannot be used as a uniform buffer

Bug: tint:294
Change-Id: I47a87d902c3bc0df6f62712b7461f51a0f292343
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54860
Auto-Submit: Sarah Mashayekhi <sarahmashay@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Sarah 2021-06-16 19:40:13 +00:00 committed by Sarah Mashayekhi
parent 10442eff7d
commit 52b6a004b8
2 changed files with 33 additions and 1 deletions

View File

@ -744,6 +744,21 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
} }
return false; return false;
} }
for (auto* member : str->Members()) {
if (auto* arr = member->Type()->As<sem::Array>()) {
if (arr->IsRuntimeSized()) {
diagnostics_.add_error(
"structure containing a runtime sized array "
"cannot be used as a uniform buffer",
info->declaration->source());
diagnostics_.add_note("structure is declared here",
str->Declaration()->source());
return false;
}
}
}
break; break;
} }
default: default:

View File

@ -152,7 +152,24 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferNoError_Aliases) {
ASSERT_TRUE(r()->Resolve()); ASSERT_TRUE(r()->Resolve());
} }
/// TEST_F(ResolverStorageClassValidationTest, UniformBuffer_Struct_Runtime) {
// [[block]] struct S { m: array<f32>; };
// [[set(0), binding(0)]] var<uniform, > svar : S;
auto* s = Structure(Source{{12, 34}}, "S", {Member("m", ty.array<i32>())},
{create<ast::StructBlockDecoration>()});
Global(Source{{56, 78}}, "svar", ty.Of(s), ast::StorageClass::kUniform,
ast::DecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
ASSERT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"56:78 error: structure containing a runtime sized array cannot be "
"used as a uniform buffer\n12:34 note: structure is declared here");
}
TEST_F(ResolverStorageClassValidationTest, UniformBufferBool) { TEST_F(ResolverStorageClassValidationTest, UniformBufferBool) {
// var<uniform> g : bool; // var<uniform> g : bool;