From c609c5a35488c51343e144942ddd72b2f491b11b Mon Sep 17 00:00:00 2001 From: ink-soul Date: Wed, 17 Apr 2024 13:39:27 +0800 Subject: [PATCH] update GPUselection --- base/vulkanexamplebase.cpp | 24 ++++++------------------ base/vulkanexamplebase.h | 3 ++- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 64acbc6..1cb0fd5 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -481,31 +481,19 @@ void VulkanExampleBase::initVulkan() std::cerr << "Could not enumerate physical devices!" << std::endl; exit(err); } - uint32_t selectedDevice = 0; -#if !defined(VK_USE_PLATFORM_ANDROID_KHR) - for (size_t i = 0; i < args.size(); i++) { - if ((args[i] == std::string("-g")) || (args[i] == std::string("--gpu"))) { - char* endptr; - selectedPhysicalDeviceIndex = strtol(args[i + 1], &endptr, 10); - if (endptr != args[i + 1]) { - if (selectedPhysicalDeviceIndex > gpuCount - 1) { - std::cerr << "Selected device index " << selectedPhysicalDeviceIndex << " is out of range, reverting to device 0 (use -listgpus to show available Vulkan devices)" << std::endl; - } else { - std::cout << "Selected Vulkan device " << selectedPhysicalDeviceIndex << std::endl; - selectedDevice = selectedPhysicalDeviceIndex; - } - }; - break; - } + uint32_t selectedDevice = settings.selectedPhysicalDeviceIndex; + if (settings.selectedPhysicalDeviceIndex > gpuCount) + { + std::cerr << "wrong GPU selection,check selectedPhysicalDeviceIndex in config file,fallback to 0" << std::endl; + selectedDevice = 0; } -#endif physicalDevice = physicalDevices[selectedDevice]; vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties); vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures); vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties); - + /* queueFamilyIndex creation */ diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index bf371b1..354cd5f 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -80,7 +80,7 @@ protected: //void windowResize(); public: static std::vector args; - uint32_t selectedPhysicalDeviceIndex = 0; + bool prepared = false; uint32_t width = 1280; uint32_t height = 720; @@ -102,6 +102,7 @@ public: }signal; struct Settings { + uint32_t selectedPhysicalDeviceIndex = 7; bool validation = true; // 校验层开关 bool fullscreen = false; // 全屏开关 bool vsync = false; // 垂直同步开关