Fix vulkan linking issues and add iGPU support

- Fix vulkan linking by setting correct VK_LAYER_PATH and correct
  vulkan library path
- Add priority to GPU selection. Prioritizing dedicated GPUs over
  integrated GPUs
This commit is contained in:
Thraix
2023-05-14 20:24:04 +02:00
parent 412d74ade3
commit 05d2c2940b
8 changed files with 44 additions and 30 deletions
+24 -20
View File
@@ -63,25 +63,26 @@ namespace Copium
std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, devices.data());
std::vector<std::pair<VkPhysicalDevice, uint32_t>> devicePriorities;
devicePriorities.reserve(deviceCount);
CP_INFO("Available devices:");
for (auto&& device : devices)
{
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
CP_INFO_CONT("\t%s", deviceProperties.deviceName);
devicePriorities.emplace_back(device, GetPhysicalDevicePriority(device));
}
for (auto&& device : devices)
{
if (IsPhysicalDeviceSuitable(device))
{
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
physicalDevice = device;
CP_INFO("Selecting device: %s", deviceProperties.deviceName);
break;
}
}
CP_ASSERT(physicalDevice != VK_NULL_HANDLE, "Failed to find suitable GPU");
std::sort(devicePriorities.begin(), devicePriorities.end(), [](const std::pair<VkPhysicalDevice, uint32_t>& lhs, const std::pair<VkPhysicalDevice, uint32_t>& rhs) { return lhs.second > rhs.second; });
auto&& it = devicePriorities.begin();
CP_ASSERT(it->second != 0, "Failed to find suitable GPU");
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(it->first, &deviceProperties);
physicalDevice = it->first;
CP_INFO("Selecting device: %s", deviceProperties.deviceName);
}
void Device::InitializeLogicalDevice()
@@ -130,30 +131,33 @@ namespace Copium
CP_VK_ASSERT(vkCreateCommandPool(device, &createInfo, nullptr, &commandPool), "Failed to initialize command pool");
}
bool Device::IsPhysicalDeviceSuitable(VkPhysicalDevice device)
uint32_t Device::GetPhysicalDevicePriority(VkPhysicalDevice device)
{
uint32_t priority = 0;
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
if (deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
return false;
if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
priority = 100;
else
priority = 50;
VkPhysicalDeviceFeatures deviceFeatures;
vkGetPhysicalDeviceFeatures(device, &deviceFeatures);
if (!deviceFeatures.fillModeNonSolid || !deviceFeatures.samplerAnisotropy)
return false;
return 0;
QueueFamiliesQuery query{Vulkan::GetWindow().GetSurface(), device};
if (!query.AllRequiredFamiliesSupported())
return false;
return 0;
if (!CheckDeviceExtensionSupport(device))
return false;
return 0;
SwapChainSupportDetails details{Vulkan::GetWindow().GetSurface(), device};
if (!details.Valid())
return false;
return 0;
return true;
return priority;
}
bool Device::CheckDeviceExtensionSupport(VkPhysicalDevice device)
+1 -1
View File
@@ -38,7 +38,7 @@ namespace Copium
void SelectPhysicalDevice();
void InitializeLogicalDevice();
void InitializeCommandPool();
bool IsPhysicalDeviceSuitable(VkPhysicalDevice device);
uint32_t GetPhysicalDevicePriority(VkPhysicalDevice device);
bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
std::vector<const char*> GetRequiredDeviceExtensions();
};
+1 -1
View File
@@ -17,7 +17,7 @@ namespace Copium
void Vulkan::Initialize()
{
instance = std::make_unique<Instance>("Copium Engine");
window = std::make_unique<Window>("Copium Engine", 1920, 1080, WindowMode::Windowed);
window = std::make_unique<Window>("Copium Engine", 1440, 810, WindowMode::Windowed);
device = std::make_unique<Device>();
swapChain = std::make_unique<SwapChain>();
+6 -4
View File
@@ -45,15 +45,15 @@ namespace Copium
{
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), glfwGetPrimaryMonitor(), nullptr);
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr);
break;
}
case WindowMode::BorderlessWindowed:
{
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwWindowHint(GLFW_DECORATED, false);
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
break;
}
case WindowMode::Windowed:
@@ -83,6 +83,8 @@ namespace Copium
void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
{
if (width == 0 || height == 0)
return;
Vulkan::GetSwapChain().ResizeFramebuffer();
EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
}