/* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 Vladimír Vondruš Copyright © 2016 Jonathan Hale Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "PhysicalDevice.h" #include #include #include namespace Magnum { namespace Vk { PhysicalDevice::~PhysicalDevice() { } VkFormat PhysicalDevice::getSupportedDepthFormat() { // Since all depth formats may be optional, we need to find a suitable depth format to use // Start with the highest precision packed format std::vector depthFormats = { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D16_UNORM }; VkFormatProperties formatProps; for(auto& format : depthFormats) { vkGetPhysicalDeviceFormatProperties(_physicalDevice, format, &formatProps); // Format must support depth stencil attachment for optimal tiling if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { return format; } } return VK_FORMAT_UNDEFINED; } UnsignedInt PhysicalDevice::getQueueFamilyIndex(QueueFamily family) { // Find a queue that supports graphics UnsignedInt queueCount; vkGetPhysicalDeviceQueueFamilyProperties(_physicalDevice, &queueCount, nullptr); if(queueCount <= 0) { // TODO I belive there allways is at least one queue of a certain specified type, lookup in spec Error() << "Physical Device does not provide queues"; // TODO } std::vector queueProps; // TODO Use NoInit Containers::Array queueProps.resize(queueCount); vkGetPhysicalDeviceQueueFamilyProperties(_physicalDevice, &queueCount, queueProps.data()); for(UnsignedInt i = 0; i < queueCount; ++i) { if(queueProps[i].queueFlags & VkQueueFlags(family)) { return i; } } CORRADE_ASSERT(false, "The device does not support the given queue family.", -1); // TODO } UnsignedInt PhysicalDevice::getMemoryType(UnsignedInt supportedTypeBits, MemoryProperties properties) { if(_deviceMemoryProperties.memoryHeapCount == 0 && _deviceMemoryProperties.memoryTypeCount == 0) { /* first query for physical device memory properties */ vkGetPhysicalDeviceMemoryProperties(_physicalDevice, &_deviceMemoryProperties); } const UnsignedInt p = UnsignedInt(properties); for (UnsignedInt i = 0; i < 32; ++i) { /* check whether the memory type at index i is supported */ const UnsignedInt memoryTypeSupported = (supportedTypeBits >> i) & 1; if(memoryTypeSupported != 0 && (_deviceMemoryProperties.memoryTypes[i].propertyFlags & p) == p) { /* memory type and properties match */ return i; } } CORRADE_ASSERT(false, "Physical devices does not support memory with given properties.", -1); // TODO } }}