From 13533bd053d71065e3e1510ea884eb05f3be96f9 Mon Sep 17 00:00:00 2001 From: francoisatt Date: Mon, 31 Aug 2026 01:43:17 +0200 Subject: [PATCH] cli: add --gpu to select a Vulkan physical deviceFeature gpu select (#417) * cli: add --gpu to select a Vulkan physical device Select the Vulkan physical device by enumeration index, defaulting to automatic selection (-1). Invalid or out-of-range indices fall back to automatic selection with a clear message, and the selected device is logged. Co-Authored-By: Claude * cli: reject invalid --gpu index, translate comments, apply clang-format An invalid --gpu index now prints an error and exits with code 1 (usage), matching --user-id / --present-mode / --console-language. The automatic fallback is kept only for out-of-range indices detected at runtime. Comments translated to English and the touched files brought in line with clang-format (pre-commit v22.1.3). Co-Authored-By: Claude * cli: simplify Vulkan device selection --------- Co-authored-by: Claude Co-authored-by: nmzik --- src/common/emulatorConfig.cpp | 4 ++++ src/common/emulatorConfig.h | 2 ++ src/graphics/presentation/window/vulkanWindow.cpp | 4 ++++ src/main.cpp | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/src/common/emulatorConfig.cpp b/src/common/emulatorConfig.cpp index 0a716e9b2..5e77e8e6d 100644 --- a/src/common/emulatorConfig.cpp +++ b/src/common/emulatorConfig.cpp @@ -47,6 +47,10 @@ PresentMode GetPresentMode() { return g_config->present_mode; } +int32_t GetGpuIndex() { + return g_config->gpu_index; +} + bool FullscreenEnabled() { return g_config->fullscreen_enabled; } diff --git a/src/common/emulatorConfig.h b/src/common/emulatorConfig.h index 0b21fc82a..ea2793243 100644 --- a/src/common/emulatorConfig.h +++ b/src/common/emulatorConfig.h @@ -48,6 +48,7 @@ struct ConfigOptions { std::string user_name = "Kyty"; int32_t user_id = DEFAULT_USER_ID; PresentMode present_mode = PresentMode::Fifo; + int32_t gpu_index = -1; bool fullscreen_enabled = false; uint32_t vblank_frequency = 60; uint32_t console_language = DEFAULT_CONSOLE_LANGUAGE; @@ -80,6 +81,7 @@ uint32_t GetScreenHeight(); const std::string& GetUserName(); int32_t GetUserId(); PresentMode GetPresentMode(); +int32_t GetGpuIndex(); bool FullscreenEnabled(); uint32_t GetVblankFrequency(); uint32_t GetConsoleLanguage(); diff --git a/src/graphics/presentation/window/vulkanWindow.cpp b/src/graphics/presentation/window/vulkanWindow.cpp index 1ebdc831a..ae67bea18 100644 --- a/src/graphics/presentation/window/vulkanWindow.cpp +++ b/src/graphics/presentation/window/vulkanWindow.cpp @@ -157,6 +157,10 @@ static void VulkanFindPhysicalDevice(vk::Instance instance, vk::SurfaceKHR surfa }); EXIT_NOT_IMPLEMENTED(devices.empty()); + if (Config::GetGpuIndex() >= 0) { + devices = {devices[Config::GetGpuIndex()]}; + } + vk::PhysicalDevice best_device = nullptr; uint32_t best_queue_family = static_cast(-1); SurfaceCapabilities best_capabilities; diff --git a/src/main.cpp b/src/main.cpp index e186fea52..9248f7fc9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,6 +52,8 @@ static void PrintUsage() { Config::DEFAULT_USER_ID); ::printf( " --present-mode Fifo, Mailbox, or Immediate. Default: Fifo.\n"); + ::printf( + " --gpu Vulkan physical device index. Default: auto.\n"); ::printf(" --fullscreen Run in borderless desktop fullscreen.\n"); ::printf(" --vblank-frequency Virtual vblank frequency. Default: 60.\n"); ::printf(" --console-language <0-29> Console language. Default: 1 (English US).\n"); @@ -234,6 +236,8 @@ static bool ParseArgs(int argc, char* argv[], RunOptions& options, bool& show_he ::printf("invalid present mode: %s\n", value.c_str()); return false; } + } else if (arg == "--gpu") { + options.config.gpu_index = Common::ToInt32(value); } else if (arg == "--vblank-frequency") { const int32_t vblank_frequency = Common::ToInt32(value); options.config.vblank_frequency =