Skip to content

Commit e05ceaa

Browse files
committed
Qt: Add Windows Auto HDR option to Graphics display settings.
Registers PCSX2 in the Windows registry to force Auto HDR to activate. Requires restarting PCSX2 to take effect.
1 parent ba8804e commit e05ceaa

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

pcsx2-qt/QtHost.cpp

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,74 @@ static void SignalHandler(int signal)
20372037

20382038
#ifdef _WIN32
20392039

2040+
static void RegisterAutoHDR(bool enable)
2041+
{
2042+
// Get the actual exe path (varies by build: pcsx2-qt.exe, pcsx2-qtx64.exe, etc.)
2043+
wchar_t exe_path[MAX_PATH];
2044+
if (GetModuleFileNameW(nullptr, exe_path, MAX_PATH) == 0)
2045+
return;
2046+
2047+
HKEY base_key;
2048+
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Direct3D",
2049+
0, nullptr, 0, KEY_READ | KEY_WRITE, nullptr, &base_key, nullptr) != ERROR_SUCCESS)
2050+
return;
2051+
2052+
// Find an existing entry for this exe or the first free slot.
2053+
wchar_t subkey_name[32];
2054+
HKEY app_key = nullptr;
2055+
bool is_existing = false;
2056+
for (int i = 0; i < 128; i++)
2057+
{
2058+
swprintf_s(subkey_name, L"Application%d", i);
2059+
2060+
HKEY candidate;
2061+
if (RegCreateKeyExW(base_key, subkey_name, 0, nullptr, 0, KEY_READ | KEY_WRITE,
2062+
nullptr, &candidate, nullptr) != ERROR_SUCCESS)
2063+
break;
2064+
2065+
wchar_t name_val[MAX_PATH] = {};
2066+
DWORD name_val_size = sizeof(name_val);
2067+
DWORD type = 0;
2068+
const bool has_name = RegQueryValueExW(candidate, L"Name", nullptr, &type,
2069+
reinterpret_cast<BYTE*>(name_val), &name_val_size) == ERROR_SUCCESS;
2070+
2071+
if (!has_name || _wcsicmp(name_val, exe_path) == 0)
2072+
{
2073+
app_key = candidate;
2074+
is_existing = has_name;
2075+
break;
2076+
}
2077+
RegCloseKey(candidate);
2078+
}
2079+
2080+
if (app_key)
2081+
{
2082+
if (enable)
2083+
{
2084+
RegSetValueExW(app_key, L"Name", 0, REG_SZ,
2085+
reinterpret_cast<const BYTE*>(exe_path), static_cast<DWORD>((wcslen(exe_path) + 1) * sizeof(wchar_t)));
2086+
2087+
constexpr const wchar_t behaviors[] = L"BufferUpgradeOverride=1";
2088+
RegSetValueExW(app_key, L"D3DBehaviors", 0, REG_SZ,
2089+
reinterpret_cast<const BYTE*>(behaviors), sizeof(behaviors));
2090+
}
2091+
else if (is_existing)
2092+
{
2093+
// Remove D3DBehaviors so Auto HDR no longer activates.
2094+
RegDeleteValueW(app_key, L"D3DBehaviors");
2095+
}
2096+
2097+
RegCloseKey(app_key);
2098+
}
2099+
2100+
RegCloseKey(base_key);
2101+
}
2102+
2103+
void QtHost::UpdateAutoHDRRegistration(bool enable)
2104+
{
2105+
RegisterAutoHDR(enable);
2106+
}
2107+
20402108
static BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
20412109
{
20422110
if (dwCtrlType != CTRL_C_EVENT)
@@ -2297,8 +2365,8 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptr<VM
22972365
Console.Warning("Skipping autoboot due to no boot parameters.");
22982366
autoboot.reset();
22992367
}
2300-
2301-
if(autoboot && autoboot->start_turbo.value_or(false) && autoboot->start_unlimited.value_or(false))
2368+
2369+
if (autoboot && autoboot->start_turbo.value_or(false) && autoboot->start_unlimited.value_or(false))
23022370
{
23032371
Console.Warning("Both turbo and unlimited frame limit modes requested. Using unlimited.");
23042372
autoboot->start_turbo.reset();
@@ -2415,6 +2483,10 @@ int main(int argc, char* argv[])
24152483
if (!QtHost::InitializeConfig())
24162484
return EXIT_FAILURE;
24172485

2486+
#ifdef _WIN32
2487+
RegisterAutoHDR(Host::GetBoolSettingValue("EmuCore/GS", "EnableAutoHDR", false));
2488+
#endif
2489+
24182490
// Are we just setting up the configuration?
24192491
if (s_test_config_and_exit)
24202492
return EXIT_SUCCESS;

pcsx2-qt/QtHost.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,9 @@ namespace QtHost
298298
/// inside its exec function, which would cause a crash.
299299
void LockVMWithDialog();
300300
void UnlockVMWithDialog();
301+
302+
#ifdef _WIN32
303+
/// Registers or unregisters PCSX2 with Windows for Auto HDR.
304+
void UpdateAutoHDRRegistration(bool enable);
305+
#endif
301306
} // namespace QtHost

