On 9 January 2012 12:21, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
These generators create two kinds of tests. The first verifies that<br>
pre- and post-increment/decrement operations cannot be assignment<br>
targets. These look like:<br>
<br>
uniform float u;<br>
varying vec4 v;<br>
<br>
void main()<br>
{<br>
float t = u;<br>
<br>
++t = float(v.x);<br>
gl_FragColor = vec4(t, v.yzw);<br>
}<br>
<br>
The second kind of test verifies that pre- and<br>
post-increment/decrement operations cannot be used for function 'out'<br>
parameters. These look like:<br>
<br>
uniform ivec4 u;<br>
attribute vec4 v;<br>
<br>
void f(out ivec4 p)<br>
{<br>
p = ivec4(v);<br>
}<br>
<br>
void main()<br>
{<br>
ivec4 t = u;<br>
<br>
f(t--);<br>
gl_Position = vec4(t);<br>
}<br>
<br>
Function 'inout' parameters are not explicitly tested.<br>
<br>
A test is generated for both vertex and fragment targets for each<br>
int and float vector or scalar datatype. Matrix types and GLSL 1.30<br>
unsigned types are not tested.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
---<br>
generated_tests/CMakeLists.txt | 6 +-<br>
generated_tests/gen_non-lvalue_tests.py | 162 +++++++++++++++++++++++++++++++<br>
2 files changed, 167 insertions(+), 1 deletions(-)<br>
create mode 100644 generated_tests/gen_non-lvalue_tests.py<br>
<br>
diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt<br>
index ea6072b..1b52775 100644<br>
--- a/generated_tests/CMakeLists.txt<br>
+++ b/generated_tests/CMakeLists.txt<br>
@@ -30,10 +30,14 @@ piglit_make_generated_tests(<br>
piglit_make_generated_tests(<br>
interpolation_tests.list<br>
gen_interpolation_tests.py)<br>
+piglit_make_generated_tests(<br>
+ non-lvalue_tests.list<br>
+ gen_non-lvalue_tests.py)<br>
<br>
# Add a "gen-tests" target that can be used to generate all the<br>
# tests without doing any other compilation.<br>
add_custom_target(gen-tests ALL<br>
DEPENDS builtin_uniform_tests.list<br>
constant_array_size_tests.list<br>
- interpolation_tests.list)<br>
+ interpolation_tests.list<br>
+ non-lvalue_tests.list)<br>
diff --git a/generated_tests/gen_non-lvalue_tests.py b/generated_tests/gen_non-lvalue_tests.py<br>
new file mode 100644<br>
index 0000000..9d7687d<br>
--- /dev/null<br>
+++ b/generated_tests/gen_non-lvalue_tests.py<br>
@@ -0,0 +1,162 @@<br>
+# coding=utf-8<br>
+#<br>
+# Copyright © 2012 Intel Corporation<br>
+#<br>
+# Permission is hereby granted, free of charge, to any person obtaining a<br>
+# copy of this software and associated documentation files (the "Software"),<br>
+# to deal in the Software without restriction, including without limitation<br>
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+# and/or sell copies of the Software, and to permit persons to whom the<br>
+# Software is furnished to do so, subject to the following conditions:<br>
+#<br>
+# The above copyright notice and this permission notice (including the next<br>
+# paragraph) shall be included in all copies or substantial portions of the<br>
+# Software.<br>
+#<br>
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+# DEALINGS IN THE SOFTWARE.<br>
+<br>
+import os<br>
+<br>
+<br>
+class Test(object):<br>
+ def __init__(self, type_name, op, usage, shader_target):<br>
+ self.type_name = type_name<br>
+ self.op = op<br>
+ self.usage = usage<br>
+ self.shader_target = shader_target<br>
+<br>
+ def filename(self):<br>
+ if self.op == "++t":<br>
+ name_base = "preincrement"<br>
+ elif self.op == "--t":<br>
+ name_base = "predecrement"<br>
+ elif self.op == "t++":<br>
+ name_base = "postincrement"<br>
+ elif self.op == "t--":<br>
+ name_base = "postdecrement"<br>
+<br>
+ return os.path.join('spec',<br>
+ 'glsl-1.10',<br>
+ 'compiler',<br>
+ 'expressions',<br>
+ '{0}-{1}-non-lvalue-for-{2}.{3}'.format(<br>
+ name_base, self.type_name, self.usage,<br>
+ self.shader_target))<br>
+<br>
+ def generate(self):<br>
+ if self.usage == 'assignment':<br>
+ test = """/* [config]<br>
+ * expect_result: fail<br>
+ * glsl_version: 1.10<br>
+ * [end config]<br>
+ *<br>
+ * Page 32 (page 38 of the PDF) of the GLSL 1.10 spec says:<br>
+ *<br>
+ * "Variables that are built-in types, entire structures, structure<br>
+ * fields, l-values with the field selector ( . ) applied to select<br>
+ * components or swizzles without repeated fields, and l-values<br>
+ * dereferenced with the array subscript operator ( [ ] ) are all<br>
+ * l-values. Other binary or unary expressions, non-dereferenced arrays,<br>
+ * function names, swizzles with repeated fields, and constants cannot be<br>
+ * l-values. The ternary operator (?:) is also not allowed as an<br>
+ * l-value."<br>
+ */<br>
+uniform {0} u;<br>
+{5} vec4 v;<br>
+<br>
+void main()<br>
+{{<br>
+ {0} t = u;<br>
+<br>
+ {1} = {0}(v{2});<br>
+ {3} = {4};<br>
+}}<br>
+"""<br></blockquote><div><br>Minor suggestion: to make this template easier to read, use named keyword arguments to format(), e.g.:<br><br>uniform {self.type_name} u;<br>{mode} vec4 v;<br><br>void main()<br>
{{<br> {self.type_name} t = u;<br><br> {self.op} = {self.type_name}(v{components});<br> {dest} = {var_as_vec4};<br>}}<br><br>Then, the call to format() would look like:<br><br>test = test.format(self = self, components = components, dest = dest, var_as_vec4 = var_as_vec4, mode = mode)<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ else:<br>
+ test = """/* [config]<br>
+ * expect_result: fail<br>
+ * glsl_version: 1.10<br>
+ * [end config]<br>
+ *<br>
+ * Page 32 (page 38 of the PDF) of the GLSL 1.10 spec says:<br>
+ *<br>
+ * "Variables that are built-in types, entire structures, structure<br>
+ * fields, l-values with the field selector ( . ) applied to select<br>
+ * components or swizzles without repeated fields, and l-values<br>
+ * dereferenced with the array subscript operator ( [ ] ) are all<br>
+ * l-values. Other binary or unary expressions, non-dereferenced arrays,<br>
+ * function names, swizzles with repeated fields, and constants cannot be<br>
+ * l-values. The ternary operator (?:) is also not allowed as an<br>
+ * l-value."<br>
+ */<br>
+uniform {0} u;<br>
+{5} vec4 v;<br>
+<br>
+void f(out {0} p)<br>
+{{<br>
+ p = {0}(v{2});<br>
+}}<br>
+<br>
+void main()<br>
+{{<br>
+ {0} t = u;<br>
+<br>
+ f({1});<br>
+ {3} = {4};<br>
+}}<br>
+"""<br>
+ if '2' in self.type_name:<br>
+ var_as_vec4 = 'vec4(t.xyxy)'<br>
+ components = '.xy'<br>
+ elif '3' in self.type_name:<br>
+ var_as_vec4 = 'vec4(t.xyzx)'<br>
+ components = '.xyz'<br>
+ elif '4' in self.type_name:<br>
+ var_as_vec4 = 'vec4(t)'<br>
+ components = ''<br>
+ else:<br>
+ var_as_vec4 = 'vec4(t)'<br>
+ components = '.x'<br>
+<br>
+ if self.shader_target == 'vert':<br>
+ dest = "gl_Position"<br>
+ mode = 'attribute'<br>
+ else:<br>
+ mode = 'varying'<br>
+ dest = "gl_FragColor"<br>
+<br>
+ test = test.format(self.type_name, self.op, components,<br>
+ dest,<br>
+ var_as_vec4,<br>
+ mode)<br>
+<br>
+ filename = self.filename()<br>
+ dirname = os.path.dirname(filename)<br>
+ if not os.path.exists(dirname):<br>
+ os.makedirs(dirname)<br>
+ with open(filename, 'w') as f:<br>
+ f.write(test)<br>
+<br>
+<br>
+def all_tests():<br>
+ for type_name in ['float', 'vec2', 'vec3', 'vec4',<br>
+ 'int', 'ivec2', 'ivec3', 'ivec4']:<br>
+ for op in ["++t", "--t", "t++", "t--"]:<br>
+ for usage in ['assignment', 'out-parameter']:<br>
+ for shader_target in ['vert', 'frag']:<br>
+ yield Test(type_name, op, usage, shader_target)<br></blockquote><div><br>Would it be worth testing uint/uvec as well?<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+def main():<br>
+ for test in all_tests():<br>
+ test.generate()<br>
+ print test.filename()<br>
+<br>
+<br>
+if __name__ == '__main__':<br>
+ main()<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.6.4<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br>