From 38f2ba69db8320a7ba3505fb3438cac63be82fef Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 31 Jan 2023 12:43:02 +0800 Subject: [PATCH] Force use of Dedicated GPU --- Assets/Editor/Editor.SHConfig | 2 +- .../src/Graphics/Devices/SHVkPhysicalDevice.h | 1 + .../Devices/SHVkPhysicalDeviceLibrary.cpp | 26 +++++++++++++++++-- .../Devices/SHVkPhysicalDeviceLibrary.h | 1 + .../src/Graphics/Instance/SHVkInstance.cpp | 2 ++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig index b492a983..c56772c9 100644 --- a/Assets/Editor/Editor.SHConfig +++ b/Assets/Editor/Editor.SHConfig @@ -1,4 +1,4 @@ Start Maximized: true Working Scene ID: 97402985 -Window Size: {x: 1920, y: 1080} +Window Size: {x: 1920, y: 1013} Style: 0 \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDevice.h b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDevice.h index a273da74..e2533106 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDevice.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDevice.h @@ -10,6 +10,7 @@ namespace SHADE enum class SH_PHYSICAL_DEVICE_TYPE { BEST, + DEDICATED, }; class SHVkPhysicalDevice diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.cpp index 050ca769..ebda72c8 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.cpp @@ -160,9 +160,31 @@ namespace SHADE } } + return bestDevice; } + vk::PhysicalDevice SHVkPhysicalDeviceLibrary::GetFirstDedicatedDevice(uint32_t apiVersion /*= SHVulkanAPIVersion::V_1_2*/) + { + if (!queried || physicalDevices.empty()) + return nullptr; + + for (auto const& device : physicalDevices) + { + // Check for API version and device type. Ignore if queried device doesn't support version passed in + if (device.getProperties().apiVersion < static_cast(apiVersion)) + continue; + + //VkDeviceSize biggestDeviceHeapSize = device.getMemoryProperties().; + if (device.getProperties().deviceType == vk::PhysicalDeviceType::eDiscreteGpu) + return device; + + } + + + return nullptr; + } + /***************************************************************************/ /*! @@ -181,10 +203,10 @@ namespace SHADE } #ifdef DEBUG - SHLOG_TRACE("Successfully queried Physical Devices:"); + SHLOG_INFO("Successfully queried Physical Devices:"); for (auto const& device : physicalDevices) { - SHLOG_TRACE(std::string_view (std::string("\t-") + GetDeviceTypeName(device.getProperties().deviceType) + device.getProperties().deviceName.operator std::string())); + SHLOG_INFO(std::string_view (std::string("\t-") + GetDeviceTypeName(device.getProperties().deviceType) + device.getProperties().deviceName.operator std::string())); } #endif diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.h b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.h index 79516987..4def81fa 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkPhysicalDeviceLibrary.h @@ -26,6 +26,7 @@ namespace SHADE static void QueryPhysicalDevices(bool printInfo) noexcept; //static std::vector> GetDevicesByType(VkPhysicalDeviceType gpuType, SHVulkanAPIVersion apiVersion = SHVulkanAPIVersion::V_1_2) noexcept; static vk::PhysicalDevice GetBestDevice(uint32_t apiVersion = VK_API_VERSION_1_3); + static vk::PhysicalDevice GetFirstDedicatedDevice(uint32_t apiVersion = VK_API_VERSION_1_3); }; } diff --git a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp index 237c6fee..067645ff 100644 --- a/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp +++ b/SHADE_Engine/src/Graphics/Instance/SHVkInstance.cpp @@ -213,6 +213,8 @@ namespace SHADE { case SH_PHYSICAL_DEVICE_TYPE::BEST: return resourceManager.Create(SHVkPhysicalDeviceLibrary::GetBestDevice()); + case SH_PHYSICAL_DEVICE_TYPE::DEDICATED: + return resourceManager.Create(SHVkPhysicalDeviceLibrary::GetFirstDedicatedDevice()); default: return resourceManager.Create(SHVkPhysicalDeviceLibrary::GetBestDevice()); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index c4990153..ca5841c1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -65,7 +65,7 @@ namespace SHADE #endif // Get Physical Device - physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST); + physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::DEDICATED); if (!physicalDevice->GetVkPhysicalDevice()) { throw std::runtime_error("[Graphics System] No supported Vulkan 1.3 compatible GPU was detected!"); -- 2.40.1