diff options
author | Paul Berry <stereotype441@gmail.com> | 2011-08-02 16:11:00 -0700 |
---|---|---|
committer | Paul Berry <stereotype441@gmail.com> | 2011-08-05 14:53:57 -0700 |
commit | 801d6debf196e2c77fe0ed372731edcedbead462 (patch) | |
tree | 79e3b3123d6e2c4f6d4582713f25309dd1cb9c74 | |
parent | fcaa47b28ba46f692b1ff05ff09b14a67c766a88 (diff) |
Test implicit type conversion of out parameters.
This patch adds six tests of the proper behavior of function out
parameters when used in a context that requires implicit type
conversion.
Two of the tests are based on an explicit example in the GLSL-1.30
spec. The remaining tests adapt this example to GLSL 1.20 (which
seems to be intended to have the same conversion rules, though they
are less clearly articulated).
6 files changed, 272 insertions, 0 deletions
diff --git a/tests/spec/glsl-1.20/compiler/qualifiers/out-conversion-int-to-float.vert b/tests/spec/glsl-1.20/compiler/qualifiers/out-conversion-int-to-float.vert new file mode 100644 index 00000000..a17a5ad2 --- /dev/null +++ b/tests/spec/glsl-1.20/compiler/qualifiers/out-conversion-int-to-float.vert @@ -0,0 +1,31 @@ +/* + * [config] + * glsl_version: 1.20 + * expect_result: pass + * [end_config] + * + * Test that implicit type conversion of out parameters is properly + * used to match function calls to callees. + * + * From the GLSL 1.30 spec (which clarifies, but does not change, the + * rules for implicit type conversion in GLSL 1.20), section 6.1 + * (Function Definitions): + * + * Mismatched types on output parameters (out or inout) must have a + * conversion from the formal parameter type to the calling argument + * type. + */ + +#version 120 + +void f(out int x) +{ + x = 0; +} + +void +main() { + float x; + f(x); + gl_Position = gl_Vertex; +} diff --git a/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-int-float-to-float-float-float-return.shader_test b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-int-float-to-float-float-float-return.shader_test new file mode 100644 index 00000000..15743c53 --- /dev/null +++ b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-int-float-to-float-float-float-return.shader_test @@ -0,0 +1,46 @@ +# Test that implicit type conversion of out parameters works properly. +# +# From the GLSL 1.30 spec (which clarifies, but does not change, the +# rules for implicit type conversion in GLSL 1.20), section 6.1 +# (Function Definitions): +# +# Mismatched types on output parameters (out or inout) must have a +# conversion from the formal parameter type to the calling argument +# type. +# +# This test uses a complex function signature with three out +# parameters of various types, and a return value, to make sure the +# outputs aren't mixed up. + +[require] +GLSL >= 1.20 + +[vertex shader] +#version 120 +float f(out int x, out int y, out float z) +{ + x = 4; + y = 5; + z = 0.75; + return 0.5; +} + +void main() +{ + gl_Position = gl_Vertex; + float value1; + float value2; + float value3; + float value4 = f(value1, value2, value3); + gl_FrontColor = vec4(1.0/value1, 1.0/value2, value3, value4); +} + +[fragment shader] +void main() +{ + gl_FragColor = gl_Color; +} + +[test] +draw rect -1 -1 2 2 +probe all rgba 0.25 0.2 0.75 0.5 diff --git a/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float-return.shader_test b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float-return.shader_test new file mode 100644 index 00000000..cf7f2b9f --- /dev/null +++ b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float-return.shader_test @@ -0,0 +1,41 @@ +# Test that implicit type conversion of out parameters works properly. +# +# From the GLSL 1.30 spec (which clarifies, but does not change, the +# rules for implicit type conversion in GLSL 1.20), section 6.1 +# (Function Definitions): +# +# Mismatched types on output parameters (out or inout) must have a +# conversion from the formal parameter type to the calling argument +# type. +# +# This test uses a simple function returning float and taking a single +# out parameter. + +[require] +GLSL >= 1.20 + +[vertex shader] +#version 120 +float f(out int x) +{ + x = 4; + return 0.5; +} + +void main() +{ + gl_Position = gl_Vertex; + float value1; + float value2 = f(value1); + gl_FrontColor = vec4(1.0/value1, value2, 0.0, 0.0); +} + +[fragment shader] +void main() +{ + gl_FragColor = gl_Color; +} + +[test] +draw rect -1 -1 2 2 +probe all rgba 0.25 0.5 0.0 0.0 diff --git a/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float.shader_test b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float.shader_test new file mode 100644 index 00000000..2c3a2ce7 --- /dev/null +++ b/tests/spec/glsl-1.20/execution/qualifiers/vs-out-conversion-int-to-float.shader_test @@ -0,0 +1,40 @@ +# Test that implicit type conversion of out parameters works properly. +# +# From the GLSL 1.30 spec (which clarifies, but does not change, the +# rules for implicit type conversion in GLSL 1.20), section 6.1 +# (Function Definitions): +# +# Mismatched types on output parameters (out or inout) must have a +# conversion from the formal parameter type to the calling argument +# type. +# +# This test uses a simple function returning void and taking a single +# out parameter. + +[require] +GLSL >= 1.20 + +[vertex shader] +#version 120 +void f(out int x) +{ + x = 4; +} + +void main() +{ + gl_Position = gl_Vertex; + float value; + f(value); + gl_FrontColor = vec4(1.0/value); +} + +[fragment shader] +void main() +{ + gl_FragColor = gl_Color; +} + +[test] +draw rect -1 -1 2 2 +probe all rgba 0.25 0.25 0.25 0.25 diff --git a/tests/spec/glsl-1.30/compiler/qualifiers/out-conversion-ambiguous.vert b/tests/spec/glsl-1.30/compiler/qualifiers/out-conversion-ambiguous.vert new file mode 100644 index 00000000..32c84d44 --- /dev/null +++ b/tests/spec/glsl-1.30/compiler/qualifiers/out-conversion-ambiguous.vert @@ -0,0 +1,47 @@ +/* [config] + * expect_result: fail + * glsl_version: 1.30 + * [end config] + * + * Test that the GLSL compiler properly detects an error in the case + * where the conversion of an out parameter causes a function call to + * be ambiguous. + * + * From the GLSL 1.30 spec, p55 (Function Definitions): + * + * For example, + * + * vec4 f(in vec4 x, out vec4 y); + * vec4 f(in vec4 x, out ivec4 y); // okay, different argument type + * ... + * + * Calling the first two functions above with the following argument + * types yields + * + * ... + * f(ivec4, vec4) // error, convertible to both + * + * This test verifies that the call f(ivec4, vec4) generates an error. + */ + +#version 130 + +vec4 f(in vec4 x, out vec4 y) +{ + y = vec4(0.0); + return vec4(0.0); +} + +vec4 f(in vec4 x, out ivec4 y) +{ + y = ivec4(0); + return vec4(0.0); +} + +void main() +{ + ivec4 x_actual = ivec4(1, 3, 3, 7); + vec4 y_actual; + vec4 f_result = f(x_actual, y_actual); + gl_Position = f_result + y_actual; +} diff --git a/tests/spec/glsl-1.30/execution/qualifiers/vs-out-conversion-ivec4-to-vec4.shader_test b/tests/spec/glsl-1.30/execution/qualifiers/vs-out-conversion-ivec4-to-vec4.shader_test new file mode 100644 index 00000000..08caf4c5 --- /dev/null +++ b/tests/spec/glsl-1.30/execution/qualifiers/vs-out-conversion-ivec4-to-vec4.shader_test @@ -0,0 +1,67 @@ +# From the GLSL 1.30 spec, p55 (Function Definitions): +# +# For example, +# +# vec4 f(in vec4 x, out vec4 y); +# vec4 f(in vec4 x, out ivec4 y); // okay, different argument type +# ... +# +# Calling the first two functions above with the following argument +# types yields +# +# ... +# f(ivec4, vec4) // error, convertible to both +# +# This would seem to imply that if the declaration "vec4 f(in vec4 x, +# out vec4 y)" were removed, the call would no longer be ambiguous, +# and would successfully match "vec4 f(in vec4 x, out ivec4 y)". This +# test verifies that with the ambiguous declaration removed, the call +# does indeed match, and that the correct values are passed. + +[require] +GLSL >= 1.30 + +[vertex shader] +#version 130 +vec4 f(in vec4 x, out ivec4 y) +{ + // Verify that the correct values were passed in. + if (x != vec4(1.0, 3.0, 3.0, 7.0)) { + // They weren't, so output zeros + y = ivec4(0); + return vec4(0.0); + } else { + // They were, so output some constants the caller can recognize. + y = ivec4(5, 10, 15, 20); + return vec4(1.0, 0.5, 0.25, 0.125); + } +} + +void main() +{ + gl_Position = gl_Vertex; + + // Call f, passing it the input it expects. + ivec4 x_actual = ivec4(1, 3, 3, 7); + vec4 y_actual; + vec4 f_result = f(x_actual, y_actual); + + // Check that the outputs are as expected. + if (y_actual == vec4(5.0, 10.0, 15.0, 20.0) + && f_result == vec4(1.0, 0.5, 0.25, 0.125)) { + gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0); // Green + } else { + gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0); // Red + } +} + +[fragment shader] +#version 130 +void main() +{ + gl_FragColor = gl_Color; +} + +[test] +draw rect -1 -1 2 2 +probe all rgba 0.0 1.0 0.0 1.0 |