1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/usr/bin/env python3
from getopt import getopt, GetoptError
import re
import sys, os, time
import subprocess
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count
def usage():
USAGE = """\
Usage: %(progName)s <dir | shader.shader_test | shader.frag | shader.vert>...
Options:
-h, --help Show this message
"""
print(USAGE % {'progName': sys.argv[0]})
sys.exit(1)
def process_directories(dirpath):
filenames = set()
if os.path.isdir(dirpath):
for filename in os.listdir(dirpath):
filenames.update(process_directories(os.path.join(dirpath, filename)))
else:
filenames.add(dirpath)
return filenames
def run_test(filename):
if ".out" in filename:
return ""
if ".shader_test" in filename:
command = ['./bin/shader_runner',
filename,
'-auto',
'-fbo']
else:
command = ['./bin/glslparsertest',
filename,
'pass']
timebefore = time.time()
try:
p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
results = (stdout + stderr).decode("utf-8")
except KeyboardInterrupt:
exit(1)
except:
return filename + " FAIL\n"
timeafter = time.time()
with open(filename + '.out', 'w') as file:
file.write(results)
current_type = 'UNKNOWN'
counts = {}
lines = list(results.split('\n'))
re_builtin_shader = re.compile("shader 0")
re_fs_8 = re.compile("^Native code for .*fragment.*(8-wide|SIMD8)")
re_fs_16 = re.compile("^Native code for .*fragment.*(16-wide|SIMD16)")
re_gs = re.compile("^Native code for .*geometry")
re_vs = re.compile("^Native code for .*vertex")
re_align = re.compile("{ align")
re_2q = re.compile("\(8\).* 2Q };")
counts["ignore"] = 0
counts["vs "] = 0
counts["gs "] = 0
counts["fs8 "] = 0
counts["fs16"] = 0
last_was_paired8 = False
for line in lines:
if (re_builtin_shader.search(line)):
current_type = "ignore"
elif (re_vs.search(line)):
current_type = "vs "
elif (re_gs.search(line)):
current_type = "gs "
elif (re_fs_8.search(line)):
current_type = "fs8 "
elif (re_fs_16.search(line)):
current_type = "fs16"
elif (re_align.search(line)):
# Skip the 2Q (second half) SIMD8 instructions, since the
# 1Q+2Q pair should be the same cost as a single 1H
# (SIMD16) instruction, other than icache pressure.
if current_type != "fs16" or not re_2q.search(line):
counts[current_type] = counts[current_type] + 1
del counts["ignore"]
timestr = " {:.3f} secs".format(timeafter - timebefore)
out = ''
for t in counts:
if counts[t] != 0:
out += "{0:40} {1} : {2:6}{3}\n".format(filename, t, counts[t], timestr)
timestr = ""
return out
def main():
try:
option_list = [
"help",
]
options, args = getopt(sys.argv[1:], "h", option_list)
except GetoptError:
usage()
env_add = {}
env_add["shader_precompile"] = "true"
env_add["force_glsl_extensions_warn"] = "true"
env_add["INTEL_DEBUG"] = "vs,wm,gs"
os.environ.update(env_add)
for name, value in options:
if name in ('-h', '--help'):
usage()
if len(args) < 1:
args.append("shaders")
try:
os.stat("bin/glslparsertest")
except:
print("./bin must be a symlink to a built piglit bin directory")
sys.exit(1)
runtimebefore = time.time()
filenames = set()
for i in args:
filenames.update(process_directories(i))
executor = ThreadPoolExecutor(cpu_count())
for t in executor.map(run_test, filenames):
sys.stdout.write(t)
runtimeafter = time.time()
print("shader-db run completed in {:.1f} secs".format(runtimeafter - runtimebefore))
if __name__ == "__main__":
main()
|