22 PhysicalDevice* physicalDevice = VulkanContext::getCurrent()->getPhysicalDevice();
27 float queuePriority = 1.0f;
28 vector<VkDeviceQueueCreateInfo> queueCreateInfos;
29 for (set<int32_t>::iterator it = queueFamilies.begin(); it != queueFamilies.end(); it++) {
30 VkDeviceQueueCreateInfo queueCreateInfo = {};
31 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
32 queueCreateInfo.queueFamilyIndex = *it;
33 queueCreateInfo.queueCount = 1;
34 queueCreateInfo.pQueuePriorities = &queuePriority;
35 queueCreateInfos.push_back(queueCreateInfo);
39 vector<const char*> requiredLayers;
41 requiredLayers.push_back(
"VK_LAYER_LUNARG_standard_validation");
45 vector<const char*> requiredExtensions;
46 requiredExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
49 VkPhysicalDeviceFeatures physicalDeviceFeatures = {};
52 VkDeviceCreateInfo createInfo = {};
53 createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
54 createInfo.queueCreateInfoCount = queueCreateInfos.size();
55 createInfo.pQueueCreateInfos = queueCreateInfos.data();
56 createInfo.enabledLayerCount = requiredLayers.size();
57 createInfo.ppEnabledLayerNames = requiredLayers.data();
58 createInfo.enabledExtensionCount = requiredExtensions.size();
59 createInfo.ppEnabledExtensionNames = requiredExtensions.data();
60 createInfo.pEnabledFeatures = &physicalDeviceFeatures;
63 if (vkCreateDevice(physicalDevice->
getHandle(), &createInfo,
nullptr, &handle) != VK_SUCCESS) {
64 throw runtime_error(
"Could not create a logical device!");
68 vkGetDeviceQueue(handle, queueFamilyIndices.
graphics, 0, &queues.graphics);
69 vkGetDeviceQueue(handle, queueFamilyIndices.
presentation, 0, &queues.presentation);
72 Device::~Device(
void) {
73 vkDestroyDevice(handle,
nullptr);
76 VkDevice Device::getHandle() {
This class wraps a Vulkan physical device and represents a graphics card.
int32_t presentation
The index of the presentation queue family.
This struct stores relevant device queues.
This struct stores relevant queue family indices.
Generic namespace for the SimpleGL framework.
VkPhysicalDevice getHandle()
Returns the handle of the physical device.
QueueFamilyIndices getQueueFamilyIndices()
Returns the queue family indices of the physical device.
const bool debugMode
Tells if the library is compiled in debug mode.
int32_t graphics
The index of the graphics queue family.