update GPUselection

main-headless
ink-soul 2024-04-17 13:39:27 +08:00
parent dfeca1b376
commit c609c5a354
2 changed files with 8 additions and 19 deletions

View File

@ -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
*/

View File

@ -80,7 +80,7 @@ protected:
//void windowResize();
public:
static std::vector<const char*> 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; // 垂直同步开关