blob: b753a2e75933016dcf6183ed2abd3ec8f06d5354 [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;
Mark Lobodzinski61280492017-05-25 16:22:48 -060052 bool khr_sampler_mirror_clamp_to_edge;
53 bool img_filter_cubic;
54 bool amd_rasterization_order;
55 bool amd_shader_trinary_minmax;
56 bool amd_shader_explicit_vertex_parameter;
57 bool amd_gcn_shader;
58 bool nv_dedicated_allocation;
59 bool amd_gpu_shader_half_float;
60 bool amd_shader_ballot;
61 bool amd_texture_gather_bias_lod;
62 bool khx_multiview;
63 bool img_format_pvrtc;
64 bool nv_win32_keyed_mutex;
65 bool khx_win32_keyed_mutex;
66 bool khx_external_memory;
67 bool khx_external_semaphore;
68 bool nvx_multiview_per_view_attributes;
69 bool nv_viewport_swizzle;
70 bool ext_hdr_metadata;
Chris Forbes3fdf41f2017-05-02 14:32:26 -070071
72 void InitFromDeviceCreateInfo(const VkDeviceCreateInfo *pCreateInfo) {
73 using E = DeviceExtensions;
74
75 static const std::pair<char const *, bool E::*> known_extensions[]{
76 {VK_KHR_SWAPCHAIN_EXTENSION_NAME, &E::khr_swapchain},
77 {VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME, &E::khr_display_swapchain},
78 {VK_NV_GLSL_SHADER_EXTENSION_NAME, &E::nv_glsl_shader},
79 {VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, &E::khr_descriptor_update_template},
80 {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, &E::khr_shader_draw_parameters},
81 {VK_KHR_MAINTENANCE1_EXTENSION_NAME, &E::khr_maintenance1},
82 {VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME, &E::nv_geometry_shader_passthrough},
83 {VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME, &E::nv_sample_mask_override_coverage},
84 {VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, &E::nv_viewport_array2},
85 {VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME, &E::khr_subgroup_ballot},
86 {VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, &E::khr_subgroup_vote},
Chris Forbes8976f742017-05-02 14:52:05 -070087 {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, &E::khr_push_descriptor},
88 {VK_KHX_DEVICE_GROUP_EXTENSION_NAME, &E::khx_device_group},
89 {VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME, &E::khx_external_memory_fd},
90 {VK_KHX_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, &E::khx_external_semaphore_fd},
91#ifdef VK_USE_PLATFORM_WIN32_KHX
92 {VK_KHX_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::khx_external_memory_win32},
93 {VK_KHX_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME, &E::khx_external_semaphore_win32},
94#endif
95 {VK_EXT_DEBUG_MARKER_EXTENSION_NAME, &E::ext_debug_marker},
96 {VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME, &E::ext_discard_rectangles},
97 {VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME, &E::ext_display_control},
98 {VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME, &E::amd_draw_indirect_count},
99 {VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME, &E::amd_negative_viewport_height},
Chris Forbes7d11b8e2017-05-03 08:21:33 -0700100 {VK_NV_CLIP_SPACE_W_SCALING_EXTENSION_NAME, &E::nv_clip_space_w_scaling},
Chris Forbes8976f742017-05-02 14:52:05 -0700101 {VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME, &E::nv_external_memory},
Chris Forbes7d11b8e2017-05-03 08:21:33 -0700102 {VK_NVX_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME, &E::nvx_device_generated_commands},
Chris Forbes8976f742017-05-02 14:52:05 -0700103 {VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, &E::khr_incremental_present},
Mark Lobodzinski087380c2017-05-16 14:42:25 -0600104 {VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, &E::khr_shared_presentable_image},
Mark Lobodzinski61280492017-05-25 16:22:48 -0600105 {VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME, &E::khr_sampler_mirror_clamp_to_edge},
106 {VK_IMG_FILTER_CUBIC_EXTENSION_NAME, &E::img_filter_cubic},
107 {VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME, &E::amd_rasterization_order},
108 {VK_AMD_SHADER_TRINARY_MINMAX_EXTENSION_NAME, &E::amd_shader_trinary_minmax},
109 {VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_EXTENSION_NAME, &E::amd_shader_explicit_vertex_parameter},
110 {VK_AMD_GCN_SHADER_EXTENSION_NAME, &E::amd_gcn_shader},
111 {VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME, &E::nv_dedicated_allocation},
112 {VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME, &E::amd_gpu_shader_half_float},
113 {VK_AMD_SHADER_BALLOT_EXTENSION_NAME, &E::amd_shader_ballot},
114 {VK_AMD_TEXTURE_GATHER_BIAS_LOD_EXTENSION_NAME, &E::amd_texture_gather_bias_lod},
115 {VK_KHX_MULTIVIEW_EXTENSION_NAME, &E::khx_multiview},
116 {VK_IMG_FORMAT_PVRTC_EXTENSION_NAME, &E::img_format_pvrtc},
117#ifdef VK_USE_PLATFORM_WIN32_KHR
118 {VK_KHX_WIN32_KEYED_MUTEX_EXTENSION_NAME, &E::khx_win32_keyed_mutex},
119 {VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, &E::nv_external_memory_win32},
120 {VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME, &E::nv_win32_keyed_mutex},
121#endif
122 {VK_KHX_EXTERNAL_MEMORY_EXTENSION_NAME, &E::khx_external_memory},
123 {VK_KHX_EXTERNAL_SEMAPHORE_EXTENSION_NAME, &E::khx_external_semaphore},
124 {VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_EXTENSION_NAME, &E::nvx_multiview_per_view_attributes},
125 {VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, &E::nv_viewport_swizzle},
126 {VK_EXT_HDR_METADATA_EXTENSION_NAME, &E::ext_hdr_metadata},
Chris Forbes3fdf41f2017-05-02 14:32:26 -0700127 };
128
129 for (auto ext : known_extensions) {
130 this->*(ext.second) = false;
131 }
132
133 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
134 for (auto ext : known_extensions) {
135 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
136 this->*(ext.second) = true;
137 break;
138 }
139 }
140 }
141 }
142};
143
Chris Forbesff37d382017-05-02 15:39:16 -0700144struct InstanceExtensions {
145 bool khr_surface;
146 bool khr_display;
147 bool khr_android_surface;
148 bool khr_xcb_surface;
149 bool khr_xlib_surface;
150 bool khr_win32_surface;
151 bool khr_wayland_surface;
152 bool khr_mir_surface;
Chris Forbes8130cc52017-05-02 15:47:16 -0700153 bool khr_get_physical_device_properties2;
Mike Schuchardt6991a392017-05-17 07:54:02 -0600154 bool khr_get_surface_capabilities2;
Chris Forbes8130cc52017-05-02 15:47:16 -0700155 bool khx_device_group_creation;
156 bool khx_external_memory_capabilities;
157 bool khx_external_semaphore_capabilities;
158 bool ext_acquire_xlib_display;
159 bool ext_direct_mode_display;
160 bool ext_display_surface_counter;
161 bool nv_external_memory_capabilities;
Mark Lobodzinski61280492017-05-25 16:22:48 -0600162 bool ext_debug_report;
163 bool ext_validation_flags;
164 bool nn_vi_surface;
165 bool ext_swapchain_color_space;
166 bool mvk_ios_surface;
167 bool mvk_macos_surface;
Chris Forbesff37d382017-05-02 15:39:16 -0700168
169 void InitFromInstanceCreateInfo(const VkInstanceCreateInfo *pCreateInfo) {
170 using E = InstanceExtensions;
171
172 static const std::pair<char const *, bool E::*> known_extensions[]{
173 {VK_KHR_SURFACE_EXTENSION_NAME, &E::khr_surface},
174 {VK_KHR_DISPLAY_EXTENSION_NAME, &E::khr_display},
175#ifdef VK_USE_PLATFORM_ANDROID_KHR
176 {VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, &E::khr_android_surface},
177#endif
178#ifdef VK_USE_PLATFORM_XCB_KHR
179 {VK_KHR_XCB_SURFACE_EXTENSION_NAME, &E::khr_xcb_surface},
180#endif
181#ifdef VK_USE_PLATFORM_XLIB_KHR
182 {VK_KHR_XLIB_SURFACE_EXTENSION_NAME, &E::khr_xlib_surface},
183#endif
184#ifdef VK_USE_PLATFORM_WIN32_KHR
185 {VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &E::khr_win32_surface},
186#endif
187#ifdef VK_USE_PLATFORM_WAYLAND_KHR
188 {VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, &E::khr_wayland_surface},
189#endif
190#ifdef VK_USE_PLATFORM_MIR_KHR
191 {VK_KHR_MIR_SURFACE_EXTENSION_NAME, &E::khr_mir_surface},
192#endif
Chris Forbes8130cc52017-05-02 15:47:16 -0700193 {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, &E::khr_get_physical_device_properties2},
Mike Schuchardt6991a392017-05-17 07:54:02 -0600194 {VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, &E::khr_get_surface_capabilities2},
Chris Forbes8130cc52017-05-02 15:47:16 -0700195 {VK_KHX_DEVICE_GROUP_CREATION_EXTENSION_NAME, &E::khx_device_group_creation},
196 {VK_KHX_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::khx_external_memory_capabilities},
197 {VK_KHX_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, &E::khx_external_semaphore_capabilities},
198#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
199 {VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME, &E::ext_acquire_xlib_display},
200#endif
201 {VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME, &E::ext_direct_mode_display},
202 {VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME, &E::ext_display_surface_counter},
203 {VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, &E::nv_external_memory_capabilities},
Mark Lobodzinski61280492017-05-25 16:22:48 -0600204 {VK_EXT_DEBUG_REPORT_EXTENSION_NAME, &E::ext_debug_report},
205 {VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME, &E::ext_validation_flags},
206#ifdef VK_USE_PLATFORM_VI_NN
207 {VK_NN_VI_SURFACE_EXTENSION_NAME, &E::nn_vi_surface},
208#endif
209 {VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME, &E::ext_swapchain_color_space},
210#ifdef VK_USE_PLATFORM_IOS_MVK
211 {VK_MVK_IOS_SURFACE_EXTENSION_NAME, &E::mvk_ios_surface},
212#endif
213#ifdef VK_USE_PLATFORM_MACOS_MVK
214 {VK_MVK_MACOS_SURFACE_EXTENSION_NAME, &E::mvk_macos_surface},
215#endif
Chris Forbesff37d382017-05-02 15:39:16 -0700216 };
217
218 for (auto ext : known_extensions) {
219 this->*(ext.second) = false;
220 }
221
222 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
223 for (auto ext : known_extensions) {
224 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
225 this->*(ext.second) = true;
226 break;
227 }
228 }
229 }
230 }
231};
232
Mike Schuchardt6991a392017-05-17 07:54:02 -0600233#endif