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 argparse 26import re 27 28sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts")) 29 30from ctsbuild.common import DEQP_DIR, execute 31from khr_util.format import writeInlFile 32 33VULKAN_HEADERS_INCLUDE_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include") 34VULKAN_H = { "" : [ os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codecs_common.h"), 35 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std.h"), 36 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std_encode.h"), 37 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h265std.h"), 38 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std_decode.h"), 39 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h265std_decode.h"), 40 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vulkan", "vulkan_core.h") ], 41 "SC" : [ os.path.join(os.path.dirname(__file__), "src", "vulkan_sc_core.h") ] } 42DEFAULT_OUTPUT_DIR = { "" : os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan", "generated", "vulkan"), 43 "SC" : os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan", "generated", "vulkansc") } 44 45INL_HEADER = """\ 46/* WARNING: This is auto-generated file. Do not modify, since changes will 47 * be lost! Modify the generating script instead. 48 * This file was generated by /scripts/gen_framework_c.py 49 */\ 50 51""" 52 53TYPE_SUBSTITUTIONS = [ 54 ("uint8_t", "deUint8"), 55 ("uint16_t", "deUint16"), 56 ("uint32_t", "deUint32"), 57 ("uint64_t", "deUint64"), 58 ("int8_t", "deInt8"), 59 ("int16_t", "deInt16"), 60 ("int32_t", "deInt32"), 61 ("int64_t", "deInt64"), 62 ("bool32_t", "deUint32"), 63 ("size_t", "deUintptr"), 64] 65 66def readFile (filename): 67 with open(filename, 'rt') as f: 68 return f.read() 69 70def writeVulkanCHeader (src, filename): 71 def gen (): 72 dst = re.sub(r'(#include "[^\s,\n}]+")', '', src) 73 74 for old_type, new_type in TYPE_SUBSTITUTIONS: 75 dst = dst.replace(old_type, new_type) 76 yield dst 77 writeInlFile(filename, INL_HEADER, gen()) 78 79def parseCmdLineArgs(): 80 parser = argparse.ArgumentParser(description = "Generate Vulkan INL files", 81 formatter_class=argparse.ArgumentDefaultsHelpFormatter) 82 parser.add_argument("-a", 83 "--api", 84 dest="api", 85 default="", 86 help="Choose between Vulkan and Vulkan SC") 87 parser.add_argument("-o", 88 "--outdir", 89 dest="outdir", 90 default="", 91 help="Choose output directory") 92 return parser.parse_args() 93 94def getApiName (args): 95 if len(args)<2: 96 return '' 97 return args[1] 98 99if __name__ == "__main__": 100 args = parseCmdLineArgs() 101 102 outputPath = DEFAULT_OUTPUT_DIR[args.api] 103 # if argument was specified it is interpreted as a path to which .inl file will be written 104 if args.outdir != '': 105 outputPath = args.outdir 106 src = "" 107 108 # Generate vulkan headers from vk.xml 109 currentDir = os.getcwd() 110 pythonExecutable = sys.executable or "python" 111 os.chdir(os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "..", "xml")) 112 vkTargets = ["vulkan_core.h"] 113 for target in vkTargets: 114 execute([pythonExecutable, "../scripts/genvk.py", "-o", "../include/vulkan", target]) 115 116 videoDir = "../include/vk_video" 117 if (not os.path.isdir(videoDir)): 118 os.mkdir(videoDir) 119 120 videoTargets = [ 121 'vulkan_video_codecs_common.h', 122 'vulkan_video_codec_h264std.h', 123 'vulkan_video_codec_h264std_decode.h', 124 'vulkan_video_codec_h264std_encode.h', 125 'vulkan_video_codec_h265std.h', 126 'vulkan_video_codec_h265std_decode.h', 127 ] 128 for target in videoTargets: 129 execute([pythonExecutable, "../scripts/genvk.py", "-registry", "video.xml", "-o", videoDir, target]) 130 131 os.chdir(currentDir) 132 133 for file in VULKAN_H[args.api]: 134 src += readFile(file) 135 136 writeVulkanCHeader (src, os.path.join(outputPath, "vkVulkan_c.inl")) 137