Created a logical device
This commit is contained in:
parent
7b6317f4de
commit
87d20ff820
1 changed files with 45 additions and 0 deletions
45
src/main.c
45
src/main.c
|
|
@ -35,6 +35,9 @@ typedef struct Application {
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
VkDebugUtilsMessengerEXT debugMessenger;
|
VkDebugUtilsMessengerEXT debugMessenger;
|
||||||
|
VkPhysicalDevice physicalDevice;
|
||||||
|
VkDevice device;
|
||||||
|
VkQueue graphicsQueue;
|
||||||
} Application;
|
} Application;
|
||||||
|
|
||||||
bool checkValidationLayerSupport() {
|
bool checkValidationLayerSupport() {
|
||||||
|
|
@ -274,12 +277,53 @@ void pickPhysicalDevice(Application *app) {
|
||||||
fprintf(stderr, "Failed to find suitable GPU\n");
|
fprintf(stderr, "Failed to find suitable GPU\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app->physicalDevice = physicalDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
void createLogicalDevice(Application *app) {
|
||||||
|
// Specify Queues
|
||||||
|
QueueFamilyIndices indeces = findQueueFamilies(app->physicalDevice);
|
||||||
|
VkDeviceQueueCreateInfo queueCreateInfo = {};
|
||||||
|
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||||
|
queueCreateInfo.queueFamilyIndex = indeces.graphicsFamily;
|
||||||
|
queueCreateInfo.queueCount = 1;
|
||||||
|
float queuePriority = 1.0f;
|
||||||
|
queueCreateInfo.pQueuePriorities = &queuePriority;
|
||||||
|
|
||||||
|
// Specify device features
|
||||||
|
VkPhysicalDeviceFeatures deviceFeatures = {VK_FALSE};
|
||||||
|
|
||||||
|
// Specify logical device
|
||||||
|
VkDeviceCreateInfo createInfo = {};
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||||
|
createInfo.pQueueCreateInfos = &queueCreateInfo;
|
||||||
|
createInfo.pEnabledFeatures = &deviceFeatures;
|
||||||
|
createInfo.queueCreateInfoCount = 1;
|
||||||
|
|
||||||
|
// Old Vulkan specify layers
|
||||||
|
createInfo.enabledLayerCount = 0;
|
||||||
|
createInfo.ppEnabledLayerNames = 0;
|
||||||
|
if (enableValidationLayers) {
|
||||||
|
createInfo.enabledLayerCount = validationLayerCount;
|
||||||
|
createInfo.ppEnabledLayerNames = validationLayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vkCreateDevice(app->physicalDevice, &createInfo, NULL, &app->device) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
|
fprintf(stderr, "Failed to create logical device.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set graphics queue from logical device
|
||||||
|
vkGetDeviceQueue(app->device, indeces.graphicsFamily, 0, &app->graphicsQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initVulkan(Application *app) {
|
void initVulkan(Application *app) {
|
||||||
createInstance(app);
|
createInstance(app);
|
||||||
setupDebugMessenger(app);
|
setupDebugMessenger(app);
|
||||||
pickPhysicalDevice(app);
|
pickPhysicalDevice(app);
|
||||||
|
createLogicalDevice(app);
|
||||||
}
|
}
|
||||||
void mainLoop(Application *app) {
|
void mainLoop(Application *app) {
|
||||||
while (!glfwWindowShouldClose(app->window)) {
|
while (!glfwWindowShouldClose(app->window)) {
|
||||||
|
|
@ -287,6 +331,7 @@ void mainLoop(Application *app) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cleanup(Application *app) {
|
void cleanup(Application *app) {
|
||||||
|
vkDestroyDevice(app->device, NULL);
|
||||||
if (enableValidationLayers) {
|
if (enableValidationLayers) {
|
||||||
DestroyDebugUtilsMessengerEXT(app->instance, app->debugMessenger, NULL);
|
DestroyDebugUtilsMessengerEXT(app->instance, app->debugMessenger, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue