1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2015 Google Inc.
9 # Permission is hereby granted, free of charge, to any person obtaining a
10 # copy of this software and/or associated documentation files (the
11 # "Materials"), to deal in the Materials without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Materials, and to
14 # permit persons to whom the Materials are furnished to do so, subject to
15 # the following conditions:
17 # The above copyright notice(s) and this permission notice shall be
18 # included in all copies or substantial portions of the Materials.
20 # The Materials are Confidential Information as defined by the
21 # Khronos Membership Agreement until designated non-confidential by
22 # Khronos, at which point this condition clause shall be removed.
24 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 #-------------------------------------------------------------------------
42 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
44 from build.common import *
45 from build.config import *
46 from build.build import *
49 def __init__ (self, name, dirName, binName):
51 self.dirName = dirName
52 self.binName = binName
54 VULKAN_MODULE = Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk")
55 DEFAULT_BUILD_DIR = os.path.join(tempfile.gettempdir(), "spirv-binaries", "{targetName}-{buildType}")
56 DEFAULT_TARGET = "null"
57 DEFAULT_DST_DIR = os.path.join(DEQP_DIR, "external", "vulkancts", "data", "vulkan", "prebuilt")
59 def getBuildConfig (buildPathPtrn, targetName, buildType):
60 buildPath = buildPathPtrn.format(
61 targetName = targetName,
62 buildType = buildType)
64 return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
66 def cleanDstDir (dstPath):
67 binFiles = [f for f in os.listdir(dstPath) if os.path.isfile(os.path.join(dstPath, f)) and fnmatch.fnmatch(f, "*.spirv")]
69 for binFile in binFiles:
70 print "Removing %s" % os.path.join(dstPath, binFile)
71 os.remove(os.path.join(dstPath, binFile))
73 def execBuildPrograms (buildCfg, generator, module, mode, dstPath):
74 workDir = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
76 pushWorkingDir(workDir)
79 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
80 execute([binPath, "--mode", mode, "--dst-path", dstPath])
85 parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
86 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
87 parser.add_argument("-b",
90 default=DEFAULT_BUILD_DIR,
91 help="Temporary build directory")
92 parser.add_argument("-t",
97 parser.add_argument("-c",
100 default=DEFAULT_TARGET,
101 help="dEQP build target")
102 parser.add_argument("--mode",
105 help="Build mode (build or verify)")
106 parser.add_argument("-d",
109 default=DEFAULT_DST_DIR,
110 help="Destination path")
111 return parser.parse_args()
113 if __name__ == "__main__":
116 generator = ANY_GENERATOR
117 buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType)
118 module = VULKAN_MODULE
120 build(buildCfg, generator, ["vk-build-programs"])
122 if args.mode == "build":
123 if os.path.exists(args.dstPath):
124 cleanDstDir(args.dstPath)
126 os.makedirs(args.dstPath)
128 execBuildPrograms(buildCfg, generator, module, args.mode, args.dstPath)