[glsl][ir] Force entry point name to `main`.
The GLSL backend requires a single entry point, and that it is named
`main`. This cl changes the printer to always emit `main` as the entry
point name. This means we must run single-entrypoint, but that currently
always happens anyway.
Bug: 42251044
Change-Id: Ide08106b42fb3577379ec987dd620b366c375908
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/204374
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/glsl/writer/constant_test.cc b/src/tint/lang/glsl/writer/constant_test.cc
index a93d1a9..99739f8 100644
--- a/src/tint/lang/glsl/writer/constant_test.cc
+++ b/src/tint/lang/glsl/writer/constant_test.cc
@@ -43,7 +43,7 @@
return false;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -58,7 +58,7 @@
return true;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -73,7 +73,7 @@
return -12345;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -88,7 +88,7 @@
return (-2147483647 - 1);
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -103,7 +103,7 @@
return 56779u;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -119,7 +119,7 @@
return 1073741824.0f;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
@@ -136,7 +136,7 @@
return 32752.0hf;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
diff --git a/src/tint/lang/glsl/writer/function_test.cc b/src/tint/lang/glsl/writer/function_test.cc
index 8b005f9..91a5564 100644
--- a/src/tint/lang/glsl/writer/function_test.cc
+++ b/src/tint/lang/glsl/writer/function_test.cc
@@ -53,7 +53,7 @@
void my_func(float a, int b) {
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void unused_entry_point() {
+void main() {
}
)");
}
diff --git a/src/tint/lang/glsl/writer/printer/printer.cc b/src/tint/lang/glsl/writer/printer/printer.cc
index ec54a22..855db24 100644
--- a/src/tint/lang/glsl/writer/printer/printer.cc
+++ b/src/tint/lang/glsl/writer/printer/printer.cc
@@ -185,7 +185,18 @@
// TODO(dsinclair): Handle return type attributes
EmitType(out, func->ReturnType());
- out << " " << ir_.NameOf(func).Name() << "(";
+ out << " ";
+
+ // Switch the entry point name to `main`. This makes the assumption that single entry
+ // point is always run for GLSL, which is has to be, there can be only one entry point.
+ // So, we swap the entry point name to `main` which is required for GLSL.
+ if (func->Stage() != core::ir::Function::PipelineStage::kUndefined) {
+ out << "main";
+ } else {
+ out << ir_.NameOf(func).Name();
+ }
+
+ out << "(";
size_t i = 0;
for (auto* param : func->Params()) {
diff --git a/src/tint/lang/glsl/writer/type_test.cc b/src/tint/lang/glsl/writer/type_test.cc
index e717b37..b90b222 100644
--- a/src/tint/lang/glsl/writer/type_test.cc
+++ b/src/tint/lang/glsl/writer/type_test.cc
@@ -55,7 +55,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
bool a[4] = bool[4](false, false, false, false);
}
)");
@@ -72,7 +72,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
bool a[5][4] = bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false));
}
)");
@@ -90,7 +90,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
bool a[6][5][4] = bool[6][5][4](bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)), bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)), bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)), bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)), bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)), bool[5][4](bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false), bool[4](false, false, false, false)));
}
)");
@@ -107,7 +107,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
bool a = false;
}
)");
@@ -124,7 +124,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
float a = 0.0f;
}
)");
@@ -142,7 +142,7 @@
EXPECT_EQ(output_.glsl, GlslHeader() + R"(#extension GL_AMD_gpu_shader_half_float: require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
float16_t a = 0.0hf;
}
)");
@@ -159,7 +159,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
int a = 0;
}
)");
@@ -176,7 +176,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
mat2x3 a = mat2x3(vec3(0.0f), vec3(0.0f));
}
)");
@@ -193,7 +193,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
mat2 a = mat2(vec2(0.0f), vec2(0.0f));
}
)");
@@ -211,7 +211,7 @@
EXPECT_EQ(output_.glsl, GlslHeader() + R"(#extension GL_AMD_gpu_shader_half_float: require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
f16mat2x3 a = f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf));
}
)");
@@ -228,7 +228,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
uint a = 0u;
}
)");
@@ -245,7 +245,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo(inout uint a) {
+void main(inout uint a) {
}
)");
}
@@ -261,7 +261,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo(inout int a) {
+void main(inout int a) {
}
)");
}
@@ -277,7 +277,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
vec3 a = vec3(0.0f);
}
)");
@@ -295,7 +295,7 @@
EXPECT_EQ(output_.glsl, GlslHeader() + R"(#extension GL_AMD_gpu_shader_half_float: require
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
f16vec3 a = f16vec3(0.0hf);
}
)");
@@ -312,7 +312,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
ivec2 a = ivec2(0);
}
)");
@@ -329,7 +329,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
uvec4 a = uvec4(0u);
}
)");
@@ -346,7 +346,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
bvec3 a = bvec3(false);
}
)");
@@ -361,7 +361,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
}
)");
}
@@ -386,7 +386,7 @@
};
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
S a = S(0, 0.0f);
}
)");
@@ -413,7 +413,7 @@
};
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
S a = S(0, 0.0f);
S b = S(0, 0.0f);
}
@@ -451,7 +451,7 @@
};
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
S a = S(0, Inner(0u, vec4(0.0f)));
}
)");
@@ -468,7 +468,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
}
)");
}
@@ -484,7 +484,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo() {
+void main() {
}
)");
}
@@ -514,7 +514,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, GlslHeader() + R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo()" + params.result +
+void main()" + params.result +
R"( a) {
}
)");
@@ -540,7 +540,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo(sampler2DMS a) {
+void main(sampler2DMS a) {
}
)");
}
@@ -590,7 +590,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo()" + params.result +
+void main()" + params.result +
R"( a) {
}
)");
@@ -638,7 +638,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo(usampler2DMS a) {
+void main(usampler2DMS a) {
}
)");
}
@@ -669,7 +669,7 @@
ASSERT_TRUE(Generate()) << err_ << output_.glsl;
EXPECT_EQ(output_.glsl, R"(
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void foo()" + params.result +
+void main()" + params.result +
R"( a) {
}
)");