| 1552 | } |
| 1553 | |
| 1554 | bool GPUDeviceVulkan::Init() |
| 1555 | { |
| 1556 | TotalGraphicsMemory = 0; |
| 1557 | |
| 1558 | _state = DeviceState::Created; |
| 1559 | const auto gpu = Adapter->Gpu; |
| 1560 | |
| 1561 | // Get queues properties |
| 1562 | uint32 queueCount = 0; |
| 1563 | vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queueCount, nullptr); |
| 1564 | ASSERT(queueCount >= 1); |
| 1565 | QueueFamilyProps.AddDefault(queueCount); |
| 1566 | vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queueCount, QueueFamilyProps.Get()); |
| 1567 | |
| 1568 | // Query device features |
| 1569 | RenderToolsVulkan::ZeroStruct(PhysicalDeviceFeatures12, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES); |
| 1570 | vkGetPhysicalDeviceFeatures(gpu, &PhysicalDeviceFeatures); |
| 1571 | if (vkGetPhysicalDeviceFeatures2) |
| 1572 | { |
| 1573 | VkPhysicalDeviceFeatures2 features2; |
| 1574 | RenderToolsVulkan::ZeroStruct(features2, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2); |
| 1575 | features2.pNext = &PhysicalDeviceFeatures12; |
| 1576 | vkGetPhysicalDeviceFeatures2(gpu, &features2); |
| 1577 | } |
| 1578 | |
| 1579 | // Get extensions and layers |
| 1580 | Array<const char*> deviceExtensions; |
| 1581 | Array<const char*> validationLayers; |
| 1582 | GetDeviceExtensionsAndLayers(gpu, deviceExtensions, validationLayers); |
| 1583 | ParseOptionalDeviceExtensions(deviceExtensions); |
| 1584 | |
| 1585 | // Setup device info |
| 1586 | VkDeviceCreateInfo deviceInfo; |
| 1587 | RenderToolsVulkan::ZeroStruct(deviceInfo, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); |
| 1588 | deviceInfo.enabledExtensionCount = deviceExtensions.Count(); |
| 1589 | deviceInfo.ppEnabledExtensionNames = deviceExtensions.Get(); |
| 1590 | deviceInfo.enabledLayerCount = validationLayers.Count(); |
| 1591 | deviceInfo.ppEnabledLayerNames = deviceInfo.enabledLayerCount > 0 ? validationLayers.Get() : nullptr; |
| 1592 | |
| 1593 | // Setup queues info |
| 1594 | Array<VkDeviceQueueCreateInfo> queueFamilyInfos; |
| 1595 | int32 graphicsQueueFamilyIndex = -1; |
| 1596 | int32 computeQueueFamilyIndex = -1; |
| 1597 | int32 transferQueueFamilyIndex = -1; |
| 1598 | LOG(Info, "Found {0} queue families:", QueueFamilyProps.Count()); |
| 1599 | uint32 numPriorities = 0; |
| 1600 | for (int32 familyIndex = 0; familyIndex < QueueFamilyProps.Count(); familyIndex++) |
| 1601 | { |
| 1602 | const VkQueueFamilyProperties& curProps = QueueFamilyProps[familyIndex]; |
| 1603 | |
| 1604 | bool isValidQueue = false; |
| 1605 | if ((curProps.queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT) |
| 1606 | { |
| 1607 | if (graphicsQueueFamilyIndex == -1) |
| 1608 | { |
| 1609 | graphicsQueueFamilyIndex = familyIndex; |
| 1610 | isValidQueue = true; |
| 1611 | } |
no test coverage detected