blob: ac9ff419df10cbfb88f530e75e5331d4b642f326 [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;
Chris Forbes3fdf41f2017-05-02 14:32:26 -070051
52 void InitFromDeviceCreateInfo(const VkDeviceCreateInfo *pCreateInfo) {
53 using E = DeviceExtensions;
54
55 static const std::pair<char const *, bool E::*> known_extensions[]{
56 {VK_KHR_SWAPCHAIN_EXTENSION_NAME, &E::khr_swapchain},
57 {VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME, &E::khr_display_swapchain},
58 {VK_NV_GLSL_SHADER_EXTENSION_NAME, &E::nv_glsl_shader},
59 {VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, &E::khr_descriptor_update_template},
60 {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, &E::khr_shader_draw_parameters},
61 {VK_KHR_MAINTENANCE1_EXTENSION_NAME, &E::khr_maintenance1},
62 {VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME, &E::nv_geometry_shader_passthrough},
63 {VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME, &E::nv_sample_mask_override_coverage},
64 {VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, &E::nv_viewport_array2},
65 {VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME, &E::khr_subgroup_ballot},
66 {VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, &E::khr_subgroup_vote},
Chris Forbes8976f742017-05-02 14:52:05 -070067 {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, &E::khr_push_descriptor},
68 {VK_KHX_DEVICE_GROUP_EXTENSION_NAME, &E::khx_device_group},
69 {VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME, &E::khx_external_memory_fd},
70 {VK_KHX_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, &E::khx_external_semaphore_fd},
71#ifdef VK_USE_PLATFORM_WIN32_KHX
72 {VK_KHX_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::khx_external_memory_win32},
73 {VK_KHX_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME, &E::khx_external_semaphore_win32},
74#endif
75 {VK_EXT_DEBUG_MARKER_EXTENSION_NAME, &E::ext_debug_marker},
76 {VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME, &E::ext_discard_rectangles},
77 {VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME, &E::ext_display_control},
78 {VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME, &E::amd_draw_indirect_count},
79 {VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME, &E::amd_negative_viewport_height},
80 {VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME, &E::nv_external_memory},
81#ifdef VK_USE_PLATFORM_WIN32_KHR
82 {VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::nv_external_memory_win32},
83#endif
84 {VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, &E::khr_incremental_present},
Chris Forbes3fdf41f2017-05-02 14:32:26 -070085 };
86
87 for (auto ext : known_extensions) {
88 this->*(ext.second) = false;
89 }
90
91 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
92 for (auto ext : known_extensions) {
93 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
94 this->*(ext.second) = true;
95 break;
96 }
97 }
98 }
99 }
100};
101
Chris Forbesff37d382017-05-02 15:39:16 -0700102struct InstanceExtensions {
103 bool khr_surface;
104 bool khr_display;
105 bool khr_android_surface;
106 bool khr_xcb_surface;
107 bool khr_xlib_surface;
108 bool khr_win32_surface;
109 bool khr_wayland_surface;
110 bool khr_mir_surface;
Chris Forbes8130cc52017-05-02 15:47:16 -0700111 bool khr_get_physical_device_properties2;
112 bool khx_device_group_creation;
113 bool khx_external_memory_capabilities;
114 bool khx_external_semaphore_capabilities;
115 bool ext_acquire_xlib_display;
116 bool ext_direct_mode_display;
117 bool ext_display_surface_counter;
118 bool nv_external_memory_capabilities;
Chris Forbesff37d382017-05-02 15:39:16 -0700119
120 void InitFromInstanceCreateInfo(const VkInstanceCreateInfo *pCreateInfo) {
121 using E = InstanceExtensions;
122
123 static const std::pair<char const *, bool E::*> known_extensions[]{
124 {VK_KHR_SURFACE_EXTENSION_NAME, &E::khr_surface},
125 {VK_KHR_DISPLAY_EXTENSION_NAME, &E::khr_display},
126#ifdef VK_USE_PLATFORM_ANDROID_KHR
127 {VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, &E::khr_android_surface},
128#endif
129#ifdef VK_USE_PLATFORM_XCB_KHR
130 {VK_KHR_XCB_SURFACE_EXTENSION_NAME, &E::khr_xcb_surface},
131#endif
132#ifdef VK_USE_PLATFORM_XLIB_KHR
133 {VK_KHR_XLIB_SURFACE_EXTENSION_NAME, &E::khr_xlib_surface},
134#endif
135#ifdef VK_USE_PLATFORM_WIN32_KHR
136 {VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &E::khr_win32_surface},
137#endif
138#ifdef VK_USE_PLATFORM_WAYLAND_KHR
139 {VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, &E::khr_wayland_surface},
140#endif
141#ifdef VK_USE_PLATFORM_MIR_KHR
142 {VK_KHR_MIR_SURFACE_EXTENSION_NAME, &E::khr_mir_surface},
143#endif
Chris Forbes8130cc52017-05-02 15:47:16 -0700144 {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, &E::khr_get_physical_device_properties2},
145 {VK_KHX_DEVICE_GROUP_CREATION_EXTENSION_NAME, &E::khx_device_group_creation},
146 {VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::khx_external_memory_capabilities},
147 {VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, &E::khx_external_semaphore_capabilities},
148#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
149 {VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME, &E::ext_acquire_xlib_display},
150#endif
151 {VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME, &E::ext_direct_mode_display},
152 {VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME, &E::ext_display_surface_counter},
153 {VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::nv_external_memory_capabilities},
Chris Forbesff37d382017-05-02 15:39:16 -0700154 };
155
156 for (auto ext : known_extensions) {
157 this->*(ext.second) = false;
158 }
159
160 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
161 for (auto ext : known_extensions) {
162 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
163 this->*(ext.second) = true;
164 break;
165 }
166 }
167 }
168 }
169};
170
Chris Forbes3fdf41f2017-05-02 14:32:26 -0700171#endif