GitLab will be down for maintenance this Sunday 13th June, from approx 7-11am UTC. This is for a PostgreSQL migration. See the tracker issue for more informations.

Commit cbbfe747 authored by Dylan Baker's avatar Dylan Baker
Browse files

interpolation_qualifier...: combine loops



This uses a single loop (generated by itertools.product), and individual
generators functions to produce tests. The obvious advantage is that we
loop over the same data a fewer number of times, the other advantage is
a clearer division of code by splitting a function with several hundred
lines of code into multiple functions.
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
parent e3531a82
......@@ -23,6 +23,7 @@
from __future__ import print_function
import os
import itertools
from templates import template_dir
......@@ -62,6 +63,107 @@ vertex_shader_to_fragment_shader_variable_map = {
}
def make_fs_vs_tests(fs_mode, vs_mode, dirname):
if vs_mode == fs_mode:
return
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'{0}-{1}-{2}-{3}.shader_test'.format(
vs_mode, var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template('vs-fs.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
def make_vs_unused_tests(vs_mode, dirname):
if vs_mode == 'default':
return
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'{0}-{1}-unused-{2}.shader_test'.format(vs_mode, var,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(
TEMPLATES.get_template('vs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var))
def make_fs_unused_tests(fs_mode, vs_mode, dirname):
if fs_mode == 'default':
return
for var in vertex_shader_variables_front_only:
filename = os.path.join(
dirname,
'unused-{0}-{1}-{2}.shader_test'.format(
var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template('fs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
def make_vs_fs_unused_tests(fs_mode, vs_mode, dirname):
if vs_mode == fs_mode:
return
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
vs_mode, var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template(
'fs-vs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
def make_vs_fs_flip_tests(fs_mode, vs_mode, dirname):
if vs_mode == fs_mode:
return
for this_side in vertex_shader_variables:
other_side = other_side_map[this_side]
filename = os.path.join(
dirname,
'{0}-{1}-{2}-{3}.shader_test'.format(
vs_mode, this_side, fs_mode, other_side))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template(
'vs-fs-flip.shader_test.mako').render(
vs_mode=vs_mode,
this_side_variable=this_side,
other_side_variable=other_side,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[this_side]))
def main():
"""main function."""
dirname = os.path.join('spec', 'glsl-1.30', 'linker',
......@@ -70,105 +172,12 @@ def main():
if not os.path.exists(dirname):
os.makedirs(dirname)
for fs_mode in interpolation_modes:
for vs_mode in interpolation_modes:
if vs_mode == fs_mode:
continue
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'{0}-{1}-{2}-{3}.shader_test'.format(
vs_mode, var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template('vs-fs.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
for vs_mode in interpolation_modes:
if vs_mode == 'default':
continue
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'{0}-{1}-unused-{2}.shader_test'.format(vs_mode, var,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(
TEMPLATES.get_template('vs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var))
for fs_mode in interpolation_modes:
if fs_mode == 'default':
continue
for var in vertex_shader_variables_front_only:
filename = os.path.join(
dirname,
'unused-{0}-{1}-{2}.shader_test'.format(
var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template('fs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
for fs_mode in interpolation_modes:
for vs_mode in interpolation_modes:
if vs_mode == fs_mode:
continue
for var in vertex_shader_variables:
filename = os.path.join(
dirname,
'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
vs_mode, var, fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template(
'fs-vs-unused.shader_test.mako').render(
vs_mode=vs_mode,
vs_variable=var,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[var]))
for fs_mode in interpolation_modes:
for vs_mode in interpolation_modes:
if vs_mode == fs_mode:
continue
for this_side in vertex_shader_variables:
other_side = other_side_map[this_side]
filename = os.path.join(
dirname,
'{0}-{1}-{2}-{3}.shader_test'.format(
vs_mode, this_side, fs_mode, other_side))
print(filename)
with open(filename, 'w') as f:
f.write(TEMPLATES.get_template(
'vs-fs-flip.shader_test.mako').render(
vs_mode=vs_mode,
this_side_variable=this_side,
other_side_variable=other_side,
fs_mode=fs_mode,
fs_variable=vertex_shader_to_fragment_shader_variable_map[this_side]))
for fs_mode, vs_mode in itertools.product(interpolation_modes, repeat=2):
make_fs_vs_tests(fs_mode, vs_mode, dirname)
make_vs_unused_tests(vs_mode, dirname)
make_fs_unused_tests(fs_mode, vs_mode, dirname)
make_vs_fs_unused_tests(fs_mode, vs_mode, dirname)
make_vs_fs_flip_tests(fs_mode, vs_mode, dirname)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment