From 744cfbd924fba96a54b016fb809c3fd81d0db241 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 23 Dec 2020 01:17:10 +1000 Subject: [PATCH] Frontends: Add PGXP Depth Buffer options --- android/app/src/main/res/values/strings.xml | 2 + .../main/res/xml/enhancements_preferences.xml | 7 ++ .../libretro_host_interface.cpp | 13 +++- src/duckstation-qt/advancedsettingswidget.cpp | 25 +++---- .../enhancementsettingswidget.cpp | 6 ++ .../enhancementsettingswidget.ui | 15 +++-- src/duckstation-qt/gamepropertiesdialog.cpp | 14 ++++ src/duckstation-qt/gamepropertiesdialog.ui | 66 +++++++++++++------ src/duckstation-sdl/sdl_host_interface.cpp | 16 ++++- 9 files changed, 126 insertions(+), 38 deletions(-) diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 0068f7c37..1f745e58b 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -106,6 +106,8 @@ Uses perspective-correct interpolation for texture coordinates and colors, straightening out warped textures. Requires geometry correction enabled. PGXP Preserve Projection Precision Enables additional precision for PGXP. May improve visuals in some games but break others. + PGXP Depth Buffer + Attempts to reduce polygon Z-fighting by testing pixels against the depth values from PGXP. Low compatibility, but can work well in some games. Resume Last Session Start File Start BIOS diff --git a/android/app/src/main/res/xml/enhancements_preferences.xml b/android/app/src/main/res/xml/enhancements_preferences.xml index d7da35dc5..b5d5b24d4 100644 --- a/android/app/src/main/res/xml/enhancements_preferences.xml +++ b/android/app/src/main/res/xml/enhancements_preferences.xml @@ -131,4 +131,11 @@ app:summary="@string/settings_summary_pgxp_preserve_projection_precision" app:iconSpaceReserved="false" /> + + diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index b807522db..39c8174f7 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -489,7 +489,7 @@ void LibretroHostInterface::OnSystemDestroyed() m_using_hardware_renderer = false; } -static std::array s_option_definitions = {{ +static std::array s_option_definitions = {{ {"duckstation_Console.Region", "Console Region", "Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.", @@ -684,6 +684,12 @@ static std::array s_option_definitions = {{ "Requires geometry correction enabled.", {{"true", "Enabled"}, {"false", "Disabled"}}, "true"}, + {"duckstation_GPU.PGXPDepthBuffer", + "PGXP Depth Buffer", + "Attempts to reduce polygon Z-fighting by testing pixels against the depth values from PGXP. Low compatibility, " + "but can work well in some games. Requires geometry correction enabled.", + {{"true", "Enabled"}, {"false", "Disabled"}}, + "false"}, {"duckstation_GPU.PGXPVertexCache", "PGXP Vertex Cache", "Uses screen coordinates as a fallback when tracking vertices through memory fails. May improve PGXP compatibility.", @@ -864,6 +870,11 @@ static std::array s_option_definitions = {{ {"19", "19"}, {"20", "20"}, {"21", "21"}, {"22", "22"}, {"23", "23"}, {"24", "24"}, {"25", "25"}, {"26", "26"}, {"27", "27"}, {"28", "28"}, {"29", "29"}, {"30", "30"}}, "0"}, + {"duckstation_GPU.PGXPPreserveProjFP", + "PGXP Preserve Projection Precision", + "Enables additional precision for PGXP. May improve visuals in some games but break others.", + {{"true", "Enabled"}, {"false", "Disabled"}}, + "false"}, {"duckstation_GPU.PGXPTolerance", "PGXP Geometry Tolerance", "Ignores precise positions if the difference exceeds this threshold.", diff --git a/src/duckstation-qt/advancedsettingswidget.cpp b/src/duckstation-qt/advancedsettingswidget.cpp index 74b3ee856..c32445ca6 100644 --- a/src/duckstation-qt/advancedsettingswidget.cpp +++ b/src/duckstation-qt/advancedsettingswidget.cpp @@ -151,6 +151,8 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(QtHostInterface* host_interface, "PGXPPreserveProjFP", false); addFloatRangeTweakOption(m_host_interface, m_ui.tweakOptionTable, tr("PGXP Geometry Tolerance"), "GPU", "PGXPTolerance", -1.0f, 10.0f, 0.5f, -1.0f); + addFloatRangeTweakOption(m_host_interface, m_ui.tweakOptionTable, tr("PGXP Depth Clear Threshold"), "GPU", + "PGXPDepthClearThreshold", 0.0f, 4096.0f, 1.0f, Settings::DEFAULT_GPU_PGXP_DEPTH_THRESHOLD); addBooleanTweakOption(m_host_interface, m_ui.tweakOptionTable, tr("Enable Recompiler Memory Exceptions"), "CPU", "RecompilerMemoryExceptions", false); @@ -189,17 +191,18 @@ void AdvancedSettingsWidget::onResetToDefaultClicked() setBooleanTweakOption(m_ui.tweakOptionTable, 1, false); setBooleanTweakOption(m_ui.tweakOptionTable, 2, false); setFloatRangeTweakOption(m_ui.tweakOptionTable, 3, -1.0f); - setBooleanTweakOption(m_ui.tweakOptionTable, 4, false); - setChoiceTweakOption(m_ui.tweakOptionTable, 5, Settings::DEFAULT_CPU_FASTMEM_MODE); - setBooleanTweakOption(m_ui.tweakOptionTable, 6, false); - setIntRangeTweakOption(m_ui.tweakOptionTable, 7, static_cast(Settings::DEFAULT_DMA_MAX_SLICE_TICKS)); - setIntRangeTweakOption(m_ui.tweakOptionTable, 8, static_cast(Settings::DEFAULT_DMA_HALT_TICKS)); - setIntRangeTweakOption(m_ui.tweakOptionTable, 9, static_cast(Settings::DEFAULT_GPU_FIFO_SIZE)); - setIntRangeTweakOption(m_ui.tweakOptionTable, 10, static_cast(Settings::DEFAULT_GPU_MAX_RUN_AHEAD)); - setBooleanTweakOption(m_ui.tweakOptionTable, 11, false); - setIntRangeTweakOption(m_ui.tweakOptionTable, 12, 0); - setBooleanTweakOption(m_ui.tweakOptionTable, 13, true); + setFloatRangeTweakOption(m_ui.tweakOptionTable, 4, Settings::DEFAULT_GPU_PGXP_DEPTH_THRESHOLD); + setBooleanTweakOption(m_ui.tweakOptionTable, 5, false); + setChoiceTweakOption(m_ui.tweakOptionTable, 6, Settings::DEFAULT_CPU_FASTMEM_MODE); + setBooleanTweakOption(m_ui.tweakOptionTable, 7, false); + setIntRangeTweakOption(m_ui.tweakOptionTable, 8, static_cast(Settings::DEFAULT_DMA_MAX_SLICE_TICKS)); + setIntRangeTweakOption(m_ui.tweakOptionTable, 9, static_cast(Settings::DEFAULT_DMA_HALT_TICKS)); + setIntRangeTweakOption(m_ui.tweakOptionTable, 10, static_cast(Settings::DEFAULT_GPU_FIFO_SIZE)); + setIntRangeTweakOption(m_ui.tweakOptionTable, 11, static_cast(Settings::DEFAULT_GPU_MAX_RUN_AHEAD)); + setBooleanTweakOption(m_ui.tweakOptionTable, 12, false); + setIntRangeTweakOption(m_ui.tweakOptionTable, 13, 0); + setBooleanTweakOption(m_ui.tweakOptionTable, 14, true); #ifdef WIN32 - setBooleanTweakOption(m_ui.tweakOptionTable, 14, false); + setBooleanTweakOption(m_ui.tweakOptionTable, 15, false); #endif } diff --git a/src/duckstation-qt/enhancementsettingswidget.cpp b/src/duckstation-qt/enhancementsettingswidget.cpp index e2058b25f..21924e555 100644 --- a/src/duckstation-qt/enhancementsettingswidget.cpp +++ b/src/duckstation-qt/enhancementsettingswidget.cpp @@ -29,6 +29,7 @@ EnhancementSettingsWidget::EnhancementSettingsWidget(QtHostInterface* host_inter SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pgxpCulling, "GPU", "PGXPCulling", true); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pgxpTextureCorrection, "GPU", "PGXPTextureCorrection", true); + SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.pgxpDepthBuffer, "GPU", "PGXPDepthBuffer", true); connect(m_ui.resolutionScale, QOverload::of(&QComboBox::currentIndexChanged), this, &EnhancementSettingsWidget::updateScaledDitheringEnabled); @@ -101,6 +102,10 @@ EnhancementSettingsWidget::EnhancementSettingsWidget(QtHostInterface* host_inter dialog->registerWidgetHelp(m_ui.pgxpTextureCorrection, tr("Texture Correction"), tr("Checked"), tr("Uses perspective-correct interpolation for texture coordinates and colors, " "straightening out warped textures. Requires geometry correction enabled.")); + dialog->registerWidgetHelp( + m_ui.pgxpTextureCorrection, tr("Depth Buffer"), tr("Unchecked"), + tr("Attempts to reduce polygon Z-fighting by testing pixels against the depth values from PGXP. Low compatibility, " + "but can work well in some games. Other games may need a threshold adjustment.")); } EnhancementSettingsWidget::~EnhancementSettingsWidget() = default; @@ -137,6 +142,7 @@ void EnhancementSettingsWidget::updatePGXPSettingsEnabled() const bool enabled = m_ui.pgxpEnable->isChecked(); m_ui.pgxpCulling->setEnabled(enabled); m_ui.pgxpTextureCorrection->setEnabled(enabled); + m_ui.pgxpDepthBuffer->setEnabled(enabled); } void EnhancementSettingsWidget::msaaModeChanged(int index) diff --git a/src/duckstation-qt/enhancementsettingswidget.ui b/src/duckstation-qt/enhancementsettingswidget.ui index 2b5359720..872907418 100644 --- a/src/duckstation-qt/enhancementsettingswidget.ui +++ b/src/duckstation-qt/enhancementsettingswidget.ui @@ -128,28 +128,35 @@ PGXP (Precision Geometry Transform Pipeline) - - + + Geometry Correction - + Culling Correction - + Texture Correction + + + + Depth Buffer + + + diff --git a/src/duckstation-qt/gamepropertiesdialog.cpp b/src/duckstation-qt/gamepropertiesdialog.cpp index 15ce96d2e..6e87ce02e 100644 --- a/src/duckstation-qt/gamepropertiesdialog.cpp +++ b/src/duckstation-qt/gamepropertiesdialog.cpp @@ -325,6 +325,11 @@ void GamePropertiesDialog::populateGameSettings() QSignalBlocker sb(m_ui.gpuPGXPTolerance); m_ui.gpuPGXPTolerance->setValue(static_cast(gs.gpu_pgxp_tolerance.value())); } + if (gs.gpu_pgxp_depth_threshold.has_value()) + { + QSignalBlocker sb(m_ui.gpuPGXPDepthThreshold); + m_ui.gpuPGXPDepthThreshold->setValue(static_cast(gs.gpu_pgxp_depth_threshold.value())); + } if (gs.display_crop_mode.has_value()) { @@ -383,6 +388,7 @@ void GamePropertiesDialog::populateGameSettings() populateBooleanUserSetting(m_ui.userWidescreenHack, gs.gpu_widescreen_hack); populateBooleanUserSetting(m_ui.userForce43For24Bit, gs.display_force_4_3_for_24bit); populateBooleanUserSetting(m_ui.userPGXP, gs.gpu_pgxp); + populateBooleanUserSetting(m_ui.userPGXPDepthBuffer, gs.gpu_pgxp_depth_buffer); if (gs.controller_1_type.has_value()) { @@ -561,6 +567,7 @@ void GamePropertiesDialog::connectUi() connectBooleanUserSetting(m_ui.userWidescreenHack, &m_game_settings.gpu_widescreen_hack); connectBooleanUserSetting(m_ui.userForce43For24Bit, &m_game_settings.display_force_4_3_for_24bit); connectBooleanUserSetting(m_ui.userPGXP, &m_game_settings.gpu_pgxp); + connectBooleanUserSetting(m_ui.userPGXPDepthBuffer, &m_game_settings.gpu_pgxp_depth_buffer); connect(m_ui.userControllerType1, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { if (index <= 0) @@ -704,6 +711,13 @@ void GamePropertiesDialog::connectUi() m_game_settings.gpu_pgxp_tolerance = static_cast(value); saveGameSettings(); }); + connect(m_ui.gpuPGXPDepthThreshold, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { + if (value <= 0.0) + m_game_settings.gpu_pgxp_depth_threshold.reset(); + else + m_game_settings.gpu_pgxp_depth_threshold = static_cast(value); + saveGameSettings(); + }); } void GamePropertiesDialog::updateCPUClockSpeedLabel() diff --git a/src/duckstation-qt/gamepropertiesdialog.ui b/src/duckstation-qt/gamepropertiesdialog.ui index b078f8757..5fe8cb6f2 100644 --- a/src/duckstation-qt/gamepropertiesdialog.ui +++ b/src/duckstation-qt/gamepropertiesdialog.ui @@ -7,7 +7,7 @@ 0 0 750 - 548 + 567 @@ -346,16 +346,6 @@ - - - - True Color Rendering (24-bit, disables dithering) - - - true - - - @@ -366,10 +356,10 @@ - - + + - Widescreen Hack + Force 4:3 For 24-Bit Display (disable widescreen for FMVs) true @@ -386,10 +376,10 @@ - - + + - Force 4:3 For 24-Bit Display (disable widescreen for FMVs) + True Color Rendering (24-bit, disables dithering) true @@ -406,6 +396,26 @@ + + + + Widescreen Hack + + + true + + + + + + + PGXP Depth Buffer + + + true + + + @@ -798,16 +808,30 @@ - -1 + -1.000000000000000 - 10 + 10.000000000000000 - 0.5 + 0.000000000000000 - -1 + -1.000000000000000 + + + + + + + PGXP Depth Threshold: + + + + + + + 4096.000000000000000 diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index cb86449d9..141fa5b23 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -1042,6 +1042,8 @@ void SDLHostInterface::DrawQuickSettingsMenu() ImGui::MenuItem("PGXP CPU Instructions", nullptr, &m_settings_copy.gpu_pgxp_cpu, m_settings_copy.gpu_pgxp_enable); settings_changed |= ImGui::MenuItem("PGXP Preserve Projection Precision", nullptr, &m_settings_copy.gpu_pgxp_preserve_proj_fp, m_settings_copy.gpu_pgxp_enable); + settings_changed |= ImGui::MenuItem("PGXP Depth Buffer", nullptr, &m_settings_copy.gpu_pgxp_depth_buffer, + m_settings_copy.gpu_pgxp_enable); ImGui::EndMenu(); } @@ -1603,7 +1605,19 @@ void SDLHostInterface::DrawSettingsWindow() settings_changed |= ImGui::Checkbox("PGXP Culling", &m_settings_copy.gpu_pgxp_culling); settings_changed |= ImGui::Checkbox("PGXP Texture Correction", &m_settings_copy.gpu_pgxp_texture_correction); settings_changed |= ImGui::Checkbox("PGXP Vertex Cache", &m_settings_copy.gpu_pgxp_vertex_cache); - settings_changed |= ImGui::Checkbox("PGXP CPU", &m_settings_copy.gpu_pgxp_cpu); + settings_changed |= ImGui::Checkbox("PGXP CPU Instructions", &m_settings_copy.gpu_pgxp_cpu); + settings_changed |= ImGui::Checkbox("PGXP Preserve Projection Precision", &m_settings_copy.gpu_pgxp_enable); + settings_changed |= ImGui::Checkbox("PGXP Depth Buffer", &m_settings_copy.gpu_pgxp_depth_buffer); + + ImGui::Text("PGXP Depth Clear Threshold:"); + ImGui::SameLine(indent); + + float depth_clear_threshold = m_settings_copy.GetPGXPDepthClearThreshold(); + if (ImGui::SliderFloat("##clear_threshold", &depth_clear_threshold, 0.0f, 4096.0f)) + { + m_settings_copy.SetPGXPDepthClearThreshold(depth_clear_threshold); + settings_changed = true; + } } ImGui::EndTabItem();