Skip to content

Commit e695a84

Browse files
authored
Add spirvopt option to vulkan worker driver (#47)
1 parent f3c0a76 commit e695a84

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

python/src/main/python/drivers/worker_vk.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def prepareVertFile():
7878

7979
################################################################################
8080

81-
def prepareShaders(frag):
81+
def prepareShaders(args, frag):
8282
shutil.copy(frag, 'test.frag')
8383
prepareVertFile()
8484

@@ -95,13 +95,19 @@ def prepareShaders(frag):
9595
cmd = glslang + ' test.frag -V -o test.frag.spv'
9696
subprocess.run(cmd, shell=True, check=True)
9797

98+
# Optimize
99+
if args.spirvopt:
100+
cmd = os.path.dirname(HERE) + '/../../bin/' + binType + '/spirv-opt ' + args.spirvopt + ' test.frag.spv -o test.frag.spv.opt'
101+
subprocess.run(cmd, shell=True, check=True)
102+
shutil.move('test.frag.spv.opt', 'test.frag.spv')
103+
98104
# Vert
99105
cmd = glslang + ' test.vert -V -o test.vert.spv'
100106
subprocess.run(cmd, shell=True, check=True)
101107

102108
################################################################################
103109

104-
def getImageVulkanAndroid(frag):
110+
def getImageVulkanAndroid(args, frag):
105111

106112
app = 'vulkan.samples.vulkan_worker'
107113

@@ -111,7 +117,7 @@ def getImageVulkanAndroid(frag):
111117
remove('image.png')
112118
adb('shell rm -rf /sdcard/graphicsfuzz/*')
113119

114-
prepareShaders(frag)
120+
prepareShaders(args, frag)
115121

116122
# FIXME: Clean up preparation of shader files. Right now it's
117123
# convenient to have a copy of the JSON with the original name of
@@ -186,7 +192,7 @@ def getImageVulkanAndroid(frag):
186192

187193
################################################################################
188194

189-
def doImageJob(imageJob):
195+
def doImageJob(args, imageJob):
190196
name = imageJob.name.replace('.frag','')
191197
fragFile = name + '.frag'
192198
jsonFile = name + '.json'
@@ -205,7 +211,7 @@ def doImageJob(imageJob):
205211
remove(png)
206212
remove(log)
207213

208-
getimageResult = getImageVulkanAndroid(fragFile)
214+
getimageResult = getImageVulkanAndroid(args, fragFile)
209215

210216
# Try to get our own log file in any case
211217
if os.path.exists('log.txt'):
@@ -296,6 +302,10 @@ def get_service(server, args):
296302
default='http://localhost:8080',
297303
help='Server URL (default: http://localhost:8080 )')
298304

305+
parser.add_argument(
306+
'--spirvopt',
307+
help='Enable spirv-opt with these optimisation flags (e.g. --spirvopt=-O)')
308+
299309
args = parser.parse_args()
300310

301311
print('token: ' + args.token)
@@ -336,7 +346,7 @@ def get_service(server, args):
336346
else:
337347
assert(job.imageJob != None)
338348
print("#### Image job: " + job.imageJob.name)
339-
job.imageJob.result = doImageJob(job.imageJob)
349+
job.imageJob.result = doImageJob(args, job.imageJob)
340350
print("Send back, results status: {}".format(job.imageJob.result.status))
341351
service.jobDone(token, job)
342352

0 commit comments

Comments
 (0)