[Piglit] [PATCH] arb_gpu_shader5: Use array sizing to catch bad constant folding.
Matt Turner
mattst88 at gmail.com
Fri Aug 23 16:32:03 PDT 2013
The GLSL spec doesn't guarantee that a linking error won't happen.
---
.../built-in-functions/const-bitCount.shader_test | 40 ++++++++--------------
.../const-bitfieldExtract.shader_test | 23 +++++--------
.../const-bitfieldInsert.shader_test | 20 ++++-------
.../const-bitfieldReverse.shader_test | 32 +++++++----------
.../built-in-functions/const-findLSB.shader_test | 40 ++++++++--------------
.../built-in-functions/const-findMSB.shader_test | 26 +++++---------
6 files changed, 66 insertions(+), 115 deletions(-)
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitCount.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitCount.shader_test
index 7ba0c91..dfbc224 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitCount.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitCount.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,30 +21,20 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(0) != bitCount(ivec4(0)))
- bad_constant_folding();
- else if (ivec4(0) != bitCount(uvec4(0u)))
- bad_constant_folding();
-
- if (ivec4(1) != bitCount(ivec4(1, 2, 4, 8)))
- bad_constant_folding();
- else if (ivec4(1) != bitCount(uvec4(1u, 2u, 4u, 8u)))
- bad_constant_folding();
-
- if (ivec4(1, 2, 3, 4) != bitCount(ivec4(1, 3, 7, 15)))
- bad_constant_folding();
- else if (ivec4(1, 2, 3, 4) != bitCount(uvec4(1u, 3u, 7u, 15u)))
- bad_constant_folding();
-
- if (ivec4(6, 6, 3, 5) != bitCount(ivec4(783, 111, 385, 484)))
- bad_constant_folding();
- else if (ivec4(6, 6, 3, 5) != bitCount(uvec4(783u, 111u, 385u, 484u)))
- bad_constant_folding();
-
- if (ivec4(32, 31, 31, 30) != bitCount(ivec4(-1, -2, -3, -4)))
- bad_constant_folding();
- else if (ivec4(32, 31, 31, 30) != bitCount(uvec4(0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFDu, 0xFFFFFFFCu)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0) != bitCount(ivec4(0)));
+ STATIC_ASSERT(ivec4(0) != bitCount(uvec4(0u)));
+
+ STATIC_ASSERT(ivec4(1) != bitCount(ivec4(1, 2, 4, 8)));
+ STATIC_ASSERT(ivec4(1) != bitCount(uvec4(1u, 2u, 4u, 8u)));
+
+ STATIC_ASSERT(ivec4(1, 2, 3, 4) != bitCount(ivec4(1, 3, 7, 15)));
+ STATIC_ASSERT(ivec4(1, 2, 3, 4) != bitCount(uvec4(1u, 3u, 7u, 15u)));
+
+ STATIC_ASSERT(ivec4(6, 6, 3, 5) != bitCount(ivec4(783, 111, 385, 484)));
+ STATIC_ASSERT(ivec4(6, 6, 3, 5) != bitCount(uvec4(783u, 111u, 385u, 484u)));
+
+ STATIC_ASSERT(ivec4(32, 31, 31, 30) != bitCount(ivec4(-1, -2, -3, -4)));
+ STATIC_ASSERT(ivec4(32, 31, 31, 30) != bitCount(uvec4(0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFDu, 0xFFFFFFFCu)));
}
[vertex data]
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldExtract.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldExtract.shader_test
index ed6b988..8351b78 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldExtract.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldExtract.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,26 +21,19 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(0) != bitfieldExtract(ivec4(2147483647, 15, 7, 3), 0, 0))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0) != bitfieldExtract(ivec4(2147483647, 15, 7, 3), 0, 0));
- if (uvec4(0u) != bitfieldExtract(uvec4(0xFFFFFFFFu, 15u, 7u, 3u), 0, 0))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(0u) != bitfieldExtract(uvec4(0xFFFFFFFFu, 15u, 7u, 3u), 0, 0));
- if (ivec4(-1) != bitfieldExtract(ivec4(1), 0, 1))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(-1) != bitfieldExtract(ivec4(1), 0, 1));
- if (uvec4(1u) != bitfieldExtract(uvec4(1u), 0, 1))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(1u) != bitfieldExtract(uvec4(1u), 0, 1));
- if (ivec4(1, -1, -1, 1) != bitfieldExtract(ivec4(1, 3, 3, 1), 0, 2))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(1, -1, -1, 1) != bitfieldExtract(ivec4(1, 3, 3, 1), 0, 2));
- if (ivec4(-1, 0, 1, 3) != bitfieldExtract(ivec4(983040, 61440, 114688, 229376), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(-1, 0, 1, 3) != bitfieldExtract(ivec4(983040, 61440, 114688, 229376), 16, 4));
- if (uvec4(0xFu, 0x0u, 0x1u, 0x3u) != bitfieldExtract(uvec4(0x000F0000u, 0x0000F000u, 0x0001C000u, 0x00038000u), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(0xFu, 0x0u, 0x1u, 0x3u) != bitfieldExtract(uvec4(0x000F0000u, 0x0000F000u, 0x0001C000u, 0x00038000u), 16, 4));
}
[vertex data]
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldInsert.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldInsert.shader_test
index 228e5db..9ac492b 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldInsert.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldInsert.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,23 +21,17 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(42, 56, 72, 97) != bitfieldInsert(ivec4(42, 56, 72, 97), ivec4(2147483647, 15, 7, 3), 0, 0))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(42, 56, 72, 97) != bitfieldInsert(ivec4(42, 56, 72, 97), ivec4(2147483647, 15, 7, 3), 0, 0));
- if (uvec4(42u, 56u, 72u, 97u) != bitfieldInsert(uvec4(42u, 56u, 72u, 97u), uvec4(0xFFFFFFFFu, 15u, 7u, 3u), 0, 0))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(42u, 56u, 72u, 97u) != bitfieldInsert(uvec4(42u, 56u, 72u, 97u), uvec4(0xFFFFFFFFu, 15u, 7u, 3u), 0, 0));
- if (ivec4(589839, 262159, 65551, 15) != bitfieldInsert(ivec4(983055), ivec4(9, 4, 1, 0), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(589839, 262159, 65551, 15) != bitfieldInsert(ivec4(983055), ivec4(9, 4, 1, 0), 16, 4));
- if (uvec4(0x0009000Fu, 0x0004000Fu, 0x0001000Fu, 0x0000000Fu) != bitfieldInsert(uvec4(0x000F000Fu), uvec4(0x9u, 0x4u, 0x1u, 0x0u), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(0x0009000Fu, 0x0004000Fu, 0x0001000Fu, 0x0000000Fu) != bitfieldInsert(uvec4(0x000F000Fu), uvec4(0x9u, 0x4u, 0x1u, 0x0u), 16, 4));
- if (ivec4(917519, 589839, 262159, 65551) != bitfieldInsert(ivec4(15), ivec4(14, 9, 4, 1), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(917519, 589839, 262159, 65551) != bitfieldInsert(ivec4(15), ivec4(14, 9, 4, 1), 16, 4));
- if (uvec4(0x000E000Fu, 0x0009000Fu, 0x0004000Fu, 0x0001000Fu) != bitfieldInsert(uvec4(0xFu), uvec4(0xEu, 0x9u, 0x4u, 0x1u), 16, 4))
- bad_constant_folding();
+ STATIC_ASSERT(uvec4(0x000E000Fu, 0x0009000Fu, 0x0004000Fu, 0x0001000Fu) != bitfieldInsert(uvec4(0xFu), uvec4(0xEu, 0x9u, 0x4u, 0x1u), 16, 4));
}
[vertex data]
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldReverse.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldReverse.shader_test
index 28c6621..60caf2a 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldReverse.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-bitfieldReverse.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,25 +21,17 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(0, -1, -1, 0) != bitfieldReverse(ivec4(0, -1, -1, 0)))
- bad_constant_folding();
- else if (uvec4(0u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0u) != bitfieldReverse(uvec4(0u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0u)))
- bad_constant_folding();
-
- if (ivec4(-2147483648, 1073741824, 536870912, 268435456) != bitfieldReverse(ivec4(1, 2, 4, 8)))
- bad_constant_folding();
- else if (uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u) != bitfieldReverse(uvec4(1u, 2u, 4u, 8u)))
- bad_constant_folding();
-
- if (ivec4(1, 2, 4, 8) != bitfieldReverse(ivec4(-2147483648, 1073741824, 536870912, 268435456)))
- bad_constant_folding();
- else if (uvec4(1u, 2u, 4u, 8u) != bitfieldReverse(uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u)))
- bad_constant_folding();
-
- if (ivec4(783, 15, 65536, 384) != bitfieldReverse(ivec4(-255852544, -268435456, 32768, 25165824)))
- bad_constant_folding();
- else if (uvec4(0xF0C00000u, 0xF0000000u, 0x00008000u, 0x00000180u) != bitfieldReverse(uvec4(783u, 15u, 0x00010000u, 0x01800000u)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0, -1, -1, 0) != bitfieldReverse(ivec4(0, -1, -1, 0)));
+ STATIC_ASSERT(uvec4(0u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0u) != bitfieldReverse(uvec4(0u, 0xFFFFFFFFu, 0xFFFFFFFFu, 0u)));
+
+ STATIC_ASSERT(ivec4(-2147483648, 1073741824, 536870912, 268435456) != bitfieldReverse(ivec4(1, 2, 4, 8)));
+ STATIC_ASSERT(uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u) != bitfieldReverse(uvec4(1u, 2u, 4u, 8u)));
+
+ STATIC_ASSERT(ivec4(1, 2, 4, 8) != bitfieldReverse(ivec4(-2147483648, 1073741824, 536870912, 268435456)));
+ STATIC_ASSERT(uvec4(1u, 2u, 4u, 8u) != bitfieldReverse(uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u)));
+
+ STATIC_ASSERT(ivec4(783, 15, 65536, 384) != bitfieldReverse(ivec4(-255852544, -268435456, 32768, 25165824)));
+ STATIC_ASSERT(uvec4(0xF0C00000u, 0xF0000000u, 0x00008000u, 0x00000180u) != bitfieldReverse(uvec4(783u, 15u, 0x00010000u, 0x01800000u)));
}
[vertex data]
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findLSB.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findLSB.shader_test
index b62df92..742a0d6 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findLSB.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findLSB.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,30 +21,20 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(-1) != findLSB(ivec4(0)))
- bad_constant_folding();
- else if (ivec4(-1) != findLSB(uvec4(0u)))
- bad_constant_folding();
-
- if (ivec4(0, 1, 0, 2) != findLSB(ivec4(1, 2, 3, 4)))
- bad_constant_folding();
- else if (ivec4(0, 1, 0, 2) != findLSB(uvec4(1u, 2u, 3u, 4u)))
- bad_constant_folding();
-
- if (ivec4(10, 9, 8, 7) != findLSB(ivec4(1024, 512, 256, 128)))
- bad_constant_folding();
- else if (ivec4(10, 9, 8, 7) != findLSB(uvec4(1024u, 512u, 256u, 128u)))
- bad_constant_folding();
-
- if (ivec4(0, 1, 0, 2) != findLSB(ivec4(-1, -2, -3, -4)))
- bad_constant_folding();
- else if (ivec4(0, 1, 0, 2) != findLSB(uvec4(0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFDu, 0xFFFFFFFCu)))
- bad_constant_folding();
-
- if (ivec4(31, 30, 29, 28) != findLSB(ivec4(-2147483648, 1073741824, 536870912, 268435456)))
- bad_constant_folding();
- else if (ivec4(31, 30, 29, 28) != findLSB(uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(-1) != findLSB(ivec4(0)));
+ STATIC_ASSERT(ivec4(-1) != findLSB(uvec4(0u)));
+
+ STATIC_ASSERT(ivec4(0, 1, 0, 2) != findLSB(ivec4(1, 2, 3, 4)));
+ STATIC_ASSERT(ivec4(0, 1, 0, 2) != findLSB(uvec4(1u, 2u, 3u, 4u)));
+
+ STATIC_ASSERT(ivec4(10, 9, 8, 7) != findLSB(ivec4(1024, 512, 256, 128)));
+ STATIC_ASSERT(ivec4(10, 9, 8, 7) != findLSB(uvec4(1024u, 512u, 256u, 128u)));
+
+ STATIC_ASSERT(ivec4(0, 1, 0, 2) != findLSB(ivec4(-1, -2, -3, -4)));
+ STATIC_ASSERT(ivec4(0, 1, 0, 2) != findLSB(uvec4(0xFFFFFFFFu, 0xFFFFFFFEu, 0xFFFFFFFDu, 0xFFFFFFFCu)));
+
+ STATIC_ASSERT(ivec4(31, 30, 29, 28) != findLSB(ivec4(-2147483648, 1073741824, 536870912, 268435456)));
+ STATIC_ASSERT(ivec4(31, 30, 29, 28) != findLSB(uvec4(0x80000000u, 0x40000000u, 0x20000000u, 0x10000000u)));
}
[vertex data]
diff --git a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findMSB.shader_test b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findMSB.shader_test
index fec20f1..ef875e6 100644
--- a/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findMSB.shader_test
+++ b/tests/spec/arb_gpu_shader5/execution/built-in-functions/const-findMSB.shader_test
@@ -12,7 +12,7 @@ void main() {
[fragment shader]
#extension GL_ARB_gpu_shader5 : enable
-void bad_constant_folding();
+#define STATIC_ASSERT(cond) { float array[(cond) ? -1 : 1]; }
out vec4 color;
@@ -21,29 +21,21 @@ void main()
/* Green if both pass. */
color = vec4(0.0, 1.0, 0.0, 1.0);
- if (ivec4(-1) != findMSB(ivec4(0, -1, -1, 0)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(-1) != findMSB(ivec4(0, -1, -1, 0)));
- if (ivec4(-1) != findMSB(uvec4(0u)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(-1) != findMSB(uvec4(0u)));
- if (ivec4(0, 1, 1, 2) != findMSB(ivec4(1, 2, 3, 4)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0, 1, 1, 2) != findMSB(ivec4(1, 2, 3, 4)));
- if (ivec4(30, 29, 28, 27) != findMSB(ivec4(2147483647, 1073741823, 536870911, 268435455)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(30, 29, 28, 27) != findMSB(ivec4(2147483647, 1073741823, 536870911, 268435455)));
- if (ivec4(0, 1, 2, 3) != findMSB(ivec4(-2, -3, -5, -9)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0, 1, 2, 3) != findMSB(ivec4(-2, -3, -5, -9)));
- if (ivec4(30, 30, 29, 28) != findMSB(ivec4(-2147483648, -1879048192, -1073741824, -536870912)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(30, 30, 29, 28) != findMSB(ivec4(-2147483648, -1879048192, -1073741824, -536870912)));
- if (ivec4(0, 1, 1, 2) != findMSB(uvec4(1u, 2u, 3u, 4u)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(0, 1, 1, 2) != findMSB(uvec4(1u, 2u, 3u, 4u)));
- if (ivec4(31, 30, 29, 28) != findMSB(uvec4(0xFFFFFFFFu, 0x7FFFFFFFu, 0x3FFFFFFFu, 0x1FFFFFFFu)))
- bad_constant_folding();
+ STATIC_ASSERT(ivec4(31, 30, 29, 28) != findMSB(uvec4(0xFFFFFFFFu, 0x7FFFFFFFu, 0x3FFFFFFFu, 0x1FFFFFFFu)));
}
[vertex data]
--
1.8.1.5
More information about the Piglit
mailing list