Skip to content

Commit d9e442e

Browse files
committed
GPUDevice: Don't duplicate fullscreen modes
Also sort the list while we're at it.
1 parent 424a8e7 commit d9e442e

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/util/d3d_common.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
1+
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <stenzek@gmail.com>
22
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
33

44
#include "d3d_common.h"
@@ -14,6 +14,7 @@
1414

1515
#include "fmt/format.h"
1616

17+
#include <algorithm>
1718
#include <d3d11.h>
1819
#include <d3d12.h>
1920
#include <d3dcompiler.h>
@@ -344,12 +345,16 @@ std::optional<GPUDevice::AdapterInfoList> D3DCommon::GetAdapterInfoList(Error* e
344345
{
345346
for (const DXGI_MODE_DESC& mode : dmodes)
346347
{
347-
ai.fullscreen_modes.push_back(
348-
GPUDevice::ExclusiveFullscreenMode{.width = mode.Width,
349-
.height = mode.Height,
350-
.refresh_rate = static_cast<float>(mode.RefreshRate.Numerator) /
351-
static_cast<float>(mode.RefreshRate.Denominator)});
348+
const GPUDevice::ExclusiveFullscreenMode efm{.width = mode.Width,
349+
.height = mode.Height,
350+
.refresh_rate =
351+
static_cast<float>(mode.RefreshRate.Numerator) /
352+
static_cast<float>(mode.RefreshRate.Denominator)};
353+
if (std::ranges::find(ai.fullscreen_modes, efm) == ai.fullscreen_modes.end())
354+
ai.fullscreen_modes.push_back(efm);
352355
}
356+
357+
std::sort(ai.fullscreen_modes.begin(), ai.fullscreen_modes.end());
353358
}
354359
else
355360
{

src/util/gpu_device.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,25 @@ TinyString GPUDevice::ExclusiveFullscreenMode::ToString() const
848848
return TinyString::from_format("{} x {} @ {} hz", width, height, refresh_rate);
849849
}
850850

851+
bool GPUDevice::ExclusiveFullscreenMode::operator==(const ExclusiveFullscreenMode& rhs) const
852+
{
853+
return (width == rhs.width && height == rhs.height && refresh_rate == rhs.refresh_rate);
854+
}
855+
856+
bool GPUDevice::ExclusiveFullscreenMode::operator!=(const ExclusiveFullscreenMode& rhs) const
857+
{
858+
return (width != rhs.width || height != rhs.height || refresh_rate != rhs.refresh_rate);
859+
}
860+
861+
bool GPUDevice::ExclusiveFullscreenMode::operator<(const ExclusiveFullscreenMode& rhs) const
862+
{
863+
if (width != rhs.width)
864+
return width < rhs.width;
865+
if (height != rhs.height)
866+
return height < rhs.height;
867+
return refresh_rate < rhs.refresh_rate;
868+
}
869+
851870
void GPUDevice::DumpBadShader(std::string_view code, std::string_view errors)
852871
{
853872
static u32 next_bad_shader_id = 0;

src/util/gpu_device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ class GPUDevice
586586

587587
TinyString ToString() const;
588588

589+
bool operator==(const ExclusiveFullscreenMode& rhs) const;
590+
bool operator!=(const ExclusiveFullscreenMode& rhs) const;
591+
bool operator<(const ExclusiveFullscreenMode& rhs) const;
592+
589593
static std::optional<ExclusiveFullscreenMode> Parse(std::string_view str);
590594
};
591595

0 commit comments

Comments
 (0)