[Piglit] [PATCH 1/6] generators: port variable-index-read.sh to python
Dylan Baker
baker.dylan.c at gmail.com
Fri May 29 12:37:34 PDT 2015
This patch replaces a bash based generator with a python generator. This
has the obvious advantage of remove a large swath of generated tests
from the check-in, and prevents modification of a generated file. It
also is much faster than the bash generator, so running at compile time
isn't a problem.
This produces white spaces differences only. All tests that passed
with the bash versions pass with the python versions on HSW GT3e.
Tested with python2.7 and python3.3
v2: - rename generated test .list file (Emil)
- Use a shared function to add the license header, reducing LOC
(also removes a typo spotted by Emil)
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
generated_tests/CMakeLists.txt | 9 +-
generated_tests/gen_variable_index_read_tests.py | 261 +++++++++++
generated_tests/modules/utils.py | 22 +
.../fs.shader_test.mako | 31 ++
.../gen_variable_index_read_tests/helpers.mako | 238 ++++++++++
.../vs.shader_test.mako | 31 ++
tests/spec/glsl-1.10/variable-index-read.sh | 521 ---------------------
tests/spec/glsl-1.10/variable-index-regen.sh | 2 -
8 files changed, 591 insertions(+), 524 deletions(-)
create mode 100644 generated_tests/gen_variable_index_read_tests.py
create mode 100644 generated_tests/templates/gen_variable_index_read_tests/fs.shader_test.mako
create mode 100644 generated_tests/templates/gen_variable_index_read_tests/helpers.mako
create mode 100644 generated_tests/templates/gen_variable_index_read_tests/vs.shader_test.mako
delete mode 100755 tests/spec/glsl-1.10/variable-index-read.sh
diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index 5036a5d..665d661 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -120,6 +120,12 @@ piglit_make_generated_tests(
piglit_make_generated_tests(
shader_image_load_store_tests.list
gen_shader_image_load_store_tests.py)
+piglit_make_generated_tests(
+ variable_index_read_tests.list
+ gen_variable_index_read_tests.py
+ templates/gen_variable_index_read_tests/vs.shader_test.mako
+ templates/gen_variable_index_read_tests/fs.shader_test.mako
+ templates/gen_variable_index_read_tests/helpers.mako)
# OpenCL Test generators
piglit_make_generated_tests(
@@ -161,11 +167,12 @@ add_custom_target(gen-gl-tests
constant_array_size_tests_fp64.list
shader_precision_tests.list
shader_image_load_store_tests.list
+ variable_index_read_tests.list
)
# Create a custom target for generating OpenCL tests
# This is not added to the default target, instead it is added
-# as a dependency of gen-etsts if OpenCL tests are enabled
+# as a dependency of gen-tests if OpenCL tests are enabled
add_custom_target(gen-cl-tests
DEPENDS builtin_cl_int_tests.list
builtin_cl_math_tests.list
diff --git a/generated_tests/gen_variable_index_read_tests.py b/generated_tests/gen_variable_index_read_tests.py
new file mode 100644
index 0000000..7c597cb
--- /dev/null
+++ b/generated_tests/gen_variable_index_read_tests.py
@@ -0,0 +1,261 @@
+# Copyright (c) 2015 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+"""Generate tests for glsl 1.10 and 1.20 variable index reads."""
+
+from __future__ import print_function, absolute_import, division
+import os
+import itertools
+
+from six.moves import range
+
+from templates import template_dir
+from modules.utils import lazy_property, safe_makedirs
+
+TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
+FS_TEMPLATE = TEMPLATES.get_template('fs.shader_test.mako')
+VS_TEMPLATE = TEMPLATES.get_template('vs.shader_test.mako')
+DIRNAME = os.path.join('spec', 'glsl-{}', 'execution', 'variable-indexing')
+
+
+class TestParams(object):
+ """Parameters for a single test.
+
+ This is all of the non-formatting logic of the test. Each property is
+ wrapped with a lazy_property decorator, which means the data is cached
+ after it is calculated once.
+
+ """
+ def __init__(self, matrix_dim, array_dim, mode, index_value, col,
+ expect_type, glsl_version):
+ self.matrix_dim = matrix_dim
+ self.array_dim = array_dim
+ self.mode = mode
+ self.index_value = index_value
+ self.col = col
+ self.expect_type = expect_type
+
+ assert glsl_version in [110, 120]
+ self.glsl_version = glsl_version
+
+ @lazy_property
+ def idx(self):
+ if self.array_dim != 0:
+ return '[{}]'.format(self.index_value)
+ else:
+ return ''
+
+ @lazy_property
+ def cxr_type(self):
+ return 'mat{0}x{0}'.format(self.matrix_dim)
+
+ @lazy_property
+ def base_type(self):
+ if self.glsl_version == 120:
+ return self.cxr_type
+ else:
+ return 'mat{}'.format(self.matrix_dim)
+
+ @lazy_property
+ def type(self):
+ if self.array_dim !=0 and self.glsl_version == 120:
+ return '{}[{}]'.format(self.base_type, self.array_dim)
+ else:
+ return self.base_type
+
+ @lazy_property
+ def dim(self):
+ if self.array_dim != 0 and self.glsl_version == 110:
+ return '[{}]'.format(self.array_dim)
+ else:
+ # XXX: should this be an error?
+ return ''
+
+ @lazy_property
+ def row(self):
+ if self.expect_type == 'float':
+ return '[row]'
+ else:
+ # XXX: Should this be an error?
+ return ''
+
+ @lazy_property
+ def test_sizes(self):
+ if self.array_dim == 0:
+ return [1]
+ elif self.index_value == 'index':
+ return list(range(1, 1 + self.array_dim))
+ else:
+ return [2]
+
+ @lazy_property
+ def test_columns(self):
+ if self.col == 'col':
+ return list(range(1, 1 + self.matrix_dim))
+ else:
+ return [2]
+
+ @lazy_property
+ def test_rows(self):
+ if self.expect_type == 'float':
+ return list(range(1, 1 + self.matrix_dim))
+ else:
+ return [1]
+
+ @lazy_property
+ def test_array_dim(self):
+ if (self.mode == 'uniform' and
+ self.glsl_version == 110 and
+ self.array_dim != 0 and
+ self.index_value != 'index'):
+ return self.index_value + 1
+ else:
+ return self.array_dim
+
+ @lazy_property
+ def varying_comps(self):
+ if self.array_dim != 0:
+ return 4 + self.matrix_dim**2 * self.array_dim
+ else:
+ return 4 + self.matrix_dim**2
+
+ @lazy_property
+ def formated_version(self):
+ return '{:.2f}'.format(float(self.glsl_version) / 100)
+
+
+def make_fs(name, params):
+ """Generate a fragment shader test."""
+ dirname = DIRNAME.format(params.formated_version)
+ safe_makedirs(dirname)
+ with open(os.path.join(dirname, name), 'w') as f:
+ f.write(FS_TEMPLATE.render_unicode(params=params))
+ print(name)
+
+
+def make_vs(name, params):
+ """Generate a vertex shader test."""
+ dirname = DIRNAME.format(params.formated_version)
+ safe_makedirs(dirname)
+ with open(os.path.join(dirname, name), 'w') as f:
+ f.write(VS_TEMPLATE.render_unicode(params=params))
+ print(name)
+
+
+def main():
+ """Generate the tests."""
+ modes = ['temp', 'uniform', 'varying']
+ array_dims = [0, 3]
+ matrix_dims = [2, 3, 4]
+ glsl_versions = [110, 120]
+ iter_ = itertools.product(modes, array_dims, matrix_dims, glsl_versions)
+ for mode, array_dim, matrix_dim, glsl_version in iter_:
+ if array_dim != 0:
+ arr = 'array-'
+ idx_text = 'index-'
+
+ # TODO: This can certainly be rolled up into a loop
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-col-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 'col', 'float',
+ glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 1, 'float',
+ glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-col-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 'col',
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 1,
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-col-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 'col', 'float',
+ glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 1, 'float',
+ glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-col-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 'col',
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 1, 1,
+ 'vec{}'.format(matrix_dim), glsl_version))
+ else:
+ arr = ''
+ idx_text = ''
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-{idx_text}col-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 'col', 'float',
+ glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-{idx_text}row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 1, 'float',
+ glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-{idx_text}col-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 'col',
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_fs(
+ 'fs-{mode}-{arr}mat{matrix_dim}-{idx_text}rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 1,
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-{idx_text}col-row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 'col', 'float',
+ glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-{idx_text}row-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 1, 'float',
+ glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-{idx_text}col-rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 'col',
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+ make_vs(
+ 'vs-{mode}-{arr}mat{matrix_dim}-{idx_text}rd.shader_test'.format(**locals()),
+ TestParams(matrix_dim, array_dim, mode, 'index', 1,
+ 'vec{}'.format(matrix_dim), glsl_version))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/generated_tests/modules/utils.py b/generated_tests/modules/utils.py
index 2889383..5495ad8 100644
--- a/generated_tests/modules/utils.py
+++ b/generated_tests/modules/utils.py
@@ -23,6 +23,7 @@
from __future__ import print_function, absolute_import
import os
import errno
+import functools
def safe_makedirs(dirs):
@@ -43,3 +44,24 @@ def safe_makedirs(dirs):
pass
else:
raise
+
+
+class lazy_property(object):
+ """Decorator for lazy property loading.
+
+ A property decorated with this class will execute it's code the first time
+ it's run, but will store the value after that. This is useful for values
+ that are either 1) expensive to compute, or 2) need to be computed only
+ once and then read multiple times
+
+ """
+ def __init__(self, func):
+ functools.wraps(func)
+ self.__func = func
+
+ def __get__(self, obj, cls):
+ if not obj:
+ return self
+ value = self.__func(obj)
+ setattr(obj, self.__func.__name__, value)
+ return value
diff --git a/generated_tests/templates/gen_variable_index_read_tests/fs.shader_test.mako b/generated_tests/templates/gen_variable_index_read_tests/fs.shader_test.mako
new file mode 100644
index 0000000..39b0be5
--- /dev/null
+++ b/generated_tests/templates/gen_variable_index_read_tests/fs.shader_test.mako
@@ -0,0 +1,31 @@
+## Copyright (c) 2015 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining a copy
+## of this software and associated documentation files (the "Software"), to deal
+## in the Software without restriction, including without limitation the rights
+## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+## copies of the Software, and to permit persons to whom the Software is
+## furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included in
+## all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+## SOFTWARE.
+
+<%namespace name="helpers" file="helpers.mako"/>
+
+${helpers.license()}
+
+${helpers.emit_header(params)}
+
+${helpers.emit_vs(params, 0)}
+
+${helpers.emit_fs(params, 1)}
+
+${helpers.emit_test_vectors(params)}
diff --git a/generated_tests/templates/gen_variable_index_read_tests/helpers.mako b/generated_tests/templates/gen_variable_index_read_tests/helpers.mako
new file mode 100644
index 0000000..cb0bff4
--- /dev/null
+++ b/generated_tests/templates/gen_variable_index_read_tests/helpers.mako
@@ -0,0 +1,238 @@
+## Copyright (c) 2015 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining a copy
+## of this software and associated documentation files (the "Software"), to deal
+## in the Software without restriction, including without limitation the rights
+## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+## copies of the Software, and to permit persons to whom the Software is
+## furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included in
+## all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+## SOFTWARE.
+<%!
+ from six.moves import range
+
+ def dedent(text):
+ return '\n'.join(l.lstrip() for l in text.splitlines())
+
+ def newlines(text):
+ return '\n'.join(l for l in text.splitlines() if l.strip())
+%>
+
+<%def name="license()">
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+</%def>
+
+<%def name="emit_header(params)" filter="dedent,newlines">
+ ## Generated test, do not edit
+ [require]
+ GLSL >= ${params.formated_version}
+ % if params.mode == 'varying':
+ GL_MAX_VARYING_COMPONENTS >= ${params.varying_comps}
+ % endif
+</%def>
+
+<%def name="matrix_data(first, dim, delim=', ')" filter="trim,dedent,newlines">
+ ${delim.join(str(float(x)) for x in range(first, first + dim**2))}
+</%def>
+
+<%def name="emit_matrix_array_initializer(matrix_dim, array_dim, base_type)" filter="trim,newlines">
+ % for c in range(array_dim):
+${base_type}(${matrix_data(c * matrix_dim**2 + 1, matrix_dim)})\
+ % if c < array_dim - 1:
+, \
+ % endif
+ % endfor
+</%def>
+
+<%def name="emit_set_matrix(params)" filter="dedent,newlines">
+ % if params.array_dim != 0:
+ % if params.mode == 'temp':
+ % if params.glsl_version == 120:
+ ${params.type} m${params.dim} = ${params.type}(${emit_matrix_array_initializer(params.matrix_dim, params.array_dim, params.base_type)});
+ % else:
+ ${params.type} m${params.dim};
+ % endif
+ % endif
+ % if params.glsl_version == 110 or params.mode == 'varying':
+ % for i in range(params.array_dim):
+ m[${i}] = mat${params.matrix_dim}(${matrix_data(1 + i * params.matrix_dim**2, params.matrix_dim)});
+ % endfor
+ % endif
+ % else:
+ % if params.mode == 'temp':
+ ${params.type} m = ${params.type}(${matrix_data(1, params.matrix_dim)});
+ % else:
+ m = ${params.type}(${matrix_data(1, params.matrix_dim)});
+ % endif
+ % endif
+</%def>
+
+<%def name="emit_globals(params)" filter="dedent,newlines">
+ % if params.array_dim != 0 and params.index_value == 'index':
+ uniform int index;
+ % endif
+
+ % if params.col == 'col':
+ uniform int col;
+ % endif
+
+ % if params.expect_type == 'float':
+ uniform int row;
+ % endif
+
+ uniform ${params.expect_type} expect;
+
+ % if params.glsl_version == 120 and params.mode == 'uniform':
+ % if params.array_dim == 0:
+ ${params.mode} ${params.type} m = ${params.type}(${matrix_data(1, params.matrix_dim)});
+ % else:
+ ${params.mode} ${params.type} m${params.dim} = ${params.type}(${emit_matrix_array_initializer(params.matrix_dim, params.array_dim, params.base_type)});
+ % endif
+ % elif params.mode != 'temp':
+ ${params.mode} ${params.type} m${params.dim};
+ % endif
+ varying vec4 color;
+</%def>
+
+## TODO: convert do_compare into a bool
+<%def name="emit_vs(params, do_compare)" filter="newlines">
+[vertex shader]
+${emit_globals(params)}
+
+void main()
+{
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+
+ % if params.mode == 'varying' or (params.mode == 'temp' and do_compare != 0):
+ ${emit_set_matrix(params)}
+ % endif
+
+ % if do_compare != 0:
+ % if params.mode == 'varying':
+ /* From page 23 (page 30 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "A vertex shader may also read varying variables, getting back the
+ * same values it has written. Reading a varying variable in a vertex
+ * shader returns undefined values if it is read before being
+ * written."
+ */
+ % endif
+ ## TODO: Could probably simplify this with the use of params.row
+ % if params.expect_type == 'float':
+ color = (m${params.idx}[${params.col}][row] == expect) \
+ % else:
+ color = (m${params.idx}[${params.col}] == expect) \
+ % endif
+ ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
+ % endif
+}
+</%def>
+
+## TODO: convert do_compare into a bool
+<%def name="emit_fs(params, do_compare)" filter="newlines">
+[fragment shader]
+${emit_globals(params)}
+
+void main()
+{
+ % if do_compare == 0 and params.mode == 'varying':
+ /* There is some trickery here. The fragment shader has to actually use
+ * the varyings generated by the vertex shader, or the compiler (more
+ * likely the linker) might demote the varying outputs to just be vertex
+ * shader global variables. Since the point of the test is the vertex
+ * shader reading from a varying, that would defeat the test.
+ */
+ % endif
+ % if do_compare != 0 or params.mode == 'varying':
+ % if params.mode == 'temp':
+ ${emit_set_matrix(params)}
+ % endif
+ gl_FragColor = (m${params.idx}[${params.col}]${params.row} == expect) \
+ % if do_compare == 0:
+ ? color : vec4(1.0, 0.0, 0.0, 1.0);
+ % else:
+ ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
+ % endif
+ % else:
+ gl_FragColor = color;
+ % endif
+}
+</%def>
+
+<%def name="emit_test_vectors(params)" filter="dedent">
+ <%block filter="newlines">
+ [test]
+ clear color 0.5 0.5 0.5 0.5
+ clear
+ ortho
+ % if params.mode == 'uniform' and params.glsl_version == 110 and params.test_array_dim == 0:
+ uniform ${params.cxr_type} m ${matrix_data(1, params.matrix_dim, delim=' ')}
+ % endif
+
+ </%block>
+ % for size in params.test_sizes:
+ <%block filter="newlines">
+ % if params.mode == 'uniform' and params.glsl_version == 110 and params.test_array_dim != 0:
+ % for c in range(params.test_array_dim):
+ uniform ${params.cxr_type} m[${c}] ${matrix_data(1 + c * params.matrix_dim**2, params.matrix_dim, delim=' ')}
+ % endfor
+ % endif
+ % if params.test_array_dim != 0 and params.index_value == 'index':
+ uniform int index ${size - 1}
+ % endif
+ </%block>
+ <% x_base = ((size - 1) * (15 * params.matrix_dim + 10)) %>
+ % for column in params.test_columns:
+ <%block filter="newlines">
+ % if params.col == 'col':
+ uniform int col ${column - 1}
+ % endif
+ </%block>
+
+ % for row in params.test_rows:
+ <%block filter="newlines">
+ <% expect = (size - 1) * params.matrix_dim**2 + (column - 1) * params.matrix_dim + row %>
+ % if params.expect_type == 'float':
+ uniform int row ${row - 1}
+ uniform float expect ${expect}
+ % else:
+ uniform ${params.expect_type} expect ${' '.join(str(i) for i in range(expect, expect + params.matrix_dim))}
+ % endif
+
+ <%
+ x = x_base + 15 * column - 10
+ y = 15 * row - 10
+ %>
+ draw rect ${x} ${y} 10 10
+ probe rgb ${x + 5} ${y + 5} 0.0 1.0 0.0
+ </%block>
+
+ % endfor
+ % endfor
+ % endfor
+</%def>
diff --git a/generated_tests/templates/gen_variable_index_read_tests/vs.shader_test.mako b/generated_tests/templates/gen_variable_index_read_tests/vs.shader_test.mako
new file mode 100644
index 0000000..b2f8138
--- /dev/null
+++ b/generated_tests/templates/gen_variable_index_read_tests/vs.shader_test.mako
@@ -0,0 +1,31 @@
+## Copyright (c) 2015 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining a copy
+## of this software and associated documentation files (the "Software"), to deal
+## in the Software without restriction, including without limitation the rights
+## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+## copies of the Software, and to permit persons to whom the Software is
+## furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included in
+## all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+## SOFTWARE.
+
+<%namespace name="helpers" file="helpers.mako"/>
+
+${helpers.license()}
+
+${helpers.emit_header(params)}
+
+${helpers.emit_vs(params, 1)}
+
+${helpers.emit_fs(params, 0)}
+
+${helpers.emit_test_vectors(params)}
diff --git a/tests/spec/glsl-1.10/variable-index-read.sh b/tests/spec/glsl-1.10/variable-index-read.sh
deleted file mode 100755
index 2fdf980..0000000
--- a/tests/spec/glsl-1.10/variable-index-read.sh
+++ /dev/null
@@ -1,521 +0,0 @@
-#!/bin/bash
-
-# Generate a set of data for a sized matrix. Elements start with a specified
-# value and increment by 1.0 for each element.
-function matrix_data
-{
- first=$1
- dim=$2
-
- last=$(($first + $dim * $dim - 1))
- seq $first $last | tr '\n' ' ' | sed 's/ /.0, /g;s/, $//;s/ *$//g'
-}
-
-
-function emit_matrix_array_initializer
-{
- matrix_dim=$1
- array_dim=$2
- base_type=$3
- indent=$4
-
- for c in $(seq $array_dim); do
- if [ $c -ne 1 ]; then
- echo ","
- fi
-
- first=$(((c - 1) * matrix_dim * matrix_dim + 1))
- echo -n "${indent} ${base_type}("
- matrix_data $first $matrix_dim
- echo -n ")"
- done
-
-}
-
-
-# Emit global variable declarations for either the vertex shader or the
-# fragment shader.
-function emit_globals
-{
- matrix_dim=$1
- array_dim=$2
- mode=$3
- index_value=$4
- col=$5
- expect_type=$6
-
- v=${version/./}
- if [ $v -ge 120 ]; then
- base_type="mat${matrix_dim}x${matrix_dim}"
- else
- base_type="mat${matrix_dim}"
- fi
-
- type=$base_type
- dim=""
- if [ $array_dim -ne 0 ]; then
- if [ $v -ge 120 ]; then
- type="${type}[$array_dim]"
- else
- dim="[${array_dim}]"
- fi
- fi
-
- if [ $array_dim -ne 0 -a "x$index_value" = "xindex" ]; then
- echo "uniform int index;"
- fi
-
- if [ "x$col" = "xcol" ]; then
- echo "uniform int col;"
- fi
-
- if [ "x$expect_type" == "xfloat" ]; then
- echo "uniform int row;"
- fi
-
- echo "uniform ${expect_type} expect;"
-
- if [ $v -ge 120 -a "x$mode" = "xuniform" ]; then
- if [ $array_dim -eq 0 ]; then
- echo -n "${mode} ${type} m = ${type}("
- matrix_data 1 $matrix_dim
- echo ");"
- else
- echo "${mode} ${type} m${dim} = ${type}("
- emit_matrix_array_initializer $matrix_dim $array_dim $base_type ""
- echo ");"
- fi
- elif [ "x$mode" != "xtemp" ]; then
- echo "${mode} ${type} m${dim};"
- fi
- echo "varying vec4 color;"
- echo
-}
-
-
-function emit_set_matrix
-{
- matrix_dim=$1
- array_dim=$2
- mode=$3
-
- v=${version/./}
- if [ $v -ge 120 ]; then
- base_type="mat${matrix_dim}x${matrix_dim}"
- else
- base_type="mat${matrix_dim}"
- fi
-
- type=$base_type
- dim=""
- if [ $array_dim -ne 0 ]; then
- if [ $v -ge 120 ]; then
- type="${type}[$array_dim]"
- else
- dim="[${array_dim}]"
- fi
- fi
-
- if [ $array_dim -ne 0 ]; then
- if [ "x$mode" = "xtemp" ]; then
- if [ $v -ge 120 ]; then
- echo " ${type} m${dim} = ${type}("
- emit_matrix_array_initializer $matrix_dim $array_dim $base_type " "
- echo ");"
- else
- echo " ${type} m${dim};"
- fi
- fi
-
- if [ $v -lt 120 -o "x$mode" = "xvarying" ]; then
- for i in $(seq 0 $(($array_dim - 1))); do
- first=$((1 + $i * $matrix_dim * $matrix_dim))
- echo -n " m[$i] = mat${matrix_dim}("
- matrix_data $first $matrix_dim
- echo ");"
- done
- fi
- else
- matrix_values=$(matrix_data 1 $matrix_dim)
-
- if [ "x$mode" = "xtemp" ] ; then
- echo " ${type} m = ${type}(${matrix_values});"
- else
- echo " m = ${type}(${matrix_values});"
- fi
- fi
-}
-
-
-function emit_vs
-{
- matrix_dim=$1
- array_dim=$2
- mode=$3
- index_value=$4
- col=$5
- expect_type=$6
- do_compare=$7
-
- if [ $array_dim -ne 0 ]; then
- idx="[${index_value}]"
- else
- idx=""
- fi
-
- echo "[vertex shader]"
- emit_globals $*
-
- echo "void main()"
- echo "{"
- echo " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
-
- # Only emit the code to set the matrix if the vertex shader is generating
- # varyings for a fragment shader or the matrix is in local storage and the
- # vertex shader is doing the comparison.
- if [ "x$mode" = "xvarying" -o \( "x$mode" = "xtemp" -a $do_compare -ne 0 \) ]; then
- echo
- emit_set_matrix $matrix_dim $array_dim $mode
- fi
-
- if [ $do_compare -ne 0 ]; then
- # Many people thing that a vertex shader cannot read a varying. Quote
- # some bits from the GLSL spec so that people won't get the wrong idea
- # when reading the test.
- if [ "x$mode" = "xvarying" ]; then
- cat <<EOF
-
- /* From page 23 (page 30 of the PDF) of the GLSL 1.10 spec:
- *
- * "A vertex shader may also read varying variables, getting back the
- * same values it has written. Reading a varying variable in a vertex
- * shader returns undefined values if it is read before being
- * written."
- */
-EOF
- fi
-
- if [ "x$expect_type" = "xfloat" ]; then
- echo " color = (m${idx}[$col][row] == expect)"
- else
- echo " color = (m${idx}[$col] == expect)"
- fi
- echo " ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);"
- fi
- echo -e "}\n"
-}
-
-
-emit_fs()
-{
- matrix_dim=$1
- array_dim=$2
- mode=$3
- index_value=$4
- col=$5
- expect_type=$6
- do_compare=$7
-
- echo "[fragment shader]"
- emit_globals $*
-
- echo "void main()"
- echo "{"
-
- if [ $do_compare -eq 0 -a "x$mode" = "xvarying" ]; then
- cat <<EOF
- /* There is some trickery here. The fragment shader has to actually use
- * the varyings generated by the vertex shader, or the compiler (more
- * likely the linker) might demote the varying outputs to just be vertex
- * shader global variables. Since the point of the test is the vertex
- * shader reading from a varying, that would defeat the test.
- */
-EOF
- fi
-
- if [ $do_compare -ne 0 -o "x$mode" = "xvarying" ]; then
- if [ "x$mode" = "xtemp" ]; then
- emit_set_matrix $matrix_dim $array_dim $mode
- echo
- fi
-
- if [ $array_dim -ne 0 ]; then
- idx="[$index_value]"
- else
- idx=""
- fi
-
- if [ "x$expect_type" = "xfloat" ]; then
- row="[row]"
- else
- row=""
- fi
-
- echo " gl_FragColor = (m${idx}[${col}]${row} == expect)"
-
- if [ $do_compare -eq 0 ]; then
- echo " ? color : vec4(1.0, 0.0, 0.0, 1.0);"
- else
- echo " ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);"
- fi
- else
- echo " gl_FragColor = color;"
- fi
-
- echo "}"
- echo
-}
-
-
-function emit_test_vectors
-{
- matrix_dim=$1
- local array_dim=$2
- mode=$3
- index_value=$4
- col=$5
- expect_type=$6
-
- # Optimizing GLSL linkers may reduce the size of the uniform array if tail
- # elements are not accessed. Shader runner will fail the test if one of
- # the set uniforms doesn't have a location.
- if [ "x$mode" = "xuniform" -a $v -le 110 -a $array_dim -ne 0 -a "x$index_value" != "xindex" ]; then
- array_dim=$((index_value+1))
- fi
-
- cat <<EOF
-[test]
-clear color 0.5 0.5 0.5 0.5
-clear
-ortho
-
-EOF
-
- # NOTE: shader_runner uses the matCxR names even for GLSL 1.10
- v=${version/./}
- type="mat${matrix_dim}x${matrix_dim}"
- if [ "x$mode" = "xuniform" -a $v -le 110 ]; then
- if [ $array_dim -eq 0 ]; then
- echo -n "uniform ${type} m "
- matrix_data 1 $matrix_dim | sed 's/,//g'
- echo
- fi
- fi
-
- if [ $array_dim -eq 0 ]; then
- sizes="1"
- elif [ "x$index_value" = "xindex" ]; then
- sizes=$(seq $array_dim)
- else
- sizes="2"
- fi
-
- if [ "x$col" = "xcol" ]; then
- columns=$(seq $matrix_dim)
- else
- columns=2
- fi
-
- if [ "x$expect_type" = "xfloat" ]; then
- rows=$(seq $matrix_dim)
- else
- rows=1
- fi
-
- for i in $sizes; do
- if [ "x$mode" = "xuniform" -a $v -le 110 ]; then
- if [ $array_dim -ne 0 ]; then
- for c in $(seq 0 $(($array_dim - 1))); do
- first=$((1 + c * matrix_dim * matrix_dim))
- echo -n "uniform ${type} m[$c] "
- matrix_data $first $matrix_dim | sed 's/,//g'
- echo
- done
- fi
- fi
-
- if [ $array_dim -ne 0 -a "x$index_value" = "xindex" ]; then
- echo "uniform int index $((i - 1))"
- fi
-
- x_base=$(((i - 1) * (15 * matrix_dim + 10)))
- for c in $columns; do
- if [ "x$col" = "xcol" ]; then
- echo "uniform int col $((c - 1))"
- fi
-
- for r in $rows; do
- expect=$(((i - 1) * (matrix_dim * matrix_dim) + (c - 1) * matrix_dim + r))
- if [ "x$expect_type" = "xfloat" ]; then
- echo "uniform int row $((r - 1))"
- echo "uniform float expect $expect"
- else
- e=$(seq $expect $((expect + matrix_dim - 1)) | tr '\n' ' ' | sed 's/[[:space:]]*$//g')
- echo "uniform ${expect_type} expect $e"
- fi
-
- x=$((x_base + 15 * c - 10))
- y=$((15 * r - 10))
- echo "draw rect $x $y 10 10"
-
- x=$((x + 5))
- y=$((y + 5))
- echo "probe rgb $x $y 0.0 1.0 0.0"
- echo
- done
- done
- done
-}
-
-# Generate a test that read from an (array of) matrix using a non-constant
-# index in the fragment shader.
-function emit_fs_rd_test
-{
- echo "# Test generated by:"
- echo "# ${cmd}"
- echo
- echo "[require]"
- echo "GLSL >= $version"
- if [ "x$mode" = "xvarying" ]; then
- echo "GL_MAX_VARYING_COMPONENTS >= $varying_comps"
- fi
- echo
-
- emit_vs $* 0
- emit_fs $* 1
-
- emit_test_vectors $*
-}
-
-
-# Generate a test that read from an (array of) matrix using a non-constant
-# index in the fragment shader.
-function emit_vs_rd_test
-{
- echo "# Test generated by:"
- echo "# ${cmd}"
- echo
- echo "[require]"
- echo "GLSL >= $version"
- if [ "x$mode" = "xvarying" ]; then
- echo "GL_MAX_VARYING_COMPONENTS >= $varying_comps"
- fi
- echo
-
- emit_vs $* 1
- emit_fs $* 0
-
- emit_test_vectors $*
-}
-
-cmd="$0 $*"
-
-if [ "x$1" = "x" ]; then
- version="1.10"
-else
- case "$1" in
- 1.[12]0) version="$1";;
- *)
- echo "Bogus GLSL version \"$1\" specified."
- exit 1
- ;;
- esac
-fi
-
-for mode in temp uniform varying; do
- # More than 3 is unlikely to work for the varying tests due to using too
- # many varying vectors. mat4[3] uses 12 varying vectors by itself.
- for array_dim in 0 3; do
- for matrix_dim in 2 3 4; do
- if [ $array_dim -ne 0 ]; then
- varying_comps=$((4 + matrix_dim * matrix_dim * array_dim))
- arr="array-"
- idx_txt="index-"
-
- name="fs-${mode}-${arr}mat${matrix_dim}-col-row-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode 1 col float \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-row-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode 1 1 float \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-col-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode 1 col vec${matrix_dim} \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode 1 1 vec${matrix_dim} \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-col-row-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode 1 col float \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-row-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode 1 1 float \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-col-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode 1 col vec${matrix_dim} \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode 1 1 vec${matrix_dim} \
- > $name
- echo $name
- else
- varying_comps=$((4 + matrix_dim * matrix_dim))
- arr=""
- idx_txt=""
- fi
-
- name="fs-${mode}-${arr}mat${matrix_dim}-${idx_txt}col-row-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode index col float \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-${idx_txt}row-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode index 1 float \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-${idx_txt}col-rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode index col vec${matrix_dim} \
- > $name
- echo $name
-
- name="fs-${mode}-${arr}mat${matrix_dim}-${idx_txt}rd.shader_test"
- emit_fs_rd_test $matrix_dim $array_dim $mode index 1 vec${matrix_dim} \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-${idx_txt}col-row-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode index col float \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-${idx_txt}row-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode index 1 float \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-${idx_txt}col-rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode index col vec${matrix_dim} \
- > $name
- echo $name
-
- name="vs-${mode}-${arr}mat${matrix_dim}-${idx_txt}rd.shader_test"
- emit_vs_rd_test $matrix_dim $array_dim $mode index 1 vec${matrix_dim} \
- > $name
- echo $name
- done
- done
-done
diff --git a/tests/spec/glsl-1.10/variable-index-regen.sh b/tests/spec/glsl-1.10/variable-index-regen.sh
index 3df8082..f1fcfc2 100755
--- a/tests/spec/glsl-1.10/variable-index-regen.sh
+++ b/tests/spec/glsl-1.10/variable-index-regen.sh
@@ -4,9 +4,7 @@
# variable-indexing scripts.
(cd execution/variable-indexing &&
- ../../../glsl-1.10/variable-index-read.sh 1.10 &&
../../../glsl-1.10/variable-index-write.sh 1.10)
(cd ../glsl-1.20/execution/variable-indexing &&
- ../../../glsl-1.10/variable-index-read.sh 1.20 &&
../../../glsl-1.10/variable-index-write.sh 1.20)
--
2.4.2
More information about the Piglit
mailing list