• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# Vulkan CTS
5# ----------
6#
7# Copyright (c) 2015 Google Inc.
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import os
24import sys
25import string
26import argparse
27import tempfile
28import shutil
29import fnmatch
30
31sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts"))
32
33from build.common import *
34from build.config import *
35from build.build import *
36
37class Module:
38	def __init__ (self, name, dirName, binName):
39		self.name		= name
40		self.dirName	= dirName
41		self.binName	= binName
42
43VULKAN_MODULE		= Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
44DEFAULT_BUILD_DIR	= os.path.join(tempfile.gettempdir(), "spirv-binaries", "{targetName}-{buildType}")
45DEFAULT_TARGET		= "null"
46DEFAULT_DST_DIR		= os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
47DEFAULT_VULKAN_VERSION	= "1.1"
48
49def getBuildConfig (buildPathPtrn, targetName, buildType):
50	buildPath = buildPathPtrn.format(
51		targetName	= targetName,
52		buildType	= buildType)
53
54	return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
55
56def cleanDstDir (dstPath):
57	binFiles = [f for f in os.listdir(dstPath) if os.path.isfile(os.path.join(dstPath, f)) and fnmatch.fnmatch(f, "*.spv")]
58
59	for binFile in binFiles:
60		print "Removing %s" % os.path.join(dstPath, binFile)
61		os.remove(os.path.join(dstPath, binFile))
62
63def execBuildPrograms (buildCfg, generator, module, dstPath, vulkanVersion):
64	fullDstPath	= os.path.realpath(dstPath)
65	workDir		= os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
66
67	pushWorkingDir(workDir)
68
69	try:
70		binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
71		execute([binPath, "--validate-spv", "--dst-path", fullDstPath, "--target-vulkan-version", vulkanVersion])
72	finally:
73		popWorkingDir()
74
75def parseArgs ():
76	parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
77									 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
78	parser.add_argument("-b",
79						"--build-dir",
80						dest="buildDir",
81						default=DEFAULT_BUILD_DIR,
82						help="Temporary build directory")
83	parser.add_argument("-t",
84						"--build-type",
85						dest="buildType",
86						default="Debug",
87						help="Build type")
88	parser.add_argument("-c",
89						"--deqp-target",
90						dest="targetName",
91						default=DEFAULT_TARGET,
92						help="dEQP build target")
93	parser.add_argument("-d",
94						"--dst-path",
95						dest="dstPath",
96						default=DEFAULT_DST_DIR,
97						help="Destination path")
98	parser.add_argument("-u",
99						"--target-vulkan-version",
100						dest="vulkanVersion",
101						default="1.1",
102						choices=["1.0", "1.1"],
103						help="Target Vulkan version")
104	return parser.parse_args()
105
106if __name__ == "__main__":
107	args = parseArgs()
108
109	generator	= ANY_GENERATOR
110	buildCfg	= getBuildConfig(args.buildDir, args.targetName, args.buildType)
111	module		= VULKAN_MODULE
112
113	build(buildCfg, generator, ["vk-build-programs"])
114
115	if not os.path.exists(args.dstPath):
116		os.makedirs(args.dstPath)
117
118	execBuildPrograms(buildCfg, generator, module, args.dstPath, args.vulkanVersion)
119