2016-03-02 20:09:16 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2017-01-25 09:26:39 +03:00
|
|
|
import os.path
|
2016-03-02 20:09:16 +03:00
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
import re
|
|
|
|
import itertools
|
|
|
|
import hashlib
|
|
|
|
import shutil
|
2016-03-22 16:44:12 +03:00
|
|
|
import argparse
|
2017-02-04 12:19:44 +03:00
|
|
|
import codecs
|
2016-03-02 20:09:16 +03:00
|
|
|
|
2017-02-05 13:04:45 +03:00
|
|
|
force_no_external_validation = False
|
2017-01-25 11:01:53 +03:00
|
|
|
|
2016-03-02 20:09:16 +03:00
|
|
|
def parse_stats(stats):
|
|
|
|
m = re.search('([0-9]+) work registers', stats)
|
|
|
|
registers = int(m.group(1)) if m else 0
|
|
|
|
|
|
|
|
m = re.search('([0-9]+) uniform registers', stats)
|
|
|
|
uniform_regs = int(m.group(1)) if m else 0
|
|
|
|
|
|
|
|
m_list = re.findall('(-?[0-9]+)\s+(-?[0-9]+)\s+(-?[0-9]+)', stats)
|
|
|
|
alu_short = float(m_list[1][0]) if m_list else 0
|
|
|
|
ls_short = float(m_list[1][1]) if m_list else 0
|
|
|
|
tex_short = float(m_list[1][2]) if m_list else 0
|
|
|
|
alu_long = float(m_list[2][0]) if m_list else 0
|
|
|
|
ls_long = float(m_list[2][1]) if m_list else 0
|
|
|
|
tex_long = float(m_list[2][2]) if m_list else 0
|
|
|
|
|
|
|
|
return (registers, uniform_regs, alu_short, ls_short, tex_short, alu_long, ls_long, tex_long)
|
|
|
|
|
|
|
|
def get_shader_type(shader):
|
|
|
|
_, ext = os.path.splitext(shader)
|
|
|
|
if ext == '.vert':
|
|
|
|
return '--vertex'
|
|
|
|
elif ext == '.frag':
|
|
|
|
return '--fragment'
|
|
|
|
elif ext == '.comp':
|
|
|
|
return '--compute'
|
|
|
|
elif ext == '.tesc':
|
|
|
|
return '--tessellation_control'
|
|
|
|
elif ext == '.tese':
|
|
|
|
return '--tessellation_evaluation'
|
|
|
|
elif ext == '.geom':
|
|
|
|
return '--geometry'
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def get_shader_stats(shader):
|
|
|
|
f, path = tempfile.mkstemp()
|
|
|
|
|
|
|
|
os.close(f)
|
|
|
|
p = subprocess.Popen(['malisc', get_shader_type(shader), '--core', 'Mali-T760', '-V', shader], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
os.remove(path)
|
|
|
|
|
|
|
|
if p.returncode != 0:
|
|
|
|
print(stderr.decode('utf-8'))
|
|
|
|
raise OSError('malisc failed')
|
|
|
|
p.wait()
|
|
|
|
|
|
|
|
returned = stdout.decode('utf-8')
|
|
|
|
return parse_stats(returned)
|
|
|
|
|
2017-01-31 06:55:21 +03:00
|
|
|
def print_msl_compiler_version():
|
|
|
|
try:
|
|
|
|
subprocess.check_call(['xcrun', '--sdk', 'iphoneos', 'metal', '--version'])
|
|
|
|
print('...are the Metal compiler characteristics.\n') # display after so xcrun FNF is silent
|
|
|
|
except OSError as e:
|
|
|
|
if (e.errno != os.errno.ENOENT): # Ignore xcrun not found error
|
|
|
|
raise
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def validate_shader_msl(shader, opt):
|
|
|
|
msl_path = reference_path(shader[0], shader[1], opt)
|
2018-04-04 11:00:37 +03:00
|
|
|
msl2 = '.msl2.' in msl_path
|
2017-01-31 06:55:21 +03:00
|
|
|
try:
|
2017-06-15 22:24:22 +03:00
|
|
|
msl_os = 'macosx'
|
|
|
|
# msl_os = 'iphoneos'
|
2018-04-03 15:26:24 +03:00
|
|
|
subprocess.check_call(['xcrun', '--sdk', msl_os, 'metal', '-x', 'metal', '-std=osx-metal{}'.format('2.0' if msl2 else '1.2'), '-Werror', '-Wno-unused-variable', msl_path])
|
2017-01-31 06:55:21 +03:00
|
|
|
print('Compiled Metal shader: ' + msl_path) # display after so xcrun FNF is silent
|
|
|
|
except OSError as oe:
|
|
|
|
if (oe.errno != os.errno.ENOENT): # Ignore xcrun not found error
|
|
|
|
raise
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('Error compiling Metal shader: ' + msl_path)
|
|
|
|
sys.exit(1)
|
2016-03-22 16:44:12 +03:00
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def cross_compile_msl(shader, spirv, opt):
|
2018-04-03 15:26:24 +03:00
|
|
|
msl2 = '.msl2.' in shader
|
2017-01-18 21:05:57 +03:00
|
|
|
spirv_f, spirv_path = tempfile.mkstemp()
|
|
|
|
msl_f, msl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
|
|
|
|
os.close(spirv_f)
|
|
|
|
os.close(msl_f)
|
2017-09-29 12:07:11 +03:00
|
|
|
|
|
|
|
if spirv:
|
|
|
|
subprocess.check_call(['spirv-as', '-o', spirv_path, shader])
|
|
|
|
else:
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['glslangValidator', '--target-env', 'vulkan1.1', '-V', '-o', spirv_path, shader])
|
2017-09-29 12:07:11 +03:00
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
if opt:
|
|
|
|
subprocess.check_call(['spirv-opt', '-O', '-o', spirv_path, spirv_path])
|
|
|
|
|
2017-01-18 21:05:57 +03:00
|
|
|
spirv_cross_path = './spirv-cross'
|
2018-04-03 15:26:24 +03:00
|
|
|
|
|
|
|
msl_args = [spirv_cross_path, '--entry', 'main', '--output', msl_path, spirv_path, '--msl']
|
|
|
|
if msl2:
|
|
|
|
msl_args.append('--msl-version')
|
|
|
|
msl_args.append('20000')
|
|
|
|
|
|
|
|
subprocess.check_call(msl_args)
|
2018-04-11 11:28:39 +03:00
|
|
|
|
|
|
|
if not shader_is_invalid_spirv(msl_path):
|
|
|
|
subprocess.check_call(['spirv-val', '--target-env', 'vulkan1.1', spirv_path])
|
|
|
|
|
2017-01-18 21:05:57 +03:00
|
|
|
return (spirv_path, msl_path)
|
|
|
|
|
2017-12-12 13:03:46 +03:00
|
|
|
def shader_model_hlsl(shader):
|
|
|
|
if '.vert' in shader:
|
|
|
|
return '-Tvs_5_1'
|
|
|
|
elif '.frag' in shader:
|
|
|
|
return '-Tps_5_1'
|
|
|
|
elif '.comp' in shader:
|
|
|
|
return '-Tcs_5_1'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2017-12-12 15:23:56 +03:00
|
|
|
def shader_to_win_path(shader):
|
|
|
|
# It's (very) convenient to be able to run HLSL testing in wine on Unix-likes, so support that.
|
|
|
|
try:
|
|
|
|
with subprocess.Popen(['winepath', '-w', shader], stdout = subprocess.PIPE, stderr = subprocess.PIPE) as f:
|
|
|
|
stdout_data, stderr_data = f.communicate()
|
|
|
|
return stdout_data.decode('utf-8')
|
|
|
|
except OSError as oe:
|
|
|
|
if (oe.errno != os.errno.ENOENT): # Ignore not found errors
|
|
|
|
return shader
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
raise
|
|
|
|
|
2017-12-12 15:33:13 +03:00
|
|
|
return shader
|
|
|
|
|
2018-04-18 17:43:28 +03:00
|
|
|
ignore_fxc = False
|
2017-01-26 13:46:29 +03:00
|
|
|
def validate_shader_hlsl(shader):
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['glslangValidator', '-e', 'main', '-D', '--target-env', 'vulkan1.1', '-V', shader])
|
2017-12-12 15:23:56 +03:00
|
|
|
is_no_fxc = '.nofxc.' in shader
|
2018-04-18 17:43:28 +03:00
|
|
|
global ignore_fxc
|
|
|
|
if (not ignore_fxc) and (not force_no_external_validation) and (not is_no_fxc):
|
2017-12-12 15:23:56 +03:00
|
|
|
try:
|
|
|
|
win_path = shader_to_win_path(shader)
|
|
|
|
subprocess.check_call(['fxc', '-nologo', shader_model_hlsl(shader), win_path])
|
|
|
|
except OSError as oe:
|
|
|
|
if (oe.errno != os.errno.ENOENT): # Ignore not found errors
|
|
|
|
raise
|
2018-04-18 17:43:28 +03:00
|
|
|
else:
|
|
|
|
ignore_fxc = True
|
2017-12-12 15:23:56 +03:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print('Failed compiling HLSL shader:', shader, 'with FXC.')
|
|
|
|
sys.exit(1)
|
2017-01-26 13:46:29 +03:00
|
|
|
|
2017-06-30 11:34:21 +03:00
|
|
|
def shader_to_sm(shader):
|
2018-04-11 16:02:02 +03:00
|
|
|
if '.sm60.' in shader:
|
|
|
|
return '60'
|
|
|
|
elif '.sm51.' in shader:
|
2017-06-30 11:34:21 +03:00
|
|
|
return '51'
|
|
|
|
elif '.sm20.' in shader:
|
|
|
|
return '20'
|
|
|
|
else:
|
|
|
|
return '50'
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def cross_compile_hlsl(shader, spirv, opt):
|
2017-01-26 11:45:17 +03:00
|
|
|
spirv_f, spirv_path = tempfile.mkstemp()
|
|
|
|
hlsl_f, hlsl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
|
|
|
|
os.close(spirv_f)
|
|
|
|
os.close(hlsl_f)
|
2017-09-29 12:07:11 +03:00
|
|
|
|
|
|
|
if spirv:
|
|
|
|
subprocess.check_call(['spirv-as', '-o', spirv_path, shader])
|
|
|
|
else:
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['glslangValidator', '--target-env', 'vulkan1.1', '-V', '-o', spirv_path, shader])
|
2017-09-29 12:07:11 +03:00
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
if opt:
|
|
|
|
subprocess.check_call(['spirv-opt', '-O', '-o', spirv_path, spirv_path])
|
|
|
|
|
2017-01-26 11:45:17 +03:00
|
|
|
spirv_cross_path = './spirv-cross'
|
2017-06-30 11:34:21 +03:00
|
|
|
|
|
|
|
sm = shader_to_sm(shader)
|
|
|
|
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', hlsl_path, spirv_path, '--hlsl-enable-compat', '--hlsl', '--shader-model', sm])
|
2018-04-11 11:28:39 +03:00
|
|
|
|
|
|
|
if not shader_is_invalid_spirv(hlsl_path):
|
|
|
|
subprocess.check_call(['spirv-val', '--target-env', 'vulkan1.1', spirv_path])
|
2017-01-26 11:45:17 +03:00
|
|
|
|
2017-01-26 13:46:29 +03:00
|
|
|
validate_shader_hlsl(hlsl_path)
|
|
|
|
|
2017-01-26 12:06:05 +03:00
|
|
|
return (spirv_path, hlsl_path)
|
2017-01-26 11:45:17 +03:00
|
|
|
|
2017-01-25 09:26:39 +03:00
|
|
|
def validate_shader(shader, vulkan):
|
|
|
|
if vulkan:
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['glslangValidator', '--target-env', 'vulkan1.1', '-V', shader])
|
2017-01-25 09:26:39 +03:00
|
|
|
else:
|
|
|
|
subprocess.check_call(['glslangValidator', shader])
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def cross_compile(shader, vulkan, spirv, invalid_spirv, eliminate, is_legacy, flatten_ubo, sso, flatten_dim, opt):
|
2016-03-02 20:09:16 +03:00
|
|
|
spirv_f, spirv_path = tempfile.mkstemp()
|
|
|
|
glsl_f, glsl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
|
|
|
|
os.close(spirv_f)
|
|
|
|
os.close(glsl_f)
|
|
|
|
|
2016-05-11 00:39:41 +03:00
|
|
|
if vulkan or spirv:
|
2016-05-05 11:16:22 +03:00
|
|
|
vulkan_glsl_f, vulkan_glsl_path = tempfile.mkstemp(suffix = os.path.basename(shader))
|
|
|
|
os.close(vulkan_glsl_f)
|
|
|
|
|
2016-05-11 00:39:41 +03:00
|
|
|
if spirv:
|
|
|
|
subprocess.check_call(['spirv-as', '-o', spirv_path, shader])
|
|
|
|
else:
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['glslangValidator', '--target-env', 'vulkan1.1', '-V', '-o', spirv_path, shader])
|
2016-05-11 00:39:41 +03:00
|
|
|
|
2017-11-21 18:52:01 +03:00
|
|
|
if opt and (not invalid_spirv):
|
2017-11-21 11:52:53 +03:00
|
|
|
subprocess.check_call(['spirv-opt', '-O', '-o', spirv_path, spirv_path])
|
|
|
|
|
2016-09-12 21:11:30 +03:00
|
|
|
if not invalid_spirv:
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call(['spirv-val', '--target-env', 'vulkan1.1', spirv_path])
|
2016-05-05 11:16:22 +03:00
|
|
|
|
2017-01-17 01:19:49 +03:00
|
|
|
extra_args = []
|
|
|
|
if eliminate:
|
|
|
|
extra_args += ['--remove-unused-variables']
|
2017-01-13 18:41:27 +03:00
|
|
|
if is_legacy:
|
2017-01-17 01:19:49 +03:00
|
|
|
extra_args += ['--version', '100', '--es']
|
|
|
|
if flatten_ubo:
|
|
|
|
extra_args += ['--flatten-ubo']
|
2017-05-22 16:30:43 +03:00
|
|
|
if sso:
|
|
|
|
extra_args += ['--separate-shader-objects']
|
2017-05-22 18:40:00 +03:00
|
|
|
if flatten_dim:
|
|
|
|
extra_args += ['--flatten-multidimensional-arrays']
|
2017-01-13 18:41:27 +03:00
|
|
|
|
2016-05-11 20:39:38 +03:00
|
|
|
spirv_cross_path = './spirv-cross'
|
2016-05-05 11:16:22 +03:00
|
|
|
|
2016-05-11 20:55:57 +03:00
|
|
|
# A shader might not be possible to make valid GLSL from, skip validation for this case.
|
2016-05-11 00:39:41 +03:00
|
|
|
if (not ('nocompat' in glsl_path)) and (not spirv):
|
2018-04-11 11:28:39 +03:00
|
|
|
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--output', glsl_path, spirv_path] + extra_args)
|
2016-05-05 11:16:22 +03:00
|
|
|
validate_shader(glsl_path, False)
|
2018-04-11 11:28:39 +03:00
|
|
|
else:
|
|
|
|
os.remove(glsl_path)
|
|
|
|
glsl_path = None
|
2016-05-05 11:16:22 +03:00
|
|
|
|
2016-05-11 00:39:41 +03:00
|
|
|
if vulkan or spirv:
|
2017-01-17 01:19:49 +03:00
|
|
|
subprocess.check_call([spirv_cross_path, '--entry', 'main', '--vulkan-semantics', '--output', vulkan_glsl_path, spirv_path] + extra_args)
|
2017-06-23 10:44:41 +03:00
|
|
|
validate_shader(vulkan_glsl_path, True)
|
2016-05-05 11:16:22 +03:00
|
|
|
|
|
|
|
return (spirv_path, glsl_path, vulkan_glsl_path if vulkan else None)
|
2016-03-02 20:09:16 +03:00
|
|
|
|
2017-02-04 12:19:44 +03:00
|
|
|
def make_unix_newline(buf):
|
|
|
|
decoded = codecs.decode(buf, 'utf-8')
|
|
|
|
decoded = decoded.replace('\r', '')
|
|
|
|
return codecs.encode(decoded, 'utf-8')
|
|
|
|
|
2016-03-02 20:09:16 +03:00
|
|
|
def md5_for_file(path):
|
|
|
|
md5 = hashlib.md5()
|
|
|
|
with open(path, 'rb') as f:
|
2017-02-04 12:19:44 +03:00
|
|
|
for chunk in iter(lambda: make_unix_newline(f.read(8192)), b''):
|
2016-03-02 20:09:16 +03:00
|
|
|
md5.update(chunk)
|
|
|
|
return md5.digest()
|
|
|
|
|
|
|
|
def make_reference_dir(path):
|
|
|
|
base = os.path.dirname(path)
|
|
|
|
if not os.path.exists(base):
|
|
|
|
os.makedirs(base)
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def reference_path(directory, relpath, opt):
|
2016-05-11 20:39:38 +03:00
|
|
|
split_paths = os.path.split(directory)
|
2017-11-21 11:52:53 +03:00
|
|
|
reference_dir = os.path.join(split_paths[0], 'reference/' + ('opt/' if opt else ''))
|
2016-05-11 20:39:38 +03:00
|
|
|
reference_dir = os.path.join(reference_dir, split_paths[1])
|
|
|
|
return os.path.join(reference_dir, relpath)
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def regression_check(shader, glsl, update, keep, opt):
|
|
|
|
reference = reference_path(shader[0], shader[1], opt)
|
2016-05-11 20:39:38 +03:00
|
|
|
joined_path = os.path.join(shader[0], shader[1])
|
|
|
|
print('Reference shader path:', reference)
|
|
|
|
|
2016-03-02 20:09:16 +03:00
|
|
|
if os.path.exists(reference):
|
|
|
|
if md5_for_file(glsl) != md5_for_file(reference):
|
2016-03-22 16:44:12 +03:00
|
|
|
if update:
|
2017-08-11 21:54:58 +03:00
|
|
|
print('Generated source code has changed for {}!'.format(reference))
|
2016-03-22 16:44:12 +03:00
|
|
|
# If we expect changes, update the reference file.
|
|
|
|
if os.path.exists(reference):
|
|
|
|
os.remove(reference)
|
|
|
|
make_reference_dir(reference)
|
|
|
|
shutil.move(glsl, reference)
|
|
|
|
else:
|
2017-08-11 21:54:58 +03:00
|
|
|
print('Generated source code in {} does not match reference {}!'.format(glsl, reference))
|
2016-12-16 15:48:30 +03:00
|
|
|
with open(glsl, 'r') as f:
|
|
|
|
print('')
|
|
|
|
print('Generated:')
|
|
|
|
print('======================')
|
|
|
|
print(f.read())
|
|
|
|
print('======================')
|
|
|
|
print('')
|
|
|
|
|
2016-03-22 16:56:50 +03:00
|
|
|
# Otherwise, fail the test. Keep the shader file around so we can inspect.
|
|
|
|
if not keep:
|
|
|
|
os.remove(glsl)
|
2016-03-22 16:44:12 +03:00
|
|
|
sys.exit(1)
|
2016-03-02 20:09:16 +03:00
|
|
|
else:
|
|
|
|
os.remove(glsl)
|
|
|
|
else:
|
2017-08-11 21:54:58 +03:00
|
|
|
print('Found new shader {}. Placing generated source code in {}'.format(joined_path, reference))
|
2016-03-02 20:09:16 +03:00
|
|
|
make_reference_dir(reference)
|
|
|
|
shutil.move(glsl, reference)
|
|
|
|
|
2016-05-11 20:55:57 +03:00
|
|
|
def shader_is_vulkan(shader):
|
|
|
|
return '.vk.' in shader
|
|
|
|
|
2016-07-11 13:47:46 +03:00
|
|
|
def shader_is_desktop(shader):
|
|
|
|
return '.desktop.' in shader
|
|
|
|
|
2016-08-26 13:58:50 +03:00
|
|
|
def shader_is_eliminate_dead_variables(shader):
|
|
|
|
return '.noeliminate.' not in shader
|
|
|
|
|
2016-05-11 00:39:41 +03:00
|
|
|
def shader_is_spirv(shader):
|
|
|
|
return '.asm.' in shader
|
|
|
|
|
2016-09-12 21:11:30 +03:00
|
|
|
def shader_is_invalid_spirv(shader):
|
|
|
|
return '.invalid.' in shader
|
|
|
|
|
2017-01-13 18:41:27 +03:00
|
|
|
def shader_is_legacy(shader):
|
|
|
|
return '.legacy.' in shader
|
|
|
|
|
2017-01-17 01:19:49 +03:00
|
|
|
def shader_is_flatten_ubo(shader):
|
|
|
|
return '.flatten.' in shader
|
|
|
|
|
2017-05-22 16:30:43 +03:00
|
|
|
def shader_is_sso(shader):
|
|
|
|
return '.sso.' in shader
|
|
|
|
|
2017-05-22 18:40:00 +03:00
|
|
|
def shader_is_flatten_dimensions(shader):
|
|
|
|
return '.flatten_dim.' in shader
|
|
|
|
|
2017-11-22 13:04:29 +03:00
|
|
|
def shader_is_noopt(shader):
|
|
|
|
return '.noopt.' in shader
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def test_shader(stats, shader, update, keep, opt):
|
2016-05-11 20:39:38 +03:00
|
|
|
joined_path = os.path.join(shader[0], shader[1])
|
2016-05-11 20:55:57 +03:00
|
|
|
vulkan = shader_is_vulkan(shader[1])
|
2016-07-11 13:47:46 +03:00
|
|
|
desktop = shader_is_desktop(shader[1])
|
2016-08-26 13:58:50 +03:00
|
|
|
eliminate = shader_is_eliminate_dead_variables(shader[1])
|
2016-09-10 13:52:23 +03:00
|
|
|
is_spirv = shader_is_spirv(shader[1])
|
2016-09-12 21:11:30 +03:00
|
|
|
invalid_spirv = shader_is_invalid_spirv(shader[1])
|
2017-01-13 18:41:27 +03:00
|
|
|
is_legacy = shader_is_legacy(shader[1])
|
2017-01-17 01:19:49 +03:00
|
|
|
flatten_ubo = shader_is_flatten_ubo(shader[1])
|
2017-05-22 16:30:43 +03:00
|
|
|
sso = shader_is_sso(shader[1])
|
2017-05-22 18:40:00 +03:00
|
|
|
flatten_dim = shader_is_flatten_dimensions(shader[1])
|
2017-11-22 13:04:29 +03:00
|
|
|
noopt = shader_is_noopt(shader[1])
|
2016-05-11 20:39:38 +03:00
|
|
|
|
|
|
|
print('Testing shader:', joined_path)
|
2017-11-22 13:04:29 +03:00
|
|
|
spirv, glsl, vulkan_glsl = cross_compile(joined_path, vulkan, is_spirv, invalid_spirv, eliminate, is_legacy, flatten_ubo, sso, flatten_dim, opt and (not noopt))
|
2016-03-02 20:09:16 +03:00
|
|
|
|
2016-05-11 20:55:57 +03:00
|
|
|
# Only test GLSL stats if we have a shader following GL semantics.
|
2016-09-10 13:52:23 +03:00
|
|
|
if stats and (not vulkan) and (not is_spirv) and (not desktop):
|
2016-03-22 16:44:12 +03:00
|
|
|
cross_stats = get_shader_stats(glsl)
|
|
|
|
|
2018-04-11 11:28:39 +03:00
|
|
|
if glsl:
|
|
|
|
regression_check(shader, glsl, update, keep, opt)
|
2016-05-05 11:16:22 +03:00
|
|
|
if vulkan_glsl:
|
2017-11-21 11:52:53 +03:00
|
|
|
regression_check((shader[0], shader[1] + '.vk'), vulkan_glsl, update, keep, opt)
|
2016-03-02 20:09:16 +03:00
|
|
|
os.remove(spirv)
|
|
|
|
|
2016-09-10 13:52:23 +03:00
|
|
|
if stats and (not vulkan) and (not is_spirv) and (not desktop):
|
2016-05-11 20:39:38 +03:00
|
|
|
pristine_stats = get_shader_stats(joined_path)
|
2016-03-22 16:44:12 +03:00
|
|
|
|
|
|
|
a = []
|
2016-05-11 20:39:38 +03:00
|
|
|
a.append(shader[1])
|
2016-03-22 16:44:12 +03:00
|
|
|
for i in pristine_stats:
|
|
|
|
a.append(str(i))
|
|
|
|
for i in cross_stats:
|
|
|
|
a.append(str(i))
|
|
|
|
print(','.join(a), file = stats)
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def test_shader_msl(stats, shader, update, keep, opt):
|
2017-01-18 21:05:57 +03:00
|
|
|
joined_path = os.path.join(shader[0], shader[1])
|
2017-01-31 06:55:21 +03:00
|
|
|
print('\nTesting MSL shader:', joined_path)
|
2017-09-29 12:07:11 +03:00
|
|
|
is_spirv = shader_is_spirv(shader[1])
|
2017-11-22 13:04:29 +03:00
|
|
|
noopt = shader_is_noopt(shader[1])
|
|
|
|
spirv, msl = cross_compile_msl(joined_path, is_spirv, opt and (not noopt))
|
2017-11-21 11:52:53 +03:00
|
|
|
regression_check(shader, msl, update, keep, opt)
|
2017-12-27 00:32:45 +03:00
|
|
|
|
|
|
|
# Uncomment the following line to print the temp SPIR-V file path.
|
|
|
|
# This temp SPIR-V file is not deleted until after the Metal validation step below.
|
|
|
|
# If Metal validation fails, the temp SPIR-V file can be copied out and
|
|
|
|
# used as input to an invocation of spirv-cross to debug from Xcode directly.
|
|
|
|
# To do so, build spriv-cross using `make DEBUG=1`, then run the spriv-cross
|
|
|
|
# executable from Xcode using args: `--msl --entry main --output msl_path spirv_path`.
|
|
|
|
# print('SPRIV shader: ' + spirv)
|
2017-02-05 13:04:45 +03:00
|
|
|
|
|
|
|
if not force_no_external_validation:
|
2017-11-21 11:52:53 +03:00
|
|
|
validate_shader_msl(shader, opt)
|
2017-01-18 21:05:57 +03:00
|
|
|
|
2017-12-27 00:32:45 +03:00
|
|
|
os.remove(spirv)
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def test_shader_hlsl(stats, shader, update, keep, opt):
|
2017-01-26 11:45:17 +03:00
|
|
|
joined_path = os.path.join(shader[0], shader[1])
|
|
|
|
print('Testing HLSL shader:', joined_path)
|
2017-09-29 12:07:11 +03:00
|
|
|
is_spirv = shader_is_spirv(shader[1])
|
2017-11-22 13:04:29 +03:00
|
|
|
noopt = shader_is_noopt(shader[1])
|
|
|
|
spirv, msl = cross_compile_hlsl(joined_path, is_spirv, opt and (not noopt))
|
2017-11-21 11:52:53 +03:00
|
|
|
regression_check(shader, msl, update, keep, opt)
|
2017-01-26 11:45:17 +03:00
|
|
|
os.remove(spirv)
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def test_shaders_helper(stats, shader_dir, update, malisc, keep, opt, backend):
|
2016-05-11 20:39:38 +03:00
|
|
|
for root, dirs, files in os.walk(os.path.join(shader_dir)):
|
2017-01-31 06:55:21 +03:00
|
|
|
files = [ f for f in files if not f.startswith(".") ] #ignore system files (esp OSX)
|
2016-05-11 20:39:38 +03:00
|
|
|
for i in files:
|
|
|
|
path = os.path.join(root, i)
|
|
|
|
relpath = os.path.relpath(path, shader_dir)
|
2017-03-20 04:06:21 +03:00
|
|
|
if backend == 'msl':
|
2017-11-21 11:52:53 +03:00
|
|
|
test_shader_msl(stats, (shader_dir, relpath), update, keep, opt)
|
2017-01-26 11:45:17 +03:00
|
|
|
elif backend == 'hlsl':
|
2017-11-21 11:52:53 +03:00
|
|
|
test_shader_hlsl(stats, (shader_dir, relpath), update, keep, opt)
|
2017-01-18 21:05:57 +03:00
|
|
|
else:
|
2017-11-21 11:52:53 +03:00
|
|
|
test_shader(stats, (shader_dir, relpath), update, keep, opt)
|
2016-05-11 20:39:38 +03:00
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
def test_shaders(shader_dir, update, malisc, keep, opt, backend):
|
2016-03-22 16:44:12 +03:00
|
|
|
if malisc:
|
|
|
|
with open('stats.csv', 'w') as stats:
|
|
|
|
print('Shader,OrigRegs,OrigUniRegs,OrigALUShort,OrigLSShort,OrigTEXShort,OrigALULong,OrigLSLong,OrigTEXLong,CrossRegs,CrossUniRegs,CrossALUShort,CrossLSShort,CrossTEXShort,CrossALULong,CrossLSLong,CrossTEXLong', file = stats)
|
2017-01-18 21:05:57 +03:00
|
|
|
test_shaders_helper(stats, shader_dir, update, malisc, keep, backend)
|
2016-03-22 16:44:12 +03:00
|
|
|
else:
|
2017-11-21 11:52:53 +03:00
|
|
|
test_shaders_helper(None, shader_dir, update, malisc, keep, opt, backend)
|
2016-03-22 16:44:12 +03:00
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description = 'Script for regression testing.')
|
|
|
|
parser.add_argument('folder',
|
|
|
|
help = 'Folder containing shader files to test.')
|
|
|
|
parser.add_argument('--update',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Updates reference files if there is a mismatch. Use when legitimate changes in output is found.')
|
2016-03-22 16:56:50 +03:00
|
|
|
parser.add_argument('--keep',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Leave failed GLSL shaders on disk if they fail regression. Useful for debugging.')
|
2016-03-22 16:44:12 +03:00
|
|
|
parser.add_argument('--malisc',
|
|
|
|
action = 'store_true',
|
2016-04-04 10:36:04 +03:00
|
|
|
help = 'Use malisc offline compiler to determine static cycle counts before and after spirv-cross.')
|
2017-03-20 04:06:21 +03:00
|
|
|
parser.add_argument('--msl',
|
2017-01-18 21:05:57 +03:00
|
|
|
action = 'store_true',
|
|
|
|
help = 'Test Metal backend.')
|
2017-03-20 04:46:06 +03:00
|
|
|
parser.add_argument('--metal',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Deprecated Metal option. Use --msl instead.')
|
2017-01-26 11:45:17 +03:00
|
|
|
parser.add_argument('--hlsl',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Test HLSL backend.')
|
2017-02-05 13:04:45 +03:00
|
|
|
parser.add_argument('--force-no-external-validation',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Disable all external validation.')
|
2017-11-21 11:52:53 +03:00
|
|
|
parser.add_argument('--opt',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'Run SPIRV-Tools optimization passes as well.')
|
2016-03-22 16:44:12 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if not args.folder:
|
|
|
|
sys.stderr.write('Need shader folder.\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-03-20 04:06:21 +03:00
|
|
|
if args.msl:
|
2017-01-31 06:55:21 +03:00
|
|
|
print_msl_compiler_version()
|
2017-01-25 11:01:53 +03:00
|
|
|
|
2017-02-05 13:04:45 +03:00
|
|
|
global force_no_external_validation
|
|
|
|
force_no_external_validation = args.force_no_external_validation
|
|
|
|
|
2017-11-21 11:52:53 +03:00
|
|
|
test_shaders(args.folder, args.update, args.malisc, args.keep, args.opt, 'msl' if (args.msl or args.metal) else ('hlsl' if args.hlsl else 'glsl'))
|
2016-03-22 16:44:12 +03:00
|
|
|
if args.malisc:
|
|
|
|
print('Stats in stats.csv!')
|
2016-03-22 16:56:50 +03:00
|
|
|
print('Tests completed!')
|
2016-03-02 20:09:16 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-03-22 16:44:12 +03:00
|
|
|
main()
|