Created
November 14, 2016 00:08
-
-
Save TheBuzzSaw/c612976603d7e05602eaea67d3de2e31 to your computer and use it in GitHub Desktop.
introductory headless Vulkan device data dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vulkan/vulkan.h> | |
| #include <iostream> | |
| #include <cassert> | |
| using namespace std; | |
| void DumpPhysicalDevice(VkPhysicalDevice physicalDevice) | |
| { | |
| VkPhysicalDeviceProperties properties; | |
| vkGetPhysicalDeviceProperties(physicalDevice, &properties); | |
| cout << properties.deviceName; | |
| VkPhysicalDeviceMemoryProperties memoryProperties; | |
| vkGetPhysicalDeviceMemoryProperties(physicalDevice, &memoryProperties); | |
| cout << "\n " << memoryProperties.memoryHeapCount << " memory heap"; | |
| if (memoryProperties.memoryHeapCount != 1) cout << 's'; | |
| auto indent = "\n "; | |
| for (uint32_t i = 0; i < memoryProperties.memoryHeapCount; ++i) | |
| { | |
| auto memoryHeap = memoryProperties.memoryHeaps[i]; | |
| cout << "\n memory heap " << i << " -- " << memoryHeap.size | |
| << " bytes"; | |
| if (memoryHeap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) | |
| cout << indent << "VK_MEMORY_HEAP_DEVICE_LOCAL_BIT"; | |
| } | |
| cout << "\n " << memoryProperties.memoryTypeCount << " memory type"; | |
| if (memoryProperties.memoryTypeCount != 1) cout << 's'; | |
| for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; ++i) | |
| { | |
| auto memoryType = memoryProperties.memoryTypes[i]; | |
| cout << "\n memory type " << i << " -- heap index " | |
| << memoryType.heapIndex; | |
| if (memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) | |
| cout << indent << "VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT"; | |
| if (memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) | |
| cout << indent << "VK_MEMORY_PROPERTY_HOST_CACHED_BIT"; | |
| if (memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) | |
| cout << indent << "VK_MEMORY_PROPERTY_HOST_COHERENT_BIT"; | |
| if (memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) | |
| cout << indent << "VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"; | |
| if (memoryType.propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) | |
| cout << indent << "VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT"; | |
| } | |
| constexpr uint32_t MaxQueueFamilyCount = 8; | |
| VkQueueFamilyProperties queueFamilies[ | |
| MaxQueueFamilyCount]; | |
| uint32_t queueFamilyCount = MaxQueueFamilyCount; | |
| vkGetPhysicalDeviceQueueFamilyProperties( | |
| physicalDevice, | |
| &queueFamilyCount, | |
| queueFamilies); | |
| cout << "\n " << queueFamilyCount | |
| << " queue famil"; | |
| if (queueFamilyCount == 1) | |
| cout << 'y'; | |
| else | |
| cout << "ies"; | |
| for (uint32_t i = 0; i < queueFamilyCount; ++i) | |
| { | |
| auto queueFamily = queueFamilies[i]; | |
| cout << "\n queue family " << i << " -- " << queueFamily.queueCount | |
| << " queue"; | |
| if (queueFamily.queueCount != 1) cout << 's'; | |
| cout << " -- " << queueFamily.timestampValidBits | |
| << " timestamp valid bit"; | |
| if (queueFamily.timestampValidBits != 1) cout << 's'; | |
| if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) | |
| cout << indent << "VK_QUEUE_GRAPHICS_BIT"; | |
| if (queueFamily.queueFlags & VK_QUEUE_COMPUTE_BIT) | |
| cout << indent << "VK_QUEUE_COMPUTE_BIT"; | |
| if (queueFamily.queueFlags & VK_QUEUE_TRANSFER_BIT) | |
| cout << indent << "VK_QUEUE_TRANSFER_BIT"; | |
| if (queueFamily.queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) | |
| cout << indent << "VK_QUEUE_SPARSE_BINDING_BIT"; | |
| } | |
| cout << '\n'; | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| VkApplicationInfo ai = {}; | |
| ai.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; | |
| ai.pNext = nullptr; | |
| ai.pApplicationName = "SDL Vulkan"; | |
| ai.applicationVersion = 1; | |
| ai.pEngineName = "SDLV"; | |
| ai.engineVersion = 1; | |
| ai.apiVersion = VK_API_VERSION_1_0; | |
| VkInstanceCreateInfo ici = {}; | |
| ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | |
| ici.pNext = nullptr; | |
| ici.flags = 0; | |
| ici.pApplicationInfo = &ai; | |
| ici.enabledLayerCount = 0; | |
| ici.ppEnabledLayerNames = nullptr; | |
| ici.enabledExtensionCount = 0; | |
| ici.ppEnabledExtensionNames = nullptr; | |
| VkInstance instance; | |
| { | |
| VkResult result = vkCreateInstance(&ici, nullptr, &instance); | |
| if (result != VK_SUCCESS) | |
| { | |
| cout << "vkCreateInstance failed\n"; | |
| return 1; | |
| } | |
| } | |
| constexpr uint32_t MaxPhysicalDeviceCount = 8; | |
| VkPhysicalDevice physicalDevices[MaxPhysicalDeviceCount]; | |
| uint32_t physicalDeviceCount = MaxPhysicalDeviceCount; | |
| { | |
| VkResult result = vkEnumeratePhysicalDevices( | |
| instance, | |
| &physicalDeviceCount, | |
| physicalDevices); | |
| if (result == VK_SUCCESS) | |
| { | |
| if (physicalDeviceCount > 0) | |
| { | |
| for (uint32_t i = 0; i < physicalDeviceCount; ++i) | |
| { | |
| cout << "VkPhysicalDevice " << i << " -- "; | |
| DumpPhysicalDevice(physicalDevices[i]); | |
| } | |
| } | |
| else | |
| { | |
| cout << "vkEnumeratePhysicalDevices succeeded but found no" | |
| " devices\n"; | |
| } | |
| } | |
| else | |
| { | |
| cout << "vkEnumeratePhysicalDevices failed\n"; | |
| } | |
| } | |
| vkDestroyInstance(instance, nullptr); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment