configure_graphics.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. // SPDX-FileCopyrightText: 2016 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. // Include this early to include Vulkan headers how we want to
  4. #include "video_core/vulkan_common/vulkan_wrapper.h"
  5. #include <vector>
  6. #include <QColorDialog>
  7. #include <QGuiApplication>
  8. #include <QVulkanInstance>
  9. #include <QWindow>
  10. #include <vulkan/vulkan_core.h>
  11. #include "bootmanager.h"
  12. #include "common/common_types.h"
  13. #include "common/logging/log.h"
  14. #include "common/settings.h"
  15. #include "core/core.h"
  16. #include "core/frontend/emu_window.h"
  17. #include "ui_configure_graphics.h"
  18. #include "video_core/vulkan_common/vulkan_instance.h"
  19. #include "video_core/vulkan_common/vulkan_library.h"
  20. #include "video_core/vulkan_common/vulkan_surface.h"
  21. #include "yuzu/configuration/configuration_shared.h"
  22. #include "yuzu/configuration/configure_graphics.h"
  23. #include "yuzu/qt_common.h"
  24. #include "yuzu/uisettings.h"
  25. static const std::vector<VkPresentModeKHR> default_present_modes{VK_PRESENT_MODE_IMMEDIATE_KHR,
  26. VK_PRESENT_MODE_FIFO_KHR};
  27. // Converts a setting to a present mode (or vice versa)
  28. static constexpr VkPresentModeKHR VSyncSettingToMode(Settings::VSyncMode mode) {
  29. switch (mode) {
  30. case Settings::VSyncMode::Immediate:
  31. return VK_PRESENT_MODE_IMMEDIATE_KHR;
  32. case Settings::VSyncMode::Mailbox:
  33. return VK_PRESENT_MODE_MAILBOX_KHR;
  34. case Settings::VSyncMode::FIFO:
  35. return VK_PRESENT_MODE_FIFO_KHR;
  36. case Settings::VSyncMode::FIFORelaxed:
  37. return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
  38. default:
  39. return VK_PRESENT_MODE_FIFO_KHR;
  40. }
  41. }
  42. static constexpr Settings::VSyncMode PresentModeToSetting(VkPresentModeKHR mode) {
  43. switch (mode) {
  44. case VK_PRESENT_MODE_IMMEDIATE_KHR:
  45. return Settings::VSyncMode::Immediate;
  46. case VK_PRESENT_MODE_MAILBOX_KHR:
  47. return Settings::VSyncMode::Mailbox;
  48. case VK_PRESENT_MODE_FIFO_KHR:
  49. return Settings::VSyncMode::FIFO;
  50. case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
  51. return Settings::VSyncMode::FIFORelaxed;
  52. default:
  53. return Settings::VSyncMode::FIFO;
  54. }
  55. }
  56. ConfigureGraphics::ConfigureGraphics(const Core::System& system_, QWidget* parent)
  57. : QWidget(parent), ui{std::make_unique<Ui::ConfigureGraphics>()}, system{system_} {
  58. vulkan_device = Settings::values.vulkan_device.GetValue();
  59. RetrieveVulkanDevices();
  60. ui->setupUi(this);
  61. for (const auto& device : vulkan_devices) {
  62. ui->device->addItem(device);
  63. }
  64. ui->backend->addItem(QStringLiteral("GLSL"));
  65. ui->backend->addItem(tr("GLASM (Assembly Shaders, NVIDIA Only)"));
  66. ui->backend->addItem(tr("SPIR-V (Experimental, Mesa Only)"));
  67. SetupPerGameUI();
  68. SetConfiguration();
  69. connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, [this] {
  70. UpdateAPILayout();
  71. PopulateVSyncModeSelection();
  72. if (!Settings::IsConfiguringGlobal()) {
  73. ConfigurationShared::SetHighlight(
  74. ui->api_widget, ui->api->currentIndex() != ConfigurationShared::USE_GLOBAL_INDEX);
  75. }
  76. });
  77. connect(ui->device, qOverload<int>(&QComboBox::activated), this, [this](int device) {
  78. UpdateDeviceSelection(device);
  79. PopulateVSyncModeSelection();
  80. });
  81. connect(ui->backend, qOverload<int>(&QComboBox::activated), this,
  82. [this](int backend) { UpdateShaderBackendSelection(backend); });
  83. connect(ui->bg_button, &QPushButton::clicked, this, [this] {
  84. const QColor new_bg_color = QColorDialog::getColor(bg_color);
  85. if (!new_bg_color.isValid()) {
  86. return;
  87. }
  88. UpdateBackgroundColorButton(new_bg_color);
  89. });
  90. ui->api->setEnabled(!UISettings::values.has_broken_vulkan && ui->api->isEnabled());
  91. ui->api_widget->setEnabled(
  92. (!UISettings::values.has_broken_vulkan || Settings::IsConfiguringGlobal()) &&
  93. ui->api_widget->isEnabled());
  94. ui->bg_label->setVisible(Settings::IsConfiguringGlobal());
  95. ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal());
  96. connect(ui->fsr_sharpening_slider, &QSlider::valueChanged, this,
  97. &ConfigureGraphics::SetFSRIndicatorText);
  98. ui->fsr_sharpening_combobox->setVisible(!Settings::IsConfiguringGlobal());
  99. ui->fsr_sharpening_label->setVisible(Settings::IsConfiguringGlobal());
  100. }
  101. void ConfigureGraphics::PopulateVSyncModeSelection() {
  102. const Settings::RendererBackend backend{GetCurrentGraphicsBackend()};
  103. if (backend == Settings::RendererBackend::Null) {
  104. ui->vsync_mode_combobox->setEnabled(false);
  105. return;
  106. }
  107. ui->vsync_mode_combobox->setEnabled(true);
  108. const int current_index = //< current selected vsync mode from combobox
  109. ui->vsync_mode_combobox->currentIndex();
  110. const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR
  111. current_index == -1 ? VSyncSettingToMode(Settings::values.vsync_mode.GetValue())
  112. : vsync_mode_combobox_enum_map[current_index];
  113. int index{};
  114. const int device{ui->device->currentIndex()}; //< current selected Vulkan device
  115. const auto& present_modes = //< relevant vector of present modes for the selected device or API
  116. backend == Settings::RendererBackend::Vulkan ? device_present_modes[device]
  117. : default_present_modes;
  118. ui->vsync_mode_combobox->clear();
  119. vsync_mode_combobox_enum_map.clear();
  120. vsync_mode_combobox_enum_map.reserve(present_modes.size());
  121. for (const auto present_mode : present_modes) {
  122. const auto mode_name = TranslateVSyncMode(present_mode, backend);
  123. if (mode_name.isEmpty()) {
  124. continue;
  125. }
  126. ui->vsync_mode_combobox->insertItem(index, mode_name);
  127. vsync_mode_combobox_enum_map.push_back(present_mode);
  128. if (present_mode == current_mode) {
  129. ui->vsync_mode_combobox->setCurrentIndex(index);
  130. }
  131. index++;
  132. }
  133. }
  134. void ConfigureGraphics::UpdateDeviceSelection(int device) {
  135. if (device == -1) {
  136. return;
  137. }
  138. if (GetCurrentGraphicsBackend() == Settings::RendererBackend::Vulkan) {
  139. vulkan_device = device;
  140. }
  141. }
  142. void ConfigureGraphics::UpdateShaderBackendSelection(int backend) {
  143. if (backend == -1) {
  144. return;
  145. }
  146. if (GetCurrentGraphicsBackend() == Settings::RendererBackend::OpenGL) {
  147. shader_backend = static_cast<Settings::ShaderBackend>(backend);
  148. }
  149. }
  150. ConfigureGraphics::~ConfigureGraphics() = default;
  151. void ConfigureGraphics::SetConfiguration() {
  152. const bool runtime_lock = !system.IsPoweredOn();
  153. ui->api_widget->setEnabled(runtime_lock);
  154. ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock);
  155. ui->use_disk_shader_cache->setEnabled(runtime_lock);
  156. ui->nvdec_emulation_widget->setEnabled(runtime_lock);
  157. ui->resolution_combobox->setEnabled(runtime_lock);
  158. ui->accelerate_astc->setEnabled(runtime_lock);
  159. ui->vsync_mode_layout->setEnabled(runtime_lock ||
  160. Settings::values.renderer_backend.GetValue() ==
  161. Settings::RendererBackend::Vulkan);
  162. ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue());
  163. ui->use_asynchronous_gpu_emulation->setChecked(
  164. Settings::values.use_asynchronous_gpu_emulation.GetValue());
  165. ui->accelerate_astc->setChecked(Settings::values.accelerate_astc.GetValue());
  166. if (Settings::IsConfiguringGlobal()) {
  167. ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue()));
  168. ui->fullscreen_mode_combobox->setCurrentIndex(
  169. static_cast<int>(Settings::values.fullscreen_mode.GetValue()));
  170. ui->nvdec_emulation->setCurrentIndex(
  171. static_cast<int>(Settings::values.nvdec_emulation.GetValue()));
  172. ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue());
  173. ui->resolution_combobox->setCurrentIndex(
  174. static_cast<int>(Settings::values.resolution_setup.GetValue()));
  175. ui->scaling_filter_combobox->setCurrentIndex(
  176. static_cast<int>(Settings::values.scaling_filter.GetValue()));
  177. ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue());
  178. ui->anti_aliasing_combobox->setCurrentIndex(
  179. static_cast<int>(Settings::values.anti_aliasing.GetValue()));
  180. } else {
  181. ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend);
  182. ConfigurationShared::SetHighlight(ui->api_widget,
  183. !Settings::values.renderer_backend.UsingGlobal());
  184. ConfigurationShared::SetPerGameSetting(ui->nvdec_emulation,
  185. &Settings::values.nvdec_emulation);
  186. ConfigurationShared::SetHighlight(ui->nvdec_emulation_widget,
  187. !Settings::values.nvdec_emulation.UsingGlobal());
  188. ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox,
  189. &Settings::values.fullscreen_mode);
  190. ConfigurationShared::SetHighlight(ui->fullscreen_mode_label,
  191. !Settings::values.fullscreen_mode.UsingGlobal());
  192. ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox,
  193. &Settings::values.aspect_ratio);
  194. ConfigurationShared::SetHighlight(ui->ar_label,
  195. !Settings::values.aspect_ratio.UsingGlobal());
  196. ConfigurationShared::SetPerGameSetting(ui->resolution_combobox,
  197. &Settings::values.resolution_setup);
  198. ConfigurationShared::SetHighlight(ui->resolution_label,
  199. !Settings::values.resolution_setup.UsingGlobal());
  200. ConfigurationShared::SetPerGameSetting(ui->scaling_filter_combobox,
  201. &Settings::values.scaling_filter);
  202. ConfigurationShared::SetHighlight(ui->scaling_filter_label,
  203. !Settings::values.scaling_filter.UsingGlobal());
  204. ConfigurationShared::SetPerGameSetting(ui->anti_aliasing_combobox,
  205. &Settings::values.anti_aliasing);
  206. ConfigurationShared::SetHighlight(ui->anti_aliasing_label,
  207. !Settings::values.anti_aliasing.UsingGlobal());
  208. ui->fsr_sharpening_combobox->setCurrentIndex(
  209. Settings::values.fsr_sharpening_slider.UsingGlobal() ? 0 : 1);
  210. ui->fsr_sharpening_slider->setEnabled(
  211. !Settings::values.fsr_sharpening_slider.UsingGlobal());
  212. ui->fsr_sharpening_value->setEnabled(!Settings::values.fsr_sharpening_slider.UsingGlobal());
  213. ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout,
  214. !Settings::values.fsr_sharpening_slider.UsingGlobal());
  215. ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue());
  216. ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1);
  217. ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal());
  218. ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal());
  219. }
  220. UpdateBackgroundColorButton(QColor::fromRgb(Settings::values.bg_red.GetValue(),
  221. Settings::values.bg_green.GetValue(),
  222. Settings::values.bg_blue.GetValue()));
  223. UpdateAPILayout();
  224. PopulateVSyncModeSelection(); //< must happen after UpdateAPILayout
  225. SetFSRIndicatorText(ui->fsr_sharpening_slider->sliderPosition());
  226. // V-Sync setting needs to be determined after populating the V-Sync combobox
  227. if (Settings::IsConfiguringGlobal()) {
  228. const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue();
  229. const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting);
  230. int index{};
  231. for (const auto mode : vsync_mode_combobox_enum_map) {
  232. if (mode == vsync_mode) {
  233. break;
  234. }
  235. index++;
  236. }
  237. if (static_cast<unsigned long>(index) < vsync_mode_combobox_enum_map.size()) {
  238. ui->vsync_mode_combobox->setCurrentIndex(index);
  239. }
  240. }
  241. }
  242. void ConfigureGraphics::SetFSRIndicatorText(int percentage) {
  243. ui->fsr_sharpening_value->setText(
  244. tr("%1%", "FSR sharpening percentage (e.g. 50%)").arg(100 - (percentage / 2)));
  245. }
  246. const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode,
  247. Settings::RendererBackend backend) const {
  248. switch (mode) {
  249. case VK_PRESENT_MODE_IMMEDIATE_KHR:
  250. return backend == Settings::RendererBackend::OpenGL
  251. ? tr("Off")
  252. : QStringLiteral("Immediate (%1)").arg(tr("V-Sync Off"));
  253. case VK_PRESENT_MODE_MAILBOX_KHR:
  254. return QStringLiteral("Mailbox (%1)").arg(tr("Recommended"));
  255. case VK_PRESENT_MODE_FIFO_KHR:
  256. return backend == Settings::RendererBackend::OpenGL
  257. ? tr("On")
  258. : QStringLiteral("FIFO (%1)").arg(tr("V-Sync On"));
  259. case VK_PRESENT_MODE_FIFO_RELAXED_KHR:
  260. return QStringLiteral("FIFO Relaxed");
  261. default:
  262. return {};
  263. break;
  264. }
  265. }
  266. void ConfigureGraphics::ApplyConfiguration() {
  267. const auto resolution_setup = static_cast<Settings::ResolutionSetup>(
  268. ui->resolution_combobox->currentIndex() -
  269. ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
  270. const auto scaling_filter = static_cast<Settings::ScalingFilter>(
  271. ui->scaling_filter_combobox->currentIndex() -
  272. ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
  273. const auto anti_aliasing = static_cast<Settings::AntiAliasing>(
  274. ui->anti_aliasing_combobox->currentIndex() -
  275. ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
  276. ConfigurationShared::ApplyPerGameSetting(&Settings::values.fullscreen_mode,
  277. ui->fullscreen_mode_combobox);
  278. ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio,
  279. ui->aspect_ratio_combobox);
  280. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache,
  281. ui->use_disk_shader_cache, use_disk_shader_cache);
  282. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation,
  283. ui->use_asynchronous_gpu_emulation,
  284. use_asynchronous_gpu_emulation);
  285. ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, ui->accelerate_astc,
  286. accelerate_astc);
  287. if (Settings::IsConfiguringGlobal()) {
  288. // Guard if during game and set to game-specific value
  289. if (Settings::values.renderer_backend.UsingGlobal()) {
  290. Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend());
  291. }
  292. if (Settings::values.nvdec_emulation.UsingGlobal()) {
  293. Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation());
  294. }
  295. if (Settings::values.shader_backend.UsingGlobal()) {
  296. Settings::values.shader_backend.SetValue(shader_backend);
  297. }
  298. if (Settings::values.vulkan_device.UsingGlobal()) {
  299. Settings::values.vulkan_device.SetValue(vulkan_device);
  300. }
  301. if (Settings::values.bg_red.UsingGlobal()) {
  302. Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
  303. Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
  304. Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
  305. }
  306. if (Settings::values.resolution_setup.UsingGlobal()) {
  307. Settings::values.resolution_setup.SetValue(resolution_setup);
  308. }
  309. if (Settings::values.scaling_filter.UsingGlobal()) {
  310. Settings::values.scaling_filter.SetValue(scaling_filter);
  311. }
  312. if (Settings::values.anti_aliasing.UsingGlobal()) {
  313. Settings::values.anti_aliasing.SetValue(anti_aliasing);
  314. }
  315. Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value());
  316. const auto mode = vsync_mode_combobox_enum_map[ui->vsync_mode_combobox->currentIndex()];
  317. const auto vsync_mode = PresentModeToSetting(mode);
  318. Settings::values.vsync_mode.SetValue(vsync_mode);
  319. } else {
  320. if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  321. Settings::values.resolution_setup.SetGlobal(true);
  322. } else {
  323. Settings::values.resolution_setup.SetGlobal(false);
  324. Settings::values.resolution_setup.SetValue(resolution_setup);
  325. }
  326. if (ui->scaling_filter_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  327. Settings::values.scaling_filter.SetGlobal(true);
  328. } else {
  329. Settings::values.scaling_filter.SetGlobal(false);
  330. Settings::values.scaling_filter.SetValue(scaling_filter);
  331. }
  332. if (ui->anti_aliasing_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  333. Settings::values.anti_aliasing.SetGlobal(true);
  334. } else {
  335. Settings::values.anti_aliasing.SetGlobal(false);
  336. Settings::values.anti_aliasing.SetValue(anti_aliasing);
  337. }
  338. if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  339. Settings::values.renderer_backend.SetGlobal(true);
  340. Settings::values.shader_backend.SetGlobal(true);
  341. Settings::values.vulkan_device.SetGlobal(true);
  342. } else {
  343. Settings::values.renderer_backend.SetGlobal(false);
  344. Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend());
  345. switch (GetCurrentGraphicsBackend()) {
  346. case Settings::RendererBackend::OpenGL:
  347. case Settings::RendererBackend::Null:
  348. Settings::values.shader_backend.SetGlobal(false);
  349. Settings::values.vulkan_device.SetGlobal(true);
  350. Settings::values.shader_backend.SetValue(shader_backend);
  351. break;
  352. case Settings::RendererBackend::Vulkan:
  353. Settings::values.shader_backend.SetGlobal(true);
  354. Settings::values.vulkan_device.SetGlobal(false);
  355. Settings::values.vulkan_device.SetValue(vulkan_device);
  356. break;
  357. }
  358. }
  359. if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  360. Settings::values.nvdec_emulation.SetGlobal(true);
  361. } else {
  362. Settings::values.nvdec_emulation.SetGlobal(false);
  363. Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation());
  364. }
  365. if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  366. Settings::values.bg_red.SetGlobal(true);
  367. Settings::values.bg_green.SetGlobal(true);
  368. Settings::values.bg_blue.SetGlobal(true);
  369. } else {
  370. Settings::values.bg_red.SetGlobal(false);
  371. Settings::values.bg_green.SetGlobal(false);
  372. Settings::values.bg_blue.SetGlobal(false);
  373. Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
  374. Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
  375. Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
  376. }
  377. if (ui->fsr_sharpening_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  378. Settings::values.fsr_sharpening_slider.SetGlobal(true);
  379. } else {
  380. Settings::values.fsr_sharpening_slider.SetGlobal(false);
  381. Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value());
  382. }
  383. }
  384. }
  385. void ConfigureGraphics::changeEvent(QEvent* event) {
  386. if (event->type() == QEvent::LanguageChange) {
  387. RetranslateUI();
  388. }
  389. QWidget::changeEvent(event);
  390. }
  391. void ConfigureGraphics::RetranslateUI() {
  392. ui->retranslateUi(this);
  393. }
  394. void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
  395. bg_color = color;
  396. QPixmap pixmap(ui->bg_button->size());
  397. pixmap.fill(bg_color);
  398. const QIcon color_icon(pixmap);
  399. ui->bg_button->setIcon(color_icon);
  400. }
  401. void ConfigureGraphics::UpdateAPILayout() {
  402. if (!Settings::IsConfiguringGlobal() &&
  403. ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  404. vulkan_device = Settings::values.vulkan_device.GetValue(true);
  405. shader_backend = Settings::values.shader_backend.GetValue(true);
  406. ui->device_widget->setEnabled(false);
  407. ui->backend_widget->setEnabled(false);
  408. } else {
  409. vulkan_device = Settings::values.vulkan_device.GetValue();
  410. shader_backend = Settings::values.shader_backend.GetValue();
  411. ui->device_widget->setEnabled(true);
  412. ui->backend_widget->setEnabled(true);
  413. }
  414. switch (GetCurrentGraphicsBackend()) {
  415. case Settings::RendererBackend::OpenGL:
  416. ui->backend->setCurrentIndex(static_cast<u32>(shader_backend));
  417. ui->device_widget->setVisible(false);
  418. ui->backend_widget->setVisible(true);
  419. break;
  420. case Settings::RendererBackend::Vulkan:
  421. if (static_cast<int>(vulkan_device) < ui->device->count()) {
  422. ui->device->setCurrentIndex(vulkan_device);
  423. }
  424. ui->device_widget->setVisible(true);
  425. ui->backend_widget->setVisible(false);
  426. break;
  427. case Settings::RendererBackend::Null:
  428. ui->device_widget->setVisible(false);
  429. ui->backend_widget->setVisible(false);
  430. break;
  431. }
  432. }
  433. void ConfigureGraphics::RetrieveVulkanDevices() try {
  434. if (UISettings::values.has_broken_vulkan) {
  435. return;
  436. }
  437. using namespace Vulkan;
  438. auto* window = this->window()->windowHandle();
  439. auto wsi = YuzuQtCommon::GetWindowSystemInfo(window);
  440. vk::InstanceDispatch dld;
  441. const Common::DynamicLibrary library = OpenLibrary();
  442. const vk::Instance instance = CreateInstance(library, dld, VK_API_VERSION_1_1, wsi.type);
  443. const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices();
  444. vk::SurfaceKHR surface = //< needed to view present modes for a device
  445. CreateSurface(instance, wsi);
  446. vulkan_devices.clear();
  447. vulkan_devices.reserve(physical_devices.size());
  448. device_present_modes.clear();
  449. device_present_modes.reserve(physical_devices.size());
  450. for (const VkPhysicalDevice device : physical_devices) {
  451. const auto physical_device = vk::PhysicalDevice(device, dld);
  452. const std::string name = physical_device.GetProperties().deviceName;
  453. const std::vector<VkPresentModeKHR> present_modes =
  454. physical_device.GetSurfacePresentModesKHR(*surface);
  455. vulkan_devices.push_back(QString::fromStdString(name));
  456. device_present_modes.push_back(present_modes);
  457. }
  458. } catch (const Vulkan::vk::Exception& exception) {
  459. LOG_ERROR(Frontend, "Failed to enumerate devices with error: {}", exception.what());
  460. }
  461. Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const {
  462. if (Settings::IsConfiguringGlobal()) {
  463. return static_cast<Settings::RendererBackend>(ui->api->currentIndex());
  464. }
  465. if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  466. Settings::values.renderer_backend.SetGlobal(true);
  467. return Settings::values.renderer_backend.GetValue();
  468. }
  469. Settings::values.renderer_backend.SetGlobal(false);
  470. return static_cast<Settings::RendererBackend>(ui->api->currentIndex() -
  471. ConfigurationShared::USE_GLOBAL_OFFSET);
  472. }
  473. Settings::NvdecEmulation ConfigureGraphics::GetCurrentNvdecEmulation() const {
  474. if (Settings::IsConfiguringGlobal()) {
  475. return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex());
  476. }
  477. if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  478. Settings::values.nvdec_emulation.SetGlobal(true);
  479. return Settings::values.nvdec_emulation.GetValue();
  480. }
  481. Settings::values.nvdec_emulation.SetGlobal(false);
  482. return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex() -
  483. ConfigurationShared::USE_GLOBAL_OFFSET);
  484. }
  485. void ConfigureGraphics::SetupPerGameUI() {
  486. if (Settings::IsConfiguringGlobal()) {
  487. ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal());
  488. ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal());
  489. ui->fullscreen_mode_combobox->setEnabled(Settings::values.fullscreen_mode.UsingGlobal());
  490. ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal());
  491. ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal());
  492. ui->scaling_filter_combobox->setEnabled(Settings::values.scaling_filter.UsingGlobal());
  493. ui->fsr_sharpening_slider->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal());
  494. ui->anti_aliasing_combobox->setEnabled(Settings::values.anti_aliasing.UsingGlobal());
  495. ui->use_asynchronous_gpu_emulation->setEnabled(
  496. Settings::values.use_asynchronous_gpu_emulation.UsingGlobal());
  497. ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal());
  498. ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal());
  499. ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal());
  500. ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal());
  501. ui->fsr_slider_layout->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal());
  502. return;
  503. }
  504. connect(ui->bg_combobox, qOverload<int>(&QComboBox::activated), this, [this](int index) {
  505. ui->bg_button->setEnabled(index == 1);
  506. ConfigurationShared::SetHighlight(ui->bg_layout, index == 1);
  507. });
  508. connect(ui->fsr_sharpening_combobox, qOverload<int>(&QComboBox::activated), this,
  509. [this](int index) {
  510. ui->fsr_sharpening_slider->setEnabled(index == 1);
  511. ui->fsr_sharpening_value->setEnabled(index == 1);
  512. ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, index == 1);
  513. });
  514. ConfigurationShared::SetColoredTristate(
  515. ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache);
  516. ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc,
  517. accelerate_astc);
  518. ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation,
  519. Settings::values.use_asynchronous_gpu_emulation,
  520. use_asynchronous_gpu_emulation);
  521. ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label,
  522. Settings::values.aspect_ratio.GetValue(true));
  523. ConfigurationShared::SetColoredComboBox(
  524. ui->fullscreen_mode_combobox, ui->fullscreen_mode_label,
  525. static_cast<int>(Settings::values.fullscreen_mode.GetValue(true)));
  526. ConfigurationShared::SetColoredComboBox(
  527. ui->resolution_combobox, ui->resolution_label,
  528. static_cast<int>(Settings::values.resolution_setup.GetValue(true)));
  529. ConfigurationShared::SetColoredComboBox(
  530. ui->scaling_filter_combobox, ui->scaling_filter_label,
  531. static_cast<int>(Settings::values.scaling_filter.GetValue(true)));
  532. ConfigurationShared::SetColoredComboBox(
  533. ui->anti_aliasing_combobox, ui->anti_aliasing_label,
  534. static_cast<int>(Settings::values.anti_aliasing.GetValue(true)));
  535. ConfigurationShared::InsertGlobalItem(
  536. ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true)));
  537. ConfigurationShared::InsertGlobalItem(
  538. ui->nvdec_emulation, static_cast<int>(Settings::values.nvdec_emulation.GetValue(true)));
  539. ui->vsync_mode_layout->setVisible(false);
  540. }