GPU: Implement support for multisample antialiasing

This commit is contained in:
Connor McLaughlin
2020-10-31 00:38:06 +10:00
parent 61a4960380
commit 2eaebd8921
28 changed files with 804 additions and 407 deletions

View File

@ -36,6 +36,9 @@ EnhancementSettingsWidget::EnhancementSettingsWidget(QtHostInterface* host_inter
connect(m_ui.pgxpEnable, &QCheckBox::stateChanged, this, &EnhancementSettingsWidget::updatePGXPSettingsEnabled);
updatePGXPSettingsEnabled();
connect(m_ui.msaaMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&EnhancementSettingsWidget::msaaModeChanged);
dialog->registerWidgetHelp(
m_ui.disableInterlacing, tr("Disable Interlacing (force progressive render/scan)"), tr("Unchecked"),
tr(
@ -47,6 +50,11 @@ EnhancementSettingsWidget::EnhancementSettingsWidget(QtHostInterface* host_inter
tr("Setting this beyond 1x will enhance the resolution of rendered 3D polygons and lines. Only applies "
"to the hardware backends. <br>This option is usually safe, with most games looking fine at "
"higher resolutions. Higher resolutions require a more powerful GPU."));
dialog->registerWidgetHelp(
m_ui.msaaMode, tr("Multisample Antialiasing"), tr("Disabled"),
tr("Uses multisample antialiasing for rendering 3D objects. Can smooth out jagged edges on polygons at a lower "
"cost to performance compared to increasing the resolution scale, but may be more likely to cause rendering "
"errors in some games. Only applies to the hardware backends."));
dialog->registerWidgetHelp(
m_ui.trueColor, tr("True Color Rendering (24-bit, disables dithering)"), tr("Unchecked"),
tr("Forces the precision of colours output to the console's framebuffer to use the full 8 bits of precision per "
@ -103,6 +111,14 @@ void EnhancementSettingsWidget::updateScaledDitheringEnabled()
void EnhancementSettingsWidget::setupAdditionalUi()
{
QtUtils::FillComboBoxWithResolutionScales(m_ui.resolutionScale);
QtUtils::FillComboBoxWithMSAAModes(m_ui.msaaMode);
const QVariant current_msaa_mode(
QtUtils::GetMSAAModeValue(static_cast<uint>(m_host_interface->GetIntSettingValue("GPU", "Multisamples", 1)),
m_host_interface->GetBoolSettingValue("GPU", "PerSampleShading", false)));
const int current_msaa_index = m_ui.msaaMode->findData(current_msaa_mode);
if (current_msaa_index >= 0)
m_ui.msaaMode->setCurrentIndex(current_msaa_index);
for (u32 i = 0; i < static_cast<u32>(GPUTextureFilter::Count); i++)
{
@ -117,3 +133,13 @@ void EnhancementSettingsWidget::updatePGXPSettingsEnabled()
m_ui.pgxpCulling->setEnabled(enabled);
m_ui.pgxpTextureCorrection->setEnabled(enabled);
}
void EnhancementSettingsWidget::msaaModeChanged(int index)
{
uint multisamples;
bool ssaa;
QtUtils::DecodeMSAAModeValue(m_ui.msaaMode->itemData(index), &multisamples, &ssaa);
m_host_interface->SetIntSettingValue("GPU", "Multisamples", static_cast<int>(multisamples));
m_host_interface->SetBoolSettingValue("GPU", "PerSampleShading", ssaa);
m_host_interface->applySettings(false);
}

View File

@ -18,6 +18,7 @@ public:
private Q_SLOTS:
void updateScaledDitheringEnabled();
void updatePGXPSettingsEnabled();
void msaaModeChanged(int index);
private:
void setupAdditionalUi();

View File

@ -26,129 +26,139 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Rendering Enhancements</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Internal Resolution Scale:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="resolutionScale"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Texture Filtering:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="textureFiltering"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="trueColor">
<property name="text">
<string>True Color Rendering (24-bit, disables dithering)</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="scaledDithering">
<property name="text">
<string>Scaled Dithering (scale dither pattern to resolution)</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="widescreenHack">
<property name="text">
<string>Widescreen Hack (render 3D in 16:9)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Display Enhancements</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="disableInterlacing">
<property name="text">
<string>Disable Interlacing (force progressive render/scan)</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="forceNTSCTimings">
<property name="text">
<string>Force NTSC Timings (60hz-on-PAL)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="force43For24Bit">
<property name="text">
<string>Force 4:3 For 24-Bit Display (disable widescreen for FMVs)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>PGXP (Precision Geometry Transform Pipeline)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="pgxpEnable">
<property name="text">
<string>Geometry Correction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pgxpCulling">
<property name="text">
<string>Culling Correction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pgxpTextureCorrection">
<property name="text">
<string>Texture Correction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Rendering Enhancements</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Internal Resolution Scale:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="resolutionScale"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Texture Filtering:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="textureFiltering"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="trueColor">
<property name="text">
<string>True Color Rendering (24-bit, disables dithering)</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="scaledDithering">
<property name="text">
<string>Scaled Dithering (scale dither pattern to resolution)</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="widescreenHack">
<property name="text">
<string>Widescreen Hack (render 3D in 16:9)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Multisample Antialiasing:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="msaaMode"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Display Enhancements</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="disableInterlacing">
<property name="text">
<string>Disable Interlacing (force progressive render/scan)</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="forceNTSCTimings">
<property name="text">
<string>Force NTSC Timings (60hz-on-PAL)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="force43For24Bit">
<property name="text">
<string>Force 4:3 For 24-Bit Display (disable widescreen for FMVs)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>PGXP (Precision Geometry Transform Pipeline)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="pgxpEnable">
<property name="text">
<string>Geometry Correction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pgxpCulling">
<property name="text">
<string>Culling Correction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pgxpTextureCorrection">
<property name="text">
<string>Texture Correction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>

View File

@ -677,7 +677,7 @@ void FillComboBoxWithResolutionScales(QComboBox* cb)
cb->addItem(qApp->translate("GPUSettingsWidget", "6x (for 1440p)"));
cb->addItem(qApp->translate("GPUSettingsWidget", "7x"));
cb->addItem(qApp->translate("GPUSettingsWidget", "8x"));
cb->addItem(qApp->translate("GPUSettingsWidget", "9x"));
cb->addItem(qApp->translate("GPUSettingsWidget", "9x (for 4K)"));
cb->addItem(qApp->translate("GPUSettingsWidget", "10x"));
cb->addItem(qApp->translate("GPUSettingsWidget", "11x"));
cb->addItem(qApp->translate("GPUSettingsWidget", "12x"));
@ -687,4 +687,36 @@ void FillComboBoxWithResolutionScales(QComboBox* cb)
cb->addItem(qApp->translate("GPUSettingsWidget", "16x"));
}
QVariant GetMSAAModeValue(uint multisamples, bool ssaa)
{
const uint userdata = (multisamples & 0x7FFFFFFFu) | (static_cast<uint>(ssaa) << 31);
return QVariant(userdata);
}
void DecodeMSAAModeValue(const QVariant& userdata, uint* multisamples, bool* ssaa)
{
bool ok;
const uint value = userdata.toUInt(&ok);
if (!ok || value == 0)
{
*multisamples = 1;
*ssaa = false;
return;
}
*multisamples = value & 0x7FFFFFFFu;
*ssaa = (value & (1u << 31)) != 0u;
}
void FillComboBoxWithMSAAModes(QComboBox* cb)
{
cb->addItem(qApp->translate("GPUSettingsWidget", "Disabled"), GetMSAAModeValue(1, false));
for (uint i = 2; i <= 32; i *= 2)
cb->addItem(qApp->translate("GPUSettingsWidget", "%1x MSAA").arg(i), GetMSAAModeValue(i, false));
for (uint i = 2; i <= 32; i *= 2)
cb->addItem(qApp->translate("GPUSettingsWidget", "%1x SSAA").arg(i), GetMSAAModeValue(i, true));
}
} // namespace QtUtils

View File

@ -16,6 +16,7 @@ class QFrame;
class QKeyEvent;
class QTableView;
class QTreeView;
class QVariant;
class QWidget;
class QUrl;
@ -62,4 +63,9 @@ void OpenURL(QWidget* parent, const char* url);
/// Fills a combo box with resolution scale options.
void FillComboBoxWithResolutionScales(QComboBox* cb);
/// Fills a combo box with multisampling options.
QVariant GetMSAAModeValue(uint multisamples, bool ssaa);
void DecodeMSAAModeValue(const QVariant& userdata, uint* multisamples, bool* ssaa);
void FillComboBoxWithMSAAModes(QComboBox* cb);
} // namespace QtUtils