├── .cmake-format.py ├── .gitattributes ├── .gitignore ├── BUILD.gn ├── BUILD.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── README.md ├── cmake ├── Copyright_cmake.txt └── cmake_uninstall.cmake.in ├── include └── vulkan │ ├── vk_icd.h │ ├── vk_layer.h │ ├── vk_platform.h │ ├── vk_sdk_platform.h │ ├── vulkan.h │ ├── vulkan.hpp │ ├── vulkan_android.h │ ├── vulkan_core.h │ ├── vulkan_fuchsia.h │ ├── vulkan_ggp.h │ ├── vulkan_ios.h │ ├── vulkan_macos.h │ ├── vulkan_metal.h │ ├── vulkan_vi.h │ ├── vulkan_wayland.h │ ├── vulkan_win32.h │ ├── vulkan_xcb.h │ ├── vulkan_xlib.h │ └── vulkan_xlib_xrandr.h ├── registry ├── cgenerator.py ├── conventions.py ├── generator.py ├── genvk.py ├── reg.py ├── spec_tools │ └── util.py ├── validusage.json ├── vk.xml ├── vkconventions.py └── ziggenerator.py └── zig ├── test.zig └── vulkan_core.zig /.cmake-format.py: -------------------------------------------------------------------------------- 1 | # Configuration for cmake-format (v0.4.1, circa Jul 2018) 2 | # https://github.com/cheshirekow/cmake_format 3 | 4 | # How wide to allow formatted cmake files 5 | line_width = 132 6 | 7 | # How many spaces to tab for indent 8 | tab_size = 4 9 | 10 | # If arglists are longer than this, break them always 11 | max_subargs_per_line = 3 12 | 13 | # If true, separate flow control names from their parentheses with a space 14 | separate_ctrl_name_with_space = False 15 | 16 | # If true, separate function names from parentheses with a space 17 | separate_fn_name_with_space = False 18 | 19 | # If a statement is wrapped to more than one line, than dangle the closing 20 | # parenthesis on it's own line 21 | dangle_parens = False 22 | 23 | # What character to use for bulleted lists 24 | bullet_char = u'*' 25 | 26 | # What character to use as punctuation after numerals in an enumerated list 27 | enum_char = u'.' 28 | 29 | # What style line endings to use in the output. 30 | line_ending = u'unix' 31 | 32 | # Format command names consistently as 'lower' or 'upper' case 33 | command_case = u'lower' 34 | 35 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes 2 | # See https://help.github.com/articles/dealing-with-line-endings/ 3 | 4 | # Default behavior, if core.autocrlf is unset. 5 | * text=auto 6 | 7 | # Files to be converted to native line endings on checkout. 8 | *.cpp text 9 | *.h text 10 | 11 | # Text files to always have CRLF (dos) line endings on checkout. 12 | *.bat text eol=crlf 13 | 14 | # Text files to always have LF (unix) line endings on checkout. 15 | *.sh text eol=lf 16 | *.zig text eol=lf 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python cache 2 | __pycache__ 3 | *.pyc 4 | build 5 | .vscode/ 6 | **/.*.swp 7 | zig-cache/ 8 | -------------------------------------------------------------------------------- /BUILD.gn: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018-2019 The ANGLE Project Authors. 2 | # Copyright (C) 2019 LunarG, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | import("//build_overrides/vulkan_headers.gni") 17 | 18 | config("vulkan_headers_config") { 19 | include_dirs = [ "include" ] 20 | 21 | if (is_win) { 22 | defines = [ "VK_USE_PLATFORM_WIN32_KHR" ] 23 | } 24 | if (defined(vulkan_use_x11) && vulkan_use_x11) { 25 | defines = [ "VK_USE_PLATFORM_XCB_KHR" ] 26 | } 27 | if (is_android) { 28 | defines = [ "VK_USE_PLATFORM_ANDROID_KHR" ] 29 | } 30 | if (is_fuchsia) { 31 | defines = [ "VK_USE_PLATFORM_FUCHSIA" ] 32 | } 33 | if (is_mac) { 34 | defines = [ "VK_USE_PLATFORM_METAL_EXT" ] 35 | } 36 | if (defined(is_ggp) && is_ggp) { 37 | defines = [ "VK_USE_PLATFORM_GGP" ] 38 | } 39 | } 40 | 41 | # Vulkan headers only, no compiled sources. 42 | source_set("vulkan_headers") { 43 | sources = [ 44 | "include/vulkan/vk_icd.h", 45 | "include/vulkan/vk_layer.h", 46 | "include/vulkan/vk_platform.h", 47 | "include/vulkan/vk_sdk_platform.h", 48 | "include/vulkan/vulkan.h", 49 | "include/vulkan/vulkan.hpp", 50 | "include/vulkan/vulkan_core.h", 51 | ] 52 | public_configs = [ ":vulkan_headers_config" ] 53 | } 54 | 55 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Build Instructions 2 | 3 | Instructions for building this repository on Windows, Linux, and MacOS. 4 | 5 | ## Index 6 | 7 | 1. [Contributing](#contributing-to-the-repository) 8 | 1. [Repository Content](#repository-content) 9 | 1. [Repository Set-up](#repository-set-up) 10 | 1. [Windows Build](#building-on-windows) 11 | 1. [Linux Build](#building-on-linux) 12 | 1. [MacOS Build](#building-on-macos) 13 | 14 | ## Contributing to the Repository 15 | 16 | The contents of this repository are sourced primarily from the Khronos Vulkan 17 | API specification [repository](https://github.com/KhronosGroup/Vulkan-Docs). 18 | Please visit that repository for information on contributing. 19 | 20 | ## Repository Content 21 | 22 | This repository contains the Vulkan header files and the Vulkan API definition 23 | (registry) with its related files. This repository does not create libraries 24 | or executables. 25 | 26 | However, this repository contains CMake build configuration files to "install" 27 | the files from this repository to a specific install directory. For example, 28 | you can install the files to a system directory such as `/usr/local` on Linux. 29 | 30 | If you are building other Vulkan-related repositories such as 31 | [Vulkan-Loader](https://github.com/KhronosGroup/Vulkan-Loader), 32 | you need to build the install target of this repository and provide the 33 | resulting install directory to those repositories. 34 | 35 | ### Installed Files 36 | 37 | The `install` target installs the following files under the directory 38 | indicated by *install_dir*: 39 | 40 | - *install_dir*`/include/vulkan` : The header files found in the 41 | `include/vulkan` directory of this repository 42 | - *install_dir*`/share/vulkan/registry` : The registry files found in the 43 | `registry` directory of this repository 44 | 45 | The `uninstall` target can be used to remove the above files from the install 46 | directory. 47 | 48 | ## Repository Set-Up 49 | 50 | ### Download the Repository 51 | 52 | To create your local git repository: 53 | 54 | git clone https://github.com/KhronosGroup/Vulkan-Headers.git 55 | 56 | ### Repository Dependencies 57 | 58 | This repository does not depend on any other repositories. 59 | 60 | ### Build and Install Directories 61 | 62 | A common convention is to place the build directory in the top directory of 63 | the repository with a name of `build` and place the install directory as a 64 | child of the build directory with the name `install`. The remainder of these 65 | instructions follow this convention, although you can use any name for these 66 | directories and place them in any location. 67 | 68 | ## Building On Windows 69 | 70 | ### Windows Development Environment Requirements 71 | 72 | - Windows 73 | - Any Personal Computer version supported by Microsoft 74 | - Microsoft [Visual Studio](https://www.visualstudio.com/) 75 | - Versions 76 | - [2015](https://www.visualstudio.com/vs/older-downloads/) 77 | - [2017](https://www.visualstudio.com/vs/older-downloads/) 78 | - [2019](https://www.visualstudio.com/vs/downloads/) 79 | - The Community Edition of each of the above versions is sufficient, as 80 | well as any more capable edition. 81 | - [CMake 3.10.2](https://cmake.org/files/v3.10/cmake-3.10.2-win64-x64.zip) is recommended. 82 | - Use the installer option to add CMake to the system PATH 83 | - Git Client Support 84 | - [Git for Windows](http://git-scm.com/download/win) is a popular solution 85 | for Windows 86 | - Some IDEs (e.g., [Visual Studio](https://www.visualstudio.com/), 87 | [GitHub Desktop](https://desktop.github.com/)) have integrated 88 | Git client support 89 | 90 | ### Windows Build - Microsoft Visual Studio 91 | 92 | The general approach is to run CMake to generate the Visual Studio project 93 | files. Then either run CMake with the `--build` option to build from the 94 | command line or use the Visual Studio IDE to open the generated solution and 95 | work with the solution interactively. 96 | 97 | #### Windows Quick Start 98 | 99 | From a "Developer Command Prompt for VS 201x" console: 100 | 101 | cd Vulkan-Headers 102 | mkdir build 103 | cd build 104 | cmake .. 105 | cmake --build . --target install 106 | 107 | See below for the details. 108 | 109 | #### Use `CMake` to Create the Visual Studio Project Files 110 | 111 | From within a "Developer Command Prompt for VS 201x" console, change your 112 | current directory to the top of the cloned repository directory, create a 113 | build directory and generate the Visual Studio project files: 114 | 115 | cd Vulkan-Headers 116 | mkdir build 117 | cd build 118 | cmake .. 119 | 120 | > Note: The `..` parameter tells `cmake` the location of the top of the 121 | > repository. If you place your build directory someplace else, you'll need to 122 | > specify the location of the repository top differently. 123 | 124 | The CMake configuration files set the default install directory location to 125 | `$CMAKE_BINARY_DIR\install`, which is a child of your build directory. In this 126 | example, the install directory becomes the `Vulkan-Headers\build\install` 127 | directory. 128 | 129 | The project installs the header files to 130 | 131 | Vulkan-Headers\build\install\include\vulkan 132 | 133 | and installs the registry files to 134 | 135 | Vulkan-Headers\build\install\share\vulkan\registry 136 | 137 | You can change the install directory with the `CMAKE_INSTALL_PREFIX` CMake 138 | variable. 139 | 140 | For example: 141 | 142 | cd Vulkan-Headers 143 | mkdir build 144 | cd build 145 | cmake -DCMAKE_INSTALL_PREFIX=/c/Users/dev/install .. # MINGW64 shell 146 | 147 | As it starts generating the project files, `cmake` responds with something 148 | like: 149 | 150 | -- Building for: Visual Studio 14 2015 151 | 152 | which is a 32-bit generator. 153 | 154 | Since this repository does not compile anything, there is no need to specify a 155 | specific generator such as "Visual Studio 14 2015 Win64", so the default 156 | generator should suffice. 157 | 158 | The above steps create a Windows solution file named `Vulkan-Headers.sln` in 159 | the build directory. 160 | 161 | At this point, you can build the solution from the command line or open the 162 | generated solution with Visual Studio. 163 | 164 | #### Build the Solution From the Command Line 165 | 166 | While still in the build directory: 167 | 168 | cmake --build . --target install 169 | 170 | to build the install target. 171 | 172 | Build the `uninstall` target to remove the files from the install directory. 173 | 174 | cmake --build . --target uninstall 175 | 176 | #### Build the Solution With Visual Studio 177 | 178 | Launch Visual Studio and open the "Vulkan-Headers.sln" solution file in the 179 | build directory. Build the `INSTALL` target from the Visual Studio solution 180 | explorer. 181 | 182 | Build the `uninstall` target to remove the files from the install directory. 183 | 184 | > Note: Since there are only the `INSTALL` and `uninstall` projects in the 185 | > solution, building the solution from the command line may be more efficient 186 | > than starting Visual Studio for these simple operations. 187 | 188 | ## Building On Linux 189 | 190 | ### Linux Development Environment Requirements 191 | 192 | There are no specific Linux distribution or compiler version requirements for 193 | building this repository. The required tools are 194 | 195 | - [CMake 3.10.2](https://cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz) is recommended. 196 | - git 197 | 198 | ### Linux Build 199 | 200 | The general approach is to run CMake to generate make files. Then either run 201 | CMake with the `--build` option or `make` to build from the command line. 202 | 203 | #### Linux Quick Start 204 | 205 | cd Vulkan-Headers 206 | mkdir build 207 | cd build 208 | cmake -DCMAKE_INSTALL_PREFIX=install .. 209 | make install 210 | 211 | See below for the details. 212 | 213 | #### Use CMake to Create the Make Files 214 | 215 | Change your current directory to the top of the cloned repository directory, 216 | create a build directory and generate the make files: 217 | 218 | cd Vulkan-Headers 219 | mkdir build 220 | cd build 221 | cmake -DCMAKE_INSTALL_PREFIX=install .. 222 | 223 | > Note: The `..` parameter tells `cmake` the location of the top of the 224 | > repository. If you place your `build` directory someplace else, you'll need 225 | > to specify the location of the repository top differently. 226 | 227 | Set the `CMAKE_INSTALL_PREFIX` variable to the directory to serve as the 228 | destination directory for the `install` target. 229 | 230 | The above `cmake` command sets the install directory to 231 | `$CMAKE_BINARY_DIR/install`, which is a child of your `build` directory. In 232 | this example, the install directory becomes the `Vulkan-Headers/build/install` 233 | directory. 234 | 235 | The make file install target installs the header files to 236 | 237 | Vulkan-Headers/build/install/include/vulkan 238 | 239 | and installs the registry files to 240 | 241 | Vulkan-Headers/build/install/share/vulkan/registry 242 | 243 | > Note: For Linux, the default value for `CMAKE_INSTALL_PREFIX` is 244 | > `/usr/local`, which would be used if you do not specify 245 | > `CMAKE_INSTALL_PREFIX`. In this case, you may need to use `sudo` to install 246 | > to system directories later when you run `make install`. 247 | 248 | Note that after generating the make files, running `make`: 249 | 250 | make 251 | 252 | does nothing, since there are no libraries or executables to build. 253 | 254 | To install the header files: 255 | 256 | make install 257 | 258 | or 259 | 260 | cmake --build . --target install 261 | 262 | To uninstall the files from the install directories, you can execute: 263 | 264 | make uninstall 265 | 266 | or 267 | 268 | cmake --build . --target uninstall 269 | 270 | ## Building on MacOS 271 | 272 | The instructions for building this repository on MacOS are similar to those for Linux. 273 | 274 | [CMake 3.10.2](https://cmake.org/files/v3.10/cmake-3.10.2-Darwin-x86_64.tar.gz) is recommended. 275 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ~~~ 2 | # Copyright (c) 2018 Valve Corporation 3 | # Copyright (c) 2018 LunarG, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ~~~ 17 | 18 | # CMake project initialization --------------------------------------------------------------------------------------------------- 19 | # This section contains pre-project() initialization, and ends with the project() command. 20 | 21 | cmake_minimum_required(VERSION 3.10.2) 22 | 23 | # NONE = this project has no language toolchain requirement. 24 | project(Vulkan-Headers NONE) 25 | 26 | # User-interface declarations ---------------------------------------------------------------------------------------------------- 27 | # This section contains variables that affect development GUIs (e.g. CMake GUI and IDEs), such as option(), folders, and variables 28 | # with the CACHE property. 29 | 30 | include(GNUInstallDirs) 31 | 32 | if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 33 | # Windows: if install locations not set by user, set install prefix to "\install". 34 | set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE) 35 | endif() 36 | 37 | # -------------------------------------------------------------------------------------------------------------------------------- 38 | 39 | # define exported targets for nested project builds to consume 40 | add_library(Vulkan-Headers INTERFACE) 41 | target_include_directories(Vulkan-Headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") 42 | add_library(Vulkan::Headers ALIAS Vulkan-Headers) 43 | 44 | add_library(Vulkan-Registry INTERFACE) 45 | target_include_directories(Vulkan-Registry INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/registry") 46 | add_library(Vulkan::Registry ALIAS Vulkan-Registry) 47 | 48 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 49 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION ${CMAKE_INSTALL_DATADIR}/vulkan) 50 | 51 | # uninstall target 52 | if(NOT TARGET uninstall) 53 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" 54 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 55 | IMMEDIATE 56 | @ONLY) 57 | add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 58 | endif() 59 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | A reminder that this issue tracker is managed by the Khronos Group. Interactions here should follow the Khronos Code of Conduct (https://www.khronos.org/developers/code-of-conduct), which prohibits aggressive or derogatory language. Please keep the discussion friendly and civil. 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vulkan-Headers 2 | 3 | Vulkan header files and API registry 4 | 5 | ## Repository Content 6 | 7 | The contents of this repository are largely obtained from other repositories and are 8 | collected, coordinated, and curated here. 9 | 10 | Do not propose pull requests to this repository which modify any files under 11 | include/vulkan/ or registry/. All such files are generated from the 12 | Vulkan-Docs repository and, in the case of include/vulkan/vulkan.hpp, the 13 | Vulkan-Hpp repository. Any changes must be made in those repositories. 14 | 15 | The projects for these repositories are: 16 | 17 | - [KhronosGroup/Vulkan-Docs](https://github.com/KhronosGroup/Vulkan-Docs) 18 | - Core Vulkan headers and Registry 19 | - [KhronosGroup/Vulkan-Hpp](https://github.com/KhronosGroup/Vulkan-Hpp) 20 | - C++ Bindings for Vulkan 21 | 22 | Please visit the appropriate project in the above list for obtaining additional information, 23 | asking questions, or opening issues. 24 | 25 | ## Version Tagging Scheme 26 | 27 | Updates to the `Vulkan-Headers` repository which correspond to a new Vulkan 28 | specification release are tagged using the following format: 29 | `v<`_`version`_`>` (e.g., `v1.1.96`). 30 | 31 | **Note**: Marked version releases have undergone thorough testing but do not 32 | imply the same quality level as SDK tags. SDK tags follow the 33 | `sdk-<`_`version`_`>.<`_`patch`_`>` format (e.g., `sdk-1.1.92.0`). 34 | 35 | This scheme was adopted following the 1.1.96 Vulkan specification release. 36 | -------------------------------------------------------------------------------- /cmake/Copyright_cmake.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2018 Kitware, Inc. and Contributors 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Kitware, Inc. nor the names of Contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ------------------------------------------------------------------------------ 33 | 34 | The following individuals and institutions are among the Contributors: 35 | 36 | * Aaron C. Meadows 37 | * Adriaan de Groot 38 | * Aleksey Avdeev 39 | * Alexander Neundorf 40 | * Alexander Smorkalov 41 | * Alexey Sokolov 42 | * Alex Turbov 43 | * Andreas Pakulat 44 | * Andreas Schneider 45 | * André Rigland Brodtkorb 46 | * Axel Huebl, Helmholtz-Zentrum Dresden - Rossendorf 47 | * Benjamin Eikel 48 | * Bjoern Ricks 49 | * Brad Hards 50 | * Christopher Harvey 51 | * Christoph Grüninger 52 | * Clement Creusot 53 | * Daniel Blezek 54 | * Daniel Pfeifer 55 | * Enrico Scholz 56 | * Eran Ifrah 57 | * Esben Mose Hansen, Ange Optimization ApS 58 | * Geoffrey Viola 59 | * Google Inc 60 | * Gregor Jasny 61 | * Helio Chissini de Castro 62 | * Ilya Lavrenov 63 | * Insight Software Consortium 64 | * Jan Woetzel 65 | * Kelly Thompson 66 | * Konstantin Podsvirov 67 | * Mario Bensi 68 | * Mathieu Malaterre 69 | * Matthaeus G. Chajdas 70 | * Matthias Kretz 71 | * Matthias Maennich 72 | * Michael Stürmer 73 | * Miguel A. Figueroa-Villanueva 74 | * Mike Jackson 75 | * Mike McQuaid 76 | * Nicolas Bock 77 | * Nicolas Despres 78 | * Nikita Krupen'ko 79 | * NVIDIA Corporation 80 | * OpenGamma Ltd. 81 | * Patrick Stotko 82 | * Per Øyvind Karlsen 83 | * Peter Collingbourne 84 | * Petr Gotthard 85 | * Philip Lowman 86 | * Philippe Proulx 87 | * Raffi Enficiaud, Max Planck Society 88 | * Raumfeld 89 | * Roger Leigh 90 | * Rolf Eike Beer 91 | * Roman Donchenko 92 | * Roman Kharitonov 93 | * Ruslan Baratov 94 | * Sebastian Holtermann 95 | * Stephen Kelly 96 | * Sylvain Joubert 97 | * Thomas Sondergaard 98 | * Tobias Hunger 99 | * Todd Gamblin 100 | * Tristan Carel 101 | * University of Dundee 102 | * Vadim Zhukov 103 | * Will Dicharry 104 | 105 | See version control history for details of individual contributions. 106 | 107 | The above copyright and license notice applies to distributions of 108 | CMake in source and binary form. Third-party software packages supplied 109 | with CMake under compatible licenses provide their own copyright notices 110 | documented in corresponding subdirectories or source files. 111 | 112 | ------------------------------------------------------------------------------ 113 | 114 | CMake was initially developed by Kitware with the following sponsorship: 115 | 116 | * National Library of Medicine at the National Institutes of Health 117 | as part of the Insight Segmentation and Registration Toolkit (ITK). 118 | 119 | * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel 120 | Visualization Initiative. 121 | 122 | * National Alliance for Medical Image Computing (NAMIC) is funded by the 123 | National Institutes of Health through the NIH Roadmap for Medical Research, 124 | Grant U54 EB005149. 125 | 126 | * Kitware, Inc. 127 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 9 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | if(NOT "${rm_retval}" STREQUAL 0) 16 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 17 | endif(NOT "${rm_retval}" STREQUAL 0) 18 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 19 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 20 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | endforeach(file) 22 | -------------------------------------------------------------------------------- /include/vulkan/vk_icd.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_icd.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, 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 | #ifndef VKICD_H 24 | #define VKICD_H 25 | 26 | #include "vulkan.h" 27 | #include 28 | 29 | // Loader-ICD version negotiation API. Versions add the following features: 30 | // Version 0 - Initial. Doesn't support vk_icdGetInstanceProcAddr 31 | // or vk_icdNegotiateLoaderICDInterfaceVersion. 32 | // Version 1 - Add support for vk_icdGetInstanceProcAddr. 33 | // Version 2 - Add Loader/ICD Interface version negotiation 34 | // via vk_icdNegotiateLoaderICDInterfaceVersion. 35 | // Version 3 - Add ICD creation/destruction of KHR_surface objects. 36 | // Version 4 - Add unknown physical device extension qyering via 37 | // vk_icdGetPhysicalDeviceProcAddr. 38 | // Version 5 - Tells ICDs that the loader is now paying attention to the 39 | // application version of Vulkan passed into the ApplicationInfo 40 | // structure during vkCreateInstance. This will tell the ICD 41 | // that if the loader is older, it should automatically fail a 42 | // call for any API version > 1.0. Otherwise, the loader will 43 | // manually determine if it can support the expected version. 44 | #define CURRENT_LOADER_ICD_INTERFACE_VERSION 5 45 | #define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0 46 | #define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4 47 | typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion); 48 | 49 | // This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this 50 | // file directly, it won't be found. 51 | #ifndef PFN_GetPhysicalDeviceProcAddr 52 | typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName); 53 | #endif 54 | 55 | /* 56 | * The ICD must reserve space for a pointer for the loader's dispatch 57 | * table, at the start of . 58 | * The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro. 59 | */ 60 | 61 | #define ICD_LOADER_MAGIC 0x01CDC0DE 62 | 63 | typedef union { 64 | uintptr_t loaderMagic; 65 | void *loaderData; 66 | } VK_LOADER_DATA; 67 | 68 | static inline void set_loader_magic_value(void *pNewObject) { 69 | VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject; 70 | loader_info->loaderMagic = ICD_LOADER_MAGIC; 71 | } 72 | 73 | static inline bool valid_loader_magic_value(void *pNewObject) { 74 | const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject; 75 | return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC; 76 | } 77 | 78 | /* 79 | * Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that 80 | * contains the platform-specific connection and surface information. 81 | */ 82 | typedef enum { 83 | VK_ICD_WSI_PLATFORM_MIR, 84 | VK_ICD_WSI_PLATFORM_WAYLAND, 85 | VK_ICD_WSI_PLATFORM_WIN32, 86 | VK_ICD_WSI_PLATFORM_XCB, 87 | VK_ICD_WSI_PLATFORM_XLIB, 88 | VK_ICD_WSI_PLATFORM_ANDROID, 89 | VK_ICD_WSI_PLATFORM_MACOS, 90 | VK_ICD_WSI_PLATFORM_IOS, 91 | VK_ICD_WSI_PLATFORM_DISPLAY, 92 | VK_ICD_WSI_PLATFORM_HEADLESS, 93 | VK_ICD_WSI_PLATFORM_METAL, 94 | } VkIcdWsiPlatform; 95 | 96 | typedef struct { 97 | VkIcdWsiPlatform platform; 98 | } VkIcdSurfaceBase; 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | typedef struct { 102 | VkIcdSurfaceBase base; 103 | MirConnection *connection; 104 | MirSurface *mirSurface; 105 | } VkIcdSurfaceMir; 106 | #endif // VK_USE_PLATFORM_MIR_KHR 107 | 108 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 109 | typedef struct { 110 | VkIcdSurfaceBase base; 111 | struct wl_display *display; 112 | struct wl_surface *surface; 113 | } VkIcdSurfaceWayland; 114 | #endif // VK_USE_PLATFORM_WAYLAND_KHR 115 | 116 | #ifdef VK_USE_PLATFORM_WIN32_KHR 117 | typedef struct { 118 | VkIcdSurfaceBase base; 119 | HINSTANCE hinstance; 120 | HWND hwnd; 121 | } VkIcdSurfaceWin32; 122 | #endif // VK_USE_PLATFORM_WIN32_KHR 123 | 124 | #ifdef VK_USE_PLATFORM_XCB_KHR 125 | typedef struct { 126 | VkIcdSurfaceBase base; 127 | xcb_connection_t *connection; 128 | xcb_window_t window; 129 | } VkIcdSurfaceXcb; 130 | #endif // VK_USE_PLATFORM_XCB_KHR 131 | 132 | #ifdef VK_USE_PLATFORM_XLIB_KHR 133 | typedef struct { 134 | VkIcdSurfaceBase base; 135 | Display *dpy; 136 | Window window; 137 | } VkIcdSurfaceXlib; 138 | #endif // VK_USE_PLATFORM_XLIB_KHR 139 | 140 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 141 | typedef struct { 142 | VkIcdSurfaceBase base; 143 | struct ANativeWindow *window; 144 | } VkIcdSurfaceAndroid; 145 | #endif // VK_USE_PLATFORM_ANDROID_KHR 146 | 147 | #ifdef VK_USE_PLATFORM_MACOS_MVK 148 | typedef struct { 149 | VkIcdSurfaceBase base; 150 | const void *pView; 151 | } VkIcdSurfaceMacOS; 152 | #endif // VK_USE_PLATFORM_MACOS_MVK 153 | 154 | #ifdef VK_USE_PLATFORM_IOS_MVK 155 | typedef struct { 156 | VkIcdSurfaceBase base; 157 | const void *pView; 158 | } VkIcdSurfaceIOS; 159 | #endif // VK_USE_PLATFORM_IOS_MVK 160 | 161 | typedef struct { 162 | VkIcdSurfaceBase base; 163 | VkDisplayModeKHR displayMode; 164 | uint32_t planeIndex; 165 | uint32_t planeStackIndex; 166 | VkSurfaceTransformFlagBitsKHR transform; 167 | float globalAlpha; 168 | VkDisplayPlaneAlphaFlagBitsKHR alphaMode; 169 | VkExtent2D imageExtent; 170 | } VkIcdSurfaceDisplay; 171 | 172 | typedef struct { 173 | VkIcdSurfaceBase base; 174 | } VkIcdSurfaceHeadless; 175 | 176 | #ifdef VK_USE_PLATFORM_METAL_EXT 177 | typedef struct { 178 | VkIcdSurfaceBase base; 179 | const CAMetalLayer *pLayer; 180 | } VkIcdSurfaceMetal; 181 | #endif // VK_USE_PLATFORM_METAL_EXT 182 | 183 | #endif // VKICD_H 184 | -------------------------------------------------------------------------------- /include/vulkan/vk_layer.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_layer.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2017 The Khronos Group Inc. 6 | * Copyright (c) 2015-2017 Valve Corporation 7 | * Copyright (c) 2015-2017 LunarG, 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 | /* Need to define dispatch table 24 | * Core struct can then have ptr to dispatch table at the top 25 | * Along with object ptrs for current and next OBJ 26 | */ 27 | #pragma once 28 | 29 | #include "vulkan.h" 30 | #if defined(__GNUC__) && __GNUC__ >= 4 31 | #define VK_LAYER_EXPORT __attribute__((visibility("default"))) 32 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) 33 | #define VK_LAYER_EXPORT __attribute__((visibility("default"))) 34 | #else 35 | #define VK_LAYER_EXPORT 36 | #endif 37 | 38 | #define MAX_NUM_UNKNOWN_EXTS 250 39 | 40 | // Loader-Layer version negotiation API. Versions add the following features: 41 | // Versions 0/1 - Initial. Doesn't support vk_layerGetPhysicalDeviceProcAddr 42 | // or vk_icdNegotiateLoaderLayerInterfaceVersion. 43 | // Version 2 - Add support for vk_layerGetPhysicalDeviceProcAddr and 44 | // vk_icdNegotiateLoaderLayerInterfaceVersion. 45 | #define CURRENT_LOADER_LAYER_INTERFACE_VERSION 2 46 | #define MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION 1 47 | 48 | #define VK_CURRENT_CHAIN_VERSION 1 49 | 50 | // Typedef for use in the interfaces below 51 | typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName); 52 | 53 | // Version negotiation values 54 | typedef enum VkNegotiateLayerStructType { 55 | LAYER_NEGOTIATE_UNINTIALIZED = 0, 56 | LAYER_NEGOTIATE_INTERFACE_STRUCT = 1, 57 | } VkNegotiateLayerStructType; 58 | 59 | // Version negotiation structures 60 | typedef struct VkNegotiateLayerInterface { 61 | VkNegotiateLayerStructType sType; 62 | void *pNext; 63 | uint32_t loaderLayerInterfaceVersion; 64 | PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr; 65 | PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr; 66 | PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr; 67 | } VkNegotiateLayerInterface; 68 | 69 | // Version negotiation functions 70 | typedef VkResult (VKAPI_PTR *PFN_vkNegotiateLoaderLayerInterfaceVersion)(VkNegotiateLayerInterface *pVersionStruct); 71 | 72 | // Function prototype for unknown physical device extension command 73 | typedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device); 74 | 75 | // ------------------------------------------------------------------------------------------------ 76 | // CreateInstance and CreateDevice support structures 77 | 78 | /* Sub type of structure for instance and device loader ext of CreateInfo. 79 | * When sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO 80 | * or sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO 81 | * then VkLayerFunction indicates struct type pointed to by pNext 82 | */ 83 | typedef enum VkLayerFunction_ { 84 | VK_LAYER_LINK_INFO = 0, 85 | VK_LOADER_DATA_CALLBACK = 1, 86 | VK_LOADER_LAYER_CREATE_DEVICE_CALLBACK = 2 87 | } VkLayerFunction; 88 | 89 | typedef struct VkLayerInstanceLink_ { 90 | struct VkLayerInstanceLink_ *pNext; 91 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 92 | PFN_GetPhysicalDeviceProcAddr pfnNextGetPhysicalDeviceProcAddr; 93 | } VkLayerInstanceLink; 94 | 95 | /* 96 | * When creating the device chain the loader needs to pass 97 | * down information about it's device structure needed at 98 | * the end of the chain. Passing the data via the 99 | * VkLayerDeviceInfo avoids issues with finding the 100 | * exact instance being used. 101 | */ 102 | typedef struct VkLayerDeviceInfo_ { 103 | void *device_info; 104 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 105 | } VkLayerDeviceInfo; 106 | 107 | typedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance, 108 | void *object); 109 | typedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device, 110 | void *object); 111 | typedef VkResult (VKAPI_PTR *PFN_vkLayerCreateDevice)(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, 112 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA); 113 | typedef void (VKAPI_PTR *PFN_vkLayerDestroyDevice)(VkDevice physicalDevice, const VkAllocationCallbacks *pAllocator, PFN_vkDestroyDevice destroyFunction); 114 | typedef struct { 115 | VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO 116 | const void *pNext; 117 | VkLayerFunction function; 118 | union { 119 | VkLayerInstanceLink *pLayerInfo; 120 | PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData; 121 | struct { 122 | PFN_vkLayerCreateDevice pfnLayerCreateDevice; 123 | PFN_vkLayerDestroyDevice pfnLayerDestroyDevice; 124 | } layerDevice; 125 | } u; 126 | } VkLayerInstanceCreateInfo; 127 | 128 | typedef struct VkLayerDeviceLink_ { 129 | struct VkLayerDeviceLink_ *pNext; 130 | PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; 131 | PFN_vkGetDeviceProcAddr pfnNextGetDeviceProcAddr; 132 | } VkLayerDeviceLink; 133 | 134 | typedef struct { 135 | VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO 136 | const void *pNext; 137 | VkLayerFunction function; 138 | union { 139 | VkLayerDeviceLink *pLayerInfo; 140 | PFN_vkSetDeviceLoaderData pfnSetDeviceLoaderData; 141 | } u; 142 | } VkLayerDeviceCreateInfo; 143 | 144 | #ifdef __cplusplus 145 | extern "C" { 146 | #endif 147 | 148 | VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct); 149 | 150 | typedef enum VkChainType { 151 | VK_CHAIN_TYPE_UNKNOWN = 0, 152 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES = 1, 153 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_LAYER_PROPERTIES = 2, 154 | VK_CHAIN_TYPE_ENUMERATE_INSTANCE_VERSION = 3, 155 | } VkChainType; 156 | 157 | typedef struct VkChainHeader { 158 | VkChainType type; 159 | uint32_t version; 160 | uint32_t size; 161 | } VkChainHeader; 162 | 163 | typedef struct VkEnumerateInstanceExtensionPropertiesChain { 164 | VkChainHeader header; 165 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceExtensionPropertiesChain *, const char *, uint32_t *, 166 | VkExtensionProperties *); 167 | const struct VkEnumerateInstanceExtensionPropertiesChain *pNextLink; 168 | 169 | #if defined(__cplusplus) 170 | inline VkResult CallDown(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties) const { 171 | return pfnNextLayer(pNextLink, pLayerName, pPropertyCount, pProperties); 172 | } 173 | #endif 174 | } VkEnumerateInstanceExtensionPropertiesChain; 175 | 176 | typedef struct VkEnumerateInstanceLayerPropertiesChain { 177 | VkChainHeader header; 178 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceLayerPropertiesChain *, uint32_t *, VkLayerProperties *); 179 | const struct VkEnumerateInstanceLayerPropertiesChain *pNextLink; 180 | 181 | #if defined(__cplusplus) 182 | inline VkResult CallDown(uint32_t *pPropertyCount, VkLayerProperties *pProperties) const { 183 | return pfnNextLayer(pNextLink, pPropertyCount, pProperties); 184 | } 185 | #endif 186 | } VkEnumerateInstanceLayerPropertiesChain; 187 | 188 | typedef struct VkEnumerateInstanceVersionChain { 189 | VkChainHeader header; 190 | VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceVersionChain *, uint32_t *); 191 | const struct VkEnumerateInstanceVersionChain *pNextLink; 192 | 193 | #if defined(__cplusplus) 194 | inline VkResult CallDown(uint32_t *pApiVersion) const { 195 | return pfnNextLayer(pNextLink, pApiVersion); 196 | } 197 | #endif 198 | } VkEnumerateInstanceVersionChain; 199 | 200 | #ifdef __cplusplus 201 | } 202 | #endif 203 | -------------------------------------------------------------------------------- /include/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 58 | // calling convention, i.e. float parameters are passed in registers. This 59 | // is true even if the rest of the application passes floats on the stack, 60 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /include/vulkan/vk_sdk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_sdk_platform.h 3 | // 4 | /* 5 | * Copyright (c) 2015-2016 The Khronos Group Inc. 6 | * Copyright (c) 2015-2016 Valve Corporation 7 | * Copyright (c) 2015-2016 LunarG, 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 | #ifndef VK_SDK_PLATFORM_H 23 | #define VK_SDK_PLATFORM_H 24 | 25 | #if defined(_WIN32) 26 | #define NOMINMAX 27 | #ifndef __cplusplus 28 | #undef inline 29 | #define inline __inline 30 | #endif // __cplusplus 31 | 32 | #if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) 33 | // C99: 34 | // Microsoft didn't implement C99 in Visual Studio; but started adding it with 35 | // VS2013. However, VS2013 still didn't have snprintf(). The following is a 36 | // work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the 37 | // "CMakeLists.txt" file). 38 | // NOTE: This is fixed in Visual Studio 2015. 39 | #define snprintf _snprintf 40 | #endif 41 | 42 | #define strdup _strdup 43 | 44 | #endif // _WIN32 45 | 46 | // Check for noexcept support using clang, with fallback to Windows or GCC version numbers 47 | #ifndef NOEXCEPT 48 | #if defined(__clang__) 49 | #if __has_feature(cxx_noexcept) 50 | #define HAS_NOEXCEPT 51 | #endif 52 | #else 53 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 54 | #define HAS_NOEXCEPT 55 | #else 56 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS 57 | #define HAS_NOEXCEPT 58 | #endif 59 | #endif 60 | #endif 61 | 62 | #ifdef HAS_NOEXCEPT 63 | #define NOEXCEPT noexcept 64 | #else 65 | #define NOEXCEPT 66 | #endif 67 | #endif 68 | 69 | #endif // VK_SDK_PLATFORM_H 70 | -------------------------------------------------------------------------------- /include/vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | #include "vk_platform.h" 21 | #include "vulkan_core.h" 22 | 23 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 24 | #include "vulkan_android.h" 25 | #endif 26 | 27 | #ifdef VK_USE_PLATFORM_FUCHSIA 28 | #include 29 | #include "vulkan_fuchsia.h" 30 | #endif 31 | 32 | #ifdef VK_USE_PLATFORM_IOS_MVK 33 | #include "vulkan_ios.h" 34 | #endif 35 | 36 | 37 | #ifdef VK_USE_PLATFORM_MACOS_MVK 38 | #include "vulkan_macos.h" 39 | #endif 40 | 41 | #ifdef VK_USE_PLATFORM_METAL_EXT 42 | #include "vulkan_metal.h" 43 | #endif 44 | 45 | #ifdef VK_USE_PLATFORM_VI_NN 46 | #include "vulkan_vi.h" 47 | #endif 48 | 49 | 50 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 51 | #include 52 | #include "vulkan_wayland.h" 53 | #endif 54 | 55 | 56 | #ifdef VK_USE_PLATFORM_WIN32_KHR 57 | #include 58 | #include "vulkan_win32.h" 59 | #endif 60 | 61 | 62 | #ifdef VK_USE_PLATFORM_XCB_KHR 63 | #include 64 | #include "vulkan_xcb.h" 65 | #endif 66 | 67 | 68 | #ifdef VK_USE_PLATFORM_XLIB_KHR 69 | #include 70 | #include "vulkan_xlib.h" 71 | #endif 72 | 73 | 74 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 75 | #include 76 | #include 77 | #include "vulkan_xlib_xrandr.h" 78 | #endif 79 | 80 | 81 | #ifdef VK_USE_PLATFORM_GGP 82 | #include 83 | #include "vulkan_ggp.h" 84 | #endif 85 | 86 | #endif // VULKAN_H_ 87 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_android.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_ANDROID_H_ 2 | #define VULKAN_ANDROID_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_android_surface 1 33 | struct ANativeWindow; 34 | #define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6 35 | #define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface" 36 | typedef VkFlags VkAndroidSurfaceCreateFlagsKHR; 37 | typedef struct VkAndroidSurfaceCreateInfoKHR { 38 | VkStructureType sType; 39 | const void* pNext; 40 | VkAndroidSurfaceCreateFlagsKHR flags; 41 | struct ANativeWindow* window; 42 | } VkAndroidSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | 46 | #ifndef VK_NO_PROTOTYPES 47 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( 48 | VkInstance instance, 49 | const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, 50 | const VkAllocationCallbacks* pAllocator, 51 | VkSurfaceKHR* pSurface); 52 | #endif 53 | 54 | 55 | #define VK_ANDROID_external_memory_android_hardware_buffer 1 56 | struct AHardwareBuffer; 57 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_SPEC_VERSION 3 58 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME "VK_ANDROID_external_memory_android_hardware_buffer" 59 | typedef struct VkAndroidHardwareBufferUsageANDROID { 60 | VkStructureType sType; 61 | void* pNext; 62 | uint64_t androidHardwareBufferUsage; 63 | } VkAndroidHardwareBufferUsageANDROID; 64 | 65 | typedef struct VkAndroidHardwareBufferPropertiesANDROID { 66 | VkStructureType sType; 67 | void* pNext; 68 | VkDeviceSize allocationSize; 69 | uint32_t memoryTypeBits; 70 | } VkAndroidHardwareBufferPropertiesANDROID; 71 | 72 | typedef struct VkAndroidHardwareBufferFormatPropertiesANDROID { 73 | VkStructureType sType; 74 | void* pNext; 75 | VkFormat format; 76 | uint64_t externalFormat; 77 | VkFormatFeatureFlags formatFeatures; 78 | VkComponentMapping samplerYcbcrConversionComponents; 79 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 80 | VkSamplerYcbcrRange suggestedYcbcrRange; 81 | VkChromaLocation suggestedXChromaOffset; 82 | VkChromaLocation suggestedYChromaOffset; 83 | } VkAndroidHardwareBufferFormatPropertiesANDROID; 84 | 85 | typedef struct VkImportAndroidHardwareBufferInfoANDROID { 86 | VkStructureType sType; 87 | const void* pNext; 88 | struct AHardwareBuffer* buffer; 89 | } VkImportAndroidHardwareBufferInfoANDROID; 90 | 91 | typedef struct VkMemoryGetAndroidHardwareBufferInfoANDROID { 92 | VkStructureType sType; 93 | const void* pNext; 94 | VkDeviceMemory memory; 95 | } VkMemoryGetAndroidHardwareBufferInfoANDROID; 96 | 97 | typedef struct VkExternalFormatANDROID { 98 | VkStructureType sType; 99 | void* pNext; 100 | uint64_t externalFormat; 101 | } VkExternalFormatANDROID; 102 | 103 | typedef VkResult (VKAPI_PTR *PFN_vkGetAndroidHardwareBufferPropertiesANDROID)(VkDevice device, const struct AHardwareBuffer* buffer, VkAndroidHardwareBufferPropertiesANDROID* pProperties); 104 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryAndroidHardwareBufferANDROID)(VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, struct AHardwareBuffer** pBuffer); 105 | 106 | #ifndef VK_NO_PROTOTYPES 107 | VKAPI_ATTR VkResult VKAPI_CALL vkGetAndroidHardwareBufferPropertiesANDROID( 108 | VkDevice device, 109 | const struct AHardwareBuffer* buffer, 110 | VkAndroidHardwareBufferPropertiesANDROID* pProperties); 111 | 112 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryAndroidHardwareBufferANDROID( 113 | VkDevice device, 114 | const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, 115 | struct AHardwareBuffer** pBuffer); 116 | #endif 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_fuchsia.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_FUCHSIA_H_ 2 | #define VULKAN_FUCHSIA_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_FUCHSIA_imagepipe_surface 1 33 | #define VK_FUCHSIA_IMAGEPIPE_SURFACE_SPEC_VERSION 1 34 | #define VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME "VK_FUCHSIA_imagepipe_surface" 35 | typedef VkFlags VkImagePipeSurfaceCreateFlagsFUCHSIA; 36 | typedef struct VkImagePipeSurfaceCreateInfoFUCHSIA { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkImagePipeSurfaceCreateFlagsFUCHSIA flags; 40 | zx_handle_t imagePipeHandle; 41 | } VkImagePipeSurfaceCreateInfoFUCHSIA; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateImagePipeSurfaceFUCHSIA)(VkInstance instance, const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA( 47 | VkInstance instance, 48 | const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_ggp.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_GGP_H_ 2 | #define VULKAN_GGP_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_GGP_stream_descriptor_surface 1 33 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1 34 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface" 35 | typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP; 36 | typedef struct VkStreamDescriptorSurfaceCreateInfoGGP { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkStreamDescriptorSurfaceCreateFlagsGGP flags; 40 | GgpStreamDescriptor streamDescriptor; 41 | } VkStreamDescriptorSurfaceCreateInfoGGP; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP( 47 | VkInstance instance, 48 | const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | 54 | #define VK_GGP_frame_token 1 55 | #define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1 56 | #define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token" 57 | typedef struct VkPresentFrameTokenGGP { 58 | VkStructureType sType; 59 | const void* pNext; 60 | GgpFrameToken frameToken; 61 | } VkPresentFrameTokenGGP; 62 | 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_IOS_H_ 2 | #define VULKAN_IOS_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_MVK_ios_surface 1 33 | #define VK_MVK_IOS_SURFACE_SPEC_VERSION 2 34 | #define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" 35 | typedef VkFlags VkIOSSurfaceCreateFlagsMVK; 36 | typedef struct VkIOSSurfaceCreateInfoMVK { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkIOSSurfaceCreateFlagsMVK flags; 40 | const void* pView; 41 | } VkIOSSurfaceCreateInfoMVK; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( 47 | VkInstance instance, 48 | const VkIOSSurfaceCreateInfoMVK* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_MACOS_H_ 2 | #define VULKAN_MACOS_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_MVK_macos_surface 1 33 | #define VK_MVK_MACOS_SURFACE_SPEC_VERSION 2 34 | #define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" 35 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 36 | typedef struct VkMacOSSurfaceCreateInfoMVK { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkMacOSSurfaceCreateFlagsMVK flags; 40 | const void* pView; 41 | } VkMacOSSurfaceCreateInfoMVK; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( 47 | VkInstance instance, 48 | const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_metal.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_METAL_H_ 2 | #define VULKAN_METAL_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_EXT_metal_surface 1 33 | 34 | #ifdef __OBJC__ 35 | @class CAMetalLayer; 36 | #else 37 | typedef void CAMetalLayer; 38 | #endif 39 | 40 | #define VK_EXT_METAL_SURFACE_SPEC_VERSION 1 41 | #define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface" 42 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; 43 | typedef struct VkMetalSurfaceCreateInfoEXT { 44 | VkStructureType sType; 45 | const void* pNext; 46 | VkMetalSurfaceCreateFlagsEXT flags; 47 | const CAMetalLayer* pLayer; 48 | } VkMetalSurfaceCreateInfoEXT; 49 | 50 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMetalSurfaceEXT)(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 51 | 52 | #ifndef VK_NO_PROTOTYPES 53 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT( 54 | VkInstance instance, 55 | const VkMetalSurfaceCreateInfoEXT* pCreateInfo, 56 | const VkAllocationCallbacks* pAllocator, 57 | VkSurfaceKHR* pSurface); 58 | #endif 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VI_H_ 2 | #define VULKAN_VI_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_NN_vi_surface 1 33 | #define VK_NN_VI_SURFACE_SPEC_VERSION 1 34 | #define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" 35 | typedef VkFlags VkViSurfaceCreateFlagsNN; 36 | typedef struct VkViSurfaceCreateInfoNN { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkViSurfaceCreateFlagsNN flags; 40 | void* window; 41 | } VkViSurfaceCreateInfoNN; 42 | 43 | typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 44 | 45 | #ifndef VK_NO_PROTOTYPES 46 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( 47 | VkInstance instance, 48 | const VkViSurfaceCreateInfoNN* pCreateInfo, 49 | const VkAllocationCallbacks* pAllocator, 50 | VkSurfaceKHR* pSurface); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_wayland.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WAYLAND_H_ 2 | #define VULKAN_WAYLAND_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_wayland_surface 1 33 | #define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" 35 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 36 | typedef struct VkWaylandSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkWaylandSurfaceCreateFlagsKHR flags; 40 | struct wl_display* display; 41 | struct wl_surface* surface; 42 | } VkWaylandSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( 49 | VkInstance instance, 50 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | struct wl_display* display); 58 | #endif 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_win32.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WIN32_H_ 2 | #define VULKAN_WIN32_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_win32_surface 1 33 | #define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface" 35 | typedef VkFlags VkWin32SurfaceCreateFlagsKHR; 36 | typedef struct VkWin32SurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkWin32SurfaceCreateFlagsKHR flags; 40 | HINSTANCE hinstance; 41 | HWND hwnd; 42 | } VkWin32SurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( 49 | VkInstance instance, 50 | const VkWin32SurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex); 57 | #endif 58 | 59 | 60 | #define VK_KHR_external_memory_win32 1 61 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 62 | #define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32" 63 | typedef struct VkImportMemoryWin32HandleInfoKHR { 64 | VkStructureType sType; 65 | const void* pNext; 66 | VkExternalMemoryHandleTypeFlagBits handleType; 67 | HANDLE handle; 68 | LPCWSTR name; 69 | } VkImportMemoryWin32HandleInfoKHR; 70 | 71 | typedef struct VkExportMemoryWin32HandleInfoKHR { 72 | VkStructureType sType; 73 | const void* pNext; 74 | const SECURITY_ATTRIBUTES* pAttributes; 75 | DWORD dwAccess; 76 | LPCWSTR name; 77 | } VkExportMemoryWin32HandleInfoKHR; 78 | 79 | typedef struct VkMemoryWin32HandlePropertiesKHR { 80 | VkStructureType sType; 81 | void* pNext; 82 | uint32_t memoryTypeBits; 83 | } VkMemoryWin32HandlePropertiesKHR; 84 | 85 | typedef struct VkMemoryGetWin32HandleInfoKHR { 86 | VkStructureType sType; 87 | const void* pNext; 88 | VkDeviceMemory memory; 89 | VkExternalMemoryHandleTypeFlagBits handleType; 90 | } VkMemoryGetWin32HandleInfoKHR; 91 | 92 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 93 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 94 | 95 | #ifndef VK_NO_PROTOTYPES 96 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR( 97 | VkDevice device, 98 | const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, 99 | HANDLE* pHandle); 100 | 101 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR( 102 | VkDevice device, 103 | VkExternalMemoryHandleTypeFlagBits handleType, 104 | HANDLE handle, 105 | VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); 106 | #endif 107 | 108 | 109 | #define VK_KHR_win32_keyed_mutex 1 110 | #define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1 111 | #define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex" 112 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR { 113 | VkStructureType sType; 114 | const void* pNext; 115 | uint32_t acquireCount; 116 | const VkDeviceMemory* pAcquireSyncs; 117 | const uint64_t* pAcquireKeys; 118 | const uint32_t* pAcquireTimeouts; 119 | uint32_t releaseCount; 120 | const VkDeviceMemory* pReleaseSyncs; 121 | const uint64_t* pReleaseKeys; 122 | } VkWin32KeyedMutexAcquireReleaseInfoKHR; 123 | 124 | 125 | 126 | #define VK_KHR_external_semaphore_win32 1 127 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1 128 | #define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32" 129 | typedef struct VkImportSemaphoreWin32HandleInfoKHR { 130 | VkStructureType sType; 131 | const void* pNext; 132 | VkSemaphore semaphore; 133 | VkSemaphoreImportFlags flags; 134 | VkExternalSemaphoreHandleTypeFlagBits handleType; 135 | HANDLE handle; 136 | LPCWSTR name; 137 | } VkImportSemaphoreWin32HandleInfoKHR; 138 | 139 | typedef struct VkExportSemaphoreWin32HandleInfoKHR { 140 | VkStructureType sType; 141 | const void* pNext; 142 | const SECURITY_ATTRIBUTES* pAttributes; 143 | DWORD dwAccess; 144 | LPCWSTR name; 145 | } VkExportSemaphoreWin32HandleInfoKHR; 146 | 147 | typedef struct VkD3D12FenceSubmitInfoKHR { 148 | VkStructureType sType; 149 | const void* pNext; 150 | uint32_t waitSemaphoreValuesCount; 151 | const uint64_t* pWaitSemaphoreValues; 152 | uint32_t signalSemaphoreValuesCount; 153 | const uint64_t* pSignalSemaphoreValues; 154 | } VkD3D12FenceSubmitInfoKHR; 155 | 156 | typedef struct VkSemaphoreGetWin32HandleInfoKHR { 157 | VkStructureType sType; 158 | const void* pNext; 159 | VkSemaphore semaphore; 160 | VkExternalSemaphoreHandleTypeFlagBits handleType; 161 | } VkSemaphoreGetWin32HandleInfoKHR; 162 | 163 | typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 164 | typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 165 | 166 | #ifndef VK_NO_PROTOTYPES 167 | VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR( 168 | VkDevice device, 169 | const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); 170 | 171 | VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR( 172 | VkDevice device, 173 | const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, 174 | HANDLE* pHandle); 175 | #endif 176 | 177 | 178 | #define VK_KHR_external_fence_win32 1 179 | #define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1 180 | #define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32" 181 | typedef struct VkImportFenceWin32HandleInfoKHR { 182 | VkStructureType sType; 183 | const void* pNext; 184 | VkFence fence; 185 | VkFenceImportFlags flags; 186 | VkExternalFenceHandleTypeFlagBits handleType; 187 | HANDLE handle; 188 | LPCWSTR name; 189 | } VkImportFenceWin32HandleInfoKHR; 190 | 191 | typedef struct VkExportFenceWin32HandleInfoKHR { 192 | VkStructureType sType; 193 | const void* pNext; 194 | const SECURITY_ATTRIBUTES* pAttributes; 195 | DWORD dwAccess; 196 | LPCWSTR name; 197 | } VkExportFenceWin32HandleInfoKHR; 198 | 199 | typedef struct VkFenceGetWin32HandleInfoKHR { 200 | VkStructureType sType; 201 | const void* pNext; 202 | VkFence fence; 203 | VkExternalFenceHandleTypeFlagBits handleType; 204 | } VkFenceGetWin32HandleInfoKHR; 205 | 206 | typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 207 | typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); 208 | 209 | #ifndef VK_NO_PROTOTYPES 210 | VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR( 211 | VkDevice device, 212 | const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); 213 | 214 | VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR( 215 | VkDevice device, 216 | const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, 217 | HANDLE* pHandle); 218 | #endif 219 | 220 | 221 | #define VK_NV_external_memory_win32 1 222 | #define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 223 | #define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32" 224 | typedef struct VkImportMemoryWin32HandleInfoNV { 225 | VkStructureType sType; 226 | const void* pNext; 227 | VkExternalMemoryHandleTypeFlagsNV handleType; 228 | HANDLE handle; 229 | } VkImportMemoryWin32HandleInfoNV; 230 | 231 | typedef struct VkExportMemoryWin32HandleInfoNV { 232 | VkStructureType sType; 233 | const void* pNext; 234 | const SECURITY_ATTRIBUTES* pAttributes; 235 | DWORD dwAccess; 236 | } VkExportMemoryWin32HandleInfoNV; 237 | 238 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle); 239 | 240 | #ifndef VK_NO_PROTOTYPES 241 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( 242 | VkDevice device, 243 | VkDeviceMemory memory, 244 | VkExternalMemoryHandleTypeFlagsNV handleType, 245 | HANDLE* pHandle); 246 | #endif 247 | 248 | 249 | #define VK_NV_win32_keyed_mutex 1 250 | #define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 2 251 | #define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex" 252 | typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV { 253 | VkStructureType sType; 254 | const void* pNext; 255 | uint32_t acquireCount; 256 | const VkDeviceMemory* pAcquireSyncs; 257 | const uint64_t* pAcquireKeys; 258 | const uint32_t* pAcquireTimeoutMilliseconds; 259 | uint32_t releaseCount; 260 | const VkDeviceMemory* pReleaseSyncs; 261 | const uint64_t* pReleaseKeys; 262 | } VkWin32KeyedMutexAcquireReleaseInfoNV; 263 | 264 | 265 | 266 | #define VK_EXT_full_screen_exclusive 1 267 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_SPEC_VERSION 4 268 | #define VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME "VK_EXT_full_screen_exclusive" 269 | 270 | typedef enum VkFullScreenExclusiveEXT { 271 | VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT = 0, 272 | VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT = 1, 273 | VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT = 2, 274 | VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT = 3, 275 | VK_FULL_SCREEN_EXCLUSIVE_BEGIN_RANGE_EXT = VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT, 276 | VK_FULL_SCREEN_EXCLUSIVE_END_RANGE_EXT = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, 277 | VK_FULL_SCREEN_EXCLUSIVE_RANGE_SIZE_EXT = (VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT - VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT + 1), 278 | VK_FULL_SCREEN_EXCLUSIVE_MAX_ENUM_EXT = 0x7FFFFFFF 279 | } VkFullScreenExclusiveEXT; 280 | typedef struct VkSurfaceFullScreenExclusiveInfoEXT { 281 | VkStructureType sType; 282 | void* pNext; 283 | VkFullScreenExclusiveEXT fullScreenExclusive; 284 | } VkSurfaceFullScreenExclusiveInfoEXT; 285 | 286 | typedef struct VkSurfaceCapabilitiesFullScreenExclusiveEXT { 287 | VkStructureType sType; 288 | void* pNext; 289 | VkBool32 fullScreenExclusiveSupported; 290 | } VkSurfaceCapabilitiesFullScreenExclusiveEXT; 291 | 292 | typedef struct VkSurfaceFullScreenExclusiveWin32InfoEXT { 293 | VkStructureType sType; 294 | const void* pNext; 295 | HMONITOR hmonitor; 296 | } VkSurfaceFullScreenExclusiveWin32InfoEXT; 297 | 298 | typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); 299 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 300 | typedef VkResult (VKAPI_PTR *PFN_vkReleaseFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain); 301 | typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModes2EXT)(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkDeviceGroupPresentModeFlagsKHR* pModes); 302 | 303 | #ifndef VK_NO_PROTOTYPES 304 | VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModes2EXT( 305 | VkPhysicalDevice physicalDevice, 306 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 307 | uint32_t* pPresentModeCount, 308 | VkPresentModeKHR* pPresentModes); 309 | 310 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireFullScreenExclusiveModeEXT( 311 | VkDevice device, 312 | VkSwapchainKHR swapchain); 313 | 314 | VKAPI_ATTR VkResult VKAPI_CALL vkReleaseFullScreenExclusiveModeEXT( 315 | VkDevice device, 316 | VkSwapchainKHR swapchain); 317 | 318 | VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModes2EXT( 319 | VkDevice device, 320 | const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, 321 | VkDeviceGroupPresentModeFlagsKHR* pModes); 322 | #endif 323 | 324 | #ifdef __cplusplus 325 | } 326 | #endif 327 | 328 | #endif 329 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_xcb_surface 1 33 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 35 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 36 | typedef struct VkXcbSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkXcbSurfaceCreateFlagsKHR flags; 40 | xcb_connection_t* connection; 41 | xcb_window_t window; 42 | } VkXcbSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 49 | VkInstance instance, 50 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | xcb_connection_t* connection, 58 | xcb_visualid_t visual_id); 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_KHR_xlib_surface 1 33 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 34 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 35 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 36 | typedef struct VkXlibSurfaceCreateInfoKHR { 37 | VkStructureType sType; 38 | const void* pNext; 39 | VkXlibSurfaceCreateFlagsKHR flags; 40 | Display* dpy; 41 | Window window; 42 | } VkXlibSurfaceCreateInfoKHR; 43 | 44 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 45 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 46 | 47 | #ifndef VK_NO_PROTOTYPES 48 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 49 | VkInstance instance, 50 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 51 | const VkAllocationCallbacks* pAllocator, 52 | VkSurfaceKHR* pSurface); 53 | 54 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 55 | VkPhysicalDevice physicalDevice, 56 | uint32_t queueFamilyIndex, 57 | Display* dpy, 58 | VisualID visualID); 59 | #endif 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/vulkan/vulkan_xlib_xrandr.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_XRANDR_H_ 2 | #define VULKAN_XLIB_XRANDR_H_ 1 3 | 4 | /* 5 | ** Copyright (c) 2015-2020 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | /* 21 | ** This header is generated from the Khronos Vulkan XML API Registry. 22 | ** 23 | */ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | 32 | #define VK_EXT_acquire_xlib_display 1 33 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 34 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" 35 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); 36 | typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( 40 | VkPhysicalDevice physicalDevice, 41 | Display* dpy, 42 | VkDisplayKHR display); 43 | 44 | VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( 45 | VkPhysicalDevice physicalDevice, 46 | Display* dpy, 47 | RROutput rrOutput, 48 | VkDisplayKHR* pDisplay); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /registry/cgenerator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -i 2 | # 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import os 18 | import re 19 | from generator import (GeneratorOptions, OutputGenerator, noneStr, 20 | regSortFeatures, write) 21 | 22 | 23 | class CGeneratorOptions(GeneratorOptions): 24 | """CGeneratorOptions - subclass of GeneratorOptions. 25 | 26 | Adds options used by COutputGenerator objects during C language header 27 | generation.""" 28 | 29 | def __init__(self, 30 | prefixText="", 31 | genFuncPointers=True, 32 | protectFile=True, 33 | protectFeature=True, 34 | protectProto=None, 35 | protectProtoStr=None, 36 | apicall='', 37 | apientry='', 38 | apientryp='', 39 | indentFuncProto=True, 40 | indentFuncPointer=False, 41 | alignFuncParam=0, 42 | genEnumBeginEndRange=False, 43 | genAliasMacro=False, 44 | aliasMacro='', 45 | **kwargs 46 | ): 47 | """Constructor. 48 | Additional parameters beyond parent class: 49 | 50 | - prefixText - list of strings to prefix generated header with 51 | (usually a copyright statement + calling convention macros). 52 | - protectFile - True if multiple inclusion protection should be 53 | generated (based on the filename) around the entire header. 54 | - protectFeature - True if #ifndef..#endif protection should be 55 | generated around a feature interface in the header file. 56 | - genFuncPointers - True if function pointer typedefs should be 57 | generated 58 | - protectProto - If conditional protection should be generated 59 | around prototype declarations, set to either '#ifdef' 60 | to require opt-in (#ifdef protectProtoStr) or '#ifndef' 61 | to require opt-out (#ifndef protectProtoStr). Otherwise 62 | set to None. 63 | - protectProtoStr - #ifdef/#ifndef symbol to use around prototype 64 | declarations, if protectProto is set 65 | - apicall - string to use for the function declaration prefix, 66 | such as APICALL on Windows. 67 | - apientry - string to use for the calling convention macro, 68 | in typedefs, such as APIENTRY. 69 | - apientryp - string to use for the calling convention macro 70 | in function pointer typedefs, such as APIENTRYP. 71 | - indentFuncProto - True if prototype declarations should put each 72 | parameter on a separate line 73 | - indentFuncPointer - True if typedefed function pointers should put each 74 | parameter on a separate line 75 | - alignFuncParam - if nonzero and parameters are being put on a 76 | separate line, align parameter names at the specified column 77 | - genEnumBeginEndRange - True if BEGIN_RANGE / END_RANGE macros should 78 | be generated for enumerated types 79 | - genAliasMacro - True if the OpenXR alias macro should be generated 80 | for aliased types (unclear what other circumstances this is useful) 81 | - aliasMacro - alias macro to inject when genAliasMacro is True""" 82 | GeneratorOptions.__init__(self, **kwargs) 83 | 84 | self.prefixText = prefixText 85 | """list of strings to prefix generated header with (usually a copyright statement + calling convention macros).""" 86 | 87 | self.genFuncPointers = genFuncPointers 88 | """True if function pointer typedefs should be generated""" 89 | 90 | self.protectFile = protectFile 91 | """True if multiple inclusion protection should be generated (based on the filename) around the entire header.""" 92 | 93 | self.protectFeature = protectFeature 94 | """True if #ifndef..#endif protection should be generated around a feature interface in the header file.""" 95 | 96 | self.protectProto = protectProto 97 | """If conditional protection should be generated around prototype declarations, set to either '#ifdef' to require opt-in (#ifdef protectProtoStr) or '#ifndef' to require opt-out (#ifndef protectProtoStr). Otherwise set to None.""" 98 | 99 | self.protectProtoStr = protectProtoStr 100 | """#ifdef/#ifndef symbol to use around prototype declarations, if protectProto is set""" 101 | 102 | self.apicall = apicall 103 | """string to use for the function declaration prefix, such as APICALL on Windows.""" 104 | 105 | self.apientry = apientry 106 | """string to use for the calling convention macro, in typedefs, such as APIENTRY.""" 107 | 108 | self.apientryp = apientryp 109 | """string to use for the calling convention macro in function pointer typedefs, such as APIENTRYP.""" 110 | 111 | self.indentFuncProto = indentFuncProto 112 | """True if prototype declarations should put each parameter on a separate line""" 113 | 114 | self.indentFuncPointer = indentFuncPointer 115 | """True if typedefed function pointers should put each parameter on a separate line""" 116 | 117 | self.alignFuncParam = alignFuncParam 118 | """if nonzero and parameters are being put on a separate line, align parameter names at the specified column""" 119 | 120 | self.genEnumBeginEndRange = genEnumBeginEndRange 121 | """True if BEGIN_RANGE / END_RANGE macros should be generated for enumerated types""" 122 | 123 | self.genAliasMacro = genAliasMacro 124 | """True if the OpenXR alias macro should be generated for aliased types (unclear what other circumstances this is useful)""" 125 | 126 | self.aliasMacro = aliasMacro 127 | """alias macro to inject when genAliasMacro is True""" 128 | 129 | 130 | class COutputGenerator(OutputGenerator): 131 | """Generates C-language API interfaces.""" 132 | 133 | # This is an ordered list of sections in the header file. 134 | TYPE_SECTIONS = ['include', 'define', 'basetype', 'handle', 'enum', 135 | 'group', 'bitmask', 'funcpointer', 'struct'] 136 | ALL_SECTIONS = TYPE_SECTIONS + ['commandPointer', 'command'] 137 | 138 | def __init__(self, *args, **kwargs): 139 | super().__init__(*args, **kwargs) 140 | # Internal state - accumulators for different inner block text 141 | self.sections = {section: [] for section in self.ALL_SECTIONS} 142 | self.feature_not_empty = False 143 | self.may_alias = None 144 | 145 | def beginFile(self, genOpts): 146 | OutputGenerator.beginFile(self, genOpts) 147 | # C-specific 148 | # 149 | # Multiple inclusion protection & C++ wrappers. 150 | if genOpts.protectFile and self.genOpts.filename: 151 | headerSym = re.sub(r'\.h', '_h_', 152 | os.path.basename(self.genOpts.filename)).upper() 153 | write('#ifndef', headerSym, file=self.outFile) 154 | write('#define', headerSym, '1', file=self.outFile) 155 | self.newline() 156 | 157 | # User-supplied prefix text, if any (list of strings) 158 | if genOpts.prefixText: 159 | for s in genOpts.prefixText: 160 | write(s, file=self.outFile) 161 | 162 | # C++ extern wrapper - after prefix lines so they can add includes. 163 | self.newline() 164 | write('#ifdef __cplusplus', file=self.outFile) 165 | write('extern "C" {', file=self.outFile) 166 | write('#endif', file=self.outFile) 167 | self.newline() 168 | 169 | def endFile(self): 170 | # C-specific 171 | # Finish C++ wrapper and multiple inclusion protection 172 | self.newline() 173 | write('#ifdef __cplusplus', file=self.outFile) 174 | write('}', file=self.outFile) 175 | write('#endif', file=self.outFile) 176 | if self.genOpts.protectFile and self.genOpts.filename: 177 | self.newline() 178 | write('#endif', file=self.outFile) 179 | # Finish processing in superclass 180 | OutputGenerator.endFile(self) 181 | 182 | def beginFeature(self, interface, emit): 183 | # Start processing in superclass 184 | OutputGenerator.beginFeature(self, interface, emit) 185 | # C-specific 186 | # Accumulate includes, defines, types, enums, function pointer typedefs, 187 | # end function prototypes separately for this feature. They're only 188 | # printed in endFeature(). 189 | self.sections = {section: [] for section in self.ALL_SECTIONS} 190 | self.feature_not_empty = False 191 | 192 | def endFeature(self): 193 | "Actually write the interface to the output file." 194 | # C-specific 195 | if self.emit: 196 | if self.feature_not_empty: 197 | if self.genOpts.conventions.writeFeature(self.featureExtraProtect, self.genOpts.filename): 198 | self.newline() 199 | if self.genOpts.protectFeature: 200 | write('#ifndef', self.featureName, file=self.outFile) 201 | # If type declarations are needed by other features based on 202 | # this one, it may be necessary to suppress the ExtraProtect, 203 | # or move it below the 'for section...' loop. 204 | if self.featureExtraProtect is not None: 205 | write('#ifdef', self.featureExtraProtect, file=self.outFile) 206 | self.newline() 207 | write('#define', self.featureName, '1', file=self.outFile) 208 | for section in self.TYPE_SECTIONS: 209 | contents = self.sections[section] 210 | if contents: 211 | write('\n'.join(contents), file=self.outFile) 212 | if self.genOpts.genFuncPointers and self.sections['commandPointer']: 213 | write('\n'.join(self.sections['commandPointer']), file=self.outFile) 214 | self.newline() 215 | if self.sections['command']: 216 | if self.genOpts.protectProto: 217 | write(self.genOpts.protectProto, 218 | self.genOpts.protectProtoStr, file=self.outFile) 219 | write('\n'.join(self.sections['command']), end='', file=self.outFile) 220 | if self.genOpts.protectProto: 221 | write('#endif', file=self.outFile) 222 | else: 223 | self.newline() 224 | if self.featureExtraProtect is not None: 225 | write('#endif /*', self.featureExtraProtect, '*/', file=self.outFile) 226 | if self.genOpts.protectFeature: 227 | write('#endif /*', self.featureName, '*/', file=self.outFile) 228 | # Finish processing in superclass 229 | OutputGenerator.endFeature(self) 230 | 231 | def appendSection(self, section, text): 232 | "Append a definition to the specified section" 233 | # self.sections[section].append('SECTION: ' + section + '\n') 234 | self.sections[section].append(text) 235 | self.feature_not_empty = True 236 | 237 | def genType(self, typeinfo, name, alias): 238 | "Generate type." 239 | OutputGenerator.genType(self, typeinfo, name, alias) 240 | typeElem = typeinfo.elem 241 | 242 | # Vulkan: 243 | # Determine the category of the type, and the type section to add 244 | # its definition to. 245 | # 'funcpointer' is added to the 'struct' section as a workaround for 246 | # internal issue #877, since structures and function pointer types 247 | # can have cross-dependencies. 248 | category = typeElem.get('category') 249 | if category == 'funcpointer': 250 | section = 'struct' 251 | else: 252 | section = category 253 | 254 | if category in ('struct', 'union'): 255 | # If the type is a struct type, generate it using the 256 | # special-purpose generator. 257 | self.genStruct(typeinfo, name, alias) 258 | else: 259 | # OpenXR: this section was not under 'else:' previously, just fell through 260 | if alias: 261 | # If the type is an alias, just emit a typedef declaration 262 | body = 'typedef ' + alias + ' ' + name + ';\n' 263 | else: 264 | # Replace tags with an APIENTRY-style string 265 | # (from self.genOpts). Copy other text through unchanged. 266 | # If the resulting text is an empty string, don't emit it. 267 | body = noneStr(typeElem.text) 268 | for elem in typeElem: 269 | if elem.tag == 'apientry': 270 | body += self.genOpts.apientry + noneStr(elem.tail) 271 | else: 272 | body += noneStr(elem.text) + noneStr(elem.tail) 273 | if body: 274 | # Add extra newline after multi-line entries. 275 | if '\n' in body[0:-1]: 276 | body += '\n' 277 | self.appendSection(section, body) 278 | 279 | def genProtectString(self, protect_str): 280 | """Generate protection string. 281 | 282 | Protection strings are the strings defining the OS/Platform/Graphics 283 | requirements for a given OpenXR command. When generating the 284 | language header files, we need to make sure the items specific to a 285 | graphics API or OS platform are properly wrapped in #ifs.""" 286 | protect_if_str = '' 287 | protect_end_str = '' 288 | if not protect_str: 289 | return (protect_if_str, protect_end_str) 290 | 291 | if ',' in protect_str: 292 | protect_list = protect_str.split(",") 293 | protect_defs = ('defined(%s)' % d for d in protect_list) 294 | protect_def_str = ' && '.join(protect_defs) 295 | protect_if_str = '#if %s\n' % protect_def_str 296 | protect_end_str = '#endif // %s\n' % protect_def_str 297 | else: 298 | protect_if_str = '#ifdef %s\n' % protect_str 299 | protect_end_str = '#endif // %s\n' % protect_str 300 | 301 | return (protect_if_str, protect_end_str) 302 | 303 | def typeMayAlias(self, typeName): 304 | if not self.may_alias: 305 | # First time we've asked if a type may alias. 306 | # So, let's populate the set of all names of types that may. 307 | 308 | # Everyone with an explicit mayalias="true" 309 | self.may_alias = set(typeName 310 | for typeName, data in self.registry.typedict.items() 311 | if data.elem.get('mayalias') == 'true') 312 | 313 | # Every type mentioned in some other type's parentstruct attribute. 314 | parent_structs = (otherType.elem.get('parentstruct') 315 | for otherType in self.registry.typedict.values()) 316 | self.may_alias.update(set(x for x in parent_structs 317 | if x is not None)) 318 | return typeName in self.may_alias 319 | 320 | def genStruct(self, typeinfo, typeName, alias): 321 | """Generate struct (e.g. C "struct" type). 322 | 323 | This is a special case of the tag where the contents are 324 | interpreted as a set of tags instead of freeform C 325 | C type declarations. The tags are just like 326 | tags - they are a declaration of a struct or union member. 327 | Only simple member declarations are supported (no nested 328 | structs etc.) 329 | 330 | If alias is not None, then this struct aliases another; just 331 | generate a typedef of that alias.""" 332 | OutputGenerator.genStruct(self, typeinfo, typeName, alias) 333 | 334 | typeElem = typeinfo.elem 335 | 336 | if alias: 337 | body = 'typedef ' + alias + ' ' + typeName + ';\n' 338 | else: 339 | body = '' 340 | (protect_begin, protect_end) = self.genProtectString(typeElem.get('protect')) 341 | if protect_begin: 342 | body += protect_begin 343 | body += 'typedef ' + typeElem.get('category') 344 | 345 | # This is an OpenXR-specific alternative where aliasing refers 346 | # to an inheritance hierarchy of types rather than C-level type 347 | # aliases. 348 | if self.genOpts.genAliasMacro and self.typeMayAlias(typeName): 349 | body += ' ' + self.genOpts.aliasMacro 350 | 351 | body += ' ' + typeName + ' {\n' 352 | 353 | targetLen = self.getMaxCParamTypeLength(typeinfo) 354 | for member in typeElem.findall('.//member'): 355 | body += self.makeCParamDecl(member, targetLen + 4) 356 | body += ';\n' 357 | body += '} ' + typeName + ';\n' 358 | if protect_end: 359 | body += protect_end 360 | 361 | self.appendSection('struct', body) 362 | 363 | def genGroup(self, groupinfo, groupName, alias=None): 364 | """Generate groups (e.g. C "enum" type). 365 | 366 | These are concatenated together with other types. 367 | 368 | If alias is not None, it is the name of another group type 369 | which aliases this type; just generate that alias.""" 370 | OutputGenerator.genGroup(self, groupinfo, groupName, alias) 371 | groupElem = groupinfo.elem 372 | 373 | # After either enumerated type or alias paths, add the declaration 374 | # to the appropriate section for the group being defined. 375 | if groupElem.get('type') == 'bitmask': 376 | section = 'bitmask' 377 | else: 378 | section = 'group' 379 | 380 | if alias: 381 | # If the group name is aliased, just emit a typedef declaration 382 | # for the alias. 383 | body = 'typedef ' + alias + ' ' + groupName + ';\n' 384 | self.appendSection(section, body) 385 | else: 386 | (section, body) = self.buildEnumCDecl(self.genOpts.genEnumBeginEndRange, groupinfo, groupName) 387 | self.appendSection(section, "\n" + body) 388 | 389 | def genEnum(self, enuminfo, name, alias): 390 | """Generate enumerants. 391 | 392 | tags may specify their values in several ways, but are usually 393 | just integers.""" 394 | OutputGenerator.genEnum(self, enuminfo, name, alias) 395 | (_, strVal) = self.enumToValue(enuminfo.elem, False) 396 | body = '#define ' + name.ljust(33) + ' ' + strVal 397 | self.appendSection('enum', body) 398 | 399 | def genCmd(self, cmdinfo, name, alias): 400 | "Command generation" 401 | OutputGenerator.genCmd(self, cmdinfo, name, alias) 402 | 403 | # if alias: 404 | # prefix = '// ' + name + ' is an alias of command ' + alias + '\n' 405 | # else: 406 | # prefix = '' 407 | 408 | prefix = '' 409 | decls = self.makeCDecls(cmdinfo.elem) 410 | self.appendSection('command', prefix + decls[0] + '\n') 411 | if self.genOpts.genFuncPointers: 412 | self.appendSection('commandPointer', decls[1]) 413 | -------------------------------------------------------------------------------- /registry/conventions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -i 2 | # 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Base class for working-group-specific style conventions, 18 | # used in generation. 19 | 20 | from enum import Enum 21 | 22 | # Type categories that respond "False" to isStructAlwaysValid 23 | # basetype is home to typedefs like ..Bool32 24 | CATEGORIES_REQUIRING_VALIDATION = set(('handle', 25 | 'enum', 26 | 'bitmask', 27 | 'basetype', 28 | None)) 29 | 30 | # These are basic C types pulled in via openxr_platform_defines.h 31 | TYPES_KNOWN_ALWAYS_VALID = set(('char', 32 | 'float', 33 | 'int8_t', 'uint8_t', 34 | 'int32_t', 'uint32_t', 35 | 'int64_t', 'uint64_t', 36 | 'size_t', 37 | 'uintptr_t', 38 | 'int', 39 | )) 40 | 41 | 42 | class ProseListFormats(Enum): 43 | """A connective, possibly with a quantifier.""" 44 | AND = 0 45 | EACH_AND = 1 46 | OR = 2 47 | ANY_OR = 3 48 | 49 | @classmethod 50 | def from_string(cls, s): 51 | if s == 'or': 52 | return cls.OR 53 | if s == 'and': 54 | return cls.AND 55 | return None 56 | 57 | @property 58 | def connective(self): 59 | if self in (ProseListFormats.OR, ProseListFormats.ANY_OR): 60 | return 'or' 61 | return 'and' 62 | 63 | def quantifier(self, n): 64 | """Return the desired quantifier for a list of a given length.""" 65 | if self == ProseListFormats.ANY_OR: 66 | if n > 1: 67 | return 'any of ' 68 | elif self == ProseListFormats.EACH_AND: 69 | if n > 2: 70 | return 'each of ' 71 | if n == 2: 72 | return 'both of ' 73 | return '' 74 | 75 | 76 | class ConventionsBase: 77 | """WG-specific conventions.""" 78 | 79 | def __init__(self): 80 | self._command_prefix = None 81 | self._type_prefix = None 82 | 83 | def formatExtension(self, name): 84 | """Mark up a name as an extension for the spec.""" 85 | return '`<<{}>>`'.format(name) 86 | 87 | @property 88 | def null(self): 89 | """Preferred spelling of NULL.""" 90 | raise NotImplementedError 91 | 92 | def makeProseList(self, elements, fmt=ProseListFormats.AND, with_verb=False, *args, **kwargs): 93 | """Make a (comma-separated) list for use in prose. 94 | 95 | Adds a connective (by default, 'and') 96 | before the last element if there are more than 1. 97 | 98 | Adds the right one of "is" or "are" to the end if with_verb is true. 99 | 100 | Optionally adds a quantifier (like 'any') before a list of 2 or more, 101 | if specified by fmt. 102 | 103 | Override with a different method or different call to 104 | _implMakeProseList if you want to add a comma for two elements, 105 | or not use a serial comma. 106 | """ 107 | return self._implMakeProseList(elements, fmt, with_verb, *args, **kwargs) 108 | 109 | @property 110 | def struct_macro(self): 111 | """Get the appropriate format macro for a structure. 112 | 113 | May override. 114 | """ 115 | return 'slink:' 116 | 117 | @property 118 | def external_macro(self): 119 | """Get the appropriate format macro for an external type like uint32_t. 120 | 121 | May override. 122 | """ 123 | return 'code:' 124 | 125 | def makeStructName(self, name): 126 | """Prepend the appropriate format macro for a structure to a structure type name. 127 | 128 | Uses struct_macro, so just override that if you want to change behavior. 129 | """ 130 | return self.struct_macro + name 131 | 132 | def makeExternalTypeName(self, name): 133 | """Prepend the appropriate format macro for an external type like uint32_t to a type name. 134 | 135 | Uses external_macro, so just override that if you want to change behavior. 136 | """ 137 | return self.external_macro + name 138 | 139 | def _implMakeProseList(self, elements, fmt, with_verb, comma_for_two_elts=False, serial_comma=True): 140 | """Internal-use implementation to make a (comma-separated) list for use in prose. 141 | 142 | Adds a connective (by default, 'and') 143 | before the last element if there are more than 1, 144 | and only includes commas if there are more than 2 145 | (if comma_for_two_elts is False). 146 | 147 | Adds the right one of "is" or "are" to the end if with_verb is true. 148 | 149 | Optionally adds a quantifier (like 'any') before a list of 2 or more, 150 | if specified by fmt. 151 | 152 | Don't edit these defaults, override self.makeProseList(). 153 | """ 154 | assert(serial_comma) # didn't implement what we didn't need 155 | if isinstance(fmt, str): 156 | fmt = ProseListFormats.from_string(fmt) 157 | 158 | my_elts = list(elements) 159 | if len(my_elts) > 1: 160 | my_elts[-1] = '{} {}'.format(fmt.connective, my_elts[-1]) 161 | 162 | if not comma_for_two_elts and len(my_elts) <= 2: 163 | prose = ' '.join(my_elts) 164 | else: 165 | prose = ', '.join(my_elts) 166 | 167 | quantifier = fmt.quantifier(len(my_elts)) 168 | 169 | parts = [quantifier, prose] 170 | 171 | if with_verb: 172 | if len(my_elts) > 1: 173 | parts.append(' are') 174 | else: 175 | parts.append(' is') 176 | return ''.join(parts) 177 | 178 | @property 179 | def file_suffix(self): 180 | """Return suffix of generated Asciidoctor files""" 181 | raise NotImplementedError 182 | 183 | def api_name(self, spectype=None): 184 | """Return API or specification name for citations in ref pages. 185 | 186 | spectype is the spec this refpage is for. 187 | 'api' (the default value) is the main API Specification. 188 | If an unrecognized spectype is given, returns None. 189 | 190 | Must implement.""" 191 | raise NotImplementedError 192 | 193 | def should_insert_may_alias_macro(self, genOpts): 194 | """Return true if we should insert a "may alias" macro in this file. 195 | 196 | Only used by OpenXR right now.""" 197 | return False 198 | 199 | @property 200 | def command_prefix(self): 201 | """Return the expected prefix of commands/functions. 202 | 203 | Implemented in terms of api_prefix.""" 204 | if not self._command_prefix: 205 | self._command_prefix = self.api_prefix[:].replace('_', '').lower() 206 | return self._command_prefix 207 | 208 | @property 209 | def type_prefix(self): 210 | """Return the expected prefix of type names. 211 | 212 | Implemented in terms of command_prefix (and in turn, api_prefix).""" 213 | if not self._type_prefix: 214 | self._type_prefix = ''.join( 215 | (self.command_prefix[0:1].upper(), self.command_prefix[1:])) 216 | return self._type_prefix 217 | 218 | @property 219 | def api_prefix(self): 220 | """Return API token prefix. 221 | 222 | Typically two uppercase letters followed by an underscore. 223 | 224 | Must implement.""" 225 | raise NotImplementedError 226 | 227 | @property 228 | def api_version_prefix(self): 229 | """Return API core version token prefix. 230 | 231 | Implemented in terms of api_prefix. 232 | 233 | May override.""" 234 | return self.api_prefix + 'VERSION_' 235 | 236 | @property 237 | def KHR_prefix(self): 238 | """Return extension name prefix for KHR extensions. 239 | 240 | Implemented in terms of api_prefix. 241 | 242 | May override.""" 243 | return self.api_prefix + 'KHR_' 244 | 245 | @property 246 | def EXT_prefix(self): 247 | """Return extension name prefix for EXT extensions. 248 | 249 | Implemented in terms of api_prefix. 250 | 251 | May override.""" 252 | return self.api_prefix + 'EXT_' 253 | 254 | def writeFeature(self, featureExtraProtect, filename): 255 | """Return True if OutputGenerator.endFeature should write this feature. 256 | 257 | Defaults to always True. 258 | Used in COutputGenerator. 259 | 260 | May override.""" 261 | return True 262 | 263 | def requires_error_validation(self, return_type): 264 | """Return True if the return_type element is an API result code 265 | requiring error validation. 266 | 267 | Defaults to always False. 268 | 269 | May override.""" 270 | return False 271 | 272 | @property 273 | def required_errors(self): 274 | """Return a list of required error codes for validation. 275 | 276 | Defaults to an empty list. 277 | 278 | May override.""" 279 | return [] 280 | 281 | def is_voidpointer_alias(self, tag, text, tail): 282 | """Return True if the declaration components (tag,text,tail) of an 283 | element represents a void * type. 284 | 285 | Defaults to a reasonable implementation. 286 | 287 | May override.""" 288 | return tag == 'type' and text == 'void' and tail.startswith('*') 289 | 290 | def make_voidpointer_alias(self, tail): 291 | """Reformat a void * declaration to include the API alias macro. 292 | 293 | Defaults to a no-op. 294 | 295 | Must override if you actually want to use this feature in your project.""" 296 | return tail 297 | 298 | def category_requires_validation(self, category): 299 | """Return True if the given type 'category' always requires validation. 300 | 301 | Defaults to a reasonable implementation. 302 | 303 | May override.""" 304 | return category in CATEGORIES_REQUIRING_VALIDATION 305 | 306 | def type_always_valid(self, typename): 307 | """Return True if the given type name is always valid (never requires validation). 308 | 309 | This is for things like integers. 310 | 311 | Defaults to a reasonable implementation. 312 | 313 | May override.""" 314 | return typename in TYPES_KNOWN_ALWAYS_VALID 315 | 316 | @property 317 | def should_skip_checking_codes(self): 318 | """Return True if more than the basic validation of return codes should 319 | be skipped for a command.""" 320 | 321 | return False 322 | 323 | @property 324 | def generate_index_terms(self): 325 | """Return True if asiidoctor index terms should be generated as part 326 | of an API interface from the docgenerator.""" 327 | 328 | return False 329 | 330 | @property 331 | def generate_enum_table(self): 332 | """Return True if asciidoctor tables describing enumerants in a 333 | group should be generated as part of group generation.""" 334 | return False 335 | 336 | def extension_include_string(self, ext): 337 | """Return format string for include:: line for an extension appendix 338 | file. ext is an object with the following members: 339 | - name - extension string string 340 | - vendor - vendor portion of name 341 | - barename - remainder of name 342 | 343 | Must implement.""" 344 | raise NotImplementedError 345 | 346 | @property 347 | def refpage_generated_include_path(self): 348 | """Return path relative to the generated reference pages, to the 349 | generated API include files. 350 | 351 | Must implement.""" 352 | raise NotImplementedError 353 | -------------------------------------------------------------------------------- /registry/generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -i 2 | # 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | """Base class for source/header/doc generators, as well as some utility functions.""" 17 | 18 | from __future__ import unicode_literals 19 | 20 | import io 21 | import os 22 | import pdb 23 | import re 24 | import shutil 25 | import sys 26 | import tempfile 27 | try: 28 | from pathlib import Path 29 | except ImportError: 30 | from pathlib2 import Path 31 | 32 | from spec_tools.util import getElemName, getElemType 33 | 34 | 35 | def write(*args, **kwargs): 36 | file = kwargs.pop('file', sys.stdout) 37 | end = kwargs.pop('end', '\n') 38 | file.write(' '.join(str(arg) for arg in args)) 39 | file.write(end) 40 | 41 | 42 | def noneStr(s): 43 | """Return string argument, or "" if argument is None. 44 | 45 | Used in converting etree Elements into text. 46 | s - string to convert""" 47 | if s: 48 | return s 49 | return "" 50 | 51 | 52 | def enquote(s): 53 | """Return string argument with surrounding quotes, 54 | for serialization into Python code.""" 55 | if s: 56 | return "'{}'".format(s) 57 | return None 58 | 59 | 60 | def regSortCategoryKey(feature): 61 | """Sort key for regSortFeatures. 62 | Sorts by category of the feature name string: 63 | 64 | - Core API features (those defined with a `` tag) 65 | - ARB/KHR/OES (Khronos extensions) 66 | - other (EXT/vendor extensions)""" 67 | 68 | if feature.elem.tag == 'feature': 69 | return 0 70 | if (feature.category == 'ARB' 71 | or feature.category == 'KHR' 72 | or feature.category == 'OES'): 73 | return 1 74 | 75 | return 2 76 | 77 | 78 | def regSortOrderKey(feature): 79 | """Sort key for regSortFeatures - key is the sortorder attribute.""" 80 | 81 | return feature.sortorder 82 | 83 | 84 | def regSortFeatureVersionKey(feature): 85 | """Sort key for regSortFeatures - key is the feature version. 86 | `` elements all have version number 0.""" 87 | 88 | return float(feature.versionNumber) 89 | 90 | 91 | def regSortExtensionNumberKey(feature): 92 | """Sort key for regSortFeatures - key is the extension number. 93 | `` elements all have extension number 0.""" 94 | 95 | return int(feature.number) 96 | 97 | 98 | def regSortFeatures(featureList): 99 | """Default sort procedure for features. 100 | 101 | - Sorts by primary key of feature category ('feature' or 'extension'), 102 | - then by sort order within the category 103 | - then by version number (for features) 104 | - then by extension number (for extensions)""" 105 | featureList.sort(key=regSortExtensionNumberKey) 106 | featureList.sort(key=regSortFeatureVersionKey) 107 | featureList.sort(key=regSortOrderKey) 108 | featureList.sort(key=regSortCategoryKey) 109 | 110 | 111 | class GeneratorOptions: 112 | """Base class for options used during header/documentation production. 113 | 114 | These options are target language independent, and used by 115 | Registry.apiGen() and by base OutputGenerator objects.""" 116 | 117 | def __init__(self, 118 | conventions=None, 119 | filename=None, 120 | directory='.', 121 | apiname=None, 122 | profile=None, 123 | versions='.*', 124 | emitversions='.*', 125 | defaultExtensions=None, 126 | addExtensions=None, 127 | removeExtensions=None, 128 | emitExtensions=None, 129 | sortProcedure=regSortFeatures, 130 | lineEndings=None): 131 | """Constructor. 132 | 133 | Arguments: 134 | 135 | - conventions - may be mandatory for some generators: 136 | an object that implements ConventionsBase 137 | - filename - basename of file to generate, or None to write to stdout. 138 | - directory - directory in which to generate filename 139 | - apiname - string matching `` 'apiname' attribute, e.g. 'gl'. 140 | - profile - string specifying API profile , e.g. 'core', or None. 141 | - versions - regex matching API versions to process interfaces for. 142 | Normally `'.*'` or `'[0-9][.][0-9]'` to match all defined versions. 143 | - emitversions - regex matching API versions to actually emit 144 | interfaces for (though all requested versions are considered 145 | when deciding which interfaces to generate). For GL 4.3 glext.h, 146 | this might be `'1[.][2-5]|[2-4][.][0-9]'`. 147 | - defaultExtensions - If not None, a string which must in its 148 | entirety match the pattern in the "supported" attribute of 149 | the ``. Defaults to None. Usually the same as apiname. 150 | - addExtensions - regex matching names of additional extensions 151 | to include. Defaults to None. 152 | - removeExtensions - regex matching names of extensions to 153 | remove (after defaultExtensions and addExtensions). Defaults 154 | to None. 155 | - emitExtensions - regex matching names of extensions to actually emit 156 | interfaces for (though all requested versions are considered when 157 | deciding which interfaces to generate). 158 | - sortProcedure - takes a list of FeatureInfo objects and sorts 159 | them in place to a preferred order in the generated output. 160 | Default is core API versions, ARB/KHR/OES extensions, all other 161 | extensions, by core API version number or extension number in each 162 | group. 163 | 164 | The regex patterns can be None or empty, in which case they match 165 | nothing.""" 166 | self.conventions = conventions 167 | """may be mandatory for some generators: 168 | an object that implements ConventionsBase""" 169 | 170 | self.filename = filename 171 | "basename of file to generate, or None to write to stdout." 172 | 173 | self.directory = directory 174 | "directory in which to generate filename" 175 | 176 | self.apiname = apiname 177 | "string matching `` 'apiname' attribute, e.g. 'gl'." 178 | 179 | self.profile = profile 180 | "string specifying API profile , e.g. 'core', or None." 181 | 182 | self.versions = self.emptyRegex(versions) 183 | """regex matching API versions to process interfaces for. 184 | Normally `'.*'` or `'[0-9][.][0-9]'` to match all defined versions.""" 185 | 186 | self.emitversions = self.emptyRegex(emitversions) 187 | """regex matching API versions to actually emit 188 | interfaces for (though all requested versions are considered 189 | when deciding which interfaces to generate). For GL 4.3 glext.h, 190 | this might be `'1[.][2-5]|[2-4][.][0-9]'`.""" 191 | 192 | self.defaultExtensions = defaultExtensions 193 | """If not None, a string which must in its 194 | entirety match the pattern in the "supported" attribute of 195 | the ``. Defaults to None. Usually the same as apiname.""" 196 | 197 | self.addExtensions = self.emptyRegex(addExtensions) 198 | """regex matching names of additional extensions 199 | to include. Defaults to None.""" 200 | 201 | self.removeExtensions = self.emptyRegex(removeExtensions) 202 | """regex matching names of extensions to 203 | remove (after defaultExtensions and addExtensions). Defaults 204 | to None.""" 205 | 206 | self.emitExtensions = self.emptyRegex(emitExtensions) 207 | """regex matching names of extensions to actually emit 208 | interfaces for (though all requested versions are considered when 209 | deciding which interfaces to generate).""" 210 | 211 | self.sortProcedure = sortProcedure 212 | """takes a list of FeatureInfo objects and sorts 213 | them in place to a preferred order in the generated output. 214 | Default is core API versions, ARB/KHR/OES extensions, all 215 | other extensions, alphabetically within each group.""" 216 | 217 | self.lineEndings = lineEndings 218 | """line endings to use for the generated header. 219 | can be '\n' (unix), '\r\n' (windows), or None (platform default)""" 220 | 221 | def emptyRegex(self, pat): 222 | """Substitute a regular expression which matches no version 223 | or extension names for None or the empty string.""" 224 | if not pat: 225 | return '_nomatch_^' 226 | 227 | return pat 228 | 229 | 230 | class OutputGenerator: 231 | """Generate specified API interfaces in a specific style, such as a C header. 232 | 233 | Base class for generating API interfaces. 234 | Manages basic logic, logging, and output file control. 235 | Derived classes actually generate formatted output. 236 | """ 237 | 238 | # categoryToPath - map XML 'category' to include file directory name 239 | categoryToPath = { 240 | 'bitmask': 'flags', 241 | 'enum': 'enums', 242 | 'funcpointer': 'funcpointers', 243 | 'handle': 'handles', 244 | 'define': 'defines', 245 | 'basetype': 'basetypes', 246 | } 247 | 248 | def __init__(self, errFile=sys.stderr, warnFile=sys.stderr, diagFile=sys.stdout): 249 | """Constructor 250 | 251 | - errFile, warnFile, diagFile - file handles to write errors, 252 | warnings, diagnostics to. May be None to not write.""" 253 | self.outFile = None 254 | self.errFile = errFile 255 | self.warnFile = warnFile 256 | self.diagFile = diagFile 257 | # Internal state 258 | self.featureName = None 259 | self.genOpts = None 260 | self.registry = None 261 | # Used for extension enum value generation 262 | self.extBase = 1000000000 263 | self.extBlockSize = 1000 264 | self.madeDirs = {} 265 | 266 | def logMsg(self, level, *args): 267 | """Write a message of different categories to different 268 | destinations. 269 | 270 | - `level` 271 | - 'diag' (diagnostic, voluminous) 272 | - 'warn' (warning) 273 | - 'error' (fatal error - raises exception after logging) 274 | 275 | - `*args` - print()-style arguments to direct to corresponding log""" 276 | if level == 'error': 277 | strfile = io.StringIO() 278 | write('ERROR:', *args, file=strfile) 279 | if self.errFile is not None: 280 | write(strfile.getvalue(), file=self.errFile) 281 | raise UserWarning(strfile.getvalue()) 282 | elif level == 'warn': 283 | if self.warnFile is not None: 284 | write('WARNING:', *args, file=self.warnFile) 285 | elif level == 'diag': 286 | if self.diagFile is not None: 287 | write('DIAG:', *args, file=self.diagFile) 288 | else: 289 | raise UserWarning( 290 | '*** FATAL ERROR in Generator.logMsg: unknown level:' + level) 291 | 292 | def enumToValue(self, elem, needsNum): 293 | """Parse and convert an `` tag into a value. 294 | 295 | Returns a list: 296 | 297 | - first element - integer representation of the value, or None 298 | if needsNum is False. The value must be a legal number 299 | if needsNum is True. 300 | - second element - string representation of the value 301 | 302 | There are several possible representations of values. 303 | 304 | - A 'value' attribute simply contains the value. 305 | - A 'bitpos' attribute defines a value by specifying the bit 306 | position which is set in that value. 307 | - An 'offset','extbase','extends' triplet specifies a value 308 | as an offset to a base value defined by the specified 309 | 'extbase' extension name, which is then cast to the 310 | typename specified by 'extends'. This requires probing 311 | the registry database, and imbeds knowledge of the 312 | API extension enum scheme in this function. 313 | - An 'alias' attribute contains the name of another enum 314 | which this is an alias of. The other enum must be 315 | declared first when emitting this enum.""" 316 | name = elem.get('name') 317 | numVal = None 318 | if 'value' in elem.keys(): 319 | value = elem.get('value') 320 | # print('About to translate value =', value, 'type =', type(value)) 321 | if needsNum: 322 | numVal = int(value, 0) 323 | # If there's a non-integer, numeric 'type' attribute (e.g. 'u' or 324 | # 'ull'), append it to the string value. 325 | # t = enuminfo.elem.get('type') 326 | # if t is not None and t != '' and t != 'i' and t != 's': 327 | # value += enuminfo.type 328 | self.logMsg('diag', 'Enum', name, '-> value [', numVal, ',', value, ']') 329 | return [numVal, value] 330 | if 'bitpos' in elem.keys(): 331 | value = elem.get('bitpos') 332 | bitpos = int(value, 0) 333 | numVal = 1 << bitpos 334 | value = '0x%08x' % numVal 335 | if bitpos >= 32: 336 | value = value + 'ULL' 337 | self.logMsg('diag', 'Enum', name, '-> bitpos [', numVal, ',', value, ']') 338 | return [numVal, value] 339 | if 'offset' in elem.keys(): 340 | # Obtain values in the mapping from the attributes 341 | enumNegative = False 342 | offset = int(elem.get('offset'), 0) 343 | extnumber = int(elem.get('extnumber'), 0) 344 | extends = elem.get('extends') 345 | if 'dir' in elem.keys(): 346 | enumNegative = True 347 | self.logMsg('diag', 'Enum', name, 'offset =', offset, 348 | 'extnumber =', extnumber, 'extends =', extends, 349 | 'enumNegative =', enumNegative) 350 | # Now determine the actual enumerant value, as defined 351 | # in the "Layers and Extensions" appendix of the spec. 352 | numVal = self.extBase + (extnumber - 1) * self.extBlockSize + offset 353 | if enumNegative: 354 | numVal *= -1 355 | value = '%d' % numVal 356 | # More logic needed! 357 | self.logMsg('diag', 'Enum', name, '-> offset [', numVal, ',', value, ']') 358 | return [numVal, value] 359 | if 'alias' in elem.keys(): 360 | return [None, elem.get('alias')] 361 | return [None, None] 362 | 363 | def checkDuplicateEnums(self, enums): 364 | """Sanity check enumerated values. 365 | 366 | - enums - list of `` Elements 367 | 368 | returns the list with duplicates stripped""" 369 | # Dictionaries indexed by name and numeric value. 370 | # Entries are [ Element, numVal, strVal ] matching name or value 371 | 372 | nameMap = {} 373 | valueMap = {} 374 | 375 | stripped = [] 376 | for elem in enums: 377 | name = elem.get('name') 378 | (numVal, strVal) = self.enumToValue(elem, True) 379 | 380 | if name in nameMap: 381 | # Duplicate name found; check values 382 | (name2, numVal2, strVal2) = nameMap[name] 383 | 384 | # Duplicate enum values for the same name are benign. This 385 | # happens when defining the same enum conditionally in 386 | # several extension blocks. 387 | if (strVal2 == strVal or (numVal is not None 388 | and numVal == numVal2)): 389 | True 390 | # self.logMsg('info', 'checkDuplicateEnums: Duplicate enum (' + name + 391 | # ') found with the same value:' + strVal) 392 | else: 393 | self.logMsg('warn', 'checkDuplicateEnums: Duplicate enum (' + name 394 | + ') found with different values:' + strVal 395 | + ' and ' + strVal2) 396 | 397 | # Don't add the duplicate to the returned list 398 | continue 399 | elif numVal in valueMap: 400 | # Duplicate value found (such as an alias); report it, but 401 | # still add this enum to the list. 402 | (name2, numVal2, strVal2) = valueMap[numVal] 403 | 404 | try: 405 | self.logMsg('warn', 'Two enums found with the same value: ' + 406 | name + ' = ' + name2.get('name') + ' = ' + strVal) 407 | except: 408 | pdb.set_trace() 409 | 410 | # Track this enum to detect followon duplicates 411 | nameMap[name] = [elem, numVal, strVal] 412 | if numVal is not None: 413 | valueMap[numVal] = [elem, numVal, strVal] 414 | 415 | # Add this enum to the list 416 | stripped.append(elem) 417 | 418 | # Return the list 419 | return stripped 420 | 421 | def buildEnumCDecl(self, expand, groupinfo, groupName): 422 | """Generate the C declaration for an enum""" 423 | groupElem = groupinfo.elem 424 | 425 | if self.genOpts.conventions.constFlagBits and groupElem.get('type') == 'bitmask': 426 | return self.buildEnumCDecl_Bitmask(groupinfo, groupName) 427 | else: 428 | return self.buildEnumCDecl_Enum(expand, groupinfo, groupName) 429 | 430 | def buildEnumCDecl_Bitmask(self, groupinfo, groupName): 431 | """Generate the C declaration for an "enum" that is actually a 432 | set of flag bits""" 433 | groupElem = groupinfo.elem 434 | flagTypeName = groupinfo.flagType.elem.get('name') 435 | 436 | # Prefix 437 | body = "// Flag bits for " + flagTypeName + "\n" 438 | 439 | # Loop over the nested 'enum' tags. 440 | for elem in groupElem.findall('enum'): 441 | # Convert the value to an integer and use that to track min/max. 442 | # Values of form -(number) are accepted but nothing more complex. 443 | # Should catch exceptions here for more complex constructs. Not yet. 444 | (_, strVal) = self.enumToValue(elem, True) 445 | name = elem.get('name') 446 | body += "static const {} {} = {};\n".format(flagTypeName, name, strVal) 447 | 448 | # Postfix 449 | 450 | return ("bitmask", body) 451 | 452 | def buildEnumCDecl_Enum(self, expand, groupinfo, groupName): 453 | """Generate the C declaration for an enumerated type""" 454 | groupElem = groupinfo.elem 455 | 456 | # Break the group name into prefix and suffix portions for range 457 | # enum generation 458 | expandName = re.sub(r'([0-9a-z_])([A-Z0-9])', r'\1_\2', groupName).upper() 459 | expandPrefix = expandName 460 | expandSuffix = '' 461 | expandSuffixMatch = re.search(r'[A-Z][A-Z]+$', groupName) 462 | if expandSuffixMatch: 463 | expandSuffix = '_' + expandSuffixMatch.group() 464 | # Strip off the suffix from the prefix 465 | expandPrefix = expandName.rsplit(expandSuffix, 1)[0] 466 | 467 | # Prefix 468 | body = ["typedef enum %s {" % groupName] 469 | 470 | # @@ Should use the type="bitmask" attribute instead 471 | isEnum = ('FLAG_BITS' not in expandPrefix) 472 | 473 | # Get a list of nested 'enum' tags. 474 | enums = groupElem.findall('enum') 475 | 476 | # Check for and report duplicates, and return a list with them 477 | # removed. 478 | enums = self.checkDuplicateEnums(enums) 479 | 480 | # Loop over the nested 'enum' tags. Keep track of the minimum and 481 | # maximum numeric values, if they can be determined; but only for 482 | # core API enumerants, not extension enumerants. This is inferred 483 | # by looking for 'extends' attributes. 484 | minName = None 485 | 486 | # Accumulate non-numeric enumerant values separately and append 487 | # them following the numeric values, to allow for aliases. 488 | # NOTE: this doesn't do a topological sort yet, so aliases of 489 | # aliases can still get in the wrong order. 490 | aliasText = [] 491 | 492 | for elem in enums: 493 | # Convert the value to an integer and use that to track min/max. 494 | # Values of form -(number) are accepted but nothing more complex. 495 | # Should catch exceptions here for more complex constructs. Not yet. 496 | (numVal, strVal) = self.enumToValue(elem, True) 497 | name = elem.get('name') 498 | 499 | # Extension enumerants are only included if they are required 500 | if self.isEnumRequired(elem): 501 | decl = " {} = {},".format(name, strVal) 502 | if numVal is not None: 503 | body.append(decl) 504 | else: 505 | aliasText.append(decl) 506 | 507 | # Don't track min/max for non-numbers (numVal is None) 508 | if isEnum and numVal is not None and elem.get('extends') is None: 509 | if minName is None: 510 | minName = maxName = name 511 | minValue = maxValue = numVal 512 | elif numVal < minValue: 513 | minName = name 514 | minValue = numVal 515 | elif numVal > maxValue: 516 | maxName = name 517 | maxValue = numVal 518 | 519 | # Now append the non-numeric enumerant values 520 | body.extend(aliasText) 521 | 522 | # Generate min/max value tokens and a range-padding enum. Need some 523 | # additional padding to generate correct names... 524 | if isEnum and expand: 525 | body.extend((" {}_BEGIN_RANGE{} = {},".format(expandPrefix, expandSuffix, minName), 526 | " {}_END_RANGE{} = {},".format( 527 | expandPrefix, expandSuffix, maxName), 528 | " {}_RANGE_SIZE{} = ({} - {} + 1),".format(expandPrefix, expandSuffix, maxName, minName))) 529 | 530 | body.append(" {}_MAX_ENUM{} = 0x7FFFFFFF".format( 531 | expandPrefix, expandSuffix)) 532 | 533 | # Postfix 534 | body.append("} %s;" % groupName) 535 | 536 | # Determine appropriate section for this declaration 537 | if groupElem.get('type') == 'bitmask': 538 | section = 'bitmask' 539 | else: 540 | section = 'group' 541 | 542 | return (section, '\n'.join(body)) 543 | 544 | def makeDir(self, path): 545 | """Create a directory, if not already done. 546 | 547 | Generally called from derived generators creating hierarchies.""" 548 | self.logMsg('diag', 'OutputGenerator::makeDir(' + path + ')') 549 | if path not in self.madeDirs: 550 | # This can get race conditions with multiple writers, see 551 | # https://stackoverflow.com/questions/273192/ 552 | if not os.path.exists(path): 553 | os.makedirs(path) 554 | self.madeDirs[path] = None 555 | 556 | def beginFile(self, genOpts): 557 | """Start a new interface file 558 | 559 | - genOpts - GeneratorOptions controlling what's generated and how""" 560 | self.genOpts = genOpts 561 | self.should_insert_may_alias_macro = \ 562 | self.genOpts.conventions.should_insert_may_alias_macro(self.genOpts) 563 | 564 | self.conventions = genOpts.conventions 565 | 566 | # Open a temporary file for accumulating output. 567 | if self.genOpts.filename is not None: 568 | self.outFile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', delete=False, newline=genOpts.lineEndings) 569 | else: 570 | self.outFile = sys.stdout 571 | 572 | def endFile(self): 573 | if self.errFile: 574 | self.errFile.flush() 575 | if self.warnFile: 576 | self.warnFile.flush() 577 | if self.diagFile: 578 | self.diagFile.flush() 579 | self.outFile.flush() 580 | if self.outFile != sys.stdout and self.outFile != sys.stderr: 581 | self.outFile.close() 582 | 583 | # On successfully generating output, move the temporary file to the 584 | # target file. 585 | if self.genOpts.filename is not None: 586 | if sys.platform == 'win32': 587 | directory = Path(self.genOpts.directory) 588 | if not Path.exists(directory): 589 | os.makedirs(directory) 590 | shutil.move(self.outFile.name, self.genOpts.directory + '/' + self.genOpts.filename) 591 | self.genOpts = None 592 | 593 | def beginFeature(self, interface, emit): 594 | """Write interface for a feature and tag generated features as having been done. 595 | 596 | - interface - element for the `` / `` to generate 597 | - emit - actually write to the header only when True""" 598 | self.emit = emit 599 | self.featureName = interface.get('name') 600 | # If there's an additional 'protect' attribute in the feature, save it 601 | self.featureExtraProtect = interface.get('protect') 602 | 603 | def endFeature(self): 604 | """Finish an interface file, closing it when done. 605 | 606 | Derived classes responsible for emitting feature""" 607 | self.featureName = None 608 | self.featureExtraProtect = None 609 | 610 | def validateFeature(self, featureType, featureName): 611 | """Validate we're generating something only inside a `` tag""" 612 | if self.featureName is None: 613 | raise UserWarning('Attempt to generate', featureType, 614 | featureName, 'when not in feature') 615 | 616 | def genType(self, typeinfo, name, alias): 617 | """Generate interface for a type 618 | 619 | - typeinfo - TypeInfo for a type 620 | 621 | Extend to generate as desired in your derived class.""" 622 | self.validateFeature('type', name) 623 | 624 | def genStruct(self, typeinfo, typeName, alias): 625 | """Generate interface for a C "struct" type. 626 | 627 | - typeinfo - TypeInfo for a type interpreted as a struct 628 | 629 | Extend to generate as desired in your derived class.""" 630 | self.validateFeature('struct', typeName) 631 | 632 | # The mixed-mode tags may contain no-op tags. 633 | # It is convenient to remove them here where all output generators 634 | # will benefit. 635 | for member in typeinfo.elem.findall('.//member'): 636 | for comment in member.findall('comment'): 637 | member.remove(comment) 638 | 639 | def genGroup(self, groupinfo, groupName, alias): 640 | """Generate interface for a group of enums (C "enum") 641 | 642 | - groupinfo - GroupInfo for a group. 643 | 644 | Extend to generate as desired in your derived class.""" 645 | 646 | self.validateFeature('group', groupName) 647 | 648 | def genEnum(self, enuminfo, typeName, alias): 649 | """Generate interface for an enum (constant). 650 | 651 | - enuminfo - EnumInfo for an enum 652 | - name - enum name 653 | 654 | Extend to generate as desired in your derived class.""" 655 | self.validateFeature('enum', typeName) 656 | 657 | def genCmd(self, cmd, cmdinfo, alias): 658 | """Generate interface for a command. 659 | 660 | - cmdinfo - CmdInfo for a command 661 | 662 | Extend to generate as desired in your derived class.""" 663 | self.validateFeature('command', cmdinfo) 664 | 665 | def makeProtoName(self, name, tail): 666 | """Turn a `` `` into C-language prototype 667 | and typedef declarations for that name. 668 | 669 | - name - contents of `` tag 670 | - tail - whatever text follows that tag in the Element""" 671 | return self.genOpts.apientry + name + tail 672 | 673 | def makeTypedefName(self, name, tail): 674 | """Make the function-pointer typedef name for a command.""" 675 | return '(' + self.genOpts.apientryp + 'PFN_' + name + tail + ')' 676 | 677 | def makeCParamDecl(self, param, aligncol): 678 | """Return a string which is an indented, formatted 679 | declaration for a `` or `` block (e.g. function parameter 680 | or structure/union member). 681 | 682 | - param - Element (`` or ``) to format 683 | - aligncol - if non-zero, attempt to align the nested `` element 684 | at this column""" 685 | indent = ' ' 686 | paramdecl = indent + noneStr(param.text) 687 | for elem in param: 688 | text = noneStr(elem.text) 689 | tail = noneStr(elem.tail) 690 | 691 | if self.should_insert_may_alias_macro and self.genOpts.conventions.is_voidpointer_alias(elem.tag, text, tail): 692 | # OpenXR-specific macro insertion - but not in apiinc for the spec 693 | tail = self.genOpts.conventions.make_voidpointer_alias(tail) 694 | if elem.tag == 'name' and aligncol > 0: 695 | self.logMsg('diag', 'Aligning parameter', elem.text, 'to column', self.genOpts.alignFuncParam) 696 | # Align at specified column, if possible 697 | paramdecl = paramdecl.rstrip() 698 | oldLen = len(paramdecl) 699 | # This works around a problem where very long type names - 700 | # longer than the alignment column - would run into the tail 701 | # text. 702 | paramdecl = paramdecl.ljust(aligncol - 1) + ' ' 703 | newLen = len(paramdecl) 704 | self.logMsg('diag', 'Adjust length of parameter decl from', oldLen, 'to', newLen, ':', paramdecl) 705 | paramdecl += text + tail 706 | if aligncol == 0: 707 | # Squeeze out multiple spaces other than the indentation 708 | paramdecl = indent + ' '.join(paramdecl.split()) 709 | return paramdecl 710 | 711 | def getCParamTypeLength(self, param): 712 | """Return the length of the type field is an indented, formatted 713 | declaration for a `` or `` block (e.g. function parameter 714 | or structure/union member). 715 | 716 | - param - Element (`` or ``) to identify""" 717 | 718 | # Allow for missing tag 719 | newLen = 0 720 | paramdecl = ' ' + noneStr(param.text) 721 | for elem in param: 722 | text = noneStr(elem.text) 723 | tail = noneStr(elem.tail) 724 | 725 | if self.should_insert_may_alias_macro and self.genOpts.conventions.is_voidpointer_alias(elem.tag, text, tail): 726 | # OpenXR-specific macro insertion 727 | tail = self.genOpts.conventions.make_voidpointer_alias(tail) 728 | if elem.tag == 'name': 729 | # Align at specified column, if possible 730 | newLen = len(paramdecl.rstrip()) 731 | self.logMsg('diag', 'Identifying length of', elem.text, 'as', newLen) 732 | paramdecl += text + tail 733 | 734 | return newLen 735 | 736 | def getMaxCParamTypeLength(self, info): 737 | """Return the length of the longest type field for a member/parameter. 738 | 739 | - info - TypeInfo or CommandInfo. 740 | """ 741 | lengths = (self.getCParamTypeLength(member) 742 | for member in info.getMembers()) 743 | return max(lengths) 744 | 745 | def getHandleParent(self, typename): 746 | """Get the parent of a handle object.""" 747 | info = self.registry.typedict.get(typename) 748 | if info is None: 749 | return None 750 | 751 | elem = info.elem 752 | if elem is not None: 753 | return elem.get('parent') 754 | 755 | return None 756 | 757 | def iterateHandleAncestors(self, typename): 758 | """Iterate through the ancestors of a handle type.""" 759 | current = self.getHandleParent(typename) 760 | while current is not None: 761 | yield current 762 | current = self.getHandleParent(current) 763 | 764 | def getHandleAncestors(self, typename): 765 | """Get the ancestors of a handle object.""" 766 | return list(self.iterateHandleAncestors(typename)) 767 | 768 | def getTypeCategory(self, typename): 769 | """Get the category of a type.""" 770 | info = self.registry.typedict.get(typename) 771 | if info is None: 772 | return None 773 | 774 | elem = info.elem 775 | if elem is not None: 776 | return elem.get('category') 777 | return None 778 | 779 | def isStructAlwaysValid(self, structname): 780 | """Try to do check if a structure is always considered valid (i.e. there's no rules to its acceptance).""" 781 | # A conventions object is required for this call. 782 | if not self.conventions: 783 | raise RuntimeError("To use isStructAlwaysValid, be sure your options include a Conventions object.") 784 | 785 | if self.conventions.type_always_valid(structname): 786 | return True 787 | 788 | category = self.getTypeCategory(structname) 789 | if self.conventions.category_requires_validation(category): 790 | return False 791 | 792 | info = self.registry.typedict.get(structname) 793 | assert(info is not None) 794 | 795 | members = info.getMembers() 796 | 797 | for member in members: 798 | member_name = getElemName(member) 799 | if member_name in (self.conventions.structtype_member_name, 800 | self.conventions.nextpointer_member_name): 801 | return False 802 | 803 | if member.get('noautovalidity'): 804 | return False 805 | 806 | member_type = getElemType(member) 807 | 808 | if member_type in ('void', 'char') or self.paramIsArray(member) or self.paramIsPointer(member): 809 | return False 810 | 811 | if self.conventions.type_always_valid(member_type): 812 | continue 813 | 814 | member_category = self.getTypeCategory(member_type) 815 | 816 | if self.conventions.category_requires_validation(member_category): 817 | return False 818 | 819 | if member_category in ('struct', 'union'): 820 | if self.isStructAlwaysValid(member_type) is False: 821 | return False 822 | 823 | return True 824 | 825 | def isEnumRequired(self, elem): 826 | """Return True if this `` element is 827 | required, False otherwise 828 | 829 | - elem - `` element to test""" 830 | required = elem.get('required') is not None 831 | self.logMsg('diag', 'isEnumRequired:', elem.get('name'), 832 | '->', required) 833 | return required 834 | 835 | # @@@ This code is overridden by equivalent code now run in 836 | # @@@ Registry.generateFeature 837 | 838 | required = False 839 | 840 | extname = elem.get('extname') 841 | if extname is not None: 842 | # 'supported' attribute was injected when the element was 843 | # moved into the group in Registry.parseTree() 844 | if self.genOpts.defaultExtensions == elem.get('supported'): 845 | required = True 846 | elif re.match(self.genOpts.addExtensions, extname) is not None: 847 | required = True 848 | elif elem.get('version') is not None: 849 | required = re.match(self.genOpts.emitversions, elem.get('version')) is not None 850 | else: 851 | required = True 852 | 853 | return required 854 | 855 | def makeCDecls(self, cmd): 856 | """Return C prototype and function pointer typedef for a 857 | `` Element, as a two-element list of strings. 858 | 859 | - cmd - Element containing a `` tag""" 860 | proto = cmd.find('proto') 861 | params = cmd.findall('param') 862 | # Begin accumulating prototype and typedef strings 863 | pdecl = self.genOpts.apicall 864 | tdecl = 'typedef ' 865 | 866 | # Insert the function return type/name. 867 | # For prototypes, add APIENTRY macro before the name 868 | # For typedefs, add (APIENTRY *) around the name and 869 | # use the PFN_cmdnameproc naming convention. 870 | # Done by walking the tree for element by element. 871 | # etree has elem.text followed by (elem[i], elem[i].tail) 872 | # for each child element and any following text 873 | # Leading text 874 | pdecl += noneStr(proto.text) 875 | tdecl += noneStr(proto.text) 876 | # For each child element, if it's a wrap in appropriate 877 | # declaration. Otherwise append its contents and tail contents. 878 | for elem in proto: 879 | text = noneStr(elem.text) 880 | tail = noneStr(elem.tail) 881 | if elem.tag == 'name': 882 | pdecl += self.makeProtoName(text, tail) 883 | tdecl += self.makeTypedefName(text, tail) 884 | else: 885 | pdecl += text + tail 886 | tdecl += text + tail 887 | 888 | if self.genOpts.alignFuncParam == 0: 889 | # Squeeze out multiple spaces - there is no indentation 890 | pdecl = ' '.join(pdecl.split()) 891 | tdecl = ' '.join(tdecl.split()) 892 | 893 | # Now add the parameter declaration list, which is identical 894 | # for prototypes and typedefs. Concatenate all the text from 895 | # a node without the tags. No tree walking required 896 | # since all tags are ignored. 897 | # Uses: self.indentFuncProto 898 | # self.indentFuncPointer 899 | # self.alignFuncParam 900 | n = len(params) 901 | # Indented parameters 902 | if n > 0: 903 | indentdecl = '(\n' 904 | indentdecl += ',\n'.join(self.makeCParamDecl(p, self.genOpts.alignFuncParam) 905 | for p in params) 906 | indentdecl += ');' 907 | else: 908 | indentdecl = '(void);' 909 | # Non-indented parameters 910 | paramdecl = '(' 911 | if n > 0: 912 | paramnames = (''.join(t for t in p.itertext()) 913 | for p in params) 914 | paramdecl += ', '.join(paramnames) 915 | else: 916 | paramdecl += 'void' 917 | paramdecl += ");" 918 | return [pdecl + indentdecl, tdecl + paramdecl] 919 | 920 | def newline(self): 921 | """Print a newline to the output file (utility function)""" 922 | write('', file=self.outFile) 923 | 924 | def setRegistry(self, registry): 925 | self.registry = registry 926 | -------------------------------------------------------------------------------- /registry/genvk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import argparse 18 | import pdb 19 | import re 20 | import sys 21 | import time 22 | import xml.etree.ElementTree as etree 23 | 24 | from cgenerator import CGeneratorOptions, COutputGenerator 25 | from ziggenerator import ZigGeneratorOptions, ZigOutputGenerator 26 | from generator import write 27 | from reg import Registry 28 | from vkconventions import VulkanConventions 29 | 30 | #from docgenerator import DocGeneratorOptions, DocOutputGenerator 31 | #from extensionmetadocgenerator import (ExtensionMetaDocGeneratorOptions, 32 | # ExtensionMetaDocOutputGenerator) 33 | #from hostsyncgenerator import HostSynchronizationOutputGenerator 34 | #from pygenerator import PyOutputGenerator 35 | #from validitygenerator import ValidityOutputGenerator 36 | 37 | 38 | # Simple timer functions 39 | startTime = None 40 | 41 | 42 | def startTimer(timeit): 43 | global startTime 44 | if timeit: 45 | startTime = time.process_time() 46 | 47 | 48 | def endTimer(timeit, msg): 49 | global startTime 50 | if timeit: 51 | endTime = time.process_time() 52 | write(msg, endTime - startTime, file=sys.stderr) 53 | startTime = None 54 | 55 | 56 | def makeREstring(strings, default=None, strings_are_regex=False): 57 | """Turn a list of strings into a regexp string matching exactly those strings.""" 58 | if strings or default is None: 59 | if not strings_are_regex: 60 | strings = (re.escape(s) for s in strings) 61 | return '^(' + '|'.join(strings) + ')$' 62 | return default 63 | 64 | 65 | def makeGenOpts(args): 66 | """Returns a directory of [ generator function, generator options ] indexed 67 | by specified short names. The generator options incorporate the following 68 | parameters: 69 | 70 | args is an parsed argument object; see below for the fields that are used.""" 71 | global genOpts 72 | genOpts = {} 73 | 74 | # Default class of extensions to include, or None 75 | defaultExtensions = args.defaultExtensions 76 | 77 | # Additional extensions to include (list of extensions) 78 | extensions = args.extension 79 | 80 | # Extensions to remove (list of extensions) 81 | removeExtensions = args.removeExtensions 82 | 83 | # Extensions to emit (list of extensions) 84 | emitExtensions = args.emitExtensions 85 | 86 | # Features to include (list of features) 87 | features = args.feature 88 | 89 | # Whether to disable inclusion protect in headers 90 | protect = args.protect 91 | 92 | # Output target directory 93 | directory = args.directory 94 | 95 | # True/False make all top-level pointers optional to work around 96 | # https://github.com/ziglang/zig/issues/3325, which could cause UB 97 | workaroundZig3325 = args.zigAvoidUB 98 | 99 | # Descriptive names for various regexp patterns used to select 100 | # versions and extensions 101 | allFeatures = allExtensions = r'.*' 102 | 103 | # Turn lists of names/patterns into matching regular expressions 104 | addExtensionsPat = makeREstring(extensions, None) 105 | removeExtensionsPat = makeREstring(removeExtensions, None) 106 | emitExtensionsPat = makeREstring(emitExtensions, allExtensions) 107 | featuresPat = makeREstring(features, allFeatures) 108 | 109 | # Copyright text prefixing all headers (list of strings). 110 | prefixStrings = [ 111 | '/*', 112 | '** Copyright (c) 2015-2020 The Khronos Group Inc.', 113 | '**', 114 | '** Licensed under the Apache License, Version 2.0 (the "License");', 115 | '** you may not use this file except in compliance with the License.', 116 | '** You may obtain a copy of the License at', 117 | '**', 118 | '** http://www.apache.org/licenses/LICENSE-2.0', 119 | '**', 120 | '** Unless required by applicable law or agreed to in writing, software', 121 | '** distributed under the License is distributed on an "AS IS" BASIS,', 122 | '** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', 123 | '** See the License for the specific language governing permissions and', 124 | '** limitations under the License.', 125 | '*/', 126 | '' 127 | ] 128 | 129 | # Text specific to Vulkan headers 130 | vkPrefixStrings = [ 131 | '/*', 132 | '** This header is generated from the Khronos Vulkan XML API Registry.', 133 | '**', 134 | '*/', 135 | '' 136 | ] 137 | 138 | # Defaults for generating re-inclusion protection wrappers (or not) 139 | protectFile = protect 140 | 141 | # An API style conventions object 142 | conventions = VulkanConventions() 143 | 144 | if False: 145 | # API include files for spec and ref pages 146 | # Overwrites include subdirectories in spec source tree 147 | # The generated include files do not include the calling convention 148 | # macros (apientry etc.), unlike the header files. 149 | # Because the 1.0 core branch includes ref pages for extensions, 150 | # all the extension interfaces need to be generated, even though 151 | # none are used by the core spec itself. 152 | genOpts['apiinc'] = [ 153 | DocOutputGenerator, 154 | DocGeneratorOptions( 155 | conventions = conventions, 156 | filename = 'timeMarker', 157 | directory = directory, 158 | apiname = 'vulkan', 159 | profile = None, 160 | versions = featuresPat, 161 | emitversions = featuresPat, 162 | defaultExtensions = None, 163 | addExtensions = addExtensionsPat, 164 | removeExtensions = removeExtensionsPat, 165 | emitExtensions = emitExtensionsPat, 166 | prefixText = prefixStrings + vkPrefixStrings, 167 | apicall = '', 168 | apientry = '', 169 | apientryp = '*', 170 | alignFuncParam = 48, 171 | expandEnumerants = False) 172 | ] 173 | 174 | # API names to validate man/api spec includes & links 175 | genOpts['vkapi.py'] = [ 176 | PyOutputGenerator, 177 | DocGeneratorOptions( 178 | conventions = conventions, 179 | filename = 'vkapi.py', 180 | directory = directory, 181 | apiname = 'vulkan', 182 | profile = None, 183 | versions = featuresPat, 184 | emitversions = featuresPat, 185 | defaultExtensions = None, 186 | addExtensions = addExtensionsPat, 187 | removeExtensions = removeExtensionsPat, 188 | emitExtensions = emitExtensionsPat) 189 | ] 190 | 191 | # API validity files for spec 192 | genOpts['validinc'] = [ 193 | ValidityOutputGenerator, 194 | DocGeneratorOptions( 195 | conventions = conventions, 196 | filename = 'timeMarker', 197 | directory = directory, 198 | apiname = 'vulkan', 199 | profile = None, 200 | versions = featuresPat, 201 | emitversions = featuresPat, 202 | defaultExtensions = None, 203 | addExtensions = addExtensionsPat, 204 | removeExtensions = removeExtensionsPat, 205 | emitExtensions = emitExtensionsPat) 206 | ] 207 | 208 | # API host sync table files for spec 209 | genOpts['hostsyncinc'] = [ 210 | HostSynchronizationOutputGenerator, 211 | DocGeneratorOptions( 212 | conventions = conventions, 213 | filename = 'timeMarker', 214 | directory = directory, 215 | apiname = 'vulkan', 216 | profile = None, 217 | versions = featuresPat, 218 | emitversions = featuresPat, 219 | defaultExtensions = None, 220 | addExtensions = addExtensionsPat, 221 | removeExtensions = removeExtensionsPat, 222 | emitExtensions = emitExtensionsPat) 223 | ] 224 | 225 | # Extension metainformation for spec extension appendices 226 | genOpts['extinc'] = [ 227 | ExtensionMetaDocOutputGenerator, 228 | ExtensionMetaDocGeneratorOptions( 229 | conventions = conventions, 230 | filename = 'timeMarker', 231 | directory = directory, 232 | apiname = 'vulkan', 233 | profile = None, 234 | versions = featuresPat, 235 | emitversions = None, 236 | defaultExtensions = defaultExtensions, 237 | addExtensions = None, 238 | removeExtensions = None, 239 | emitExtensions = emitExtensionsPat) 240 | ] 241 | 242 | # Platform extensions, in their own header files 243 | # Each element of the platforms[] array defines information for 244 | # generating a single platform: 245 | # [0] is the generated header file name 246 | # [1] is the set of platform extensions to generate 247 | # [2] is additional extensions whose interfaces should be considered, 248 | # but suppressed in the output, to avoid duplicate definitions of 249 | # dependent types like VkDisplayKHR and VkSurfaceKHR which come from 250 | # non-platform extensions. 251 | 252 | # Track all platform extensions, for exclusion from vulkan_core.h 253 | allPlatformExtensions = [] 254 | 255 | # Extensions suppressed for all platforms. 256 | # Covers common WSI extension types. 257 | commonSuppressExtensions = [ 'VK_KHR_display', 'VK_KHR_swapchain' ] 258 | 259 | platforms = [ 260 | [ 'vulkan_android.h', [ 'VK_KHR_android_surface', 261 | 'VK_ANDROID_external_memory_android_hardware_buffer' 262 | ], commonSuppressExtensions ], 263 | [ 'vulkan_fuchsia.h', [ 'VK_FUCHSIA_imagepipe_surface'], commonSuppressExtensions ], 264 | [ 'vulkan_ggp.h', [ 'VK_GGP_stream_descriptor_surface', 265 | 'VK_GGP_frame_token' ], commonSuppressExtensions ], 266 | [ 'vulkan_ios.h', [ 'VK_MVK_ios_surface' ], commonSuppressExtensions ], 267 | [ 'vulkan_macos.h', [ 'VK_MVK_macos_surface' ], commonSuppressExtensions ], 268 | [ 'vulkan_vi.h', [ 'VK_NN_vi_surface' ], commonSuppressExtensions ], 269 | [ 'vulkan_wayland.h', [ 'VK_KHR_wayland_surface' ], commonSuppressExtensions ], 270 | [ 'vulkan_win32.h', [ 'VK_.*_win32(|_.*)', 'VK_EXT_full_screen_exclusive' ], 271 | commonSuppressExtensions + 272 | [ 'VK_KHR_external_semaphore', 273 | 'VK_KHR_external_memory_capabilities', 274 | 'VK_KHR_external_fence', 275 | 'VK_KHR_external_fence_capabilities', 276 | 'VK_KHR_get_surface_capabilities2', 277 | 'VK_NV_external_memory_capabilities', 278 | ] ], 279 | [ 'vulkan_xcb.h', [ 'VK_KHR_xcb_surface' ], commonSuppressExtensions ], 280 | [ 'vulkan_xlib.h', [ 'VK_KHR_xlib_surface' ], commonSuppressExtensions ], 281 | [ 'vulkan_xlib_xrandr.h', [ 'VK_EXT_acquire_xlib_display' ], commonSuppressExtensions ], 282 | [ 'vulkan_metal.h', [ 'VK_EXT_metal_surface' ], commonSuppressExtensions ], 283 | ] 284 | 285 | for platform in platforms: 286 | headername = platform[0] 287 | 288 | allPlatformExtensions += platform[1] 289 | 290 | addPlatformExtensionsRE = makeREstring( 291 | platform[1] + platform[2], strings_are_regex=True) 292 | emitPlatformExtensionsRE = makeREstring( 293 | platform[1], strings_are_regex=True) 294 | 295 | opts = CGeneratorOptions( 296 | conventions = conventions, 297 | filename = headername, 298 | directory = directory, 299 | apiname = 'vulkan', 300 | profile = None, 301 | versions = featuresPat, 302 | emitversions = None, 303 | defaultExtensions = None, 304 | addExtensions = addPlatformExtensionsRE, 305 | removeExtensions = None, 306 | emitExtensions = emitPlatformExtensionsRE, 307 | prefixText = prefixStrings + vkPrefixStrings, 308 | genFuncPointers = True, 309 | protectFile = protectFile, 310 | protectFeature = False, 311 | protectProto = '#ifndef', 312 | protectProtoStr = 'VK_NO_PROTOTYPES', 313 | apicall = 'VKAPI_ATTR ', 314 | apientry = 'VKAPI_CALL ', 315 | apientryp = 'VKAPI_PTR *', 316 | alignFuncParam = 48, 317 | genEnumBeginEndRange = True) 318 | 319 | genOpts[headername] = [ COutputGenerator, opts ] 320 | 321 | for platform in platforms: 322 | headername = platform[0].replace(".h", ".zig"); 323 | 324 | allPlatformExtensions += platform[1] 325 | 326 | addPlatformExtensionsRE = makeREstring( 327 | platform[1] + platform[2], strings_are_regex=True) 328 | emitPlatformExtensionsRE = makeREstring( 329 | platform[1], strings_are_regex=True) 330 | 331 | opts = ZigGeneratorOptions( 332 | conventions = conventions, 333 | filename = headername, 334 | directory = directory, 335 | apiname = 'vulkan', 336 | profile = None, 337 | versions = featuresPat, 338 | emitversions = None, 339 | defaultExtensions = None, 340 | addExtensions = addPlatformExtensionsRE, 341 | removeExtensions = None, 342 | emitExtensions = emitPlatformExtensionsRE, 343 | prefixText = prefixStrings + vkPrefixStrings, 344 | workaround3325 = workaroundZig3325, 345 | lineEndings = '\n', 346 | coreFile = 'vulkan_core.zig') 347 | 348 | genOpts[headername] = [ ZigOutputGenerator, opts ] 349 | 350 | 351 | # Header for core API + extensions. 352 | # To generate just the core API, 353 | # change to 'defaultExtensions = None' below. 354 | # 355 | # By default this adds all enabled, non-platform extensions. 356 | # It removes all platform extensions (from the platform headers options 357 | # constructed above) as well as any explicitly specified removals. 358 | 359 | removeExtensionsPat = makeREstring( 360 | allPlatformExtensions + removeExtensions, None, strings_are_regex=True) 361 | 362 | genOpts['vulkan_core.h'] = [ 363 | COutputGenerator, 364 | CGeneratorOptions( 365 | conventions = conventions, 366 | filename = 'vulkan_core.h', 367 | directory = directory, 368 | apiname = 'vulkan', 369 | profile = None, 370 | versions = featuresPat, 371 | emitversions = featuresPat, 372 | defaultExtensions = defaultExtensions, 373 | addExtensions = None, 374 | removeExtensions = removeExtensionsPat, 375 | emitExtensions = emitExtensionsPat, 376 | prefixText = prefixStrings + vkPrefixStrings, 377 | genFuncPointers = True, 378 | protectFile = protectFile, 379 | protectFeature = False, 380 | protectProto = '#ifndef', 381 | protectProtoStr = 'VK_NO_PROTOTYPES', 382 | apicall = 'VKAPI_ATTR ', 383 | apientry = 'VKAPI_CALL ', 384 | apientryp = 'VKAPI_PTR *', 385 | alignFuncParam = 48, 386 | genEnumBeginEndRange = True) 387 | ] 388 | 389 | genOpts['vulkan_core.zig'] = [ 390 | ZigOutputGenerator, 391 | ZigGeneratorOptions( 392 | conventions = conventions, 393 | filename = 'vulkan_core.zig', 394 | directory = directory, 395 | apiname = 'vulkan', 396 | profile = None, 397 | versions = featuresPat, 398 | emitversions = featuresPat, 399 | defaultExtensions = defaultExtensions, 400 | addExtensions = None, 401 | removeExtensions = removeExtensionsPat, 402 | emitExtensions = emitExtensionsPat, 403 | prefixText = prefixStrings + vkPrefixStrings, 404 | workaround3325 = workaroundZig3325, 405 | lineEndings = '\n') 406 | ] 407 | 408 | # Unused - vulkan10.h target. 409 | # It is possible to generate a header with just the Vulkan 1.0 + 410 | # extension interfaces defined, but since the promoted KHR extensions 411 | # are now defined in terms of the 1.1 interfaces, such a header is very 412 | # similar to vulkan_core.h. 413 | genOpts['vulkan10.h'] = [ 414 | COutputGenerator, 415 | CGeneratorOptions( 416 | conventions = conventions, 417 | filename = 'vulkan10.h', 418 | directory = directory, 419 | apiname = 'vulkan', 420 | profile = None, 421 | versions = 'VK_VERSION_1_0', 422 | emitversions = 'VK_VERSION_1_0', 423 | defaultExtensions = defaultExtensions, 424 | addExtensions = None, 425 | removeExtensions = removeExtensionsPat, 426 | emitExtensions = emitExtensionsPat, 427 | prefixText = prefixStrings + vkPrefixStrings, 428 | genFuncPointers = True, 429 | protectFile = protectFile, 430 | protectFeature = False, 431 | protectProto = '#ifndef', 432 | protectProtoStr = 'VK_NO_PROTOTYPES', 433 | apicall = 'VKAPI_ATTR ', 434 | apientry = 'VKAPI_CALL ', 435 | apientryp = 'VKAPI_PTR *', 436 | alignFuncParam = 48) 437 | ] 438 | 439 | genOpts['alias.h'] = [ 440 | COutputGenerator, 441 | CGeneratorOptions( 442 | conventions = conventions, 443 | filename = 'alias.h', 444 | directory = directory, 445 | apiname = 'vulkan', 446 | profile = None, 447 | versions = featuresPat, 448 | emitversions = featuresPat, 449 | defaultExtensions = defaultExtensions, 450 | addExtensions = None, 451 | removeExtensions = removeExtensionsPat, 452 | emitExtensions = emitExtensionsPat, 453 | prefixText = None, 454 | genFuncPointers = False, 455 | protectFile = False, 456 | protectFeature = False, 457 | protectProto = '', 458 | protectProtoStr = '', 459 | apicall = '', 460 | apientry = '', 461 | apientryp = '', 462 | alignFuncParam = 36) 463 | ] 464 | 465 | 466 | def genTarget(args): 467 | """Generate a target based on the options in the matching genOpts{} object. 468 | 469 | This is encapsulated in a function so it can be profiled and/or timed. 470 | The args parameter is an parsed argument object containing the following 471 | fields that are used: 472 | 473 | - target - target to generate 474 | - directory - directory to generate it in 475 | - protect - True if re-inclusion wrappers should be created 476 | - extensions - list of additional extensions to include in generated interfaces""" 477 | # Create generator options with specified parameters 478 | makeGenOpts(args) 479 | 480 | if args.target in genOpts: 481 | createGenerator = genOpts[args.target][0] 482 | options = genOpts[args.target][1] 483 | 484 | if not args.quiet: 485 | write('* Building', options.filename, file=sys.stderr) 486 | write('* options.versions =', options.versions, file=sys.stderr) 487 | write('* options.emitversions =', options.emitversions, file=sys.stderr) 488 | write('* options.defaultExtensions =', options.defaultExtensions, file=sys.stderr) 489 | write('* options.addExtensions =', options.addExtensions, file=sys.stderr) 490 | write('* options.removeExtensions =', options.removeExtensions, file=sys.stderr) 491 | write('* options.emitExtensions =', options.emitExtensions, file=sys.stderr) 492 | 493 | startTimer(args.time) 494 | gen = createGenerator(errFile=errWarn, 495 | warnFile=errWarn, 496 | diagFile=diag) 497 | reg.setGenerator(gen) 498 | reg.apiGen(options) 499 | 500 | if not args.quiet: 501 | write('* Generated', options.filename, file=sys.stderr) 502 | endTimer(args.time, '* Time to generate ' + options.filename + ' =') 503 | else: 504 | write('No generator options for unknown target:', 505 | args.target, file=sys.stderr) 506 | 507 | 508 | # -feature name 509 | # -extension name 510 | # For both, "name" may be a single name, or a space-separated list 511 | # of names, or a regular expression. 512 | if __name__ == '__main__': 513 | parser = argparse.ArgumentParser() 514 | 515 | parser.add_argument('-defaultExtensions', action='store', 516 | default='vulkan', 517 | help='Specify a single class of extensions to add to targets') 518 | parser.add_argument('-extension', action='append', 519 | default=[], 520 | help='Specify an extension or extensions to add to targets') 521 | parser.add_argument('-removeExtensions', action='append', 522 | default=[], 523 | help='Specify an extension or extensions to remove from targets') 524 | parser.add_argument('-emitExtensions', action='append', 525 | default=[], 526 | help='Specify an extension or extensions to emit in targets') 527 | parser.add_argument('-feature', action='append', 528 | default=[], 529 | help='Specify a core API feature name or names to add to targets') 530 | parser.add_argument('-debug', action='store_true', 531 | help='Enable debugging') 532 | parser.add_argument('-dump', action='store_true', 533 | help='Enable dump to stderr') 534 | parser.add_argument('-diagfile', action='store', 535 | default=None, 536 | help='Write diagnostics to specified file') 537 | parser.add_argument('-errfile', action='store', 538 | default=None, 539 | help='Write errors and warnings to specified file instead of stderr') 540 | parser.add_argument('-noprotect', dest='protect', action='store_false', 541 | help='Disable inclusion protection in output headers') 542 | parser.add_argument('-profile', action='store_true', 543 | help='Enable profiling') 544 | parser.add_argument('-registry', action='store', 545 | default='vk.xml', 546 | help='Use specified registry file instead of vk.xml') 547 | parser.add_argument('-time', action='store_true', 548 | help='Enable timing') 549 | parser.add_argument('-validate', action='store_true', 550 | help='Enable group validation') 551 | parser.add_argument('-o', action='store', dest='directory', 552 | default='.', 553 | help='Create target and related files in specified directory') 554 | parser.add_argument('target', metavar='target', nargs='?', 555 | help='Specify target') 556 | parser.add_argument('-quiet', action='store_true', default=True, 557 | help='Suppress script output during normal execution.') 558 | parser.add_argument('-verbose', action='store_false', dest='quiet', default=True, 559 | help='Enable script output during normal execution.') 560 | parser.add_argument('-zigAvoidUB', action='store_true', default=False, 561 | help='Work around Zig issue 3325, which can cause unchecked UB.') 562 | 563 | args = parser.parse_args() 564 | 565 | # This splits arguments which are space-separated lists 566 | args.feature = [name for arg in args.feature for name in arg.split()] 567 | args.extension = [name for arg in args.extension for name in arg.split()] 568 | 569 | # Load & parse registry 570 | reg = Registry() 571 | 572 | startTimer(args.time) 573 | tree = etree.parse(args.registry) 574 | endTimer(args.time, '* Time to make ElementTree =') 575 | 576 | if args.debug: 577 | pdb.run('reg.loadElementTree(tree)') 578 | else: 579 | startTimer(args.time) 580 | reg.loadElementTree(tree) 581 | endTimer(args.time, '* Time to parse ElementTree =') 582 | 583 | if args.validate: 584 | reg.validateGroups() 585 | 586 | if args.dump: 587 | write('* Dumping registry to regdump.txt', file=sys.stderr) 588 | reg.dumpReg(filehandle=open('regdump.txt', 'w', encoding='utf-8')) 589 | 590 | # create error/warning & diagnostic files 591 | if args.errfile: 592 | errWarn = open(args.errfile, 'w', encoding='utf-8') 593 | else: 594 | errWarn = sys.stderr 595 | 596 | if args.diagfile: 597 | diag = open(args.diagfile, 'w', encoding='utf-8') 598 | else: 599 | diag = None 600 | 601 | if args.debug: 602 | pdb.run('genTarget(args)') 603 | elif args.profile: 604 | import cProfile 605 | import pstats 606 | cProfile.run('genTarget(args)', 'profile.txt') 607 | p = pstats.Stats('profile.txt') 608 | p.strip_dirs().sort_stats('time').print_stats(50) 609 | else: 610 | genTarget(args) 611 | -------------------------------------------------------------------------------- /registry/spec_tools/util.py: -------------------------------------------------------------------------------- 1 | """Utility functions not closely tied to other spec_tools types.""" 2 | # Copyright (c) 2018-2019 Collabora, Ltd. 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | def getElemName(elem, default=None): 19 | """Get the name associated with an element, either a name child or name attribute.""" 20 | name_elem = elem.find('name') 21 | if name_elem is not None: 22 | return name_elem.text 23 | # Fallback if there is no child. 24 | return elem.get('name', default) 25 | 26 | 27 | def getElemType(elem, default=None): 28 | """Get the type associated with an element, either a type child or type attribute.""" 29 | type_elem = elem.find('type') 30 | if type_elem is not None: 31 | return type_elem.text 32 | # Fallback if there is no child. 33 | return elem.get('type', default) 34 | 35 | 36 | def findFirstWithPredicate(collection, pred): 37 | """Return the first element that satisfies the predicate, or None if none exist. 38 | 39 | NOTE: Some places where this is used might be better served by changing to a dictionary. 40 | """ 41 | for elt in collection: 42 | if pred(elt): 43 | return elt 44 | return None 45 | 46 | 47 | def findNamedElem(elems, name): 48 | """Traverse a collection of elements with 'name' nodes or attributes, looking for and returning one with the right name. 49 | 50 | NOTE: Many places where this is used might be better served by changing to a dictionary. 51 | """ 52 | return findFirstWithPredicate(elems, lambda elem: getElemName(elem) == name) 53 | 54 | 55 | def findTypedElem(elems, typename): 56 | """Traverse a collection of elements with 'type' nodes or attributes, looking for and returning one with the right typename. 57 | 58 | NOTE: Many places where this is used might be better served by changing to a dictionary. 59 | """ 60 | return findFirstWithPredicate(elems, lambda elem: getElemType(elem) == typename) 61 | 62 | 63 | def findNamedObject(collection, name): 64 | """Traverse a collection of elements with 'name' attributes, looking for and returning one with the right name. 65 | 66 | NOTE: Many places where this is used might be better served by changing to a dictionary. 67 | """ 68 | return findFirstWithPredicate(collection, lambda elt: elt.name == name) 69 | -------------------------------------------------------------------------------- /registry/vkconventions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 -i 2 | # 3 | # Copyright (c) 2013-2020 The Khronos Group Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Working-group-specific style conventions, 18 | # used in generation. 19 | 20 | import re 21 | import os 22 | 23 | from conventions import ConventionsBase 24 | 25 | 26 | # Modified from default implementation - see category_requires_validation() below 27 | CATEGORIES_REQUIRING_VALIDATION = set(('handle', 'enum', 'bitmask')) 28 | 29 | # Tokenize into "words" for structure types, approximately per spec "Implicit Valid Usage" section 2.7.2 30 | # This first set is for things we recognize explicitly as words, 31 | # as exceptions to the general regex. 32 | # Ideally these would be listed in the spec as exceptions, as OpenXR does. 33 | SPECIAL_WORDS = set(( 34 | '16Bit', # VkPhysicalDevice16BitStorageFeatures 35 | '8Bit', # VkPhysicalDevice8BitStorageFeaturesKHR 36 | 'AABB', # VkGeometryAABBNV 37 | 'ASTC', # VkPhysicalDeviceTextureCompressionASTCHDRFeaturesEXT 38 | 'D3D12', # VkD3D12FenceSubmitInfoKHR 39 | 'Float16', # VkPhysicalDeviceShaderFloat16Int8FeaturesKHR 40 | 'ImagePipe', # VkImagePipeSurfaceCreateInfoFUCHSIA 41 | 'Int64', # VkPhysicalDeviceShaderAtomicInt64FeaturesKHR 42 | 'Int8', # VkPhysicalDeviceShaderFloat16Int8FeaturesKHR 43 | 'MacOS', # VkMacOSSurfaceCreateInfoMVK 44 | 'Uint8', # VkPhysicalDeviceIndexTypeUint8FeaturesEXT 45 | 'Win32', # VkWin32SurfaceCreateInfoKHR 46 | )) 47 | # A regex to match any of the SPECIAL_WORDS 48 | EXCEPTION_PATTERN = r'(?P{})'.format( 49 | '|'.join('(%s)' % re.escape(w) for w in SPECIAL_WORDS)) 50 | MAIN_RE = re.compile( 51 | # the negative lookahead is to prevent the all-caps pattern from being too greedy. 52 | r'({}|([0-9]+)|([A-Z][a-z]+)|([A-Z][A-Z]*(?![a-z])))'.format(EXCEPTION_PATTERN)) 53 | 54 | 55 | class VulkanConventions(ConventionsBase): 56 | @property 57 | def null(self): 58 | """Preferred spelling of NULL.""" 59 | return '`NULL`' 60 | 61 | @property 62 | def struct_macro(self): 63 | """Get the appropriate format macro for a structure. 64 | 65 | Primarily affects generated valid usage statements. 66 | """ 67 | 68 | return 'slink:' 69 | 70 | @property 71 | def constFlagBits(self): 72 | """Returns True if static const flag bits should be generated, False if an enumerated type should be generated.""" 73 | return False 74 | 75 | @property 76 | def structtype_member_name(self): 77 | """Return name of the structure type member""" 78 | return 'sType' 79 | 80 | @property 81 | def nextpointer_member_name(self): 82 | """Return name of the structure pointer chain member""" 83 | return 'pNext' 84 | 85 | @property 86 | def valid_pointer_prefix(self): 87 | """Return prefix to pointers which must themselves be valid""" 88 | return 'valid' 89 | 90 | def is_structure_type_member(self, paramtype, paramname): 91 | """Determine if member type and name match the structure type member.""" 92 | return paramtype == 'VkStructureType' and paramname == self.structtype_member_name 93 | 94 | def is_nextpointer_member(self, paramtype, paramname): 95 | """Determine if member type and name match the next pointer chain member.""" 96 | return paramtype == 'void' and paramname == self.nextpointer_member_name 97 | 98 | def generate_structure_type_from_name(self, structname): 99 | """Generate a structure type name, like VK_STRUCTURE_TYPE_CREATE_INSTANCE_INFO""" 100 | structure_type_parts = [] 101 | # Tokenize into "words" 102 | for elem in MAIN_RE.findall(structname): 103 | word = elem[0] 104 | if word == 'Vk': 105 | structure_type_parts.append('VK_STRUCTURE_TYPE') 106 | else: 107 | structure_type_parts.append(word.upper()) 108 | return '_'.join(structure_type_parts) 109 | 110 | @property 111 | def warning_comment(self): 112 | """Return warning comment to be placed in header of generated Asciidoctor files""" 113 | return '// WARNING: DO NOT MODIFY! This file is automatically generated from the vk.xml registry' 114 | 115 | @property 116 | def file_suffix(self): 117 | """Return suffix of generated Asciidoctor files""" 118 | return '.txt' 119 | 120 | def api_name(self, spectype='api'): 121 | """Return API or specification name for citations in ref pages.ref 122 | pages should link to for 123 | 124 | spectype is the spec this refpage is for: 'api' is the Vulkan API 125 | Specification. Defaults to 'api'. If an unrecognized spectype is 126 | given, returns None. 127 | """ 128 | if spectype == 'api' or spectype is None: 129 | return 'Vulkan' 130 | else: 131 | return None 132 | 133 | @property 134 | def xml_supported_name_of_api(self): 135 | """Return the supported= attribute used in API XML""" 136 | return 'vulkan' 137 | 138 | @property 139 | def api_prefix(self): 140 | """Return API token prefix""" 141 | return 'VK_' 142 | 143 | @property 144 | def write_contacts(self): 145 | """Return whether contact list should be written to extension appendices""" 146 | return True 147 | 148 | @property 149 | def write_refpage_include(self): 150 | """Return whether refpage include should be written to extension appendices""" 151 | return True 152 | 153 | @property 154 | def member_used_for_unique_vuid(self): 155 | """Return the member name used in the VUID-...-...-unique ID.""" 156 | return self.structtype_member_name 157 | 158 | def is_externsync_command(self, protoname): 159 | """Returns True if the protoname element is an API command requiring 160 | external synchronization 161 | """ 162 | return protoname is not None and 'vkCmd' in protoname 163 | 164 | def is_api_name(self, name): 165 | """Returns True if name is in the reserved API namespace. 166 | For Vulkan, these are names with a case-insensitive 'vk' prefix, or 167 | a 'PFN_vk' function pointer type prefix. 168 | """ 169 | return name[0:2].lower() == 'vk' or name[0:6] == 'PFN_vk' 170 | 171 | def specURL(self, spectype='api'): 172 | """Return public registry URL which ref pages should link to for the 173 | current all-extensions HTML specification, so xrefs in the 174 | asciidoc source that aren't to ref pages can link into it 175 | instead. N.b. this may need to change on a per-refpage basis if 176 | there are multiple documents involved. 177 | """ 178 | return 'https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html' 179 | 180 | @property 181 | def xml_api_name(self): 182 | """Return the name used in the default API XML registry for the default API""" 183 | return 'vulkan' 184 | 185 | @property 186 | def registry_path(self): 187 | """Return relpath to the default API XML registry in this project.""" 188 | return 'xml/vk.xml' 189 | 190 | @property 191 | def specification_path(self): 192 | """Return relpath to the Asciidoctor specification sources in this project.""" 193 | return '{generated}/meta' 194 | 195 | @property 196 | def extra_refpage_headers(self): 197 | """Return any extra text to add to refpage headers.""" 198 | return 'include::../config/attribs.txt[]' 199 | 200 | @property 201 | def extension_index_prefixes(self): 202 | """Return a list of extension prefixes used to group extension refpages.""" 203 | return ['VK_KHR', 'VK_EXT', 'VK'] 204 | 205 | @property 206 | def unified_flag_refpages(self): 207 | """Return True if Flags/FlagBits refpages are unified, False if 208 | they're separate. 209 | """ 210 | return False 211 | 212 | @property 213 | def spec_reflow_path(self): 214 | """Return the path to the spec source folder to reflow""" 215 | return os.getcwd() 216 | 217 | @property 218 | def spec_no_reflow_dirs(self): 219 | """Return a set of directories not to automatically descend into 220 | when reflowing spec text 221 | """ 222 | return ('scripts', 'style') 223 | 224 | @property 225 | def zero(self): 226 | return '`0`' 227 | 228 | def category_requires_validation(self, category): 229 | """Return True if the given type 'category' always requires validation. 230 | 231 | Overridden because Vulkan doesn't require "valid" text for basetype in the spec right now.""" 232 | return category in CATEGORIES_REQUIRING_VALIDATION 233 | 234 | @property 235 | def should_skip_checking_codes(self): 236 | """Return True if more than the basic validation of return codes should 237 | be skipped for a command. 238 | 239 | Vulkan mostly relies on the validation layers rather than API 240 | builtin error checking, so these checks are not appropriate. 241 | 242 | For example, passing in a VkFormat parameter will not potentially 243 | generate a VK_ERROR_FORMAT_NOT_SUPPORTED code.""" 244 | 245 | return True 246 | 247 | def extension_include_string(self, ext): 248 | """Return format string for include:: line for an extension appendix 249 | file. ext is an object with the following members: 250 | - name - extension string string 251 | - vendor - vendor portion of name 252 | - barename - remainder of name""" 253 | 254 | return 'include::{{appendices}}/{name}{suffix}[]'.format( 255 | name=ext.name, suffix=self.file_suffix) 256 | 257 | @property 258 | def refpage_generated_include_path(self): 259 | """Return path relative to the generated reference pages, to the 260 | generated API include files.""" 261 | return "{generated}" 262 | -------------------------------------------------------------------------------- /zig/test.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const vk = @import("vulkan_core.zig"); 3 | 4 | fn refAllDeclsRecursive(comptime T: type) void { 5 | comptime { 6 | for (std.meta.declarations(T)) |decl| { 7 | _ = decl; 8 | if (decl.is_pub and decl.data == .Type) { 9 | const info = @typeInfo(decl.data.Type); 10 | if (info == .Struct or info == .Union or info == .Opaque or info == .Enum) { 11 | refAllDeclsRecursive(decl.data.Type); 12 | } 13 | } 14 | } 15 | } 16 | } 17 | 18 | test "Compile All" { 19 | @setEvalBranchQuota(100000); 20 | refAllDeclsRecursive(vk); 21 | } 22 | --------------------------------------------------------------------------------