pineapple/src/yuzu/configuration/configure_graphics.cpp

420 lines
20 KiB
C++
Raw Normal View History

2020-12-28 16:15:37 +01:00
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
2021-01-17 03:19:34 +01:00
// Include this early to include Vulkan headers how we want to
#include "video_core/vulkan_common/vulkan_wrapper.h"
2020-12-28 16:15:37 +01:00
#include <QColorDialog>
#include <QComboBox>
#include <QVulkanInstance>
#include "common/common_types.h"
#include "common/logging/log.h"
2021-04-15 04:05:28 +02:00
#include "common/settings.h"
2020-12-28 16:15:37 +01:00
#include "core/core.h"
#include "ui_configure_graphics.h"
2021-01-17 03:19:34 +01:00
#include "video_core/vulkan_common/vulkan_instance.h"
#include "video_core/vulkan_common/vulkan_library.h"
2020-12-28 16:15:37 +01:00
#include "yuzu/configuration/configuration_shared.h"
#include "yuzu/configuration/configure_graphics.h"
2021-10-09 02:29:53 +02:00
ConfigureGraphics::ConfigureGraphics(const Core::System& system_, QWidget* parent)
2021-10-16 02:35:29 +02:00
: QWidget(parent), ui{std::make_unique<Ui::ConfigureGraphics>()}, system{system_} {
2020-12-28 16:15:37 +01:00
vulkan_device = Settings::values.vulkan_device.GetValue();
RetrieveVulkanDevices();
ui->setupUi(this);
2021-07-09 23:54:15 +02:00
for (const auto& device : vulkan_devices) {
ui->device->addItem(device);
}
ui->backend->addItem(QStringLiteral("GLSL"));
2021-07-26 21:28:24 +02:00
ui->backend->addItem(tr("GLASM (Assembly Shaders, NVIDIA Only)"));
2021-07-09 23:54:15 +02:00
ui->backend->addItem(QStringLiteral("SPIR-V (Experimental, Mesa Only)"));
2020-12-28 16:15:37 +01:00
SetupPerGameUI();
SetConfiguration();
connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, [this] {
2021-07-09 23:54:15 +02:00
UpdateAPILayout();
2020-12-28 16:15:37 +01:00
if (!Settings::IsConfiguringGlobal()) {
ConfigurationShared::SetHighlight(
2021-07-09 23:54:15 +02:00
ui->api_widget, ui->api->currentIndex() != ConfigurationShared::USE_GLOBAL_INDEX);
2020-12-28 16:15:37 +01:00
}
});
connect(ui->device, qOverload<int>(&QComboBox::activated), this,
[this](int device) { UpdateDeviceSelection(device); });
2021-07-09 23:54:15 +02:00
connect(ui->backend, qOverload<int>(&QComboBox::activated), this,
[this](int backend) { UpdateShaderBackendSelection(backend); });
2020-12-28 16:15:37 +01:00
connect(ui->bg_button, &QPushButton::clicked, this, [this] {
const QColor new_bg_color = QColorDialog::getColor(bg_color);
if (!new_bg_color.isValid()) {
return;
}
UpdateBackgroundColorButton(new_bg_color);
});
ui->bg_label->setVisible(Settings::IsConfiguringGlobal());
ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal());
}
void ConfigureGraphics::UpdateDeviceSelection(int device) {
if (device == -1) {
return;
}
if (GetCurrentGraphicsBackend() == Settings::RendererBackend::Vulkan) {
vulkan_device = device;
}
}
2021-07-09 23:54:15 +02:00
void ConfigureGraphics::UpdateShaderBackendSelection(int backend) {
if (backend == -1) {
return;
}
if (GetCurrentGraphicsBackend() == Settings::RendererBackend::OpenGL) {
shader_backend = static_cast<Settings::ShaderBackend>(backend);
}
}
2020-12-28 16:15:37 +01:00
ConfigureGraphics::~ConfigureGraphics() = default;
void ConfigureGraphics::SetConfiguration() {
2021-10-09 02:29:53 +02:00
const bool runtime_lock = !system.IsPoweredOn();
2020-12-28 16:15:37 +01:00
2021-07-09 23:54:15 +02:00
ui->api_widget->setEnabled(runtime_lock);
2020-12-28 16:15:37 +01:00
ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock);
ui->use_disk_shader_cache->setEnabled(runtime_lock);
2021-08-12 01:07:27 +02:00
ui->nvdec_emulation_widget->setEnabled(runtime_lock);
2021-10-24 06:39:01 +02:00
ui->resolution_combobox->setEnabled(runtime_lock);
2021-06-14 16:57:42 +02:00
ui->accelerate_astc->setEnabled(runtime_lock);
2020-12-28 16:15:37 +01:00
ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue());
ui->use_asynchronous_gpu_emulation->setChecked(
Settings::values.use_asynchronous_gpu_emulation.GetValue());
2021-06-14 16:57:42 +02:00
ui->accelerate_astc->setChecked(Settings::values.accelerate_astc.GetValue());
2020-12-28 16:15:37 +01:00
if (Settings::IsConfiguringGlobal()) {
ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue()));
2021-07-28 21:57:36 +02:00
ui->fullscreen_mode_combobox->setCurrentIndex(
static_cast<int>(Settings::values.fullscreen_mode.GetValue()));
2021-08-12 01:07:27 +02:00
ui->nvdec_emulation->setCurrentIndex(
static_cast<int>(Settings::values.nvdec_emulation.GetValue()));
2020-12-28 16:15:37 +01:00
ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue());
2021-10-24 06:39:01 +02:00
ui->resolution_combobox->setCurrentIndex(
static_cast<int>(Settings::values.resolution_setup.GetValue()));
ui->scaling_filter_combobox->setCurrentIndex(
static_cast<int>(Settings::values.scaling_filter.GetValue()));
ui->anti_aliasing_combobox->setCurrentIndex(
static_cast<int>(Settings::values.anti_aliasing.GetValue()));
2020-12-28 16:15:37 +01:00
} else {
ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend);
2021-07-09 23:54:15 +02:00
ConfigurationShared::SetHighlight(ui->api_widget,
2020-12-28 16:15:37 +01:00
!Settings::values.renderer_backend.UsingGlobal());
2021-04-05 01:30:07 +02:00
2021-08-12 01:07:27 +02:00
ConfigurationShared::SetPerGameSetting(ui->nvdec_emulation,
&Settings::values.nvdec_emulation);
ConfigurationShared::SetHighlight(ui->nvdec_emulation_widget,
!Settings::values.nvdec_emulation.UsingGlobal());
2021-04-05 01:30:07 +02:00
ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox,
&Settings::values.fullscreen_mode);
ConfigurationShared::SetHighlight(ui->fullscreen_mode_label,
!Settings::values.fullscreen_mode.UsingGlobal());
2020-12-28 16:15:37 +01:00
ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox,
&Settings::values.aspect_ratio);
2021-04-05 01:30:07 +02:00
ConfigurationShared::SetHighlight(ui->ar_label,
!Settings::values.aspect_ratio.UsingGlobal());
2020-12-28 16:15:37 +01:00
2021-10-24 06:39:01 +02:00
ConfigurationShared::SetPerGameSetting(ui->resolution_combobox,
&Settings::values.resolution_setup);
ConfigurationShared::SetHighlight(ui->resolution_label,
!Settings::values.resolution_setup.UsingGlobal());
ConfigurationShared::SetPerGameSetting(ui->scaling_filter_combobox,
&Settings::values.scaling_filter);
ConfigurationShared::SetHighlight(ui->scaling_filter_label,
!Settings::values.scaling_filter.UsingGlobal());
ConfigurationShared::SetPerGameSetting(ui->anti_aliasing_combobox,
&Settings::values.anti_aliasing);
ConfigurationShared::SetHighlight(ui->anti_aliasing_label,
!Settings::values.anti_aliasing.UsingGlobal());
2020-12-28 16:15:37 +01:00
ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1);
ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal());
ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal());
}
2021-07-16 22:17:21 +02:00
UpdateBackgroundColorButton(QColor::fromRgb(Settings::values.bg_red.GetValue(),
Settings::values.bg_green.GetValue(),
Settings::values.bg_blue.GetValue()));
2021-07-09 23:54:15 +02:00
UpdateAPILayout();
2020-12-28 16:15:37 +01:00
}
void ConfigureGraphics::ApplyConfiguration() {
2021-10-24 06:39:01 +02:00
const auto resolution_setup = static_cast<Settings::ResolutionSetup>(
ui->resolution_combobox->currentIndex() -
((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
const auto scaling_filter = static_cast<Settings::ScalingFilter>(
ui->scaling_filter_combobox->currentIndex() -
((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
const auto anti_aliasing = static_cast<Settings::AntiAliasing>(
ui->anti_aliasing_combobox->currentIndex() -
((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET));
2021-05-17 02:21:13 +02:00
ConfigurationShared::ApplyPerGameSetting(&Settings::values.fullscreen_mode,
ui->fullscreen_mode_combobox);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio,
ui->aspect_ratio_combobox);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache,
ui->use_disk_shader_cache, use_disk_shader_cache);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation,
ui->use_asynchronous_gpu_emulation,
use_asynchronous_gpu_emulation);
2021-06-14 16:57:42 +02:00
ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, ui->accelerate_astc,
accelerate_astc);
2021-05-17 02:21:13 +02:00
2020-12-28 16:15:37 +01:00
if (Settings::IsConfiguringGlobal()) {
// Guard if during game and set to game-specific value
if (Settings::values.renderer_backend.UsingGlobal()) {
Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend());
}
2021-08-12 01:07:27 +02:00
if (Settings::values.nvdec_emulation.UsingGlobal()) {
Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation());
}
2021-07-09 23:54:15 +02:00
if (Settings::values.shader_backend.UsingGlobal()) {
Settings::values.shader_backend.SetValue(shader_backend);
}
2020-12-28 16:15:37 +01:00
if (Settings::values.vulkan_device.UsingGlobal()) {
Settings::values.vulkan_device.SetValue(vulkan_device);
}
if (Settings::values.bg_red.UsingGlobal()) {
2021-07-16 22:17:21 +02:00
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
2020-12-28 16:15:37 +01:00
}
2021-10-24 06:39:01 +02:00
if (Settings::values.resolution_setup.UsingGlobal()) {
Settings::values.resolution_setup.SetValue(resolution_setup);
}
if (Settings::values.scaling_filter.UsingGlobal()) {
Settings::values.scaling_filter.SetValue(scaling_filter);
}
if (Settings::values.anti_aliasing.UsingGlobal()) {
Settings::values.anti_aliasing.SetValue(anti_aliasing);
}
2020-12-28 16:15:37 +01:00
} else {
2021-10-24 06:39:01 +02:00
if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.resolution_setup.SetGlobal(true);
} else {
Settings::values.resolution_setup.SetGlobal(false);
Settings::values.resolution_setup.SetValue(resolution_setup);
}
if (ui->scaling_filter_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.scaling_filter.SetGlobal(true);
} else {
Settings::values.scaling_filter.SetGlobal(false);
Settings::values.scaling_filter.SetValue(scaling_filter);
}
if (ui->anti_aliasing_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.anti_aliasing.SetGlobal(true);
} else {
Settings::values.anti_aliasing.SetGlobal(false);
Settings::values.anti_aliasing.SetValue(anti_aliasing);
}
2020-12-28 16:15:37 +01:00
if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.renderer_backend.SetGlobal(true);
2021-07-09 23:54:15 +02:00
Settings::values.shader_backend.SetGlobal(true);
2020-12-28 16:15:37 +01:00
Settings::values.vulkan_device.SetGlobal(true);
} else {
Settings::values.renderer_backend.SetGlobal(false);
Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend());
2021-07-09 23:54:15 +02:00
switch (GetCurrentGraphicsBackend()) {
case Settings::RendererBackend::OpenGL:
Settings::values.shader_backend.SetGlobal(false);
Settings::values.vulkan_device.SetGlobal(true);
Settings::values.shader_backend.SetValue(shader_backend);
break;
case Settings::RendererBackend::Vulkan:
Settings::values.shader_backend.SetGlobal(true);
2020-12-28 16:15:37 +01:00
Settings::values.vulkan_device.SetGlobal(false);
Settings::values.vulkan_device.SetValue(vulkan_device);
2021-07-09 23:54:15 +02:00
break;
2020-12-28 16:15:37 +01:00
}
}
2021-08-12 01:07:27 +02:00
if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.nvdec_emulation.SetGlobal(true);
} else {
Settings::values.nvdec_emulation.SetGlobal(false);
Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation());
}
2020-12-28 16:15:37 +01:00
if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.bg_red.SetGlobal(true);
Settings::values.bg_green.SetGlobal(true);
Settings::values.bg_blue.SetGlobal(true);
} else {
Settings::values.bg_red.SetGlobal(false);
Settings::values.bg_green.SetGlobal(false);
Settings::values.bg_blue.SetGlobal(false);
2021-07-16 22:17:21 +02:00
Settings::values.bg_red.SetValue(static_cast<u8>(bg_color.red()));
Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
2020-12-28 16:15:37 +01:00
}
}
}
void ConfigureGraphics::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureGraphics::RetranslateUI() {
ui->retranslateUi(this);
}
void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) {
bg_color = color;
QPixmap pixmap(ui->bg_button->size());
pixmap.fill(bg_color);
const QIcon color_icon(pixmap);
ui->bg_button->setIcon(color_icon);
}
2021-07-09 23:54:15 +02:00
void ConfigureGraphics::UpdateAPILayout() {
2020-12-28 16:15:37 +01:00
if (!Settings::IsConfiguringGlobal() &&
ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
2021-07-09 23:54:15 +02:00
vulkan_device = Settings::values.vulkan_device.GetValue(true);
shader_backend = Settings::values.shader_backend.GetValue(true);
ui->device_widget->setEnabled(false);
ui->backend_widget->setEnabled(false);
} else {
2020-12-28 16:15:37 +01:00
vulkan_device = Settings::values.vulkan_device.GetValue();
2021-07-09 23:54:15 +02:00
shader_backend = Settings::values.shader_backend.GetValue();
ui->device_widget->setEnabled(true);
ui->backend_widget->setEnabled(true);
2020-12-28 16:15:37 +01:00
}
2021-07-09 23:54:15 +02:00
2020-12-28 16:15:37 +01:00
switch (GetCurrentGraphicsBackend()) {
case Settings::RendererBackend::OpenGL:
2021-07-09 23:54:15 +02:00
ui->backend->setCurrentIndex(static_cast<u32>(shader_backend));
ui->device_widget->setVisible(false);
ui->backend_widget->setVisible(true);
2020-12-28 16:15:37 +01:00
break;
case Settings::RendererBackend::Vulkan:
ui->device->setCurrentIndex(vulkan_device);
2021-07-09 23:54:15 +02:00
ui->device_widget->setVisible(true);
ui->backend_widget->setVisible(false);
2020-12-28 16:15:37 +01:00
break;
}
}
2021-01-17 03:19:34 +01:00
void ConfigureGraphics::RetrieveVulkanDevices() try {
using namespace Vulkan;
vk::InstanceDispatch dld;
const Common::DynamicLibrary library = OpenLibrary();
const vk::Instance instance = CreateInstance(library, dld, VK_API_VERSION_1_0);
const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices();
2020-12-28 16:15:37 +01:00
vulkan_devices.clear();
2021-01-17 03:19:34 +01:00
vulkan_devices.reserve(physical_devices.size());
for (const VkPhysicalDevice device : physical_devices) {
2021-04-05 01:30:07 +02:00
const std::string name = vk::PhysicalDevice(device, dld).GetProperties().deviceName;
2020-12-28 16:15:37 +01:00
vulkan_devices.push_back(QString::fromStdString(name));
}
2021-01-17 03:19:34 +01:00
} catch (const Vulkan::vk::Exception& exception) {
LOG_ERROR(Frontend, "Failed to enumerate devices with error: {}", exception.what());
2020-12-28 16:15:37 +01:00
}
Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const {
if (Settings::IsConfiguringGlobal()) {
return static_cast<Settings::RendererBackend>(ui->api->currentIndex());
}
if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.renderer_backend.SetGlobal(true);
return Settings::values.renderer_backend.GetValue();
}
Settings::values.renderer_backend.SetGlobal(false);
return static_cast<Settings::RendererBackend>(ui->api->currentIndex() -
ConfigurationShared::USE_GLOBAL_OFFSET);
}
2021-08-12 01:07:27 +02:00
Settings::NvdecEmulation ConfigureGraphics::GetCurrentNvdecEmulation() const {
if (Settings::IsConfiguringGlobal()) {
return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex());
}
if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.nvdec_emulation.SetGlobal(true);
return Settings::values.nvdec_emulation.GetValue();
}
Settings::values.nvdec_emulation.SetGlobal(false);
return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex() -
ConfigurationShared::USE_GLOBAL_OFFSET);
}
2020-12-28 16:15:37 +01:00
void ConfigureGraphics::SetupPerGameUI() {
if (Settings::IsConfiguringGlobal()) {
ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal());
ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal());
2021-04-05 01:30:07 +02:00
ui->fullscreen_mode_combobox->setEnabled(Settings::values.fullscreen_mode.UsingGlobal());
2020-12-28 16:15:37 +01:00
ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal());
2021-10-24 06:39:01 +02:00
ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal());
ui->scaling_filter_combobox->setEnabled(Settings::values.scaling_filter.UsingGlobal());
ui->anti_aliasing_combobox->setEnabled(Settings::values.anti_aliasing.UsingGlobal());
2020-12-28 16:15:37 +01:00
ui->use_asynchronous_gpu_emulation->setEnabled(
Settings::values.use_asynchronous_gpu_emulation.UsingGlobal());
2021-08-12 01:07:27 +02:00
ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal());
2021-06-14 16:57:42 +02:00
ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal());
2020-12-28 16:15:37 +01:00
ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal());
ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal());
return;
}
connect(ui->bg_combobox, qOverload<int>(&QComboBox::activated), this, [this](int index) {
ui->bg_button->setEnabled(index == 1);
ConfigurationShared::SetHighlight(ui->bg_layout, index == 1);
});
ConfigurationShared::SetColoredTristate(
ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache);
2021-06-14 16:57:42 +02:00
ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc,
accelerate_astc);
2020-12-28 16:15:37 +01:00
ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation,
Settings::values.use_asynchronous_gpu_emulation,
use_asynchronous_gpu_emulation);
ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label,
Settings::values.aspect_ratio.GetValue(true));
2021-07-28 21:57:36 +02:00
ConfigurationShared::SetColoredComboBox(
ui->fullscreen_mode_combobox, ui->fullscreen_mode_label,
static_cast<int>(Settings::values.fullscreen_mode.GetValue(true)));
2021-10-24 06:39:01 +02:00
ConfigurationShared::SetColoredComboBox(
ui->resolution_combobox, ui->resolution_label,
static_cast<int>(Settings::values.resolution_setup.GetValue(true)));
ConfigurationShared::SetColoredComboBox(
ui->scaling_filter_combobox, ui->scaling_filter_label,
static_cast<int>(Settings::values.scaling_filter.GetValue(true)));
ConfigurationShared::SetColoredComboBox(
ui->anti_aliasing_combobox, ui->anti_aliasing_label,
static_cast<int>(Settings::values.anti_aliasing.GetValue(true)));
2020-12-28 16:15:37 +01:00
ConfigurationShared::InsertGlobalItem(
ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true)));
2021-08-12 01:07:27 +02:00
ConfigurationShared::InsertGlobalItem(
ui->nvdec_emulation, static_cast<int>(Settings::values.nvdec_emulation.GetValue(true)));
2020-12-28 16:15:37 +01:00
}