Create Vulkan device
This commit is contained in:
parent
89cdf712b8
commit
2b39c6e15b
@ -13,6 +13,9 @@ namespace nf::cli::render {
|
|||||||
, m_physicalDevice()
|
, m_physicalDevice()
|
||||||
, m_queueFIGraphics()
|
, m_queueFIGraphics()
|
||||||
, m_queueFIPresent()
|
, m_queueFIPresent()
|
||||||
|
, m_device()
|
||||||
|
, m_queueGraphics()
|
||||||
|
, m_queuePresent()
|
||||||
{
|
{
|
||||||
NFLog("Initializing render engine");
|
NFLog("Initializing render engine");
|
||||||
m_window->setDisplay(m_display);
|
m_window->setDisplay(m_display);
|
||||||
@ -21,6 +24,7 @@ namespace nf::cli::render {
|
|||||||
createInstance();
|
createInstance();
|
||||||
createSurface(m_window->getHandle());
|
createSurface(m_window->getHandle());
|
||||||
pickPhysicalDevice();
|
pickPhysicalDevice();
|
||||||
|
createDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderEngine::createInstance() {
|
void RenderEngine::createInstance() {
|
||||||
@ -125,7 +129,38 @@ namespace nf::cli::render {
|
|||||||
NFError("No Vulkan GPUs were found to be compatible");
|
NFError("No Vulkan GPUs were found to be compatible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderEngine::createDevice() {
|
||||||
|
std::set<uint32_t> uniqueQueueFamilyIndices = { m_queueFIGraphics, m_queueFIPresent };
|
||||||
|
|
||||||
|
float queuePriority = 1.0f;
|
||||||
|
std::vector<VkDeviceQueueCreateInfo> queueCIs;
|
||||||
|
for (uint32_t currentQueueFamilyIndex : uniqueQueueFamilyIndices) {
|
||||||
|
VkDeviceQueueCreateInfo queueCI = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO };
|
||||||
|
queueCI.queueFamilyIndex = currentQueueFamilyIndex;
|
||||||
|
queueCI.queueCount = 1;
|
||||||
|
queueCI.pQueuePriorities = &queuePriority;
|
||||||
|
queueCIs.push_back(queueCI);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPhysicalDeviceFeatures features = {};
|
||||||
|
|
||||||
|
VkDeviceCreateInfo deviceCI = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
|
||||||
|
deviceCI.queueCreateInfoCount = queueCIs.size();
|
||||||
|
deviceCI.pQueueCreateInfos = queueCIs.data();
|
||||||
|
deviceCI.pEnabledFeatures = &features;
|
||||||
|
|
||||||
|
const char* swapChainExtName = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
|
||||||
|
deviceCI.enabledExtensionCount = 1;
|
||||||
|
deviceCI.ppEnabledExtensionNames = &swapChainExtName;
|
||||||
|
if (vkCreateDevice(m_physicalDevice, &deviceCI, nullptr, &m_device) != VK_SUCCESS)
|
||||||
|
NFError("Could not create Vulkan device");
|
||||||
|
|
||||||
|
vkGetDeviceQueue(m_device, m_queueFIGraphics, 0, &m_queueGraphics);
|
||||||
|
vkGetDeviceQueue(m_device, m_queueFIPresent, 0, &m_queuePresent);
|
||||||
|
}
|
||||||
|
|
||||||
RenderEngine::~RenderEngine() {
|
RenderEngine::~RenderEngine() {
|
||||||
|
vkDestroyDevice(m_device, nullptr);
|
||||||
vkDestroySurfaceKHR(m_instance, m_surface, nullptr);
|
vkDestroySurfaceKHR(m_instance, m_surface, nullptr);
|
||||||
vkDestroyInstance(m_instance, nullptr);
|
vkDestroyInstance(m_instance, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace nf::cli::render {
|
|||||||
void createInstance();
|
void createInstance();
|
||||||
void createSurface(HWND window);
|
void createSurface(HWND window);
|
||||||
void pickPhysicalDevice();
|
void pickPhysicalDevice();
|
||||||
|
void createDevice();
|
||||||
|
|
||||||
std::shared_ptr<Window> m_window;
|
std::shared_ptr<Window> m_window;
|
||||||
DisplayConfig m_display;
|
DisplayConfig m_display;
|
||||||
@ -22,5 +23,7 @@ namespace nf::cli::render {
|
|||||||
VkSurfaceKHR m_surface;
|
VkSurfaceKHR m_surface;
|
||||||
VkPhysicalDevice m_physicalDevice;
|
VkPhysicalDevice m_physicalDevice;
|
||||||
uint32_t m_queueFIGraphics, m_queueFIPresent;
|
uint32_t m_queueFIGraphics, m_queueFIPresent;
|
||||||
|
VkDevice m_device;
|
||||||
|
VkQueue m_queueGraphics, m_queuePresent;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user