Fix storage buffer structs, test output.

Bug: tint:1223
Change-Id: Idbf8f882f44a7bc3dc51bd046d48da3b78a609e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66362
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Stephen White 2021-10-15 19:52:50 +00:00 committed by Tint LUCI CQ
parent 186618dfef
commit 540992ba90
5 changed files with 95 additions and 43 deletions

View File

@ -2290,12 +2290,6 @@ bool GeneratorImpl::EmitType(std::ostream& out,
const sem::Type* base_type = ary;
std::vector<uint32_t> sizes;
while (auto* arr = base_type->As<sem::Array>()) {
if (arr->IsRuntimeSized()) {
TINT_ICE(Writer, diagnostics_)
<< "Runtime arrays may only exist in storage buffers, which should "
"have been transformed into a ByteAddressBuffer";
return false;
}
sizes.push_back(arr->Count());
base_type = arr->ElemType();
}
@ -2449,14 +2443,6 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out,
bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
auto storage_class_uses = str->StorageClassUsage();
if (storage_class_uses.size() ==
(storage_class_uses.count(ast::StorageClass::kStorage))) {
// The only use of the structure is as a storage buffer.
// Structures used as storage buffer are read and written to via a
// ByteAddressBuffer instead of true structure.
return true;
}
line(b) << "struct " << StructName(str) << " {";
{
ScopedIndent si(b);
@ -2471,14 +2457,7 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
if (auto* decl = mem->Declaration()) {
for (auto* deco : decl->decorations) {
if (deco->As<ast::LocationDecoration>()) {
auto& pipeline_stage_uses = str->PipelineStageUses();
if (pipeline_stage_uses.size() != 1) {
TINT_ICE(Writer, diagnostics_)
<< "invalid entry point IO struct uses";
}
} else if (auto* interpolate =
deco->As<ast::InterpolateDecoration>()) {
if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) {
auto mod = interpolation_to_modifiers(interpolate->type,
interpolate->sampling);
if (mod.empty()) {

View File

@ -536,6 +536,10 @@ TEST_F(GlslGeneratorImplTest_Function,
EXPECT_EQ(gen.result(), R"(#version 310 es
precision mediump float;
struct Data {
int a;
float b;
};
Data coord;
@ -585,6 +589,10 @@ TEST_F(GlslGeneratorImplTest_Function,
R"(#version 310 es
precision mediump float;
struct Data {
int a;
float b;
};
Data coord;
@ -630,6 +638,10 @@ TEST_F(GlslGeneratorImplTest_Function,
EXPECT_EQ(gen.result(), R"(#version 310 es
precision mediump float;
struct Data {
int a;
float b;
};
Data coord;
@ -676,6 +688,10 @@ TEST_F(GlslGeneratorImplTest_Function,
EXPECT_EQ(gen.result(), R"(#version 310 es
precision mediump float;
struct Data {
int a;
float b;
};
Data coord;
@ -781,6 +797,9 @@ TEST_F(GlslGeneratorImplTest_Function,
R"(#version 310 es
precision mediump float;
struct S {
float x;
};
S coord;
@ -1046,6 +1065,9 @@ TEST_F(GlslGeneratorImplTest_Function,
EXPECT_EQ(gen.result(), R"(#version 310 es
precision mediump float;
struct Data {
float d;
};
Data data;

View File

@ -296,6 +296,10 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Matrix_Empty) {
R"(#version 310 es
precision mediump float;
struct Data {
int a;
mat2x3 b;
};
Data data;
@ -339,6 +343,10 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Data {
float z;
mat4x3 a;
};
Data data;
@ -380,6 +388,10 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Data {
float z;
int a[5];
};
Data data;
@ -422,6 +434,10 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Data {
float z;
int a[5];
};
Data data;
@ -461,6 +477,10 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) {
R"(#version 310 es
precision mediump float;
struct Data {
float z;
int a[5];
};
Data data;
@ -511,6 +531,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) {
R"(#version 310 es
precision mediump float;
struct Inner {
vec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;
@ -564,6 +591,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Inner {
vec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;
@ -617,6 +651,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Inner {
vec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;
@ -670,6 +711,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Inner {
vec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;
@ -719,6 +767,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_MultiLevel) {
R"(#version 310 es
precision mediump float;
struct Inner {
vec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;
@ -772,6 +827,13 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
R"(#version 310 es
precision mediump float;
struct Inner {
ivec3 a;
vec3 b;
};
struct Data {
Inner c[4];
};
Data data;

View File

@ -51,6 +51,9 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength) {
auto* expect = R"(#version 310 es
precision mediump float;
struct my_struct {
float a[0];
};
my_struct b;
@ -100,6 +103,10 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) {
auto* expect = R"(#version 310 es
precision mediump float;
struct my_struct {
float z;
float a[0];
};
my_struct b;
@ -151,6 +158,9 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) {
auto* expect = R"(#version 310 es
precision mediump float;
struct my_struct {
float a[0];
};
my_struct b;

View File

@ -183,27 +183,6 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_StructDecl) {
)");
}
TEST_F(GlslGeneratorImplTest_Type, EmitType_StructDecl_OmittedIfStorageBuffer) {
auto* s = Structure("S",
{
Member("a", ty.i32()),
Member("b", ty.f32()),
},
{create<ast::StructBlockDecoration>()});
Global("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite,
ast::DecorationList{
create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(0),
});
GeneratorImpl& gen = Build();
TextGenerator::TextBuffer buf;
auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error();
EXPECT_EQ(buf.String(), "");
}
TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct) {
auto* s = Structure("S", {
Member("a", ty.i32()),