def main(): """Main function.""" for api, requirement in six.iteritems(REQUIREMENTS): lod = 'Lod' if api == 'glsl-4.00' else 'LOD' dirname = os.path.join("spec", api.lower(), "compiler", "built-in-functions") utils.safe_makedirs(dirname) for sampler_type, coord_type in six.iteritems(SAMPLER_TYPE_TO_COORD_TYPE): requirements = [requirement['extensions']] if requirement['extensions'] else [] # samplerCubeArray types are part GLSL 4.00 # or GL_ARB_texture_cube_map_array. if api == "ARB_texture_query_lod" and sampler_type in [ 'samplerCubeArray', 'isamplerCubeArray', 'usamplerCubeArray', 'samplerCubeArrayShadow']: requirements.append('GL_ARB_texture_cube_map_array') for execution_stage in ("vs", "fs"): file_extension = 'frag' if execution_stage == 'fs' else 'vert' filename = os.path.join( dirname, "textureQuery{0}-{1}.{2}".format(lod, sampler_type, file_extension)) print(filename) with open(filename, "w") as f: f.write(TEMPLATE.render_unicode( version=requirement['version'], extensions=requirements, execution_stage=execution_stage, sampler_type=sampler_type, coord_type=coord_type, lod=lod))
def main(): utils.safe_makedirs(dirName) for t in TYPES: gen_test('', t, t, VEC_SIZES); gen_test('_half', 'float', 'half', [''] + VEC_SIZES); gen_test('_half', 'double', 'half', [''] + VEC_SIZES);
def main(): """ Generate tests """ dirname = os.path.join('spec', 'glsl-1.20', 'execution') utils.safe_makedirs(dirname) for c, r in itertools.product(range(2, 5), repeat=2): vecs = [ Parameters(c, r, 'vec', 'mat{0}x{1}'.format(r, c)), Parameters(c, r, 'ivec', 'mat{0}x{1}'.format(r, c)) ] if r == c: vecs.extend([ Parameters(c, r, 'vec', 'mat{0}'.format(r)), Parameters(c, r, 'ivec', 'mat{0}'.format(r)) ]) stages = ['vs', 'fs'] types = ['const', 'uniform'] for shader, type_, params in itertools.product(stages, types, vecs): name = os.path.join( dirname, '{shader}-outerProduct-{type}{mat}{vec}.shader_test'.format( shader=shader, type='const-' if type_ == 'const' else '', mat=params.matrix, vec='-ivec' if params.vec_type == 'ivec' else '')) print(name) with open(name, 'w+') as f: f.write(TEMPLATE.render_unicode(params=params, type=type_, shader=shader))
def create_tests(glsl_vers, in_types_array, gl_types, position_orders, arrays_array, names_only): """Creates combinations for flat qualifier tests.""" assert isinstance(glsl_vers, list) assert isinstance(in_types_array, types.GeneratorType) assert isinstance(gl_types, list) assert isinstance(position_orders, list) assert isinstance(arrays_array, list) assert isinstance(names_only, bool) if not names_only: for ver in glsl_vers: utils.safe_makedirs(TestTuple.get_dir_name(ver)) for in_types, position_order, arrays, ver in itertools.product( in_types_array, position_orders, arrays_array, glsl_vers): num_vs_in = 1 # We use an additional vec3 piglit_vertex input for idx, in_type in enumerate(in_types): num_vs_in += (in_type.columns or 1) * arrays[idx] * \ (2 if in_type.type.name == 'double' and in_type.rows in [3, 4] else 1) # dvec* and dmat* didn't appear in GLSL until 4.20 if (in_type.type.name == 'double' and not in_type.scalar) and ver == '410': ver = '420' # Skip the test if it needs too many inputs if num_vs_in > MAX_VERTEX_ATTRIBS: continue yield ver, in_types, gl_types, position_order, arrays, num_vs_in, names_only
def all_tests(names_only): """Returns all the possible contained conversion test instances.""" assert isinstance(names_only, bool) stages = ['vert', 'geom', 'frag'] dimensions = ['1', '2', '3', '4'] basic_types = ['b', 'u', 'i', 'f', 'd', 'i64', 'u64'] target_types = ['d', 'i64', 'u64'] glsl_ver = ['GL_ARB_gpu_shader_int64', 'GL_ARB_gpu_shader_fp64', '400'] if not names_only: test_types = ['compiler', 'execution'] for ver, test_type in itertools.product(glsl_ver, test_types): utils.safe_makedirs(get_dir_name(ver, test_type)) for ver, stage, first_dimension, second_dimension, basic_type, target_type in itertools.product( glsl_ver, stages, dimensions, dimensions, basic_types, target_types): has_int64 = basic_type in ('i64', 'u64') or target_type in ('i64', 'u64') if (not (first_dimension != '1' and (second_dimension == '1' or basic_type not in ('f', 'd') or target_type != 'd')) and (basic_type not in target_types or basic_type < target_type) and ((ver == 'GL_ARB_gpu_shader_int64') == has_int64)): yield RegularTestTuple(ver, stage, first_dimension, second_dimension, basic_type, target_type, names_only)
def gen(name, src, tests): """ Expand a source template for the provided list of test definitions. Generate a GLSL parser test for each of the elements of the 'tests' iterable, each of them should be a dictionary of definitions that will be used as environment to render the source template. The file name of each test will be the concatenation of the 'name' argument with the 'name' item from the respective test dictionary. """ template = Template(dedent(src)) for t in product([{'name': name}], tests): filename = os.path.join('spec', 'ARB_shader_image_load_store', 'compiler', '{0}.{1}'.format(t['name'], t['shader_stage'])) print(filename) dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(template.render(header = gen_header, **t))
def main(): """Main function.""" for ext, ver in EXTENSIONS: # Lower ext in the path name, but keep it capitalized for the generated # tests path = os.path.join('spec', ext[3:].lower(), 'preprocessor') utils.safe_makedirs(path) for stage in ['vert', 'frag', 'geom', 'tesc', 'tese', 'comp']: # Calculate the minimum version for the stage, with extensions. # This makes the maximum number of tests run on the widest swath of # hardware. version, extra_ext = glsl.MinVersion.for_stage_with_ext(stage, ver) if extra_ext is not None: extra_extensions = [extra_ext] else: extra_extensions = [] if not version.is_es: # if the actual version is less than 140 make a compat test and # a core test, otherwise just make a core test if version < 140: _gen_tests(ext, version, stage, path, 'compat', extra_extensions) _gen_tests(ext, glsl.Version('140'), stage, path, 'core', extra_extensions) else: _gen_tests(ext, version, stage, path, 'core', extra_extensions) else: _gen_tests(ext, version, stage, path, 'es', extra_extensions)
def generate_shader_test(self): """Generate the test and write it to the output file.""" shader_test = '[require]\n' shader_test += 'GLSL >= {0:1.2f}\n'.format( float(self.glsl_version()) / 100) shader_test += self.make_additional_requirements() shader_test += '\n' shader_test += '[vertex shader]\n' shader_test += self.make_vertex_shader() shader_test += '\n' gs = self.make_geometry_shader() if gs: shader_test += '[geometry shader]\n' shader_test += gs shader_test += '\n' gl = self.make_geometry_layout() if gl: shader_test += '[geometry layout]\n' shader_test += gl shader_test += '\n' shader_test += '[fragment shader]\n' shader_test += self.make_fragment_shader() shader_test += '\n' shader_test += self.make_vbo_data() shader_test += '[test]\n' shader_test += 'clear color 0.0 0.0 1.0 0.0\n' shader_test += 'clear\n' shader_test += self.make_test() filename = self.filename() dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(shader_test)
def generate_array_tests(type_list, base_name, major, minor): dirname = os.path.join("spec", "glsl-{0}.{1}".format(major, minor), "execution", "uniform-initializer") utils.safe_makedirs(dirname) def parts(): """Generate parts.""" # pylint: disable=undefined-loop-variable for j in range(2): numbers = [] for k in range(num_values): numbers.append(get_value(type_, i + j + k)) yield "{0}({1})".format(type_, ", ".join(numbers)) # pylint: enable=undefined-loop-variable vecs = [] for i, (type_, num_values) in enumerate(type_list): if type_[-1] in ["2", "3", "4"]: name = "u{0}{1}".format(type_[0], type_[-1]) else: name = "u{0}".format(type_[0]) array_type = "{0}[2]".format(type_) value = "{0}({1})".format(array_type, ", ".join(parts())) vecs.append((array_type, name, value)) for target in ("vs", "fs"): template = TEMPLATES.get_template("{0}-initializer.shader_test.mako".format(target)) test_file_name = os.path.join(dirname, "{0}-{1}-array.shader_test".format(target, base_name)) print(test_file_name) with open(test_file_name, "w") as f: f.write(template.render_unicode(type_list=vecs, major=major, minor=minor))
def generate_parser_test(self): """Generate the test and write it to the output file.""" parser_test = '/* [config]\n' parser_test += ' * expect_result: pass\n' parser_test += ' * glsl_version: {0:1.2f}\n'.format( float(self.glsl_version()) / 100) req_extensions = list(self.additional_extensions()) if req_extensions: parser_test += ' * require_extensions: {}\n'.format( ' '.join('GL_{}'.format(r) for r in req_extensions)) parser_test += ' * [end config]\n' parser_test += ' *\n' parser_test += ' * Check that the following test vectors are constant'\ ' folded correctly:\n' for test_vector in self.__test_vectors: parser_test += ' * {0} => {1}\n'.format( self.__signature.template.format( *[glsl_constant(arg) for arg in test_vector.arguments]), glsl_constant(test_vector.result)) parser_test += ' */\n' parser_test += self.make_shader() filename = self.filename() dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(parser_test)
def create_tests(type_names, glsl_vers, names_only): """Creates combinations for flat qualifier tests.""" assert isinstance(type_names, list) assert isinstance(glsl_vers, list) assert isinstance(names_only, bool) modes = ['flat', 'noperspective', 'smooth', 'default'] interface_blocks = [True, False] structs = [True, False] arrays = [True, False] if not names_only: for ver in glsl_vers: utils.safe_makedirs(get_dir_name(ver)) for t_name, mode, interface_block, struct, array, ver in itertools.product( type_names, modes, interface_blocks, structs, arrays, glsl_vers): if ver.endswith(' es'): # There is no "noperspective" interpolation mode in GLSL ES if mode == 'noperspective': continue # There is no support for arrays in input structs in GLSL ES if struct and array: continue # Input interface blocks didn't appear in GLSL until 1.50 if interface_block and ver == '130': ver = '150' # Input interface blocks didn't appear in GLSL ES until 3.20 if interface_block and ver == '300 es': ver = '320 es' # Input structs weren't allowed until 1.50 if struct and ver == '130': ver = '150' yield t_name, mode, interface_block, struct, array, ver, names_only
def make_fs(name, params): """Create a fragment shader test.""" dirname = _DIRNAME.format(params.version) utils.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(): """ Main function """ dirname = os.path.join('spec', 'glsl-1.20', 'execution', 'built-in-functions') utils.safe_makedirs(dirname) for test_id, x in enumerate(TEST_VECTORS, start=2): # make equal tests name = os.path.join( dirname, "glsl-const-builtin-equal-{0:02d}.shader_test".format(test_id)) print(name) with open(name, 'w') as f: f.write(TEMPLATE.render_unicode( func='equal', input=x[0:2], expected=x[2])) # make notEqual tests name = os.path.join( dirname, "glsl-const-builtin-notEqual-{0:02d}.shader_test".format(test_id)) # When generating the notEqual tests, each of the values in the # expected result vector need to be inverted expected = re.sub("true", "FALSE", x[2]) expected = re.sub("false", "TRUE", expected) expected = expected.lower() print(name) with open(name, 'w') as f: f.write(TEMPLATE.render_unicode( func='notEqual', input=x[0:2], expected=expected))
def generate_parser_test(self): """Generate the test and write it to the output file.""" parser_test = '/* [config]\n' parser_test += ' * expect_result: pass\n' parser_test += ' * glsl_version: {0:1.2f}\n'.format( float(self.glsl_version()) / 100) req_extensions = list(self.additional_extensions()) if req_extensions: parser_test += ' * require_extensions: {}\n'.format(' '.join( 'GL_{}'.format(r) for r in req_extensions)) parser_test += ' * [end config]\n' parser_test += ' *\n' parser_test += ' * Check that the following test vectors are constant'\ ' folded correctly:\n' for test_vector in self.__test_vectors: parser_test += ' * {0} => {1}\n'.format( self.__signature.template.format( *[glsl_constant(arg) for arg in test_vector.arguments]), glsl_constant(test_vector.result)) parser_test += ' */\n' parser_test += self.make_shader() filename = self.filename() dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(parser_test)
def make_fs(name, params): """Create a fragment shader test.""" dirname = _DIRNAME.format(params.formated_version) utils.safe_makedirs(dirname) with open(os.path.join(dirname, name), 'w') as f: f.write(_FS_TEMPLATE.render_unicode(params=params)) print(name)
def main(): """ Generate tests """ dirname = os.path.join('spec', 'glsl-1.20', 'execution') utils.safe_makedirs(dirname) for c, r in itertools.product(range(2, 5), repeat=2): vecs = [ Parameters(c, r, 'vec', 'mat{0}x{1}'.format(r, c)), Parameters(c, r, 'ivec', 'mat{0}x{1}'.format(r, c)) ] if r == c: vecs.extend([ Parameters(c, r, 'vec', 'mat{0}'.format(r)), Parameters(c, r, 'ivec', 'mat{0}'.format(r)) ]) stages = ['vs', 'fs'] types = ['const', 'uniform'] for shader, type_, params in itertools.product(stages, types, vecs): name = os.path.join( dirname, '{shader}-outerProduct-{type}{mat}{vec}.shader_test'.format( shader=shader, type='const-' if type_ == 'const' else '', mat=params.matrix, vec='-ivec' if params.vec_type == 'ivec' else '')) print(name) with open(name, 'w+') as f: f.write( TEMPLATE.render_unicode(params=params, type=type_, shader=shader))
def gen(name, src, tests): """ Expand a source template for the provided list of test definitions. Generate a GLSL parser test for each of the elements of the 'tests' iterable, each of them should be a dictionary of definitions that will be used as environment to render the source template. The file name of each test will be the concatenation of the 'name' argument with the 'name' item from the respective test dictionary. """ template = Template(dedent(src)) for t in product([{'name': name}], tests): filename = os.path.join('spec', 'ARB_shader_image_load_store', 'compiler', '{0}.{1}'.format(t['name'], t['shader_stage'])) print(filename) dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(template.render(header=gen_header, **t))
def main(): utils.safe_makedirs(dirName) for t in TYPES: gen_test('', t, t, VEC_SIZES) gen_test('_half', 'float', 'half', [''] + VEC_SIZES) gen_test('_half', 'double', 'half', [''] + VEC_SIZES)
def main(): """ Generate tests """ dirname = os.path.join("spec", "glsl-1.20", "compiler", "built-in-functions") utils.safe_makedirs(dirname) for type_ in [ "int", "float", "bool", "bvec2", "bvec3", "bvec4", "mat2", "mat2x2", "mat2x3", "mat2x4", "mat3", "mat3x2", "mat3x3", "mat3x4", "mat4", "mat4x2", "mat4x3", "mat4x4", ]: name = os.path.join(dirname, "outerProduct-{0}.vert".format(type_)) print(name) with open(name, "w+") as f: f.write(TEMPLATE.render_unicode(type=type_))
def main(): random.seed(0) utils.safe_makedirs(DIR_NAME) for t, ut in TYPES.items(): f = begin_test(t, ut) for ss, ds in itertools.product(VEC_SIZES, VEC_SIZES): ssize = int(ss) * ELEMENTS dsize = int(ds) * ELEMENTS stype_name = t + ss dtype_name = t + ds utype_name = ut + ds data1 = gen_array(ssize, MAX_VALUES['ushort']) data2 = gen_array(ssize, MAX_VALUES['ushort']) mask = gen_array(dsize, MAX_VALUES[ut]) perm = permute(data1, data2, mask, int(ss), int(ds)) f.write( textwrap.dedent(""" [test] name: shuffle2 {stype_name} {utype_name} global_size: {elements} 0 0 kernel_name: test_shuffle2_{stype_name}_{utype_name} arg_out: 0 buffer {dtype_name}[{elements}] {perm} arg_in: 1 buffer {stype_name}[{elements}] {data1} arg_in: 2 buffer {stype_name}[{elements}] {data2} arg_in: 3 buffer {utype_name}[{elements}] {mask} """.format(stype_name=stype_name, utype_name=utype_name, dtype_name=dtype_name, elements=ELEMENTS, perm=' '.join([str(x) for x in perm]), data1=' '.join([str(x) for x in data1]), data2=' '.join([str(x) for x in data2]), mask=' '.join([str(x) for x in mask])))) f.write(textwrap.dedent("""!*/""")) if t == "double": f.write( textwrap.dedent(""" #pragma OPENCL EXTENSION cl_khr_fp64: enable """)) if t == "half": f.write( textwrap.dedent(""" #pragma OPENCL EXTENSION cl_khr_fp16: enable """)) for ss, ds in itertools.product(VEC_SIZES, VEC_SIZES): type_name = t + ss utype_name = ut + ds f.write( textwrap.dedent(""" kernel void test_shuffle2_{type_name}{ssize}_{utype_name}{dsize}(global {type_name}* out, global {type_name}* in1, global {type_name}* in2, global {utype_name}* mask) {{ vstore{dsize}(shuffle2(vload{ssize}(get_global_id(0), in1), vload{ssize}(get_global_id(0), in2), vload{dsize}(get_global_id(0), mask)), get_global_id(0), out); }} """.format(type_name=t, utype_name=ut, ssize=ss, dsize=ds))) f.close()
def main(): """Main function. Generates tests.""" dirname = os.path.join('asmparsertest', 'shaders', 'ARBvp1.0') utils.safe_makedirs(dirname) targets_1 = ["1D", "2D", "3D", "CUBE", "RECT", "SHADOW1D", "SHADOW2D"] # The ordering in this loop is wierd, it's an artifact of the growth of the # original script and is required to ensure that the names of the tests # don't change for inst in ["TEX", "TXB", "TXD", "TXF", "TXL", "TXP", "TXQ"]: i = 1 template = TEMPLATES.get_template('arbvp.mako') for target in targets_1: fname = os.path.join(dirname, "{}-{:0>2d}.txt".format(inst.lower(), i)) with open(fname, 'w') as f: f.write(template.render_unicode(target=target, inst=inst)) print(fname) i += 1 template = TEMPLATES.get_template('nvvp3.mako') for target in targets_1: fname = os.path.join(dirname, "{}-{:0>2d}.txt".format(inst.lower(), i)) with open(fname, 'w') as f: f.write(template.render_unicode(target=target, inst=inst)) print(fname) i += 1 template = TEMPLATES.get_template('nvvp3_2.mako') for target in ["CUBE", "RECT"]: fname = os.path.join(dirname, "{}-{:0>2d}.txt".format(inst.lower(), i)) with open(fname, 'w') as f: f.write(template.render_unicode(target=target, inst=inst)) print(fname) i += 1 template = TEMPLATES.get_template('nvvp3.mako') fname = os.path.join(dirname, "{}-{:0>2d}.txt".format(inst.lower(), i)) with open(fname, 'w') as f: f.write(template.render_unicode(target="SHADOWRECT", inst=inst)) print(fname) i += 1 template = TEMPLATES.get_template('nvvp3_2.mako') for target in ["SHADOW1D", "SHADOW2D", "SHADOWRECT"]: fname = os.path.join(dirname, "{}-{:0>2d}.txt".format(inst.lower(), i)) with open(fname, 'w') as f: f.write(template.render_unicode(target=target, inst=inst)) print(fname) i += 1
def generate_tests(type_list, base_name, major, minor): dirname = os.path.join('spec', 'glsl-{0}.{1}'.format(major, minor), 'execution', 'uniform-initializer') utils.safe_makedirs(dirname) for target in ("vs", "fs"): for t in ALL_TEMPLATES: template = TEMPLATES.get_template( "{0}-initializer{1}.shader_test.mako".format(target, t)) test_file_name = os.path.join( dirname, '{0}-{1}{2}.shader_test'.format(target, base_name, t)) print(test_file_name) # Generate the test vectors. This is a list of tuples. Each # tuple is a type name paired with a value. The value is # formatted as a GLSL constructor. # # A set of types and values is also generated that can be set via # the OpenGL API. Some of the tests use this information. test_vectors = [] api_vectors = [] for i, (type_, num_values) in enumerate(type_list): numbers = [] alt_numbers = [] for j in range(num_values): numbers.append(get_value(type_, i + j)) alt_numbers.append(get_value(type_, i + j + 7)) value = "{0}({1})".format(type_, ", ".join(numbers)) api_type = type_ if type_ == "bool": api_type = "int" elif type_[0] == 'b': api_type = "ivec{0}".format(type_[-1]) if type_[-1] in ["2", "3", "4"]: name = 'u{0}{1}'.format(type_[0], type_[-1]) else: name = 'u{0}'.format(type_[0]) test_vectors.append((type_, name, value)) api_vectors.append((api_type, name, alt_numbers)) with open(test_file_name, "w") as f: f.write(template.render_unicode(type_list=test_vectors, api_types=api_vectors, major=major, minor=minor))
def generate_shader_test(self): """Generate the test and write it to the output file.""" shader_test = '[require]\n' shader_test += 'GLSL >= {0:1.2f}\n'.format( float(self.glsl_version()) / 100) for extension in self.extensions(): shader_test += 'GL_{}\n'.format(extension) shader_test += self.make_additional_requirements() shader_test += '\n' vs = self.make_vertex_shader() if vs: shader_test += '[vertex shader]\n' shader_test += vs shader_test += '\n' tcs = self.make_tess_ctrl_shader() if tcs: shader_test += '[tessellation control shader]\n' shader_test += tcs shader_test += '\n' tes = self.make_tess_eval_shader() if tes: shader_test += '[tessellation evaluation shader]\n' shader_test += tes shader_test += '\n' gs = self.make_geometry_shader() if gs: shader_test += '[geometry shader]\n' shader_test += gs shader_test += '\n' gl = self.make_geometry_layout() if gl: shader_test += '[geometry layout]\n' shader_test += gl shader_test += '\n' fs = self.make_fragment_shader() if fs: shader_test += '[fragment shader]\n' shader_test += fs shader_test += '\n' cs = self.make_compute_shader() if cs: shader_test += '[compute shader]\n' shader_test += cs shader_test += '\n' shader_test += '[test]\n' shader_test += 'clear color 0.0 0.0 1.0 0.0\n' shader_test += 'clear\n' shader_test += self.make_test() filename = self.filename() dirname = os.path.dirname(filename) utils.safe_makedirs(dirname) with open(filename, 'w') as f: f.write(shader_test)
def main(): """main function.""" dirname = os.path.join('spec', 'glsl-1.30', 'linker', 'interpolation-qualifiers') utils.safe_makedirs(dirname) 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)
def main(): random.seed(0) utils.safe_makedirs(DIR_NAME) for t, ut in six.iteritems(TYPES): f = begin_test(t, ut) for ss, ds in itertools.product(VEC_SIZES, VEC_SIZES): ssize = int(ss) * ELEMENTS dsize = int(ds) * ELEMENTS stype_name = t + ss dtype_name = t + ds utype_name = ut + ds data1 = gen_array(ssize, MAX_VALUES['ushort']) data2 = gen_array(ssize, MAX_VALUES['ushort']) mask = gen_array(dsize, MAX_VALUES[ut]) perm = permute(data1, data2, mask, int(ss), int(ds)) f.write(textwrap.dedent(""" [test] name: shuffle2 {stype_name} {utype_name} global_size: {elements} 0 0 kernel_name: test_shuffle2_{stype_name}_{utype_name} arg_out: 0 buffer {dtype_name}[{elements}] {perm} arg_in: 1 buffer {stype_name}[{elements}] {data1} arg_in: 2 buffer {stype_name}[{elements}] {data2} arg_in: 3 buffer {utype_name}[{elements}] {mask} """.format(stype_name=stype_name, utype_name=utype_name, dtype_name=dtype_name, elements=ELEMENTS, perm=' '.join([str(x) for x in perm]), data1=' '.join([str(x) for x in data1]), data2=' '.join([str(x) for x in data2]), mask=' '.join([str(x) for x in mask])))) f.write(textwrap.dedent("""!*/""")) if t == "double": f.write(textwrap.dedent(""" #pragma OPENCL EXTENSION cl_khr_fp64: enable """)) if t == "half": f.write(textwrap.dedent(""" #pragma OPENCL EXTENSION cl_khr_fp16: enable """)) for ss, ds in itertools.product(VEC_SIZES, VEC_SIZES): type_name = t + ss utype_name = ut + ds f.write(textwrap.dedent(""" kernel void test_shuffle2_{type_name}{ssize}_{utype_name}{dsize}(global {type_name}* out, global {type_name}* in1, global {type_name}* in2, global {utype_name}* mask) {{ vstore{dsize}(shuffle2(vload{ssize}(get_global_id(0), in1), vload{ssize}(get_global_id(0), in2), vload{dsize}(get_global_id(0), mask)), get_global_id(0), out); }} """.format(type_name=t, utype_name=ut, ssize=ss, dsize=ds))) f.close()
def all_execution_tests(names_only): """Creates all the combinations for in/out shader runner tests.""" assert isinstance(names_only, bool) type_names = ['double', 'dvec2', 'dvec3', 'dvec4'] glsl_ver = ['150', '400'] if not names_only: for ver in glsl_ver: utils.safe_makedirs(get_dir_name(ver, 'execution')) for t_name, ver in itertools.product(type_names, glsl_ver): yield t_name, ver, names_only
def main(): """ Generate tests """ dirname = os.path.join('spec', 'glsl-1.20', 'compiler', 'built-in-functions') utils.safe_makedirs(dirname) for type_ in ['int', 'float', 'bool', 'bvec2', 'bvec3', 'bvec4', 'mat2', 'mat2x2', 'mat2x3', 'mat2x4', 'mat3', 'mat3x2', 'mat3x3', 'mat3x4', 'mat4', 'mat4x2', 'mat4x3', 'mat4x4']: name = os.path.join(dirname, 'outerProduct-{0}.vert'.format(type_)) print(name) with open(name, 'w+') as f: f.write(TEMPLATE.render_unicode(type=type_))
def main(): utils.safe_makedirs(DIR_NAME) for t in TYPES: gen_test_constant('', t, t, VEC_SIZES) gen_test_global('', t, t, VEC_SIZES) gen_test_local('', t, t, VEC_SIZES) gen_test_private('', t, t, VEC_SIZES) # There's no vload_half for double type gen_test_constant('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_global('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_local('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_private('_half', 'float', 'half', [''] + VEC_SIZES)
def main(): utils.safe_makedirs(DIR_NAME) for t in TYPES: gen_test_global('', t, t, VEC_SIZES) gen_test_local('', t, t, VEC_SIZES) gen_test_private('', t, t, VEC_SIZES) gen_test_global('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_global('_half', 'double', 'half', [''] + VEC_SIZES) gen_test_local('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_local('_half', 'double', 'half', [''] + VEC_SIZES) gen_test_private('_half', 'float', 'half', [''] + VEC_SIZES) gen_test_private('_half', 'double', 'half', [''] + VEC_SIZES)
def all_tests(names_only): """Creates all the combinations for flat qualifier tests.""" assert isinstance(names_only, bool) glsl_vers = ['GL_ARB_vertex_attrib_64bit', '420'] if not names_only: for ver in glsl_vers: utils.safe_makedirs(TestTuple.get_dir_name(ver)) for mat in GLSL_DMAT_TYPES: for columns in itertools.product(range(2), repeat=mat.columns): if (0 not in columns) or (1 not in columns): continue for ver in glsl_vers: yield ColumnsTestTuple(ver, mat, columns, names_only)
def all_compilation_tests(names_only): """Creates all the combinations for in/out compilation tests.""" assert isinstance(names_only, bool) type_names = ['double', 'dvec2', 'dvec3', 'dvec4', 'dmat2', 'dmat2x3', 'dmat2x4', 'dmat3x2', 'dmat3', 'dmat3x4', 'dmat4x2', 'dmat4x3', 'dmat4'] shaders = ['frag', 'vert'] glsl_ver = ['150', '400'] if not names_only: for ver in glsl_ver: utils.safe_makedirs(get_dir_name(ver, 'compiler')) for t_name, shader, ver in itertools.product(type_names, shaders, glsl_ver): yield t_name, shader, ver, names_only
def all_tests(names_only): """Creates all the combinations for flat qualifier tests.""" assert isinstance(names_only, bool) # We need additional directories for GLSL 150 and GLSL ES 320 if not names_only: utils.safe_makedirs(get_dir_name('150')) utils.safe_makedirs(get_dir_name('320 es')) for test_args in (list(create_tests(INT_TYPES + UINT_TYPES, ['130', '300 es'], names_only)) + list(create_tests(DOUBLE_TYPES, ['GL_ARB_gpu_shader_fp64', '400'], names_only))): yield test_args
def main(): utils.safe_makedirs(DIR_NAME) for t in TYPES: gen_test_constant('', t, t, VEC_SIZES, False) gen_test_global('', t, t, VEC_SIZES, False) gen_test_local('', t, t, VEC_SIZES, False) gen_test_private('', t, t, VEC_SIZES, False) for aligned in False, True: suffix = "a_half" if aligned else "_half" vec_sizes = VEC_SIZES if aligned else [''] + VEC_SIZES # There's no vload_half for double type gen_test_constant(suffix, 'float', 'half', vec_sizes, aligned) gen_test_global(suffix, 'float', 'half', vec_sizes, aligned) gen_test_local(suffix, 'float', 'half', vec_sizes, aligned) gen_test_private(suffix, 'float', 'half', vec_sizes, aligned)
def main(): utils.safe_makedirs(DIR_NAME) for t in TYPES: gen_test_global('', t, t, VEC_SIZES, False); gen_test_local('', t, t, VEC_SIZES, False); gen_test_private('', t, t, VEC_SIZES, False); for aligned in False, True: suffix = "a_half" if aligned else "_half" vec_sizes = VEC_SIZES if aligned else [''] + VEC_SIZES gen_test_global(suffix, 'float', 'half', vec_sizes, aligned); gen_test_global(suffix, 'double', 'half', vec_sizes, aligned); gen_test_local(suffix, 'float', 'half', vec_sizes, aligned); gen_test_local(suffix, 'double', 'half', vec_sizes, aligned); gen_test_private(suffix, 'float', 'half', vec_sizes, aligned); gen_test_private(suffix, 'double', 'half', vec_sizes, aligned);
def generate_tests(type_list, base_name, major, minor): dirname = os.path.join("spec", "glsl-{0}.{1}".format(major, minor), "execution", "uniform-initializer") utils.safe_makedirs(dirname) for target in ("vs", "fs"): for t in ALL_TEMPLATES: template = TEMPLATES.get_template("{0}-initializer{1}.shader_test.mako".format(target, t)) test_file_name = os.path.join(dirname, "{0}-{1}{2}.shader_test".format(target, base_name, t)) print(test_file_name) # Generate the test vectors. This is a list of tuples. Each # tuple is a type name paired with a value. The value is # formatted as a GLSL constructor. # # A set of types and values is also generated that can be set via # the OpenGL API. Some of the tests use this information. test_vectors = [] api_vectors = [] for i, (type_, num_values) in enumerate(type_list): numbers = [] alt_numbers = [] for j in range(num_values): numbers.append(get_value(type_, i + j)) alt_numbers.append(get_value(type_, i + j + 7)) value = "{0}({1})".format(type_, ", ".join(numbers)) api_type = type_ if type_ == "bool": api_type = "int" elif type_[0] == "b": api_type = "ivec{0}".format(type_[-1]) if type_[-1] in ["2", "3", "4"]: name = "u{0}{1}".format(type_[0], type_[-1]) else: name = "u{0}".format(type_[0]) test_vectors.append((type_, name, value)) api_vectors.append((api_type, name, alt_numbers)) with open(test_file_name, "w") as f: f.write( template.render_unicode(type_list=test_vectors, api_types=api_vectors, major=major, minor=minor) )
def main(): utils.safe_makedirs(DIR_NAME) for t in TYPES: gen_test_constant('', t, t, VEC_SIZES, False); gen_test_global('', t, t, VEC_SIZES, False); gen_test_local('', t, t, VEC_SIZES, False); gen_test_private('', t, t, VEC_SIZES, False); for aligned in False, True: suffix = "a_half" if aligned else "_half" vec_sizes= VEC_SIZES if aligned else [''] + VEC_SIZES; # There's no vload_half for double type gen_test_constant(suffix, 'float', 'half', vec_sizes, aligned); gen_test_global(suffix, 'float', 'half', vec_sizes, aligned); gen_test_local(suffix, 'float', 'half', vec_sizes, aligned); gen_test_private(suffix, 'float', 'half', vec_sizes, aligned);
def main(): """main function.""" # pylint: disable=line-too-long for api, requirement in six.iteritems(REQUIREMENTS): version = requirement['version'] extensions = [requirement['extension'] ] if requirement['extension'] else [] dirname = os.path.join('spec', api.lower(), 'execution', 'built-in-functions') utils.safe_makedirs(dirname) for func, attrib in six.iteritems(FUNCS): for execution_stage in ('vs', 'fs'): for in_modifier_func, modifier_func in six.iteritems( MODIFIER_FUNCS): # Modifying the sign of an unsigned number doesn't make sense. if func == 'uintBitsToFloat' and in_modifier_func != '': continue modifier_name = '-' + in_modifier_func if in_modifier_func != '' else '' filename = os.path.join( dirname, "{0}-{1}{2}.shader_test".format( execution_stage, func, modifier_name)) print(filename) if in_modifier_func == 'neg': in_modifier_func = '-' elif in_modifier_func == 'neg_abs': in_modifier_func = '-abs' with open(filename, 'w') as f: f.write( TEMPLATE.render_unicode( version=version, extensions=extensions, execution_stage=execution_stage, func=func, modifier_func=modifier_func, in_modifier_func=in_modifier_func, in_func=attrib['in_func'], out_func=attrib['out_func'], input_type=attrib['input'], output_type=attrib['output'], test_data=TEST_DATA))
def gen(src, tests): """ Expand a source template for the provided list of test definitions. Generate a test script for each element of the 'tests' iterable, each of them should be a dictionary of definitions that will be used as environment to render the source template. The 'path' attribute of each dictionary gives the filename each test will be written to. """ template = Template(dedent(src)) for t in tests: print(t['path']) utils.safe_makedirs(os.path.dirname(t['path'])) with open(t['path'], 'w') as f: f.write(template.render(**t))
def all_tests(names_only): """Returns all the possible zero sign conversion test instances.""" assert isinstance(names_only, bool) stages = ['vert', 'geom', 'frag'] dimensions = ['1', '2', '3', '4'] basic_types = ['f'] glsl_ver = ['410', '420'] if not names_only: for ver in glsl_ver: utils.safe_makedirs(get_dir_name(ver, 'execution')) for ver, stage, first_dimension, second_dimension, basic_type in itertools.product( glsl_ver, stages, dimensions, dimensions, basic_types): if not (first_dimension != '1' and second_dimension == '1'): yield ZeroSignTestTuple(ver, stage, first_dimension, second_dimension, basic_type, names_only)
def main(): """main function.""" # pylint: disable=line-too-long for api, requirement in six.iteritems(REQUIREMENTS): version = requirement['version'] extensions = [requirement['extension']] if requirement['extension'] else [] dirname = os.path.join('spec', api.lower(), 'execution', 'built-in-functions') utils.safe_makedirs(dirname) for func, attrib in six.iteritems(FUNCS): for execution_stage in ('vs', 'fs'): for in_modifier_func, modifier_func in six.iteritems(MODIFIER_FUNCS): # Modifying the sign of an unsigned number doesn't make sense. if func == 'uintBitsToFloat' and in_modifier_func != '': continue modifier_name = '-' + in_modifier_func if in_modifier_func != '' else '' filename = os.path.join( dirname, "{0}-{1}{2}.shader_test".format(execution_stage, func, modifier_name)) print(filename) if in_modifier_func == 'neg': in_modifier_func = '-' elif in_modifier_func == 'neg_abs': in_modifier_func = '-abs' with open(filename, 'w') as f: f.write(TEMPLATE.render_unicode( version=version, extensions=extensions, execution_stage=execution_stage, func=func, modifier_func=modifier_func, in_modifier_func=in_modifier_func, in_func=attrib['in_func'], out_func=attrib['out_func'], input_type=attrib['input'], output_type=attrib['output'], test_data=TEST_DATA))
def generate_array_tests(type_list, base_name, major, minor): dirname = os.path.join('spec', 'glsl-{0}.{1}'.format(major, minor), 'execution', 'uniform-initializer') utils.safe_makedirs(dirname) def parts(): """Generate parts.""" # pylint: disable=undefined-loop-variable for j in range(2): numbers = [] for k in range(num_values): numbers.append(get_value(type_, i + j + k)) yield '{0}({1})'.format(type_, ', '.join(numbers)) # pylint: enable=undefined-loop-variable vecs = [] for i, (type_, num_values) in enumerate(type_list): if type_[-1] in ["2", "3", "4"]: name = 'u{0}{1}'.format(type_[0], type_[-1]) else: name = 'u{0}'.format(type_[0]) array_type = '{0}[2]'.format(type_) value = "{0}({1})".format(array_type, ", ".join(parts())) vecs.append((array_type, name, value)) for target in ("vs", "fs"): template = TEMPLATES.get_template( '{0}-initializer.shader_test.mako'.format(target)) test_file_name = os.path.join( dirname, '{0}-{1}-array.shader_test'.format(target, base_name)) print(test_file_name) with open(test_file_name, "w") as f: f.write(template.render_unicode(type_list=vecs, major=major, minor=minor))
def main(): utils.safe_makedirs(dirName) for t in TYPES: for s in VEC_SIZES: if s == '': size = 1 else: size = int(s) type_name = t + s f = begin_test(type_name, 'global') f.write(textwrap.dedent(""" [test] name: global address space global_size: 1 0 0 kernel_name: store_global arg_out: 0 buffer {type_name}[8] {gen_array} arg_in: 1 buffer {type_name}[8] {gen_array} [test] name: global address space work items global_size: 8 0 0 kernel_name: store_global_wi arg_out: 0 buffer {type_name}[8] {gen_array} arg_in: 1 buffer {type_name}[8] {gen_array} """.format(type_name=type_name, gen_array=gen_array(size)))) f.close() f = begin_test(type_name, 'local') f.write(textwrap.dedent(""" [test] name: local address space global_size: 8 0 0 local_size: 8 0 0 kernel_name: store_local arg_out: 0 buffer {type_name}[8] {gen_array} arg_in: 1 buffer {type_name}[8] {gen_array} """.format(type_name=type_name, gen_array=gen_array(size)))) f.close()
def create_tests(type_names, glsl_vers, names_only): """Creates combinations for flat qualifier tests.""" assert isinstance(type_names, list) assert isinstance(glsl_vers, list) assert isinstance(names_only, bool) modes = ['flat', 'noperspective', 'smooth', 'default'] interface_blocks = [True, False] structs = [True, False] arrays = [True, False] if not names_only: for ver in glsl_vers: utils.safe_makedirs(get_dir_name(ver)) for t_name, mode, interface_block, struct, array, ver in itertools.product(type_names, modes, interface_blocks, structs, arrays, glsl_vers): if ver.endswith(' es'): # There is no "noperspective" interpolation mode in GLSL ES if mode == 'noperspective': continue # There is no support for arrays in input structs in GLSL ES if struct and array: continue # Input interface blocks didn't appear in GLSL until 1.50 if interface_block and ver == '130': ver = '150' # Input interface blocks didn't appear in GLSL ES until 3.20 if interface_block and ver == '300 es': ver = '320 es' # Input structs weren't allowed until 1.50 if struct and ver == '130': ver = '150' yield t_name, mode, interface_block, struct, array, ver, names_only
def main(): """ Main function Writes tests to generated_tests/spec/arb_shader_texture_lod/ directory """ dirname = "spec/arb_shader_texture_lod/compiler" utils.safe_makedirs(dirname) for params in LOD_TESTS: name = os.path.join( dirname, "tex_lod-{mode}-{dimensions}-{coord}.frag".format( mode=params.mode, dimensions=params.dimensions, coord=params.coord ), ) print(name) with open(name, "w+") as f: f.write(TEMPLATES.get_template("frag_lod.glsl_parser_test.mako").render_unicode(param=params)) for params in GRAD_TESTS: # Generate fragment shader test name = os.path.join( dirname, "tex_grad-{mode}-{dimensions}-{coord}".format( mode=params.mode, dimensions=params.dimensions, coord=params.coord ), ) for stage in ["frag", "vert"]: print("{0}.{1}".format(name, stage)) with open("{0}.{1}".format(name, stage), "w+") as f: f.write( TEMPLATES.get_template("tex_grad.{0}.mako".format(stage)).render_unicode( param=params, extensions=get_extensions(params.mode) ) )