Make test_shaders.py more robust with out-of-tree builds.
Previous assumed that test script was run from root folder. This doesn't work with out-of-tree builds.
This commit is contained in:
Родитель
0b54291950
Коммит
78c9a80600
|
@ -78,13 +78,14 @@ def cross_compile(shader, vulkan):
|
||||||
|
|
||||||
subprocess.check_call(['glslangValidator', '-V' if vulkan else '-G', '-o', spirv_path, shader])
|
subprocess.check_call(['glslangValidator', '-V' if vulkan else '-G', '-o', spirv_path, shader])
|
||||||
|
|
||||||
subprocess.check_call(['./spirv-cross', '--output', glsl_path, spirv_path])
|
spirv_cross_path = './spirv-cross'
|
||||||
|
subprocess.check_call([spirv_cross_path, '--output', glsl_path, spirv_path])
|
||||||
|
|
||||||
if not ('nocompat' in glsl_path):
|
if not ('nocompat' in glsl_path):
|
||||||
validate_shader(glsl_path, False)
|
validate_shader(glsl_path, False)
|
||||||
|
|
||||||
if vulkan:
|
if vulkan:
|
||||||
subprocess.check_call(['./spirv-cross', '--vulkan-semantics', '--output', vulkan_glsl_path, spirv_path])
|
subprocess.check_call([spirv_cross_path, '--vulkan-semantics', '--output', vulkan_glsl_path, spirv_path])
|
||||||
validate_shader(vulkan_glsl_path, vulkan)
|
validate_shader(vulkan_glsl_path, vulkan)
|
||||||
|
|
||||||
return (spirv_path, glsl_path, vulkan_glsl_path if vulkan else None)
|
return (spirv_path, glsl_path, vulkan_glsl_path if vulkan else None)
|
||||||
|
@ -101,8 +102,17 @@ def make_reference_dir(path):
|
||||||
if not os.path.exists(base):
|
if not os.path.exists(base):
|
||||||
os.makedirs(base)
|
os.makedirs(base)
|
||||||
|
|
||||||
|
def reference_path(directory, relpath):
|
||||||
|
split_paths = os.path.split(directory)
|
||||||
|
reference_dir = os.path.join(split_paths[0], 'reference/')
|
||||||
|
reference_dir = os.path.join(reference_dir, split_paths[1])
|
||||||
|
return os.path.join(reference_dir, relpath)
|
||||||
|
|
||||||
def regression_check(shader, glsl, update, keep):
|
def regression_check(shader, glsl, update, keep):
|
||||||
reference = os.path.join('./reference', shader)
|
reference = reference_path(shader[0], shader[1])
|
||||||
|
joined_path = os.path.join(shader[0], shader[1])
|
||||||
|
print('Reference shader path:', reference)
|
||||||
|
|
||||||
if os.path.exists(reference):
|
if os.path.exists(reference):
|
||||||
if md5_for_file(glsl) != md5_for_file(reference):
|
if md5_for_file(glsl) != md5_for_file(reference):
|
||||||
if update:
|
if update:
|
||||||
|
@ -121,46 +131,49 @@ def regression_check(shader, glsl, update, keep):
|
||||||
else:
|
else:
|
||||||
os.remove(glsl)
|
os.remove(glsl)
|
||||||
else:
|
else:
|
||||||
print('Found new shader {}. Placing GLSL in {}'.format(shader, reference))
|
print('Found new shader {}. Placing GLSL in {}'.format(joined_path, reference))
|
||||||
make_reference_dir(reference)
|
make_reference_dir(reference)
|
||||||
shutil.move(glsl, reference)
|
shutil.move(glsl, reference)
|
||||||
|
|
||||||
def test_shader(stats, shader, update, keep, vulkan):
|
def test_shader(stats, shader, update, keep, vulkan):
|
||||||
print('Testing shader:', shader)
|
joined_path = os.path.join(shader[0], shader[1])
|
||||||
spirv, glsl, vulkan_glsl = cross_compile(shader, vulkan)
|
|
||||||
|
print('Testing shader:', joined_path)
|
||||||
|
spirv, glsl, vulkan_glsl = cross_compile(joined_path, vulkan)
|
||||||
|
|
||||||
if stats:
|
if stats:
|
||||||
cross_stats = get_shader_stats(glsl)
|
cross_stats = get_shader_stats(glsl)
|
||||||
|
|
||||||
regression_check(shader, glsl, update, keep)
|
regression_check(shader, glsl, update, keep)
|
||||||
if vulkan_glsl:
|
if vulkan_glsl:
|
||||||
regression_check(shader + '.vk', vulkan_glsl, update, keep)
|
regression_check((shader[0], shader[1] + '.vk'), vulkan_glsl, update, keep)
|
||||||
os.remove(spirv)
|
os.remove(spirv)
|
||||||
|
|
||||||
if stats:
|
if stats:
|
||||||
pristine_stats = get_shader_stats(shader)
|
pristine_stats = get_shader_stats(joined_path)
|
||||||
|
|
||||||
a = []
|
a = []
|
||||||
a.append(shader)
|
a.append(shader[1])
|
||||||
for i in pristine_stats:
|
for i in pristine_stats:
|
||||||
a.append(str(i))
|
a.append(str(i))
|
||||||
for i in cross_stats:
|
for i in cross_stats:
|
||||||
a.append(str(i))
|
a.append(str(i))
|
||||||
print(','.join(a), file = stats)
|
print(','.join(a), file = stats)
|
||||||
|
|
||||||
|
def test_shaders_helper(stats, shader_dir, update, malisc, keep, vulkan):
|
||||||
|
for root, dirs, files in os.walk(os.path.join(shader_dir)):
|
||||||
|
for i in files:
|
||||||
|
path = os.path.join(root, i)
|
||||||
|
relpath = os.path.relpath(path, shader_dir)
|
||||||
|
test_shader(stats, (shader_dir, relpath), update, keep, vulkan)
|
||||||
|
|
||||||
def test_shaders(shader_dir, update, malisc, keep, vulkan):
|
def test_shaders(shader_dir, update, malisc, keep, vulkan):
|
||||||
if malisc:
|
if malisc:
|
||||||
with open('stats.csv', 'w') as stats:
|
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)
|
print('Shader,OrigRegs,OrigUniRegs,OrigALUShort,OrigLSShort,OrigTEXShort,OrigALULong,OrigLSLong,OrigTEXLong,CrossRegs,CrossUniRegs,CrossALUShort,CrossLSShort,CrossTEXShort,CrossALULong,CrossLSLong,CrossTEXLong', file = stats)
|
||||||
for f in os.walk(os.path.join(shader_dir)):
|
test_shaders_helper(stats, shader_dir, update, malisc, keep, vulkan)
|
||||||
for i in f[2]:
|
|
||||||
shader = os.path.join(f[0], i)
|
|
||||||
test_shader(stats, shader, update, keep, vulkan)
|
|
||||||
else:
|
else:
|
||||||
for f in os.walk(os.path.join(shader_dir)):
|
test_shaders_helper(None, shader_dir, update, malisc, keep, vulkan)
|
||||||
for i in f[2]:
|
|
||||||
shader = os.path.join(f[0], i)
|
|
||||||
test_shader(None, shader, update, keep, vulkan)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description = 'Script for regression testing.')
|
parser = argparse.ArgumentParser(description = 'Script for regression testing.')
|
||||||
|
|
Загрузка…
Ссылка в новой задаче