OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "vk/GrVkBackendContext.h" | 8 #include "vk/GrVkBackendContext.h" |
9 #include "vk/GrVkExtensions.h" | 9 #include "vk/GrVkExtensions.h" |
10 #include "vk/GrVkInterface.h" | 10 #include "vk/GrVkInterface.h" |
11 #include "vk/GrVkUtil.h" | 11 #include "vk/GrVkUtil.h" |
12 | 12 |
13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
14 // Helper code to set up Vulkan context objects | 14 // Helper code to set up Vulkan context objects |
15 | 15 |
16 #ifdef ENABLE_VK_LAYERS | 16 #ifdef ENABLE_VK_LAYERS |
17 const char* kDebugLayerNames[] = { | 17 const char* kDebugLayerNames[] = { |
18 // elements of VK_LAYER_LUNARG_standard_validation | 18 // elements of VK_LAYER_LUNARG_standard_validation |
19 "VK_LAYER_LUNARG_threading", | 19 "VK_LAYER_LUNARG_threading", |
20 "VK_LAYER_LUNARG_param_checker", | 20 "VK_LAYER_LUNARG_param_checker", |
21 "VK_LAYER_LUNARG_device_limits", | 21 "VK_LAYER_LUNARG_device_limits", |
22 "VK_LAYER_LUNARG_object_tracker", | 22 "VK_LAYER_LUNARG_object_tracker", |
23 "VK_LAYER_LUNARG_image", | 23 "VK_LAYER_LUNARG_image", |
24 "VK_LAYER_LUNARG_mem_tracker", | 24 "VK_LAYER_LUNARG_mem_tracker", |
25 "VK_LAYER_LUNARG_draw_state", | 25 "VK_LAYER_LUNARG_draw_state", |
26 "VK_LAYER_LUNARG_swapchain", | 26 "VK_LAYER_LUNARG_swapchain", |
27 "VK_LAYER_GOOGLE_unique_objects", | 27 //"VK_LAYER_GOOGLE_unique_objects", |
28 // not included in standard_validation | 28 // not included in standard_validation |
29 //"VK_LAYER_LUNARG_api_dump", | 29 //"VK_LAYER_LUNARG_api_dump", |
30 //"VK_LAYER_LUNARG_vktrace", | 30 //"VK_LAYER_LUNARG_vktrace", |
31 //"VK_LAYER_LUNARG_screenshot", | 31 //"VK_LAYER_LUNARG_screenshot", |
32 }; | 32 }; |
33 #endif | 33 #endif |
34 | 34 |
35 // the minimum version of Vulkan supported | 35 // the minimum version of Vulkan supported |
36 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 3); | 36 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 3); |
37 | 37 |
(...skipping 23 matching lines...) Expand all Loading... |
61 #ifdef ENABLE_VK_LAYERS | 61 #ifdef ENABLE_VK_LAYERS |
62 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { | 62 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { |
63 if (extensions.hasInstanceLayer(kDebugLayerNames[i])) { | 63 if (extensions.hasInstanceLayer(kDebugLayerNames[i])) { |
64 instanceLayerNames.push_back(kDebugLayerNames[i]); | 64 instanceLayerNames.push_back(kDebugLayerNames[i]); |
65 } | 65 } |
66 } | 66 } |
67 if (extensions.hasInstanceExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) { | 67 if (extensions.hasInstanceExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) { |
68 instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); | 68 instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
69 extensionFlags |= kEXT_debug_report_GrVkExtensionFlag; | 69 extensionFlags |= kEXT_debug_report_GrVkExtensionFlag; |
70 } | 70 } |
| 71 #endif |
| 72 |
71 if (extensions.hasInstanceExtension(VK_KHR_SURFACE_EXTENSION_NAME)) { | 73 if (extensions.hasInstanceExtension(VK_KHR_SURFACE_EXTENSION_NAME)) { |
72 instanceExtensionNames.push_back(VK_KHR_SURFACE_EXTENSION_NAME); | 74 instanceExtensionNames.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
73 extensionFlags |= kKHR_surface_GrVkExtensionFlag; | 75 extensionFlags |= kKHR_surface_GrVkExtensionFlag; |
74 } | 76 } |
75 if (extensions.hasInstanceExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { | 77 if (extensions.hasInstanceExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { |
76 instanceExtensionNames.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); | 78 instanceExtensionNames.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
77 extensionFlags |= kKHR_swapchain_GrVkExtensionFlag; | 79 extensionFlags |= kKHR_swapchain_GrVkExtensionFlag; |
78 } | 80 } |
79 #ifdef SK_BUILD_FOR_WIN | 81 #ifdef SK_BUILD_FOR_WIN |
80 if (extensions.hasInstanceExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)) { | 82 if (extensions.hasInstanceExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)) { |
81 instanceExtensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); | 83 instanceExtensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
82 extensionFlags |= kKHR_win32_surface_GrVkExtensionFlag; | 84 extensionFlags |= kKHR_win32_surface_GrVkExtensionFlag; |
83 } | 85 } |
84 #elif SK_BUILD_FOR_ANDROID | 86 #elif SK_BUILD_FOR_ANDROID |
85 if (extensions.hasInstanceExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
{ | 87 if (extensions.hasInstanceExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
{ |
86 instanceExtensionNames.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); | 88 instanceExtensionNames.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
87 extensionFlags |= kKHR_android_surface_GrVkExtensionFlag; | 89 extensionFlags |= kKHR_android_surface_GrVkExtensionFlag; |
88 } | 90 } |
89 #elif SK_BUILD_FOR_UNIX | 91 #elif SK_BUILD_FOR_UNIX |
90 if (extensions.hasInstanceExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME)) { | 92 if (extensions.hasInstanceExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME)) { |
91 instanceExtensionNames.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); | 93 instanceExtensionNames.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
92 extensionFlags |= kKHR_xlib_surface_GrVkExtensionFlag; | 94 extensionFlags |= kKHR_xlib_surface_GrVkExtensionFlag; |
93 } | 95 } |
94 #endif | 96 #endif |
95 #endif | |
96 | 97 |
97 const VkInstanceCreateInfo instance_create = { | 98 const VkInstanceCreateInfo instance_create = { |
98 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType | 99 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType |
99 nullptr, // pNext | 100 nullptr, // pNext |
100 0, // flags | 101 0, // flags |
101 &app_info, // pApplicationInfo | 102 &app_info, // pApplicationInfo |
102 (uint32_t) instanceLayerNames.count(), // enabledLayerNameCount | 103 (uint32_t) instanceLayerNames.count(), // enabledLayerNameCount |
103 instanceLayerNames.begin(), // ppEnabledLayerNames | 104 instanceLayerNames.begin(), // ppEnabledLayerNames |
104 (uint32_t) instanceExtensionNames.count(), // enabledExtensionNameCount | 105 (uint32_t) instanceExtensionNames.count(), // enabledExtensionNameCount |
105 instanceExtensionNames.begin(), // ppEnabledExtensionNames | 106 instanceExtensionNames.begin(), // ppEnabledExtensionNames |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 153 |
153 SkTArray<const char*> deviceLayerNames; | 154 SkTArray<const char*> deviceLayerNames; |
154 SkTArray<const char*> deviceExtensionNames; | 155 SkTArray<const char*> deviceExtensionNames; |
155 #ifdef ENABLE_VK_LAYERS | 156 #ifdef ENABLE_VK_LAYERS |
156 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { | 157 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { |
157 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) { | 158 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) { |
158 deviceLayerNames.push_back(kDebugLayerNames[i]); | 159 deviceLayerNames.push_back(kDebugLayerNames[i]); |
159 } | 160 } |
160 } | 161 } |
161 #endif | 162 #endif |
| 163 if (extensions.hasDeviceExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { |
| 164 deviceExtensionNames.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 165 extensionFlags |= kKHR_swapchain_GrVkExtensionFlag; |
| 166 } |
162 if (extensions.hasDeviceExtension("VK_NV_glsl_shader")) { | 167 if (extensions.hasDeviceExtension("VK_NV_glsl_shader")) { |
163 deviceExtensionNames.push_back("VK_NV_glsl_shader"); | 168 deviceExtensionNames.push_back("VK_NV_glsl_shader"); |
164 extensionFlags |= kNV_glsl_shader_GrVkExtensionFlag; | 169 extensionFlags |= kNV_glsl_shader_GrVkExtensionFlag; |
165 } | 170 } |
166 | 171 |
167 // query to get the physical device properties | 172 // query to get the physical device properties |
168 VkPhysicalDeviceFeatures deviceFeatures; | 173 VkPhysicalDeviceFeatures deviceFeatures; |
169 vkGetPhysicalDeviceFeatures(physDev, &deviceFeatures); | 174 vkGetPhysicalDeviceFeatures(physDev, &deviceFeatures); |
170 // this looks like it would slow things down, | 175 // this looks like it would slow things down, |
171 // and we can't depend on it on all platforms | 176 // and we can't depend on it on all platforms |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 233 |
229 return ctx; | 234 return ctx; |
230 } | 235 } |
231 | 236 |
232 GrVkBackendContext::~GrVkBackendContext() { | 237 GrVkBackendContext::~GrVkBackendContext() { |
233 vkDestroyDevice(fDevice, nullptr); | 238 vkDestroyDevice(fDevice, nullptr); |
234 fDevice = VK_NULL_HANDLE; | 239 fDevice = VK_NULL_HANDLE; |
235 vkDestroyInstance(fInstance, nullptr); | 240 vkDestroyInstance(fInstance, nullptr); |
236 fInstance = VK_NULL_HANDLE; | 241 fInstance = VK_NULL_HANDLE; |
237 } | 242 } |
OLD | NEW |