1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2015 Google Inc.
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 #-------------------------------------------------------------------------
31 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts"))
33 from build.common import *
34 from build.config import *
35 from build.build import *
38 def __init__ (self, name, dirName, binName):
40 self.dirName = dirName
41 self.binName = binName
43 VULKAN_MODULE = Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
44 DEFAULT_BUILD_DIR = os.path.join(tempfile.gettempdir(), "spirv-binaries", "{targetName}-{buildType}")
45 DEFAULT_TARGET = "null"
46 DEFAULT_DST_DIR = os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
48 def getBuildConfig (buildPathPtrn, targetName, buildType):
49 buildPath = buildPathPtrn.format(
50 targetName = targetName,
51 buildType = buildType)
53 return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
55 def cleanDstDir (dstPath):
56 binFiles = [f for f in os.listdir(dstPath) if os.path.isfile(os.path.join(dstPath, f)) and fnmatch.fnmatch(f, "*.spv")]
58 for binFile in binFiles:
59 print "Removing %s" % os.path.join(dstPath, binFile)
60 os.remove(os.path.join(dstPath, binFile))
62 def execBuildPrograms (buildCfg, generator, module, dstPath):
63 fullDstPath = os.path.realpath(dstPath)
64 workDir = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
66 pushWorkingDir(workDir)
69 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
70 execute([binPath, "--validate-spv", "--dst-path", fullDstPath])
75 parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
76 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
77 parser.add_argument("-b",
80 default=DEFAULT_BUILD_DIR,
81 help="Temporary build directory")
82 parser.add_argument("-t",
87 parser.add_argument("-c",
90 default=DEFAULT_TARGET,
91 help="dEQP build target")
92 parser.add_argument("-d",
95 default=DEFAULT_DST_DIR,
96 help="Destination path")
97 return parser.parse_args()
99 if __name__ == "__main__":
102 generator = ANY_GENERATOR
103 buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType)
104 module = VULKAN_MODULE
106 build(buildCfg, generator, ["vk-build-programs"])
108 if not os.path.exists(args.dstPath):
109 os.makedirs(args.dstPath)
111 execBuildPrograms(buildCfg, generator, module, args.dstPath)