Update Vulkan Headers
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / scripts / gen_framework_c.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
26
27 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts"))
28
29 from build.common import DEQP_DIR
30 from khr_util.format import writeInlFile
31
32 VULKAN_H        = os.path.join(os.path.dirname(__file__), "src", "vulkan_core.h")
33 VULKAN_DIR      = os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan")
34
35 INL_HEADER = """\
36 /* WARNING: This is auto-generated file. Do not modify, since changes will
37  * be lost! Modify the generating script instead.
38  */\
39 """
40
41 TYPE_SUBSTITUTIONS              = [
42         ("uint8_t",             "deUint8"),
43         ("uint16_t",    "deUint16"),
44         ("uint32_t",    "deUint32"),
45         ("uint64_t",    "deUint64"),
46         ("int8_t",              "deInt8"),
47         ("int16_t",             "deInt16"),
48         ("int32_t",             "deInt32"),
49         ("int64_t",             "deInt64"),
50         ("bool32_t",    "deUint32"),
51         ("size_t",              "deUintptr"),
52 ]
53
54 def readFile (filename):
55         with open(filename, 'rt') as f:
56                 return f.read()
57
58 def writeVulkanCHeader (src, filename):
59         def gen ():
60                 dst = src.replace('#include "vk_platform.h"','')
61
62                 # Amber is compiled using C++11 but under MSVC __cplusplus macro
63                 # is incorrectly recognized and this triggers invalid definition
64                 dst = dst.replace('VK_NULL_HANDLE ((void*)0)','VK_NULL_HANDLE 0')
65
66                 for old_type, new_type in TYPE_SUBSTITUTIONS:
67                         dst = dst.replace(old_type, new_type)
68                 yield dst
69         writeInlFile(filename, INL_HEADER, gen())
70
71 if __name__ == "__main__":
72         src                             = readFile(VULKAN_H)
73         writeVulkanCHeader                              (src, os.path.join(VULKAN_DIR, "vkVulkan_c.inl"))