Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 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 |
| 38 // Create the base Vulkan objects needed by the GrVkGpu object | 38 // Create the base Vulkan objects needed by the GrVkGpu object |
| 39 const GrVkBackendContext* GrVkBackendContext::Create() { | 39 const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex Ptr, |
| 40 bool(*canPresent)(VkInstance, VkPhysicalDevice, uin t32_t queueIndex)) { | |
| 40 VkPhysicalDevice physDev; | 41 VkPhysicalDevice physDev; |
| 41 VkDevice device; | 42 VkDevice device; |
| 42 VkInstance inst; | 43 VkInstance inst; |
| 43 VkResult err; | 44 VkResult err; |
| 44 | 45 |
| 45 const VkApplicationInfo app_info = { | 46 const VkApplicationInfo app_info = { |
| 46 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType | 47 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType |
| 47 nullptr, // pNext | 48 nullptr, // pNext |
| 48 "vktest", // pApplicationName | 49 "vktest", // pApplicationName |
| 49 0, // applicationVersion | 50 0, // applicationVersion |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); | 136 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); |
| 136 SkASSERT(queueCount >= 1); | 137 SkASSERT(queueCount >= 1); |
| 137 | 138 |
| 138 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); | 139 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); |
| 139 // now get the actual queue props | 140 // now get the actual queue props |
| 140 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl loc.get(); | 141 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl loc.get(); |
| 141 | 142 |
| 142 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps); | 143 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps); |
| 143 | 144 |
| 144 // iterate to find the graphics queue | 145 // iterate to find the graphics queue |
| 145 uint32_t graphicsQueueIndex = -1; | 146 uint32_t graphicsQueueIndex = queueCount; |
| 146 for (uint32_t i = 0; i < queueCount; i++) { | 147 for (uint32_t i = 0; i < queueCount; i++) { |
| 147 if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { | 148 if (graphicsQueueIndex == queueCount && queueProps[i].queueFlags & VK_QU EUE_GRAPHICS_BIT) { |
|
egdaniel
2016/04/20 18:26:54
why is this needed in the if? Seems like the only
jvanverth1
2016/04/20 18:32:24
Good catch. This and the if below are from when bo
| |
| 148 graphicsQueueIndex = i; | 149 graphicsQueueIndex = i; |
| 149 break; | 150 break; |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 SkASSERT(graphicsQueueIndex < queueCount); | 153 SkASSERT(graphicsQueueIndex < queueCount); |
| 153 | 154 |
| 155 // iterate to find the present queue, if needed | |
| 156 uint32_t presentQueueIndex = graphicsQueueIndex; | |
| 157 if (presentQueueIndexPtr && canPresent) { | |
| 158 for (uint32_t i = 0; i < queueCount; i++) { | |
| 159 if (presentQueueIndex == queueCount && canPresent(inst, physDev, i)) { | |
|
egdaniel
2016/04/20 18:26:54
Assuming the assert above is true, presentQueueInd
| |
| 160 presentQueueIndex = i; | |
| 161 break; | |
| 162 } | |
| 163 } | |
| 164 SkASSERT(presentQueueIndex < queueCount); | |
| 165 *presentQueueIndexPtr = presentQueueIndex; | |
| 166 } | |
| 167 | |
| 154 extensions.initDevice(kGrVkMinimumVersion, inst, physDev); | 168 extensions.initDevice(kGrVkMinimumVersion, inst, physDev); |
| 155 | 169 |
| 156 SkTArray<const char*> deviceLayerNames; | 170 SkTArray<const char*> deviceLayerNames; |
| 157 SkTArray<const char*> deviceExtensionNames; | 171 SkTArray<const char*> deviceExtensionNames; |
| 158 #ifdef ENABLE_VK_LAYERS | 172 #ifdef ENABLE_VK_LAYERS |
| 159 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { | 173 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { |
| 160 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) { | 174 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) { |
| 161 deviceLayerNames.push_back(kDebugLayerNames[i]); | 175 deviceLayerNames.push_back(kDebugLayerNames[i]); |
| 162 } | 176 } |
| 163 } | 177 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 185 if (deviceFeatures.dualSrcBlend) { | 199 if (deviceFeatures.dualSrcBlend) { |
| 186 featureFlags |= kDualSrcBlend_GrVkFeatureFlag; | 200 featureFlags |= kDualSrcBlend_GrVkFeatureFlag; |
| 187 } | 201 } |
| 188 if (deviceFeatures.sampleRateShading) { | 202 if (deviceFeatures.sampleRateShading) { |
| 189 featureFlags |= kSampleRateShading_GrVkFeatureFlag; | 203 featureFlags |= kSampleRateShading_GrVkFeatureFlag; |
| 190 } | 204 } |
| 191 | 205 |
| 192 float queuePriorities[1] = { 0.0 }; | 206 float queuePriorities[1] = { 0.0 }; |
| 193 // Here we assume no need for swapchain queue | 207 // Here we assume no need for swapchain queue |
| 194 // If one is needed, the client will need its own setup code | 208 // If one is needed, the client will need its own setup code |
| 195 const VkDeviceQueueCreateInfo queueInfo = { | 209 const VkDeviceQueueCreateInfo queueInfo[2] = { |
| 196 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType | 210 { |
| 197 nullptr, // pNext | 211 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType |
| 198 0, // VkDeviceQueueCreateFlags | 212 nullptr, // pNext |
| 199 graphicsQueueIndex, // queueFamilyIndex | 213 0, // VkDeviceQueueCreateFl ags |
| 200 1, // queueCount | 214 graphicsQueueIndex, // queueFamilyIndex |
| 201 queuePriorities, // pQueuePriorities | 215 1, // queueCount |
| 216 queuePriorities, // pQueuePriorities | |
| 217 }, | |
| 218 { | |
| 219 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType | |
| 220 nullptr, // pNext | |
| 221 0, // VkDeviceQueueCreateFl ags | |
| 222 presentQueueIndex, // queueFamilyIndex | |
| 223 1, // queueCount | |
| 224 queuePriorities, // pQueuePriorities | |
| 225 } | |
| 202 }; | 226 }; |
| 227 uint32_t queueInfoCount = (presentQueueIndex != graphicsQueueIndex) ? 2 : 1; | |
| 228 | |
| 203 const VkDeviceCreateInfo deviceInfo = { | 229 const VkDeviceCreateInfo deviceInfo = { |
| 204 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType | 230 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType |
| 205 nullptr, // pNext | 231 nullptr, // pNext |
| 206 0, // VkDeviceCreateFlags | 232 0, // VkDeviceCreateFlags |
| 207 1, // queueCreateInfoCount | 233 queueInfoCount, // queueCreateInfoCount |
| 208 &queueInfo, // pQueueCreateInfos | 234 queueInfo, // pQueueCreateInfos |
| 209 (uint32_t) deviceLayerNames.count(), // layerCount | 235 (uint32_t) deviceLayerNames.count(), // layerCount |
| 210 deviceLayerNames.begin(), // ppEnabledLayerNames | 236 deviceLayerNames.begin(), // ppEnabledLayerNames |
| 211 (uint32_t) deviceExtensionNames.count(), // extensionCount | 237 (uint32_t) deviceExtensionNames.count(), // extensionCount |
| 212 deviceExtensionNames.begin(), // ppEnabledExtensionNames | 238 deviceExtensionNames.begin(), // ppEnabledExtensionNames |
| 213 &deviceFeatures // ppEnabledFeatures | 239 &deviceFeatures // ppEnabledFeatures |
| 214 }; | 240 }; |
| 215 | 241 |
| 216 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device); | 242 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device); |
| 217 if (err) { | 243 if (err) { |
| 218 SkDebugf("CreateDevice failed: %d\n", err); | 244 SkDebugf("CreateDevice failed: %d\n", err); |
| 219 vkDestroyInstance(inst, nullptr); | 245 vkDestroyInstance(inst, nullptr); |
| 220 return nullptr; | 246 return nullptr; |
| 221 } | 247 } |
| 222 | 248 |
| 223 VkQueue queue; | 249 VkQueue queue; |
| 224 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue); | 250 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue); |
| 225 | 251 |
| 226 GrVkBackendContext* ctx = new GrVkBackendContext(); | 252 GrVkBackendContext* ctx = new GrVkBackendContext(); |
| 227 ctx->fInstance = inst; | 253 ctx->fInstance = inst; |
| 228 ctx->fPhysicalDevice = physDev; | 254 ctx->fPhysicalDevice = physDev; |
| 229 ctx->fDevice = device; | 255 ctx->fDevice = device; |
| 230 ctx->fQueue = queue; | 256 ctx->fQueue = queue; |
| 231 ctx->fQueueFamilyIndex = graphicsQueueIndex; | 257 ctx->fGraphicsQueueIndex = graphicsQueueIndex; |
| 232 ctx->fMinAPIVersion = kGrVkMinimumVersion; | 258 ctx->fMinAPIVersion = kGrVkMinimumVersion; |
| 233 ctx->fExtensions = extensionFlags; | 259 ctx->fExtensions = extensionFlags; |
| 234 ctx->fFeatures = featureFlags; | 260 ctx->fFeatures = featureFlags; |
| 235 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags)); | 261 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags)); |
| 236 | 262 |
| 237 return ctx; | 263 return ctx; |
| 238 } | 264 } |
| 239 | 265 |
| 240 GrVkBackendContext::~GrVkBackendContext() { | 266 GrVkBackendContext::~GrVkBackendContext() { |
| 241 vkDeviceWaitIdle(fDevice); | 267 vkDeviceWaitIdle(fDevice); |
| 242 vkDestroyDevice(fDevice, nullptr); | 268 vkDestroyDevice(fDevice, nullptr); |
| 243 fDevice = VK_NULL_HANDLE; | 269 fDevice = VK_NULL_HANDLE; |
| 244 vkDestroyInstance(fInstance, nullptr); | 270 vkDestroyInstance(fInstance, nullptr); |
| 245 fInstance = VK_NULL_HANDLE; | 271 fInstance = VK_NULL_HANDLE; |
| 246 } | 272 } |
| OLD | NEW |