summaryrefslogtreecommitdiff
path: root/vulkan/scripts/null_generator.py
diff options
context:
space:
mode:
Diffstat (limited to 'vulkan/scripts/null_generator.py')
-rw-r--r--vulkan/scripts/null_generator.py159
1 files changed, 79 insertions, 80 deletions
diff --git a/vulkan/scripts/null_generator.py b/vulkan/scripts/null_generator.py
index 3a761ceb8b..2a99a1dda4 100644
--- a/vulkan/scripts/null_generator.py
+++ b/vulkan/scripts/null_generator.py
@@ -17,45 +17,31 @@
# This script provides the functions for generating the null driver
# framework directly from the vulkan registry (vk.xml).
-import generator_common as gencom
import os
+import generator_common as gencom
+
+_DRIVER_EXTENSION_DICT = {
+ 'VK_ANDROID_native_buffer',
+ 'VK_EXT_debug_report',
+ 'VK_KHR_get_physical_device_properties2'
+}
-copyright = """/*
- * Copyright 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-"""
-
-def isDriverExtension(extensionName):
- switchCase = {
- 'VK_ANDROID_native_buffer' : True,
- 'VK_EXT_debug_report' : True,
- 'VK_KHR_get_physical_device_properties2' : True
- }
-
- if extensionName in switchCase:
- return switchCase[extensionName]
- return False
-
-def isDriverFunction(functionName):
- if functionName in gencom.extensionsDict:
- return isDriverExtension(gencom.extensionsDict[functionName])
+
+def _is_driver_function(cmd):
+ if cmd in gencom.extension_dict:
+ return gencom.extension_dict[cmd] in _DRIVER_EXTENSION_DICT
return True
-def null_driver_genh():
- header = """#ifndef NULLDRV_NULL_DRIVER_H
+
+def gen_h():
+ genfile = os.path.join(os.path.dirname(__file__),
+ '..', 'nulldrv', 'null_driver_gen.h')
+
+ with open(genfile, 'w') as f:
+ f.write(gencom.copyright_and_warning(2015))
+
+ f.write("""\
+#ifndef NULLDRV_NULL_DRIVER_H
#define NULLDRV_NULL_DRIVER_H 1
#include <vulkan/vk_android_native_buffer.h>
@@ -66,27 +52,34 @@ namespace null_driver {
PFN_vkVoidFunction GetGlobalProcAddr(const char* name);
PFN_vkVoidFunction GetInstanceProcAddr(const char* name);
-"""
- genfile = os.path.join(os.path.dirname(__file__),'..','nulldrv','null_driver_gen.h')
- with open(genfile, 'w') as f:
- f.write (copyright)
- f.write (gencom.warning)
- f.write (header)
- gencom.clang_off(f,0)
-
- for cmds in gencom.allCommandsList:
- if isDriverFunction(cmds):
- paramList = [''.join(i) for i in gencom.paramDict[cmds]]
- f.write ('VKAPI_ATTR ' + gencom.returnTypeDict[cmds] + ' ' + cmds[2:] + '(' +', '.join(paramList) + ');\n')
- gencom.clang_on(f,0)
-
- f.write ('\n} // namespace null_driver\n')
- f.write ('\n#endif // NULLDRV_NULL_DRIVER_H\n')
+// clang-format off\n""")
+
+ for cmd in gencom.command_list:
+ if _is_driver_function(cmd):
+ param_list = [''.join(i) for i in gencom.param_dict[cmd]]
+ f.write('VKAPI_ATTR ' + gencom.return_type_dict[cmd] + ' ' +
+ gencom.base_name(cmd) + '(' + ', '.join(param_list) + ');\n')
+
+ f.write("""\
+// clang-format on
+
+} // namespace null_driver
+
+#endif // NULLDRV_NULL_DRIVER_H\n""")
+
f.close()
- gencom.runClangFormat(genfile)
+ gencom.run_clang_format(genfile)
-def null_driver_gencpp():
- header = """#include <algorithm>
+
+def gen_cpp():
+ genfile = os.path.join(os.path.dirname(__file__),
+ '..', 'nulldrv', 'null_driver_gen.cpp')
+
+ with open(genfile, 'w') as f:
+ f.write(gencom.copyright_and_warning(2015))
+
+ f.write("""\
+#include <algorithm>
#include "null_driver_gen.h"
@@ -116,30 +109,36 @@ PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) {
}
const NameProc kGlobalProcs[] = {
-"""
- genfile = os.path.join(os.path.dirname(__file__),'..','nulldrv','null_driver_gen.cpp')
- with open(genfile, 'w') as f:
- f.write (copyright)
- f.write (gencom.warning)
- f.write (header)
- gencom.clang_off(f,1)
-
- sortedCommandsList = sorted(gencom.allCommandsList)
- for cmds in sortedCommandsList:
- if isDriverFunction(cmds) and gencom.getDispatchTableType(cmds) == 'Global':
- f.write (gencom.clang_off_spaces + '{\"' + cmds + '\", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_' + cmds + '>(' + cmds[2:] + '))},\n')
- gencom.clang_on(f,1)
- f.write ('};\n\n')
-
- f.write ('const NameProc kInstanceProcs[] = {\n')
- gencom.clang_off(f,1)
- for cmds in sortedCommandsList:
- if isDriverFunction(cmds):
- f.write (gencom.clang_off_spaces + '{\"' + cmds + '\", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_' + cmds + '>(' + cmds[2:] + '))},\n')
- gencom.clang_on(f,1)
- f.write ('};\n\n} // namespace\n\n')
-
- f.write ("""namespace null_driver {
+ // clang-format off\n""")
+
+ sorted_command_list = sorted(gencom.command_list)
+ for cmd in sorted_command_list:
+ if (_is_driver_function(cmd) and
+ gencom.get_dispatch_table_type(cmd) == 'Global'):
+ f.write(gencom.indent(1) + '{\"' + cmd +
+ '\", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_' +
+ cmd + '>(' + gencom.base_name(cmd) + '))},\n')
+
+ f.write("""\
+ // clang-format on
+};
+
+const NameProc kInstanceProcs[] = {
+ // clang-format off\n""")
+
+ for cmd in sorted_command_list:
+ if _is_driver_function(cmd):
+ f.write(gencom.indent(1) + '{\"' + cmd +
+ '\", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_' +
+ cmd + '>(' + gencom.base_name(cmd) + '))},\n')
+
+ f.write("""\
+ // clang-format on
+};
+
+} // namespace
+
+namespace null_driver {
PFN_vkVoidFunction GetGlobalProcAddr(const char* name) {
return Lookup(name, kGlobalProcs);
@@ -150,6 +149,6 @@ PFN_vkVoidFunction GetInstanceProcAddr(const char* name) {
}
} // namespace null_driver\n""")
- f.close()
- gencom.runClangFormat(genfile)
+ f.close()
+ gencom.run_clang_format(genfile)