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:
@@ -127,7 +127,7 @@
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)libs\$(Platform)\$(Configuration)\;C:/VulkanSDK/1.3.236.0/Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)libs\$(Platform)\$(Configuration)\;$(VULKAN_SDK)/Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;shaderc_combinedd.lib;msdfgen-core.lib;msdfgen-ext.lib;msdf-atlas-gen.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
@@ -156,7 +156,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)libs\$(Platform)\$(Configuration)\;C:/VulkanSDK/1.3.236.0/Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)libs\$(Platform)\$(Configuration)\;$(VULKAN_SDK)/Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;shaderc_combined.lib;msdfgen-core.lib;msdfgen-ext.lib;msdf-atlas-gen.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerEnvironment>VK_LAYER_PATH=C:\VulkanSDK\1.3.236.0\Bin</LocalDebuggerEnvironment>
|
||||
<LocalDebuggerEnvironment>VK_LAYER_PATH=$(VULKAN_SDK)\Bin</LocalDebuggerEnvironment>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LocalDebuggerEnvironment>VK_LAYER_PATH=C:\VulkanSDK\1.3.236.0\Bin</LocalDebuggerEnvironment>
|
||||
<LocalDebuggerEnvironment>VK_LAYER_PATH=$(VULKAN_SDK)\Bin</LocalDebuggerEnvironment>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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>();
|
||||
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
@@ -161,6 +161,8 @@
|
||||
<ClCompile Include="..\..\repos\glfw\src\xkb_unicode.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\repos\glfw\include\GLFW\glfw3.h" />
|
||||
<ClInclude Include="..\..\repos\glfw\include\GLFW\glfw3native.h" />
|
||||
<ClInclude Include="..\..\repos\glfw\src\internal.h" />
|
||||
<ClInclude Include="..\..\repos\glfw\src\mappings.h" />
|
||||
<ClInclude Include="..\..\repos\glfw\src\null_joystick.h" />
|
||||
|
||||
@@ -116,5 +116,11 @@
|
||||
<ClInclude Include="..\..\repos\glfw\src\null_platform.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\repos\glfw\include\GLFW\glfw3.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\repos\glfw\include\GLFW\glfw3native.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user