1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3 4#------------------------------------------------------------------------- 5# Vulkan CTS 6# ---------- 7# 8# Copyright (c) 2015 Google Inc. 9# 10# Licensed under the Apache License, Version 2.0 (the "License"); 11# you may not use this file except in compliance with the License. 12# You may obtain a copy of the License at 13# 14# http://www.apache.org/licenses/LICENSE-2.0 15# 16# Unless required by applicable law or agreed to in writing, software 17# distributed under the License is distributed on an "AS IS" BASIS, 18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19# See the License for the specific language governing permissions and 20# limitations under the License. 21# 22#------------------------------------------------------------------------- 23 24import os 25import sys 26import argparse 27import re 28 29sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts")) 30 31from ctsbuild.common import DEQP_DIR, execute 32from khr_util.format import writeInlFile 33 34VULKAN_HEADERS_INCLUDE_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "vulkan-docs", "src", "include") 35VULKAN_H = { "" : [ os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codecs_common.h"), 36 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std.h"), 37 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std_encode.h"), 38 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h265std.h"), 39 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h264std_decode.h"), 40 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vk_video", "vulkan_video_codec_h265std_decode.h"), 41 os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "vulkan", "vulkan_core.h") ], 42 "SC" : [ os.path.join(os.path.dirname(__file__), "src", "vulkan_sc_core.h") ] } 43DEFAULT_OUTPUT_DIR = { "" : os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan", "generated", "vulkan"), 44 "SC" : os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan", "generated", "vulkansc") } 45 46INL_HEADER = """\ 47/* WARNING: This is auto-generated file. Do not modify, since changes will 48 * be lost! Modify the generating script instead. 49 * This file was generated by /scripts/gen_framework_c.py 50 */\ 51 52""" 53 54TYPE_SUBSTITUTIONS = [ 55 ("uint8_t", "deUint8"), 56 ("uint16_t", "deUint16"), 57 ("uint32_t", "deUint32"), 58 ("uint64_t", "deUint64"), 59 ("int8_t", "deInt8"), 60 ("int16_t", "deInt16"), 61 ("int32_t", "deInt32"), 62 ("int64_t", "deInt64"), 63 ("bool32_t", "deUint32"), 64 ("size_t", "deUintptr"), 65] 66 67def readFile (filename): 68 with open(filename, 'rt') as f: 69 return f.read() 70 71def writeVulkanCHeader (src, filename): 72 def gen (): 73 dst = re.sub(r'(#include "[^\s,\n}]+")', '', src) 74 75 for old_type, new_type in TYPE_SUBSTITUTIONS: 76 dst = dst.replace(old_type, new_type) 77 yield dst 78 writeInlFile(filename, INL_HEADER, gen()) 79 80def parseCmdLineArgs(): 81 parser = argparse.ArgumentParser(description = "Generate Vulkan INL files", 82 formatter_class=argparse.ArgumentDefaultsHelpFormatter) 83 parser.add_argument("-a", 84 "--api", 85 dest="api", 86 default="", 87 help="Choose between Vulkan and Vulkan SC") 88 parser.add_argument("-o", 89 "--outdir", 90 dest="outdir", 91 default="", 92 help="Choose output directory") 93 return parser.parse_args() 94 95def getApiName (args): 96 if len(args)<2: 97 return '' 98 return args[1] 99 100if __name__ == "__main__": 101 args = parseCmdLineArgs() 102 103 outputPath = DEFAULT_OUTPUT_DIR[args.api] 104 # if argument was specified it is interpreted as a path to which .inl file will be written 105 if args.outdir != '': 106 outputPath = args.outdir 107 src = "" 108 109 # Generate vulkan headers from vk.xml 110 currentDir = os.getcwd() 111 pythonExecutable = sys.executable or "python" 112 os.chdir(os.path.join(VULKAN_HEADERS_INCLUDE_DIR, "..", "xml")) 113 vkTargets = ["vulkan_core.h"] 114 for target in vkTargets: 115 execute([pythonExecutable, "../scripts/genvk.py", "-o", "../include/vulkan", target]) 116 117 videoDir = "../include/vk_video" 118 if (not os.path.isdir(videoDir)): 119 os.mkdir(videoDir) 120 121 videoTargets = [ 122 'vulkan_video_codecs_common.h', 123 'vulkan_video_codec_h264std.h', 124 'vulkan_video_codec_h264std_decode.h', 125 'vulkan_video_codec_h264std_encode.h', 126 'vulkan_video_codec_h265std.h', 127 'vulkan_video_codec_h265std_decode.h', 128 ] 129 for target in videoTargets: 130 execute([pythonExecutable, "../scripts/genvk.py", "-registry", "video.xml", "-o", videoDir, target]) 131 132 os.chdir(currentDir) 133 134 for file in VULKAN_H[args.api]: 135 src += readFile(file) 136 137 writeVulkanCHeader (src, os.path.join(outputPath, "vkVulkan_c.inl")) 138