GLSL: Don't use a typedef for array returns.

Covered by GlslGeneratorImplTest_Function.Emit_Function_WithArrayReturn

Bug: tint:1258
Change-Id: I181641ebe170ec359d9833e9022e6e70747fde9a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67240
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2021-10-21 20:43:15 +00:00 committed by Tint LUCI CQ
parent f164a4a723
commit 1e896001e6
2 changed files with 4 additions and 19 deletions

View File

@ -1465,24 +1465,10 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
{ {
auto out = line(); auto out = line();
auto name = builder_.Symbols().NameFor(func->symbol); auto name = builder_.Symbols().NameFor(func->symbol);
// If the function returns an array, then we need to declare a typedef for
// this.
if (sem->ReturnType()->Is<sem::Array>()) {
auto typedef_name = UniqueIdentifier(name + "_ret");
auto pre = line();
pre << "typedef ";
if (!EmitTypeAndName(pre, sem->ReturnType(), ast::StorageClass::kNone,
ast::Access::kReadWrite, typedef_name)) {
return false;
}
pre << ";";
out << typedef_name;
} else {
if (!EmitType(out, sem->ReturnType(), ast::StorageClass::kNone, if (!EmitType(out, sem->ReturnType(), ast::StorageClass::kNone,
ast::Access::kReadWrite, "")) { ast::Access::kReadWrite, "")) {
return false; return false;
} }
}
out << " " << name << "("; out << " " << name << "(";

View File

@ -999,8 +999,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayReturn) {
EXPECT_EQ(gen.result(), R"(#version 310 es EXPECT_EQ(gen.result(), R"(#version 310 es
precision mediump float; precision mediump float;
typedef float my_func_ret[5]; float[5] my_func() {
my_func_ret my_func() {
return float[5](0.0f, 0.0f, 0.0f, 0.0f, 0.0f); return float[5](0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
} }
)"); )");