blob: 89409f52343e436cc3c14a4c2cf98f0c831057d4 [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;
111
112 void InitFromInstanceCreateInfo(const VkInstanceCreateInfo *pCreateInfo) {
113 using E = InstanceExtensions;
114
115 static const std::pair<char const *, bool E::*> known_extensions[]{
116 {VK_KHR_SURFACE_EXTENSION_NAME, &E::khr_surface},
117 {VK_KHR_DISPLAY_EXTENSION_NAME, &E::khr_display},
118#ifdef VK_USE_PLATFORM_ANDROID_KHR
119 {VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, &E::khr_android_surface},
120#endif
121#ifdef VK_USE_PLATFORM_XCB_KHR
122 {VK_KHR_XCB_SURFACE_EXTENSION_NAME, &E::khr_xcb_surface},
123#endif
124#ifdef VK_USE_PLATFORM_XLIB_KHR
125 {VK_KHR_XLIB_SURFACE_EXTENSION_NAME, &E::khr_xlib_surface},
126#endif
127#ifdef VK_USE_PLATFORM_WIN32_KHR
128 {VK_KHR_WIN32_SURFACE_EXTENSION_NAME, &E::khr_win32_surface},
129#endif
130#ifdef VK_USE_PLATFORM_WAYLAND_KHR
131 {VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, &E::khr_wayland_surface},
132#endif
133#ifdef VK_USE_PLATFORM_MIR_KHR
134 {VK_KHR_MIR_SURFACE_EXTENSION_NAME, &E::khr_mir_surface},
135#endif
136 };
137
138 for (auto ext : known_extensions) {
139 this->*(ext.second) = false;
140 }
141
142 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
143 for (auto ext : known_extensions) {
144 if (!strcmp(ext.first, pCreateInfo->ppEnabledExtensionNames[i])) {
145 this->*(ext.second) = true;
146 break;
147 }
148 }
149 }
150 }
151};
152
Chris Forbes3fdf41f2017-05-02 14:32:26 -0700153#endif