| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 err = vkCreateInstance(&instance_create, nullptr, &inst); | 109 err = vkCreateInstance(&instance_create, nullptr, &inst); |
| 110 if (err < 0) { | 110 if (err < 0) { |
| 111 SkDebugf("vkCreateInstance failed: %d\n", err); | 111 SkDebugf("vkCreateInstance failed: %d\n", err); |
| 112 SkFAIL("failing"); | 112 SkFAIL("failing"); |
| 113 } | 113 } |
| 114 | 114 |
| 115 uint32_t gpuCount; | 115 uint32_t gpuCount; |
| 116 err = vkEnumeratePhysicalDevices(inst, &gpuCount, nullptr); | 116 err = vkEnumeratePhysicalDevices(inst, &gpuCount, nullptr); |
| 117 if (err) { | 117 if (err) { |
| 118 SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err); | 118 SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err); |
| 119 vkDestroyInstance(inst, nullptr); |
| 119 SkFAIL("failing"); | 120 SkFAIL("failing"); |
| 120 } | 121 } |
| 121 SkASSERT(gpuCount > 0); | 122 SkASSERT(gpuCount > 0); |
| 122 // Just returning the first physical device instead of getting the whole arr
ay. | 123 // Just returning the first physical device instead of getting the whole arr
ay. |
| 123 // TODO: find best match for our needs | 124 // TODO: find best match for our needs |
| 124 gpuCount = 1; | 125 gpuCount = 1; |
| 125 err = vkEnumeratePhysicalDevices(inst, &gpuCount, &physDev); | 126 err = vkEnumeratePhysicalDevices(inst, &gpuCount, &physDev); |
| 126 if (err) { | 127 if (err) { |
| 127 SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err); | 128 SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err); |
| 129 vkDestroyInstance(inst, nullptr); |
| 128 SkFAIL("failing"); | 130 SkFAIL("failing"); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // query to get the initial queue props size | 133 // query to get the initial queue props size |
| 132 uint32_t queueCount; | 134 uint32_t queueCount; |
| 133 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); | 135 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); |
| 134 SkASSERT(queueCount >= 1); | 136 SkASSERT(queueCount >= 1); |
| 135 | 137 |
| 136 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); | 138 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); |
| 137 // now get the actual queue props | 139 // now get the actual queue props |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 (uint32_t) deviceLayerNames.count(), // layerCount | 209 (uint32_t) deviceLayerNames.count(), // layerCount |
| 208 deviceLayerNames.begin(), // ppEnabledLayerNames | 210 deviceLayerNames.begin(), // ppEnabledLayerNames |
| 209 (uint32_t) deviceExtensionNames.count(), // extensionCount | 211 (uint32_t) deviceExtensionNames.count(), // extensionCount |
| 210 deviceExtensionNames.begin(), // ppEnabledExtensionNames | 212 deviceExtensionNames.begin(), // ppEnabledExtensionNames |
| 211 &deviceFeatures // ppEnabledFeatures | 213 &deviceFeatures // ppEnabledFeatures |
| 212 }; | 214 }; |
| 213 | 215 |
| 214 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device); | 216 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device); |
| 215 if (err) { | 217 if (err) { |
| 216 SkDebugf("CreateDevice failed: %d\n", err); | 218 SkDebugf("CreateDevice failed: %d\n", err); |
| 219 vkDestroyInstance(inst, nullptr); |
| 217 return nullptr; | 220 return nullptr; |
| 218 } | 221 } |
| 219 | 222 |
| 220 VkQueue queue; | 223 VkQueue queue; |
| 221 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue); | 224 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue); |
| 222 | 225 |
| 223 GrVkBackendContext* ctx = new GrVkBackendContext(); | 226 GrVkBackendContext* ctx = new GrVkBackendContext(); |
| 224 ctx->fInstance = inst; | 227 ctx->fInstance = inst; |
| 225 ctx->fPhysicalDevice = physDev; | 228 ctx->fPhysicalDevice = physDev; |
| 226 ctx->fDevice = device; | 229 ctx->fDevice = device; |
| 227 ctx->fQueue = queue; | 230 ctx->fQueue = queue; |
| 228 ctx->fQueueFamilyIndex = graphicsQueueIndex; | 231 ctx->fQueueFamilyIndex = graphicsQueueIndex; |
| 229 ctx->fMinAPIVersion = kGrVkMinimumVersion; | 232 ctx->fMinAPIVersion = kGrVkMinimumVersion; |
| 230 ctx->fExtensions = extensionFlags; | 233 ctx->fExtensions = extensionFlags; |
| 231 ctx->fFeatures = featureFlags; | 234 ctx->fFeatures = featureFlags; |
| 232 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags)); | 235 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags)); |
| 233 | 236 |
| 234 return ctx; | 237 return ctx; |
| 235 } | 238 } |
| 236 | 239 |
| 237 GrVkBackendContext::~GrVkBackendContext() { | 240 GrVkBackendContext::~GrVkBackendContext() { |
| 238 vkDestroyDevice(fDevice, nullptr); | 241 vkDestroyDevice(fDevice, nullptr); |
| 239 fDevice = VK_NULL_HANDLE; | 242 fDevice = VK_NULL_HANDLE; |
| 240 vkDestroyInstance(fInstance, nullptr); | 243 vkDestroyInstance(fInstance, nullptr); |
| 241 fInstance = VK_NULL_HANDLE; | 244 fInstance = VK_NULL_HANDLE; |
| 242 } | 245 } |
| OLD | NEW |