pcsx2-qt/Settings/GraphicsDisplaySettingsTab.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@
8787
</property>
8888
</widget>
8989
</item>
90+
<item row="3" column="1">
91+
<widget class="QCheckBox" name="enableAutoHDR">
92+
<property name="toolTip">
93+
<string>Registers PCSX2 with Windows so that Auto HDR is applied to the game image. Requires Direct3D 11 or Direct3D 12. Requires restarting PCSX2 to take effect.</string>
94+
</property>
95+
<property name="text">
96+
<string>Enable Windows Auto HDR</string>
97+
</property>
98+
</widget>
99+
</item>
90100
</layout>
91101
</item>
92102
<item row="2" column="0">

pcsx2-qt/Settings/GraphicsSettingsWidget.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: GPL-3.0+
33

44
#include "GraphicsSettingsWidget.h"
5+
#include "QtHost.h"
56
#include "QtUtils.h"
67
#include "SettingWidgetBinder.h"
78
#include "SettingsWindow.h"
@@ -222,6 +223,7 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* settings_dialog,
222223
// Advanced Settings
223224
//////////////////////////////////////////////////////////////////////////
224225
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_advanced.useBlitSwapChain, "EmuCore/GS", "UseBlitSwapChain", false);
226+
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_display.enableAutoHDR, "EmuCore/GS", "EnableAutoHDR", false);
225227
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_advanced.useDebugDevice, "EmuCore/GS", "UseDebugDevice", false);
226228
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_advanced.disableMailboxPresentation, "EmuCore/GS", "DisableMailboxPresentation", false);
227229
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_advanced.extendedUpscales, "EmuCore/GS", "ExtendedUpscalingMultipliers", false);
@@ -271,6 +273,11 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* settings_dialog,
271273

272274
connect(m_header.rendererDropdown, &QComboBox::currentIndexChanged, this, &GraphicsSettingsWidget::onRendererChanged);
273275
connect(m_header.adapterDropdown, &QComboBox::currentIndexChanged, this, &GraphicsSettingsWidget::onAdapterChanged);
276+
#ifdef _WIN32
277+
connect(m_display.enableAutoHDR, &QCheckBox::checkStateChanged, this, [](Qt::CheckState state) {
278+
QtHost::UpdateAutoHDRRegistration(state == Qt::Checked);
279+
});
280+
#endif
274281
connect(m_hw.enableHWFixes, &QCheckBox::checkStateChanged, this, &GraphicsSettingsWidget::updateRendererDependentOptions);
275282
connect(m_advanced.extendedUpscales, &QCheckBox::checkStateChanged, this, &GraphicsSettingsWidget::updateRendererDependentOptions);
276283
connect(m_hw.textureFiltering, &QComboBox::currentIndexChanged, this, &GraphicsSettingsWidget::onTextureFilteringChange);
@@ -281,6 +288,8 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* settings_dialog,
281288
// Exclusive fullscreen control is Windows-only.
282289
m_advanced.advancedOptionsFormLayout->removeRow(2);
283290
m_advanced.exclusiveFullscreenControl = nullptr;
291+
// Auto HDR is Windows-only.
292+
m_display.enableAutoHDR->setVisible(false);
284293
#endif
285294

286295
#ifndef PCSX2_DEVBUILD
@@ -738,6 +747,12 @@ GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* settings_dialog,
738747
tr("Change the compression algorithm used when creating a GS dump."));
739748

740749
//: Blit = a data operation. You might want to write it as-is, but fully uppercased. More information: https://en.wikipedia.org/wiki/Bit_blit \nSwap chain: see Microsoft's Terminology Portal.
750+
dialog()->registerWidgetHelp(m_display.enableAutoHDR, tr("Enable Windows Auto HDR"), tr("Unchecked"),
751+
tr("Registers PCSX2 with Windows to enable Auto HDR on the game image. "
752+
"Windows Auto HDR automatically enhances SDR content with high dynamic range on supported displays. "
753+
"Only applies when using the Direct3D 11 or Direct3D 12 renderers. "
754+
"Requires restarting PCSX2 to take effect."));
755+
741756
dialog()->registerWidgetHelp(m_advanced.useBlitSwapChain, tr("Use Blit Swap Chain"), tr("Unchecked"),
742757
//: Blit = a data operation. You might want to write it as-is, but fully uppercased. More information: https://en.wikipedia.org/wiki/Bit_blit
743758
tr("Uses a blit presentation model instead of flipping when using the Direct3D 11 "

0 commit comments

Comments
 (0)