GLSL: emit UBO and SSBO interface blocks.
Do not emit block-decorated structs. Combine them with the variable into a uniform or buffer interface block. Bug: tint:1223 Change-Id: I16263ea449ecab705319dc440275b7d169021bc9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67243 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:
parent
1e896001e6
commit
092326894e
|
@ -130,9 +130,11 @@ bool GeneratorImpl::Generate() {
|
|||
return false;
|
||||
}
|
||||
} else if (auto* str = decl->As<ast::Struct>()) {
|
||||
if (!str->IsBlockDecorated()) {
|
||||
if (!EmitStructType(current_buffer_, builder_.Sem().Get(str))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (auto* func = decl->As<ast::Function>()) {
|
||||
if (func->IsEntryPoint()) {
|
||||
if (!EmitEntryPointFunction(func)) {
|
||||
|
@ -1544,12 +1546,19 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) {
|
|||
bool GeneratorImpl::EmitUniformVariable(const sem::Variable* var) {
|
||||
auto* decl = var->Declaration();
|
||||
auto* type = var->Type()->UnwrapRef();
|
||||
auto out = line();
|
||||
if (!EmitTypeAndName(out, type, ast::StorageClass::kUniform, var->Access(),
|
||||
builder_.Symbols().NameFor(decl->symbol))) {
|
||||
auto* str = type->As<sem::Struct>();
|
||||
if (!str) {
|
||||
TINT_ICE(Writer, builder_.Diagnostics())
|
||||
<< "storage variable must be of struct type";
|
||||
return false;
|
||||
}
|
||||
out << ";";
|
||||
ast::VariableBindingPoint bp = decl->BindingPoint();
|
||||
line() << "layout (set = " << bp.group->value
|
||||
<< ", binding = " << bp.binding->value << ") uniform "
|
||||
<< StructName(str) << " {";
|
||||
EmitStructMembers(current_buffer_, str);
|
||||
auto name = builder_.Symbols().NameFor(decl->symbol);
|
||||
line() << "} " << name << ";";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1557,14 +1566,19 @@ bool GeneratorImpl::EmitUniformVariable(const sem::Variable* var) {
|
|||
bool GeneratorImpl::EmitStorageVariable(const sem::Variable* var) {
|
||||
auto* decl = var->Declaration();
|
||||
auto* type = var->Type()->UnwrapRef();
|
||||
auto out = line();
|
||||
if (!EmitTypeAndName(out, type, ast::StorageClass::kStorage, var->Access(),
|
||||
builder_.Symbols().NameFor(decl->symbol))) {
|
||||
auto* str = type->As<sem::Struct>();
|
||||
if (!str) {
|
||||
TINT_ICE(Writer, builder_.Diagnostics())
|
||||
<< "storage variable must be of struct type";
|
||||
return false;
|
||||
}
|
||||
|
||||
out << ";";
|
||||
|
||||
ast::VariableBindingPoint bp = decl->BindingPoint();
|
||||
line() << "layout (set = " << bp.group->value
|
||||
<< ", binding = " << bp.binding->value << ") buffer "
|
||||
<< StructName(str) << " {";
|
||||
EmitStructMembers(current_buffer_, str);
|
||||
auto name = builder_.Symbols().NameFor(decl->symbol);
|
||||
line() << "} " << name << ";";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -433,11 +433,10 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct UBO {
|
||||
vec4 coord;
|
||||
};
|
||||
|
||||
uniform UBO ubo;
|
||||
layout (set = 1, binding = 0) uniform UBO {
|
||||
vec4 coord;
|
||||
} ubo;
|
||||
|
||||
float sub_func(float param) {
|
||||
return ubo.coord.x;
|
||||
|
@ -484,11 +483,10 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Uniforms {
|
||||
vec4 coord;
|
||||
};
|
||||
|
||||
uniform Uniforms uniforms;
|
||||
layout (set = 1, binding = 0) uniform Uniforms {
|
||||
vec4 coord;
|
||||
} uniforms;
|
||||
|
||||
void frag_main() {
|
||||
float v = uniforms.coord.x;
|
||||
|
@ -536,12 +534,11 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
Data coord;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
float v = coord.b;
|
||||
|
@ -589,12 +586,11 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
Data coord;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
float v = coord.b;
|
||||
|
@ -638,12 +634,11 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
Data coord;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
coord.b = 2.0f;
|
||||
|
@ -688,12 +683,11 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
Data coord;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
coord.b = 2.0f;
|
||||
|
@ -740,11 +734,10 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct S {
|
||||
float x;
|
||||
};
|
||||
|
||||
uniform S coord;
|
||||
layout (set = 1, binding = 0) uniform S {
|
||||
float x;
|
||||
} coord;
|
||||
|
||||
float sub_func(float param) {
|
||||
return coord.x;
|
||||
|
@ -797,11 +790,10 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct S {
|
||||
float x;
|
||||
};
|
||||
|
||||
S coord;
|
||||
layout (set = 1, binding = 0) buffer S {
|
||||
float x;
|
||||
} coord;
|
||||
|
||||
float sub_func(float param) {
|
||||
return coord.x;
|
||||
|
@ -1064,11 +1056,10 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
float d;
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 0, binding = 0) buffer Data {
|
||||
float d;
|
||||
} data;
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
void a() {
|
||||
|
|
|
@ -296,12 +296,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Matrix_Empty) {
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
int a;
|
||||
mat2x3 b;
|
||||
};
|
||||
|
||||
Data data;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.b = mat2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
@ -343,12 +342,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
float z;
|
||||
mat4x3 a;
|
||||
};
|
||||
|
||||
Data data;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.a[2][1];
|
||||
|
@ -388,12 +386,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
Data data;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
int x = data.a[2];
|
||||
|
@ -434,12 +431,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
Data data;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
int x = data.a[((2 + 4) - 3)];
|
||||
|
@ -477,12 +473,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) {
|
|||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
Data data;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.a[2] = 2;
|
||||
|
@ -535,11 +530,10 @@ struct Inner {
|
|||
vec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
vec3 x = data.c[2].b;
|
||||
|
@ -595,11 +589,10 @@ struct Inner {
|
|||
vec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
vec2 x = data.c[2].b.xy;
|
||||
|
@ -655,11 +648,10 @@ struct Inner {
|
|||
vec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.c[2].b.g;
|
||||
|
@ -715,11 +707,10 @@ struct Inner {
|
|||
vec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.c[2].b[1];
|
||||
|
@ -771,11 +762,10 @@ struct Inner {
|
|||
vec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.c[2].b = vec3(1.0f, 2.0f, 3.0f);
|
||||
|
@ -831,11 +821,10 @@ struct Inner {
|
|||
ivec3 a;
|
||||
vec3 b;
|
||||
};
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
Data data;
|
||||
layout (set = 1, binding = 0) buffer Data {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.c[2].b.y = 1.0f;
|
||||
|
|
|
@ -51,11 +51,10 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength) {
|
|||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct my_struct {
|
||||
float a[0];
|
||||
};
|
||||
|
||||
my_struct b;
|
||||
layout (set = 2, binding = 1) buffer my_struct {
|
||||
float a[0];
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint tint_symbol_1 = 0u;
|
||||
|
@ -103,12 +102,11 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) {
|
|||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct my_struct {
|
||||
|
||||
layout (set = 2, binding = 1) buffer my_struct {
|
||||
float z;
|
||||
float a[0];
|
||||
};
|
||||
|
||||
my_struct b;
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint tint_symbol_1 = 0u;
|
||||
|
@ -158,11 +156,10 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) {
|
|||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct my_struct {
|
||||
float a[0];
|
||||
};
|
||||
|
||||
my_struct b;
|
||||
layout (set = 2, binding = 1) buffer my_struct {
|
||||
float a[0];
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint tint_symbol_1 = 0u;
|
||||
|
|
Loading…
Reference in New Issue