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 re
26
27sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts"))
28
29from build.common import DEQP_DIR
30from khr_util.format import writeInlFile
31
32VULKAN_H	= [
33	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codecs_common.h"),
34	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codec_h264std.h"),
35	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codec_h264std_encode.h"),
36	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codec_h265std.h"),
37	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codec_h264std_decode.h"),
38	os.path.join(os.path.dirname(__file__), "src", "vk_video", "vulkan_video_codec_h265std_decode.h"),
39	os.path.join(os.path.dirname(__file__), "src", "vulkan_core.h"),
40	]
41#VULKAN_H	= os.path.join(os.path.dirname(__file__), "src", "vulkan_core.h")
42VULKAN_DIR	= os.path.join(os.path.dirname(__file__), "..", "framework", "vulkan")
43
44INL_HEADER = """\
45/* WARNING: This is auto-generated file. Do not modify, since changes will
46 * be lost! Modify the generating script instead.
47 */\
48"""
49
50TYPE_SUBSTITUTIONS		= [
51	("uint8_t",		"deUint8"),
52	("uint16_t",	"deUint16"),
53	("uint32_t",	"deUint32"),
54	("uint64_t",	"deUint64"),
55	("int8_t",		"deInt8"),
56	("int16_t",		"deInt16"),
57	("int32_t",		"deInt32"),
58	("int64_t",		"deInt64"),
59	("bool32_t",	"deUint32"),
60	("size_t",		"deUintptr"),
61]
62
63def readFile (filename):
64	with open(filename, 'rt') as f:
65		return f.read()
66
67def writeVulkanCHeader (src, filename):
68	def gen ():
69		dst = re.sub(r'(#include "[^\s,\n}]+")', '', src)
70
71		for old_type, new_type in TYPE_SUBSTITUTIONS:
72			dst = dst.replace(old_type, new_type)
73		yield dst
74	writeInlFile(filename, INL_HEADER, gen())
75
76if __name__ == "__main__":
77	src = ""
78	for file in VULKAN_H:
79		src += readFile(file)
80
81	writeVulkanCHeader				(src, os.path.join(VULKAN_DIR, "vkVulkan_c.inl"))
82