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") 47 48def 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 55def 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 62def execBuildPrograms (buildCfg, generator, module, dstPath, vulkanVersion): 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, "--target-vulkan-version", vulkanVersion]) 71 finally: 72 popWorkingDir() 73 74def 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 parser.add_argument("-u", 98 "--target-vulkan-version", 99 dest="vulkanVersion", 100 default="1.2", 101 choices=["1.0", "1.1", "1.2"], 102 help="Target Vulkan version") 103 return parser.parse_args() 104 105if __name__ == "__main__": 106 args = parseArgs() 107 108 generator = ANY_GENERATOR 109 buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType) 110 module = VULKAN_MODULE 111 112 build(buildCfg, generator, ["vk-build-programs"]) 113 114 if not os.path.exists(args.dstPath): 115 os.makedirs(args.dstPath) 116 117 execBuildPrograms(buildCfg, generator, module, args.dstPath, args.vulkanVersion) 118