Add CTS_ARB_gl_spirv test implementation
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / scripts / build_spirv_binaries.py
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
23 import os
24 import sys
25 import string
26 import argparse
27 import tempfile
28 import shutil
29 import fnmatch
30
31 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts"))
32
33 from build.common import *
34 from build.config import *
35 from build.build import *
36
37 class Module:
38         def __init__ (self, name, dirName, binName):
39                 self.name               = name
40                 self.dirName    = dirName
41                 self.binName    = binName
42
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")
47
48 def getBuildConfig (buildPathPtrn, targetName, buildType):
49         buildPath = buildPathPtrn.format(
50                 targetName      = targetName,
51                 buildType       = buildType)
52
53         return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
54
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")]
57
58         for binFile in binFiles:
59                 print "Removing %s" % os.path.join(dstPath, binFile)
60                 os.remove(os.path.join(dstPath, binFile))
61
62 def execBuildPrograms (buildCfg, generator, module, dstPath):
63         fullDstPath     = os.path.realpath(dstPath)
64         workDir         = os.path.join(buildCfg.getBuildDir(), "modules", module.dirName)
65
66         pushWorkingDir(workDir)
67
68         try:
69                 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", "vk-build-programs"))
70                 execute([binPath, "--validate-spv", "--dst-path", fullDstPath])
71         finally:
72                 popWorkingDir()
73
74 def parseArgs ():
75         parser = argparse.ArgumentParser(description = "Build SPIR-V programs",
76                                                                          formatter_class=argparse.ArgumentDefaultsHelpFormatter)
77         parser.add_argument("-b",
78                                                 "--build-dir",
79                                                 dest="buildDir",
80                                                 default=DEFAULT_BUILD_DIR,
81                                                 help="Temporary build directory")
82         parser.add_argument("-t",
83                                                 "--build-type",
84                                                 dest="buildType",
85                                                 default="Debug",
86                                                 help="Build type")
87         parser.add_argument("-c",
88                                                 "--deqp-target",
89                                                 dest="targetName",
90                                                 default=DEFAULT_TARGET,
91                                                 help="dEQP build target")
92         parser.add_argument("-d",
93                                                 "--dst-path",
94                                                 dest="dstPath",
95                                                 default=DEFAULT_DST_DIR,
96                                                 help="Destination path")
97         return parser.parse_args()
98
99 if __name__ == "__main__":
100         args = parseArgs()
101
102         generator       = ANY_GENERATOR
103         buildCfg        = getBuildConfig(args.buildDir, args.targetName, args.buildType)
104         module          = VULKAN_MODULE
105
106         build(buildCfg, generator, ["vk-build-programs"])
107
108         if not os.path.exists(args.dstPath):
109                 os.makedirs(args.dstPath)
110
111         execBuildPrograms(buildCfg, generator, module, args.dstPath)