From aa847f9c83b5b917d9ed2207b92bcdeed65862a7 Mon Sep 17 00:00:00 2001 From: JC Date: Fri, 28 Jan 2022 11:38:43 -0800 Subject: [PATCH 1/3] use multiple CPU threads to compile --- unixBuild.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unixBuild.sh b/unixBuild.sh index 5fc6e80..78582be 100755 --- a/unixBuild.sh +++ b/unixBuild.sh @@ -2,5 +2,6 @@ mkdir -p build cd build cmake -S ../ -B . +export MAKEFLAGS=-j$(nproc) make && make Shaders && ./LveEngine -cd .. \ No newline at end of file +cd .. From 7500bfde4b405738ee68e99f0ddbbd0e6a2cc34c Mon Sep 17 00:00:00 2001 From: JC Date: Fri, 28 Jan 2022 15:40:35 -0800 Subject: [PATCH 2/3] Update unixBuild.sh --- unixBuild.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unixBuild.sh b/unixBuild.sh index 78582be..5280075 100755 --- a/unixBuild.sh +++ b/unixBuild.sh @@ -2,6 +2,10 @@ mkdir -p build cd build cmake -S ../ -B . -export MAKEFLAGS=-j$(nproc) +if [ -z "$MAKEFLAGS" ] +then + export MAKEFLAGS=-j$(nproc) +fi + make && make Shaders && ./LveEngine cd .. From 1abb1d7139553f06b7eb39fe1586b305c6bb151c Mon Sep 17 00:00:00 2001 From: JC Date: Sun, 30 Jan 2022 18:54:55 -0800 Subject: [PATCH 3/3] selecting a dedicated GPU if possible --- src/lve_device.cpp | 25 ++++++++++++++++++++++--- src/lve_device.hpp | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lve_device.cpp b/src/lve_device.cpp index 601e6f0..31ad6fd 100644 --- a/src/lve_device.cpp +++ b/src/lve_device.cpp @@ -119,7 +119,14 @@ void LveDevice::pickPhysicalDevice() { vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); for (const auto &device : devices) { - if (isDeviceSuitable(device)) { + if (isPreferredDevice(device)) { + physicalDevice = device; + return; + } + } + + for (const auto &device : devices) { + if (isSuitableDevice(device)) { physicalDevice = device; break; } @@ -195,7 +202,19 @@ void LveDevice::createCommandPool() { void LveDevice::createSurface() { window.createWindowSurface(instance, &surface_); } -bool LveDevice::isDeviceSuitable(VkPhysicalDevice device) { +bool LveDevice::isPreferredDevice(VkPhysicalDevice device) { + if (!isSuitableDevice(device)) + { + return false; + } + + auto props = VkPhysicalDeviceProperties{}; + vkGetPhysicalDeviceProperties(device, &props); + + return props.deviceType == VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; +} + +bool LveDevice::isSuitableDevice(VkPhysicalDevice device) { QueueFamilyIndices indices = findQueueFamilies(device); bool extensionsSupported = checkDeviceExtensionSupport(device); @@ -530,4 +549,4 @@ void LveDevice::createImageWithInfo( } } -} // namespace lve \ No newline at end of file +} // namespace lve diff --git a/src/lve_device.hpp b/src/lve_device.hpp index fd664b0..a7f4244 100644 --- a/src/lve_device.hpp +++ b/src/lve_device.hpp @@ -81,7 +81,8 @@ class LveDevice { void createCommandPool(); // helper functions - bool isDeviceSuitable(VkPhysicalDevice device); + bool isSuitableDevice(VkPhysicalDevice device); + bool isPreferredDevice(VkPhysicalDevice device); std::vector getRequiredExtensions(); bool checkValidationLayerSupport(); QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);