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>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<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>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;shaderc_combinedd.lib;msdfgen-core.lib;msdfgen-ext.lib;msdf-atlas-gen.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<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>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;shaderc_combined.lib;msdfgen-core.lib;msdfgen-ext.lib;msdf-atlas-gen.lib;freetype.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<ShowAllFiles>true</ShowAllFiles>
|
<ShowAllFiles>true</ShowAllFiles>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<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>
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<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>
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -63,25 +63,26 @@ namespace Copium
|
|||||||
|
|
||||||
std::vector<VkPhysicalDevice> devices(deviceCount);
|
std::vector<VkPhysicalDevice> devices(deviceCount);
|
||||||
vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, devices.data());
|
vkEnumeratePhysicalDevices(Vulkan::GetInstance(), &deviceCount, devices.data());
|
||||||
|
|
||||||
|
std::vector<std::pair<VkPhysicalDevice, uint32_t>> devicePriorities;
|
||||||
|
devicePriorities.reserve(deviceCount);
|
||||||
CP_INFO("Available devices:");
|
CP_INFO("Available devices:");
|
||||||
for (auto&& device : devices)
|
for (auto&& device : devices)
|
||||||
{
|
{
|
||||||
VkPhysicalDeviceProperties deviceProperties;
|
VkPhysicalDeviceProperties deviceProperties;
|
||||||
vkGetPhysicalDeviceProperties(device, &deviceProperties);
|
vkGetPhysicalDeviceProperties(device, &deviceProperties);
|
||||||
CP_INFO_CONT("\t%s", deviceProperties.deviceName);
|
CP_INFO_CONT("\t%s", deviceProperties.deviceName);
|
||||||
|
devicePriorities.emplace_back(device, GetPhysicalDevicePriority(device));
|
||||||
}
|
}
|
||||||
for (auto&& device : devices)
|
|
||||||
{
|
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; });
|
||||||
if (IsPhysicalDeviceSuitable(device))
|
auto&& it = devicePriorities.begin();
|
||||||
{
|
CP_ASSERT(it->second != 0, "Failed to find suitable GPU");
|
||||||
|
|
||||||
VkPhysicalDeviceProperties deviceProperties;
|
VkPhysicalDeviceProperties deviceProperties;
|
||||||
vkGetPhysicalDeviceProperties(device, &deviceProperties);
|
vkGetPhysicalDeviceProperties(it->first, &deviceProperties);
|
||||||
physicalDevice = device;
|
physicalDevice = it->first;
|
||||||
CP_INFO("Selecting device: %s", deviceProperties.deviceName);
|
CP_INFO("Selecting device: %s", deviceProperties.deviceName);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CP_ASSERT(physicalDevice != VK_NULL_HANDLE, "Failed to find suitable GPU");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::InitializeLogicalDevice()
|
void Device::InitializeLogicalDevice()
|
||||||
@@ -130,30 +131,33 @@ namespace Copium
|
|||||||
CP_VK_ASSERT(vkCreateCommandPool(device, &createInfo, nullptr, &commandPool), "Failed to initialize command pool");
|
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;
|
VkPhysicalDeviceProperties deviceProperties;
|
||||||
vkGetPhysicalDeviceProperties(device, &deviceProperties);
|
vkGetPhysicalDeviceProperties(device, &deviceProperties);
|
||||||
if (deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
||||||
return false;
|
priority = 100;
|
||||||
|
else
|
||||||
|
priority = 50;
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures deviceFeatures;
|
VkPhysicalDeviceFeatures deviceFeatures;
|
||||||
vkGetPhysicalDeviceFeatures(device, &deviceFeatures);
|
vkGetPhysicalDeviceFeatures(device, &deviceFeatures);
|
||||||
if (!deviceFeatures.fillModeNonSolid || !deviceFeatures.samplerAnisotropy)
|
if (!deviceFeatures.fillModeNonSolid || !deviceFeatures.samplerAnisotropy)
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
QueueFamiliesQuery query{Vulkan::GetWindow().GetSurface(), device};
|
QueueFamiliesQuery query{Vulkan::GetWindow().GetSurface(), device};
|
||||||
if (!query.AllRequiredFamiliesSupported())
|
if (!query.AllRequiredFamiliesSupported())
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
if (!CheckDeviceExtensionSupport(device))
|
if (!CheckDeviceExtensionSupport(device))
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
SwapChainSupportDetails details{Vulkan::GetWindow().GetSurface(), device};
|
SwapChainSupportDetails details{Vulkan::GetWindow().GetSurface(), device};
|
||||||
if (!details.Valid())
|
if (!details.Valid())
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
return true;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::CheckDeviceExtensionSupport(VkPhysicalDevice device)
|
bool Device::CheckDeviceExtensionSupport(VkPhysicalDevice device)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Copium
|
|||||||
void SelectPhysicalDevice();
|
void SelectPhysicalDevice();
|
||||||
void InitializeLogicalDevice();
|
void InitializeLogicalDevice();
|
||||||
void InitializeCommandPool();
|
void InitializeCommandPool();
|
||||||
bool IsPhysicalDeviceSuitable(VkPhysicalDevice device);
|
uint32_t GetPhysicalDevicePriority(VkPhysicalDevice device);
|
||||||
bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
|
bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
|
||||||
std::vector<const char*> GetRequiredDeviceExtensions();
|
std::vector<const char*> GetRequiredDeviceExtensions();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Copium
|
|||||||
void Vulkan::Initialize()
|
void Vulkan::Initialize()
|
||||||
{
|
{
|
||||||
instance = std::make_unique<Instance>("Copium Engine");
|
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>();
|
device = std::make_unique<Device>();
|
||||||
swapChain = std::make_unique<SwapChain>();
|
swapChain = std::make_unique<SwapChain>();
|
||||||
|
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::BorderlessWindowed:
|
case WindowMode::BorderlessWindowed:
|
||||||
{
|
{
|
||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
|
||||||
|
glfwWindowHint(GLFW_DECORATED, false);
|
||||||
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
||||||
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::Windowed:
|
case WindowMode::Windowed:
|
||||||
@@ -83,6 +83,8 @@ namespace Copium
|
|||||||
|
|
||||||
void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
|
void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
|
||||||
{
|
{
|
||||||
|
if (width == 0 || height == 0)
|
||||||
|
return;
|
||||||
Vulkan::GetSwapChain().ResizeFramebuffer();
|
Vulkan::GetSwapChain().ResizeFramebuffer();
|
||||||
EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
|
EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,8 @@
|
|||||||
<ClCompile Include="..\..\repos\glfw\src\xkb_unicode.c" />
|
<ClCompile Include="..\..\repos\glfw\src\xkb_unicode.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\internal.h" />
|
||||||
<ClInclude Include="..\..\repos\glfw\src\mappings.h" />
|
<ClInclude Include="..\..\repos\glfw\src\mappings.h" />
|
||||||
<ClInclude Include="..\..\repos\glfw\src\null_joystick.h" />
|
<ClInclude Include="..\..\repos\glfw\src\null_joystick.h" />
|
||||||
|
|||||||
@@ -116,5 +116,11 @@
|
|||||||
<ClInclude Include="..\..\repos\glfw\src\null_platform.h">
|
<ClInclude Include="..\..\repos\glfw\src\null_platform.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</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>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user