blob: d4ed8c5489f5899d1f72406bc539e6c6cc088758 [file] [log] [blame]
Chris Forbes3fdf41f2017-05-02 14:32:26 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Chris Forbes <chrisforbes@google.com>
19 */
20#ifndef DEVICE_EXTENSIONS_H_
21#define DEVICE_EXTENSIONS_H_
22
23struct DeviceExtensions {
24 bool khr_swapchain;
25 bool khr_display_swapchain;
26 bool nv_glsl_shader;
27 bool khr_descriptor_update_template;
28 bool khr_shader_draw_parameters;
29 bool khr_maintenance1;
30 bool nv_geometry_shader_passthrough;
31 bool nv_sample_mask_override_coverage;
32 bool nv_viewport_array2;
33 bool khr_subgroup_ballot;
34 bool khr_subgroup_vote;
Chris Forbes8976f742017-05-02 14:52:05 -070035 bool khr_push_descriptor;
36 bool khx_device_group;
37 bool khx_external_memory_fd;
38 bool khx_external_memory_win32;
39 bool khx_external_semaphore_fd;
40 bool khx_external_semaphore_win32;
41 bool ext_debug_marker;
42 bool ext_discard_rectangles;
43 bool ext_display_control;
44 bool amd_draw_indirect_count;
45 bool amd_negative_viewport_height;
46 bool nv_clip_space_w_scaling;
47 bool nv_external_memory;
48 bool nv_external_memory_win32;
49 bool nvx_device_generated_commands;
50 bool khr_incremental_present;
Mark Lobodzinski087380c2017-05-16 14:42:25 -060051 bool khr_shared_presentable_image;
Chris Forbes3fdf41f2017-05-02 14:32:26 -070052
53 void InitFromDeviceCreateInfo(const VkDeviceCreateInfo *pCreateInfo) {
54 using E = DeviceExtensions;
55
56 static const std::pair<char const *, bool E::*> known_extensions[]{
57 {VK_KHR_SWAPCHAIN_EXTENSION_NAME, &E::khr_swapchain},
58 {VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME, &E::khr_display_swapchain},
59 {VK_NV_GLSL_SHADER_EXTENSION_NAME, &E::nv_glsl_shader},
60 {VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, &E::khr_descriptor_update_template},
61 {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, &E::khr_shader_draw_parameters},
62 {VK_KHR_MAINTENANCE1_EXTENSION_NAME, &E::khr_maintenance1},
63 {VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME, &E::nv_geometry_shader_passthrough},
64 {VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME, &E::nv_sample_mask_override_coverage},
65 {VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, &E::nv_viewport_array2},
66 {VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME, &E::khr_subgroup_ballot},
67 {VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, &E::khr_subgroup_vote},
Chris Forbes8976f742017-05-02 14:52:05 -070068 {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, &E::khr_push_descriptor},
69 {VK_KHX_DEVICE_GROUP_EXTENSION_NAME, &E::khx_device_group},
70 {VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME, &E::khx_external_memory_fd},
71 {VK_KHX_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, &E::khx_external_semaphore_fd},
72#ifdef VK_USE_PLATFORM_WIN32_KHX
73 {VK_KHX_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::khx_external_memory_win32},
74 {VK_KHX_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME, &E::khx_external_semaphore_win32},
75#endif
76 {VK_EXT_DEBUG_MARKER_EXTENSION_NAME, &E::ext_debug_marker},
77 {VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME, &E::ext_discard_rectangles},
78 {VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME, &E::ext_display_control},
79 {VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME, &E::amd_draw_indirect_count},
80 {VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME, &E::amd_negative_viewport_height},
Chris Forbes7d11b8e2017-05-03 08:21:33 -070081 {VK_NV_CLIP_SPACE_W_SCALING_EXTENSION_NAME, &E::nv_clip_space_w_scaling},
Chris Forbes8976f742017-05-02 14:52:05 -070082 {VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME, &E::nv_external_memory},
83#ifdef VK_USE_PLATFORM_WIN32_KHR
84 {VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::nv_external_memory_win32},
85#endif
Chris Forbes7d11b8e2017-05-03 08:21:33 -070086 {VK_NVX_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME, &E::nvx_device_generated_commands},
Chris Forbes8976f742017-05-02 14:52:05 -070087 {VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, &E::khr_incremental_present},
Mark Lobodzinski087380c2017-05-16 14:42:25 -060088 {VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, &E::khr_shared_presentable_image},
89
Chris Forbes3fdf41f2017-05-02 14:32:26 -070090 };
91
92 for (auto ext : known_extensions) {
93 this->*(ext.second) = false;
94 }
95
96 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
97 for (auto ext : known_extensions) {
98 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
99 this->*(ext.second) = true;
100 break;
101 }
102 }
103 }
104 }
105};
106
Chris Forbesff37d382017-05-02 15:39:16 -0700107struct InstanceExtensions {
108 bool khr_surface;
109 bool khr_display;
110 bool khr_android_surface;
111 bool khr_xcb_surface;
112 bool khr_xlib_surface;
113 bool khr_win32_surface;
114 bool khr_wayland_surface;
115 bool khr_mir_surface;
Chris Forbes8130cc52017-05-02 15:47:16 -0700116 bool khr_get_physical_device_properties2;
Mike Schuchardt6991a392017-05-17 07:54:02 -0600117 bool khr_get_surface_capabilities2;
Chris Forbes8130cc52017-05-02 15:47:16 -0700118 bool khx_device_group_creation;
119 bool khx_external_memory_capabilities;
120 bool khx_external_semaphore_capabilities;
121 bool ext_acquire_xlib_display;
122 bool ext_direct_mode_display;
123 bool ext_display_surface_counter;
124 bool nv_external_memory_capabilities;
Chris Forbesff37d382017-05-02 15:39:16 -0700125
126 void InitFromInstanceCreateInfo(const VkInstanceCreateInfo *pCreateInfo) {
127 using E = InstanceExtensions;
128
129 static const std::pair<char const *, bool E::*> known_extensions[]{
130 {VK_KHR_SURFACE_EXTENSION_NAME, &E::khr_surface},
131 {VK_KHR_DISPLAY_EXTENSION_NAME, &E::khr_display},
132#ifdef VK_USE_PLATFORM_ANDROID_KHR
133 {VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, &E::khr_android_surface},
134#endif
135#ifdef VK_USE_PLATFORM_XCB_KHR
136 {VK_KHR_XCB_SURFACE_EXTENSION_NAME, &E::khr_xcb_surface},
137#endif
138#ifdef VK_USE_PLATFORM_XLIB_KHR
139 {VK_KHR_XLIB_SURFACE_EXTENSION_NAME, &E::khr_xlib_surface},
140#endif
141#ifdef VK_USE_PLATFORM_WIN32_KHR
142 {VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &E::khr_win32_surface},
143#endif
144#ifdef VK_USE_PLATFORM_WAYLAND_KHR
145 {VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, &E::khr_wayland_surface},
146#endif
147#ifdef VK_USE_PLATFORM_MIR_KHR
148 {VK_KHR_MIR_SURFACE_EXTENSION_NAME, &E::khr_mir_surface},
149#endif
Chris Forbes8130cc52017-05-02 15:47:16 -0700150 {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, &E::khr_get_physical_device_properties2},
Mike Schuchardt6991a392017-05-17 07:54:02 -0600151 {VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, &E::khr_get_surface_capabilities2},
Chris Forbes8130cc52017-05-02 15:47:16 -0700152 {VK_KHX_DEVICE_GROUP_CREATION_EXTENSION_NAME, &E::khx_device_group_creation},
153 {VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::khx_external_memory_capabilities},
154 {VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, &E::khx_external_semaphore_capabilities},
155#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
156 {VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME, &E::ext_acquire_xlib_display},
157#endif
158 {VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME, &E::ext_direct_mode_display},
159 {VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME, &E::ext_display_surface_counter},
160 {VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::nv_external_memory_capabilities},
Chris Forbesff37d382017-05-02 15:39:16 -0700161 };
162
163 for (auto ext : known_extensions) {
164 this->*(ext.second) = false;
165 }
166
167 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
168 for (auto ext : known_extensions) {
169 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
170 this->*(ext.second) = true;
171 break;
172 }
173 }
174 }
175 }
176};
177
Mike Schuchardt6991a392017-05-17 07:54:02 -0600178#endif