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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 // the minimum version of Vulkan supported | 34 // the minimum version of Vulkan supported |
35 #ifdef SK_BUILD_FOR_ANDROID | 35 #ifdef SK_BUILD_FOR_ANDROID |
36 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 3); | 36 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 3); |
37 #else | 37 #else |
38 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8); | 38 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8); |
39 #endif | 39 #endif |
40 | 40 |
41 // Create the base Vulkan objects needed by the GrVkGpu object | 41 // Create the base Vulkan objects needed by the GrVkGpu object |
42 const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex
Ptr, | 42 const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex
Ptr, |
43 bool(*canPresent)(VkInstance, VkPhysicalDevice, uin
t32_t queueIndex)) { | 43 bool(*canPresent)(VkInstance, VkPhysicalDevice, uin
t32_t queueIndex, |
| 44 void* platformData), |
| 45 void* platformData) { |
44 VkPhysicalDevice physDev; | 46 VkPhysicalDevice physDev; |
45 VkDevice device; | 47 VkDevice device; |
46 VkInstance inst; | 48 VkInstance inst; |
47 VkResult err; | 49 VkResult err; |
48 | 50 |
49 const VkApplicationInfo app_info = { | 51 const VkApplicationInfo app_info = { |
50 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType | 52 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType |
51 nullptr, // pNext | 53 nullptr, // pNext |
52 "vktest", // pApplicationName | 54 "vktest", // pApplicationName |
53 0, // applicationVersion | 55 0, // applicationVersion |
(...skipping 30 matching lines...) Expand all Loading... |
84 } | 86 } |
85 #ifdef SK_BUILD_FOR_WIN | 87 #ifdef SK_BUILD_FOR_WIN |
86 if (extensions.hasInstanceExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)) { | 88 if (extensions.hasInstanceExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)) { |
87 instanceExtensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); | 89 instanceExtensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
88 extensionFlags |= kKHR_win32_surface_GrVkExtensionFlag; | 90 extensionFlags |= kKHR_win32_surface_GrVkExtensionFlag; |
89 } | 91 } |
90 #elif SK_BUILD_FOR_ANDROID | 92 #elif SK_BUILD_FOR_ANDROID |
91 if (extensions.hasInstanceExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
{ | 93 if (extensions.hasInstanceExtension(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
{ |
92 instanceExtensionNames.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); | 94 instanceExtensionNames.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
93 extensionFlags |= kKHR_android_surface_GrVkExtensionFlag; | 95 extensionFlags |= kKHR_android_surface_GrVkExtensionFlag; |
94 } | 96 } |
95 #elif SK_BUILD_FOR_UNIX | 97 #elif SK_BUILD_FOR_UNIX |
96 if (extensions.hasInstanceExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME)) { | 98 if (extensions.hasInstanceExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME)) { |
97 instanceExtensionNames.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); | 99 instanceExtensionNames.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
98 extensionFlags |= kKHR_xlib_surface_GrVkExtensionFlag; | 100 extensionFlags |= kKHR_xcb_surface_GrVkExtensionFlag; |
99 } | 101 } |
100 #endif | 102 #endif |
101 | 103 |
102 const VkInstanceCreateInfo instance_create = { | 104 const VkInstanceCreateInfo instance_create = { |
103 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType | 105 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType |
104 nullptr, // pNext | 106 nullptr, // pNext |
105 0, // flags | 107 0, // flags |
106 &app_info, // pApplicationInfo | 108 &app_info, // pApplicationInfo |
107 (uint32_t) instanceLayerNames.count(), // enabledLayerNameCount | 109 (uint32_t) instanceLayerNames.count(), // enabledLayerNameCount |
108 instanceLayerNames.begin(), // ppEnabledLayerNames | 110 instanceLayerNames.begin(), // ppEnabledLayerNames |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 graphicsQueueIndex = i; | 154 graphicsQueueIndex = i; |
153 break; | 155 break; |
154 } | 156 } |
155 } | 157 } |
156 SkASSERT(graphicsQueueIndex < queueCount); | 158 SkASSERT(graphicsQueueIndex < queueCount); |
157 | 159 |
158 // iterate to find the present queue, if needed | 160 // iterate to find the present queue, if needed |
159 uint32_t presentQueueIndex = graphicsQueueIndex; | 161 uint32_t presentQueueIndex = graphicsQueueIndex; |
160 if (presentQueueIndexPtr && canPresent) { | 162 if (presentQueueIndexPtr && canPresent) { |
161 for (uint32_t i = 0; i < queueCount; i++) { | 163 for (uint32_t i = 0; i < queueCount; i++) { |
162 if (canPresent(inst, physDev, i)) { | 164 if (canPresent(inst, physDev, i, platformData)) { |
163 presentQueueIndex = i; | 165 presentQueueIndex = i; |
164 break; | 166 break; |
165 } | 167 } |
166 } | 168 } |
167 SkASSERT(presentQueueIndex < queueCount); | 169 SkASSERT(presentQueueIndex < queueCount); |
168 *presentQueueIndexPtr = presentQueueIndex; | 170 *presentQueueIndexPtr = presentQueueIndex; |
169 } | 171 } |
170 | 172 |
171 extensions.initDevice(kGrVkMinimumVersion, inst, physDev); | 173 extensions.initDevice(kGrVkMinimumVersion, inst, physDev); |
172 | 174 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return ctx; | 268 return ctx; |
267 } | 269 } |
268 | 270 |
269 GrVkBackendContext::~GrVkBackendContext() { | 271 GrVkBackendContext::~GrVkBackendContext() { |
270 vkDeviceWaitIdle(fDevice); | 272 vkDeviceWaitIdle(fDevice); |
271 vkDestroyDevice(fDevice, nullptr); | 273 vkDestroyDevice(fDevice, nullptr); |
272 fDevice = VK_NULL_HANDLE; | 274 fDevice = VK_NULL_HANDLE; |
273 vkDestroyInstance(fInstance, nullptr); | 275 vkDestroyInstance(fInstance, nullptr); |
274 fInstance = VK_NULL_HANDLE; | 276 fInstance = VK_NULL_HANDLE; |
275 } | 277 } |
OLD | NEW |