Add Vulkan queue creation
This commit is contained in:
parent
44f91d99ea
commit
d9db9693b1
3 changed files with 38 additions and 1 deletions
|
@ -3,6 +3,8 @@ project(Graph)
|
|||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(Vulkan REQUIRED)
|
||||
|
||||
|
|
36
renderer.cpp
36
renderer.cpp
|
@ -1,5 +1,8 @@
|
|||
#include "renderer.h"
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
Renderer::Renderer() {
|
||||
createInstance();
|
||||
createLogicalDevice();
|
||||
|
@ -28,12 +31,43 @@ void Renderer::createLogicalDevice() {
|
|||
for(uint32_t i = 0; i < physicalDeviceCount; i++) {
|
||||
VkPhysicalDeviceProperties properties = {};
|
||||
vkGetPhysicalDeviceProperties(physicalDevices[i], &properties);
|
||||
|
||||
|
||||
physicalDevice = physicalDevices[i];
|
||||
}
|
||||
|
||||
uint32_t queueFamilyPropertiesCount = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyPropertiesCount, nullptr);
|
||||
|
||||
VkQueueFamilyProperties* queueFamilyProperties = new VkQueueFamilyProperties[queueFamilyPropertiesCount];
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyPropertiesCount, queueFamilyProperties);
|
||||
|
||||
uint32_t graphicsFamilyIndex = 0;
|
||||
|
||||
for(uint32_t i = 0; i < queueFamilyPropertiesCount; i++) {
|
||||
if(queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||
graphicsFamilyIndex = i;
|
||||
}
|
||||
|
||||
const std::set<uint32_t> queueFamilyIndices = {graphicsFamilyIndex};
|
||||
std::vector<VkDeviceQueueCreateInfo> deviceQueueCreateInfos;
|
||||
for(auto queueFamilyIndex : queueFamilyIndices) {
|
||||
const float priority = 1.0f;
|
||||
|
||||
VkDeviceQueueCreateInfo queueCreateInfo = {};
|
||||
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
|
||||
queueCreateInfo.queueCount = 1;
|
||||
queueCreateInfo.pQueuePriorities = &priority;
|
||||
|
||||
deviceQueueCreateInfos.push_back(queueCreateInfo);
|
||||
}
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo = {};
|
||||
deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
deviceCreateInfo.queueCreateInfoCount = deviceQueueCreateInfos.size();
|
||||
deviceCreateInfo.pQueueCreateInfos = deviceQueueCreateInfos.data();
|
||||
|
||||
vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &device_);
|
||||
|
||||
vkGetDeviceQueue(device_, graphicsFamilyIndex, 0, &graphicsQueue_);
|
||||
}
|
||||
|
|
|
@ -14,4 +14,5 @@ private:
|
|||
VkInstance instance_ = nullptr;
|
||||
|
||||
VkDevice device_ = nullptr;
|
||||
VkQueue graphicsQueue_ = nullptr;
|
||||
};
|
||||
|
|
Reference in a new issue