Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/vulkan/vulkan_implementation.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 #include <vulkan/vulkan.h> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 static VkInstance vk_instance; | |
| 16 static VkDevice vk_device; | |
|
piman
2016/02/25 06:49:44
It would be nice to have these wrapped into an obj
David Yen
2016/03/01 19:54:09
Done.
| |
| 17 | |
| 18 bool InitializeVulkan() { | |
| 19 // Initialize the Vulkan Instance. | |
| 20 VkApplicationInfo app_info = {}; | |
| 21 app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; | |
| 22 app_info.pApplicationName = "Chromium"; | |
| 23 app_info.apiVersion = VK_MAKE_VERSION(1, 0, 2); | |
| 24 | |
| 25 const char* instance_extensions[] = {VK_KHR_SURFACE_EXTENSION_NAME}; | |
| 26 | |
| 27 VkInstanceCreateInfo instance_create_info = {}; | |
| 28 instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | |
| 29 instance_create_info.pApplicationInfo = &app_info; | |
| 30 instance_create_info.ppEnabledExtensionNames = instance_extensions; | |
| 31 instance_create_info.enabledExtensionCount = arraysize(instance_extensions); | |
| 32 | |
| 33 VkResult status = VK_SUCCESS; | |
| 34 status = vkCreateInstance(&instance_create_info, nullptr, &vk_instance); | |
| 35 if (VK_SUCCESS != status) | |
| 36 return false; | |
| 37 | |
| 38 // Initialize the Vulkan Device. | |
| 39 uint32_t device_count = 0; | |
| 40 status = vkEnumeratePhysicalDevices(vk_instance, &device_count, nullptr); | |
| 41 if (VK_SUCCESS != status || device_count == 0) | |
| 42 return false; | |
| 43 | |
| 44 std::vector<VkPhysicalDevice> devices(device_count); | |
| 45 status = | |
| 46 vkEnumeratePhysicalDevices(vk_instance, &device_count, devices.data()); | |
| 47 if (VK_SUCCESS != status) | |
| 48 return false; | |
| 49 | |
|
sohanjg
2016/02/24 07:24:08
sorry for the intrusion, but do we not want any la
David Yen
2016/02/25 00:27:37
The intent of this first CL is to just get linking
| |
| 50 int device_index = -1; | |
| 51 int queue_index = -1; | |
| 52 for (size_t i = 0; i < devices.size(); ++i) { | |
| 53 const VkPhysicalDevice& device = devices[i]; | |
| 54 uint32_t queue_count = 0; | |
| 55 vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_count, nullptr); | |
| 56 if (queue_count) { | |
| 57 std::vector<VkQueueFamilyProperties> queue_properties(queue_count); | |
| 58 vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_count, | |
| 59 queue_properties.data()); | |
| 60 for (size_t n = 0; n < queue_properties.size(); ++n) { | |
| 61 if (queue_properties[n].queueFlags & VK_QUEUE_GRAPHICS_BIT) { | |
|
piman
2016/02/24 01:52:13
We'll probably also want to pick a device that can
David Yen
2016/02/25 00:27:37
That would make it seem like the output surface wo
piman
2016/02/25 06:49:44
We wouldn't want a separate device per output surf
David Yen
2016/03/01 19:54:09
Done (although this currently crashes on my driver
| |
| 62 queue_index = static_cast<int>(n); | |
|
Nico
2016/02/24 01:28:57
(nit: personally, i think this function could beco
David Yen
2016/02/25 00:27:37
Done.
| |
| 63 break; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 if (-1 != queue_index) { | |
| 68 device_index = static_cast<int>(i); | |
| 69 break; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 if (queue_index == -1) | |
| 75 return false; | |
| 76 | |
| 77 float queue_priority = 0.0f; | |
| 78 VkDeviceQueueCreateInfo queue_create_info = {}; | |
| 79 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; | |
| 80 queue_create_info.queueFamilyIndex = queue_index; | |
| 81 queue_create_info.queueCount = 1; | |
| 82 queue_create_info.pQueuePriorities = &queue_priority; | |
| 83 | |
| 84 const char* device_extensions[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; | |
| 85 | |
| 86 VkDeviceCreateInfo device_create_info = {}; | |
| 87 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; | |
| 88 device_create_info.queueCreateInfoCount = 1; | |
| 89 device_create_info.pQueueCreateInfos = &queue_create_info; | |
| 90 device_create_info.enabledExtensionCount = arraysize(device_extensions); | |
| 91 device_create_info.ppEnabledExtensionNames = device_extensions; | |
| 92 | |
| 93 status = vkCreateDevice(devices[device_index], &device_create_info, nullptr, | |
| 94 &vk_device); | |
| 95 if (VK_SUCCESS != status) | |
| 96 return false; | |
| 97 | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 } // namespace gfx | |
| OLD | NEW |