[Piglit] [PATCH] piglit: Add tests to validate switch statements in OpenGL 3.0.

Dan McCabe zen3d.linux at gmail.com
Sun Aug 21 18:27:57 PDT 2011


Two sets of tests are included in this change set.

The first set of 26 tests validates compiler support. Included are tests
that test both positvely and negatively that the compiler processed valid
switch statements and detected syntax errors.

The second set of 3 tests validates that the execution the the generated
code is correct. This set generate four quadrants of color. In the test of
the switch statement alone, these quadrants are red, green, blue and white.
The second and third tests validate interactions between loops and switch
statement, nesting one inside the other. The loops compute "random" colors
at each pixel where white was drawn in the first test.
---
 .../switch-case-const-int-expression.vert          |   23 +++++++
 .../switch-statement/switch-case-const-int.vert    |   20 ++++++
 .../switch-statement/switch-case-empty-end.vert    |   19 ++++++
 .../switch-statement/switch-case-fallthrough.vert  |   22 +++++++
 .../switch-statement/switch-case-in-int.vert       |   21 ++++++
 .../switch-statement/switch-case-statement.vert    |   23 +++++++
 .../switch-statement/switch-case-uniform-int.vert  |   21 ++++++
 .../compiler/switch-statement/switch-default.vert  |   20 ++++++
 .../switch-expression-const-float.vert             |   17 +++++
 .../switch-expression-const-int.vert               |   17 +++++
 .../switch-expression-const-vec2.vert              |   17 +++++
 .../switch-expression-in-float.vert                |   19 ++++++
 .../switch-statement/switch-expression-in-int.vert |   19 ++++++
 .../switch-expression-in-vec2.vert                 |   19 ++++++
 .../switch-expression-uniform-float.vert           |   19 ++++++
 .../switch-expression-uniform-int.vert             |   19 ++++++
 .../switch-expression-uniform-vec2.vert            |   19 ++++++
 .../switch-expression-var-float.vert               |   18 +++++
 .../switch-expression-var-int.vert                 |   18 +++++
 .../switch-expression-var-vec2.vert                |   18 +++++
 .../switch-statement/switch-nested-break.vert      |   21 ++++++
 .../switch-statement/switch-nested-case.vert       |   20 ++++++
 .../switch-statement/switch-nested-default.vert    |   18 +++++
 .../switch-statement/switch-nested-loop.vert       |   18 +++++
 .../switch-statement/switch-nested-switch.vert     |   16 +++++
 .../spec/glsl-1.30/execution/switch/switch-01.frag |   33 ++++++++++
 .../glsl-1.30/execution/switch/switch-01.frag.sav  |    8 +++
 .../execution/switch/switch-01.shader_test         |   44 +++++++++++++
 .../spec/glsl-1.30/execution/switch/switch-01.vert |    6 ++
 .../spec/glsl-1.30/execution/switch/switch-02.frag |   67 ++++++++++++++++++++
 .../execution/switch/switch-02.shader_test         |   43 +++++++++++++
 .../spec/glsl-1.30/execution/switch/switch-02.vert |    6 ++
 .../spec/glsl-1.30/execution/switch/switch-03.frag |   57 +++++++++++++++++
 .../execution/switch/switch-03.shader_test         |   43 +++++++++++++
 .../spec/glsl-1.30/execution/switch/switch-03.vert |    6 ++
 35 files changed, 794 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int-expression.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-empty-end.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-fallthrough.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-in-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-statement.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-default.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-float.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-vec2.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-float.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-vec2.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-float.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-vec2.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-float.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-int.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-vec2.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-break.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-case.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-default.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-loop.vert
 create mode 100644 tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-switch.vert
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-01.frag
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-01.frag.sav
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-01.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-01.vert
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-02.frag
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-02.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-02.vert
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-03.frag
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-03.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/switch/switch-03.vert

diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int-expression.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int-expression.vert
new file mode 100644
index 0000000..169cf53
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int-expression.vert
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+#define one 1
+#define two 2
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case one + two:
+      tmp = 1;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int.vert
new file mode 100644
index 0000000..b971945
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-const-int.vert
@@ -0,0 +1,20 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 0:
+      tmp = 1;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-empty-end.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-empty-end.vert
new file mode 100644
index 0000000..456b2a1
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-empty-end.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Last case must not be empty.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    ... it is an error to have no statement between a label 
+//    and the end of the switch statement.
+
+ 
+#version 130
+
+void main() {
+   switch (1) {
+   case 0:
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-fallthrough.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-fallthrough.vert
new file mode 100644
index 0000000..64be6bf
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-fallthrough.vert
@@ -0,0 +1,22 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 1:
+      tmp = 1;
+   default:
+      tmp = 0;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-in-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-in-int.vert
new file mode 100644
index 0000000..2814c10
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-in-int.vert
@@ -0,0 +1,21 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Case expressions must by constant integer expressions.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    Production for switch-statement.
+
+#version 130
+
+in int src;
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case v:
+      tmp = 1;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-statement.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-statement.vert
new file mode 100644
index 0000000..af4c300
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-statement.vert
@@ -0,0 +1,23 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Case expressions must by constant integer expressions.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    Production for switch-statement.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 0:
+      tmp = 1;
+      break;
+   default:
+      tmp = 2;
+      break;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert
new file mode 100644
index 0000000..a2babf8
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert
@@ -0,0 +1,21 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Case expressions must by constant integer expressions.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    Production for switch-statement.
+
+#version 130
+
+uniform int src;
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case src:
+      tmp = 1;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-default.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-default.vert
new file mode 100644
index 0000000..f8a07d8
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-default.vert
@@ -0,0 +1,20 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   default:
+      tmp = 1;
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-float.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-float.vert
new file mode 100644
index 0000000..5ef71df
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-float.vert
@@ -0,0 +1,17 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   switch (1.5) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-int.vert
new file mode 100644
index 0000000..23be58e
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-int.vert
@@ -0,0 +1,17 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   switch (1) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-vec2.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-vec2.vert
new file mode 100644
index 0000000..753159f
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-const-vec2.vert
@@ -0,0 +1,17 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   switch (vec2(0, 0)) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-float.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-float.vert
new file mode 100644
index 0000000..59a267c
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-float.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+in float src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-int.vert
new file mode 100644
index 0000000..6b6f15e
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-int.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+in int src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-vec2.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-vec2.vert
new file mode 100644
index 0000000..3f24521
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-in-vec2.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+in vec2 src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-float.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-float.vert
new file mode 100644
index 0000000..461deeb
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-float.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+uniform float src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-int.vert
new file mode 100644
index 0000000..a8d6af2
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-int.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+uniform int src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-vec2.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-vec2.vert
new file mode 100644
index 0000000..e86ef1f
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-uniform-vec2.vert
@@ -0,0 +1,19 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+uniform vec2 src;
+
+void main() {
+   switch (src) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-float.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-float.vert
new file mode 100644
index 0000000..039e85d
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-float.vert
@@ -0,0 +1,18 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   float tmp = 1.5;
+   switch (tmp) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-int.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-int.vert
new file mode 100644
index 0000000..200cc79
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-int.vert
@@ -0,0 +1,18 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   int tmp = 5;
+   switch (tmp) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-vec2.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-vec2.vert
new file mode 100644
index 0000000..6d398f0
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-expression-var-vec2.vert
@@ -0,0 +1,18 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions must by scalar integers.
+//
+// From section 6.2 of the GLSL 1.30 spec:
+//    The type of init-expression in a switch statement must be a scalar 
+//    integer.
+
+#version 130
+
+void main() {
+   vec2 tmp = vec2(0, 0);
+   switch (tmp) {
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-break.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-break.vert
new file mode 100644
index 0000000..b79ab46
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-break.vert
@@ -0,0 +1,21 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Test nested break statements.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 1:
+      while (tmp < 8) {
+      	 if (tmp > 4)
+	    break;
+         tmp += 1;
+      }
+      break;	
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-case.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-case.vert
new file mode 100644
index 0000000..5f2a8a1
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-case.vert
@@ -0,0 +1,20 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Case labels cannot be nested inside other flow control within 
+// their corresonding switch.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 0:
+      while (1) {
+         case 1:
+	 tmp = 1;
+      }
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-default.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-default.vert
new file mode 100644
index 0000000..65298a9
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-default.vert
@@ -0,0 +1,18 @@
+// [config]
+// expect_result: fail
+// glsl_version: 1.30
+// [end config]
+//
+// Case labels and default labels may not be nested inside
+// other flow control within their corresonding switch.
+
+#version 130
+
+void main() {
+   switch (1) {
+   case 0:
+      while (1) {
+         default:
+      }
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-loop.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-loop.vert
new file mode 100644
index 0000000..3592c57
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-loop.vert
@@ -0,0 +1,18 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch statements may have nested loops.
+
+#version 130
+
+void main() {
+   int tmp = 0;
+   switch (1) {
+   case 1:
+      while (tmp < 8) {
+         tmp += 1;
+      }
+   }
+}
diff --git a/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-switch.vert b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-switch.vert
new file mode 100644
index 0000000..02710bc
--- /dev/null
+++ b/tests/spec/glsl-1.30/compiler/switch-statement/switch-nested-switch.vert
@@ -0,0 +1,16 @@
+// [config]
+// expect_result: pass
+// glsl_version: 1.30
+// [end config]
+//
+// Switch expressions may be nested.
+
+#version 130
+
+void main() {
+   switch (1) {
+   case 0:
+      switch (0) {
+      }
+   }
+}
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-01.frag b/tests/spec/glsl-1.30/execution/switch/switch-01.frag
new file mode 100644
index 0000000..94beb59
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-01.frag
@@ -0,0 +1,33 @@
+#version 130
+
+#define PI 3.1415927
+
+in vec4 tex_coord;
+
+void main()
+{
+	// use 0.5 * (sin(PI * foo) + 1) as a computation
+	// to map -1..1 => 0..1
+	int x = int(0.99 * (sin(PI * tex_coord.x) + 1));
+	int y = int(0.99 * (sin(PI * tex_coord.y) + 1));
+
+	int v = 2 * y + x;
+
+	switch (v) {
+	case 0:
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+		break;
+	case 1:
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+		break;
+	case 2:
+		gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
+		break;
+	case 3:
+		gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+		break;
+	default:
+		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+		break;
+	}
+}
\ No newline at end of file
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-01.frag.sav b/tests/spec/glsl-1.30/execution/switch/switch-01.frag.sav
new file mode 100644
index 0000000..e6763d2
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-01.frag.sav
@@ -0,0 +1,8 @@
+#version 130
+const float canary = 0.125;
+uniform sampler2DShadow tex;
+in vec4 tex_coord;
+void main() {
+	float s = texture(tex, tex_coord.xyy);
+	gl_FragColor = vec4(s, canary, canary, canary);
+}
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-01.shader_test b/tests/spec/glsl-1.30/execution/switch/switch-01.shader_test
new file mode 100644
index 0000000..1dc7e84
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-01.shader_test
@@ -0,0 +1,44 @@
+# [description]
+# Test switch statement with
+#   - color mapping to (x,y)
+#   - (-1,-1)..(0,0) => red
+#   - (0,-1)..(1,0) => green
+#   - (-1,0)..(0,1) => blue
+#   - (0,0)..(1,1) => white
+# This pattern repeats periodically in x,y
+
+[require]
+GLSL >= 1.30
+
+[vertex shader file]
+switch-01.vert
+
+[fragment shader file]
+switch-01.frag
+
+[test]
+# draw from -1..1 in both x and y
+draw rect -1 -1 2 2
+
+# color comparison pass
+# probe in space 0..1 in both x and y
+
+# expect red, (case 0)
+#     drawn in (-1,-1)..(0,0),
+#     probed at (-0.5,-0.5) in drawing coords
+relative probe rgba (0.25, 0.25) (1.0, 0.0, 0.0, 1.0);
+
+# expect green, (case 1)
+#     drawn in (0,-1)..(1,0),
+#     probed at (0.5,-0.5) in drawing coords
+relative probe rgba (0.75, 0.25) (0.0, 1.0, 0.0, 1.0);
+
+# expect blue, (case 2)
+#     drawn in (-1,0)..(0,1),
+#     probed at (-0.5,0.5) in drawing coords
+relative probe rgba (0.25, 0.75) (0.0, 0.0, 1.0, 1.0);
+
+# expect white, (case 3)
+#     drawn in (0,0)..(1,1),
+#     probed at (0.5,0.5) in drawing coords
+relative probe rgba (0.75, 0.75) (1.0, 1.0, 1.0, 1.0);
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-01.vert b/tests/spec/glsl-1.30/execution/switch/switch-01.vert
new file mode 100644
index 0000000..99e983c
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-01.vert
@@ -0,0 +1,6 @@
+#version 130
+out vec4 tex_coord;
+void main() {
+	gl_Position = gl_Vertex;
+	tex_coord = gl_Vertex;
+}
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-02.frag b/tests/spec/glsl-1.30/execution/switch/switch-02.frag
new file mode 100644
index 0000000..70d3bf6
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-02.frag
@@ -0,0 +1,67 @@
+#version 130
+
+#define PI 3.1415927
+
+in vec4 tex_coord;
+
+void main()
+{
+	// use 0.5 * (sin(PI * foo) + 1) as a computation
+	// to map -1..1 => 0..1
+	int x = int(0.99 * (sin(PI * tex_coord.x) + 1));
+	int y = int(0.99 * (sin(PI * tex_coord.y) + 1));
+	
+	// generate pseudo-random numbers based on x,y
+	int rand0 = int(32.0 * (sin(tex_coord.x + tex_coord.y) + 1));
+	int rand1 = int(32.0 * (cos(tex_coord.x * tex_coord.y) + 1));
+	int rand2 = int(32.0 * (cos(tex_coord.x - tex_coord.y) + 1));
+
+	float r = 0.0;
+	float g = 0.0;
+	float b = 0.0;
+	float dr = 0.2;
+	float dg = 0.4;
+	float db = 0.6;
+
+	int v = 2 * y + x;
+
+	switch (v) {
+	case 0:
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+		break;
+	case 1:
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+		break;
+	case 2:
+		gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
+		break;
+	case 3:
+	        // compute some random colors using a while loop
+	        while (rand0 >= 0) {
+		      r = r + dr;
+		      if (r > 1.0) {
+		      	       r = 0.0;
+		      }
+		      rand0 = rand0 - 1;
+		}
+		while (rand1 >= 0) {
+		      g = g + dg;
+		      if (g > 1.0) {
+		              g = 0.0;
+		      }
+		      rand1 = rand1 - 1;
+		}
+		while (rand2 >= 0) {
+		      b = b + db;
+		      if (b > 1.0) {
+		              b = 0.0;
+		      }
+		      rand2 = rand2 - 1;
+		}
+		gl_FragColor = vec4(r, g, b, 1.0);
+		break;
+	default:
+		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+		break;
+	}
+}
\ No newline at end of file
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-02.shader_test b/tests/spec/glsl-1.30/execution/switch/switch-02.shader_test
new file mode 100644
index 0000000..92afe2c
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-02.shader_test
@@ -0,0 +1,43 @@
+# [description]
+# Test switch statement with
+#   - color mapping to (x,y)
+#   - (-1,-1)..(0,0) => red
+#   - (0,-1)..(1,0) => green
+#   - (-1,0)..(0,1) => blue
+#   - (0,0)..(1,1) => multi-colored unpredicable mess
+# This pattern repeats periodically in x,y
+# The key point of this test is that the red, green,
+# and blue quads are drawn as expected and the interaction 
+# betw the while loop and the switch doesn't hang
+# the GPU but terminates nicely.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader file]
+switch-02.vert
+
+[fragment shader file]
+switch-02.frag
+
+[test]
+# draw from -1..1 in both x and y
+draw rect -1 -1 2 2
+
+# color comparison pass
+# probe in space 0..1 in both x and y
+
+# expect red, (case 0)
+#     drawn in (-1,-1)..(0,0),
+#     probed at (-0.5,-0.5) in drawing coords
+relative probe rgba (0.25, 0.25) (1.0, 0.0, 0.0, 1.0);
+
+# expect green, (case 1)
+#     drawn in (0,-1)..(1,0),
+#     probed at (0.5,-0.5) in drawing coords
+relative probe rgba (0.75, 0.25) (0.0, 1.0, 0.0, 1.0);
+
+# expect blue, (case 2)
+#     drawn in (-1,0)..(0,1),
+#     probed at (-0.5,0.5) in drawing coords
+relative probe rgba (0.25, 0.75) (0.0, 0.0, 1.0, 1.0);
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-02.vert b/tests/spec/glsl-1.30/execution/switch/switch-02.vert
new file mode 100644
index 0000000..99e983c
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-02.vert
@@ -0,0 +1,6 @@
+#version 130
+out vec4 tex_coord;
+void main() {
+	gl_Position = gl_Vertex;
+	tex_coord = gl_Vertex;
+}
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-03.frag b/tests/spec/glsl-1.30/execution/switch/switch-03.frag
new file mode 100644
index 0000000..dc99c15
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-03.frag
@@ -0,0 +1,57 @@
+#version 130
+
+#define PI 3.1415927
+
+in vec4 tex_coord;
+
+void main()
+{
+	// use 0.5 * (sin(PI * foo) + 1) as a computation
+	// to map -1..1 => 0..1
+	int x = int(0.99 * sin(PI * tex_coord.x) + 1);
+	int y = int(0.99 * sin(PI * tex_coord.y) + 1);
+	
+	// generate a pseudo-random number based on x,y
+	int rand = int(32.0 * (sin(tex_coord.x + tex_coord.y) + 1));
+
+	float r = 0.0;
+	float g = 0.0;
+	float b = 0.0;
+	float dr = 0.2;
+	float dg = 0.4;
+	float db = 0.6;
+
+	int v = 2 * y + x;
+
+        // generate some random colors with this while loop
+	while (rand >= 0) {
+	        r = r + dr;
+	        if (r > 1.0) {
+	      	        r = 0.0;
+	        }
+	        g = g + dg;
+	        if (g > 1.0) {
+	                g = 0.0;
+	        }
+	        b = b + db;
+	        if (b > 1.0) {
+	                b = 0.0;
+	        }
+	        rand = rand - 1;
+
+	        switch (v) {
+		case 0:
+			gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+			break;
+		case 1:
+			gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+			break;
+		case 2:
+			gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
+			break;
+		case 3:
+			gl_FragColor = vec4(r, g, b, 1.0);
+			break;
+		}
+	}
+}
\ No newline at end of file
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-03.shader_test b/tests/spec/glsl-1.30/execution/switch/switch-03.shader_test
new file mode 100644
index 0000000..bbe37d7
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-03.shader_test
@@ -0,0 +1,43 @@
+# [description]
+# Test switch statement with
+#   - color mapping to (x,y)
+#   - (-1,-1)..(0,0) => red
+#   - (0,-1)..(1,0) => green
+#   - (-1,0)..(0,1) => blue
+#   - (0,0)..(1,1) => multi-colored unpredicable mess
+# This pattern repeats periodically in x,y
+# The key point of this test is that the red, green,
+# and blue quads are drawn as expected and the interaction 
+# betw the while loop and the switch doesn't hang
+# the GPU but terminates nicely.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader file]
+switch-03.vert
+
+[fragment shader file]
+switch-03.frag
+
+[test]
+# draw from -1..1 in both x and y
+draw rect -1 -1 2 2
+
+# color comparison pass
+# probe in space 0..1 in both x and y
+
+# expect red, (case 0)
+#     drawn in (-1,-1)..(0,0),
+#     probed at (-0.5,-0.5) in drawing coords
+relative probe rgba (0.25, 0.25) (1.0, 0.0, 0.0, 1.0);
+
+# expect green, (case 1)
+#     drawn in (0,-1)..(1,0),
+#     probed at (0.5,-0.5) in drawing coords
+relative probe rgba (0.75, 0.25) (0.0, 1.0, 0.0, 1.0);
+
+# expect blue, (case 2)
+#     drawn in (-1,0)..(0,1),
+#     probed at (-0.5,0.5) in drawing coords
+relative probe rgba (0.25, 0.75) (0.0, 0.0, 1.0, 1.0);
diff --git a/tests/spec/glsl-1.30/execution/switch/switch-03.vert b/tests/spec/glsl-1.30/execution/switch/switch-03.vert
new file mode 100644
index 0000000..99e983c
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/switch/switch-03.vert
@@ -0,0 +1,6 @@
+#version 130
+out vec4 tex_coord;
+void main() {
+	gl_Position = gl_Vertex;
+	tex_coord = gl_Vertex;
+}
-- 
1.7.4.1



More information about the Piglit mailing list