Added MSAA level availability checks (#1446)
Some checks failed
validate-internal / build (push) Failing after 8s

This commit is contained in:
Hyper 2025-03-24 17:57:50 +00:00 committed by GitHub
parent d15bb7a501
commit 8e0d1f2873
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 8 deletions

View file

@ -1741,6 +1741,21 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver)
ApplyLowEndDefaults(); ApplyLowEndDefaults();
} }
const RenderSampleCounts colourSampleCount = g_device->getSampleCountsSupported(RenderFormat::R16G16B16A16_FLOAT);
const RenderSampleCounts depthSampleCount = g_device->getSampleCountsSupported(RenderFormat::D32_FLOAT);
const RenderSampleCounts commonSampleCount = colourSampleCount & depthSampleCount;
// Disable specific MSAA levels if they are not supported.
if ((commonSampleCount & RenderSampleCount::COUNT_2) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA2x);
if ((commonSampleCount & RenderSampleCount::COUNT_4) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA4x);
if ((commonSampleCount & RenderSampleCount::COUNT_8) == 0)
Config::AntiAliasing.InaccessibleValues.emplace(EAntiAliasing::MSAA8x);
// Set Anti-Aliasing to nearest supported level.
Config::AntiAliasing.SnapToNearestAccessibleValue(false);
g_queue = g_device->createCommandQueue(RenderCommandListType::DIRECT); g_queue = g_device->createCommandQueue(RenderCommandListType::DIRECT);
for (auto& commandList : g_commandLists) for (auto& commandList : g_commandLists)

View file

@ -1043,6 +1043,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
} }
config->Value = it->first; config->Value = it->first;
config->SnapToNearestAccessibleValue(rightTapped);
if (increment || decrement) if (increment || decrement)
Game_PlaySound("sys_actstg_pausecursor"); Game_PlaySound("sys_actstg_pausecursor");
@ -1271,7 +1272,7 @@ static void DrawConfigOptions()
DrawConfigOption(rowCount++, yOffset, &Config::VSync, true); DrawConfigOption(rowCount++, yOffset, &Config::VSync, true);
DrawConfigOption(rowCount++, yOffset, &Config::FPS, true, nullptr, FPS_MIN, 120, FPS_MAX); DrawConfigOption(rowCount++, yOffset, &Config::FPS, true, nullptr, FPS_MIN, 120, FPS_MAX);
DrawConfigOption(rowCount++, yOffset, &Config::Brightness, true); DrawConfigOption(rowCount++, yOffset, &Config::Brightness, true);
DrawConfigOption(rowCount++, yOffset, &Config::AntiAliasing, true); DrawConfigOption(rowCount++, yOffset, &Config::AntiAliasing, Config::AntiAliasing.InaccessibleValues.size() != 3, &Localise("Options_Desc_NotAvailableHardware"));
DrawConfigOption(rowCount++, yOffset, &Config::TransparencyAntiAliasing, Config::AntiAliasing != EAntiAliasing::None, &Localise("Options_Desc_NotAvailableMSAA")); DrawConfigOption(rowCount++, yOffset, &Config::TransparencyAntiAliasing, Config::AntiAliasing != EAntiAliasing::None, &Localise("Options_Desc_NotAvailableMSAA"));
DrawConfigOption(rowCount++, yOffset, &Config::ShadowResolution, true); DrawConfigOption(rowCount++, yOffset, &Config::ShadowResolution, true);
DrawConfigOption(rowCount++, yOffset, &Config::GITextureFiltering, true); DrawConfigOption(rowCount++, yOffset, &Config::GITextureFiltering, true);

View file

@ -494,6 +494,9 @@ template<typename T, bool isHidden>
void ConfigDef<T, isHidden>::MakeDefault() void ConfigDef<T, isHidden>::MakeDefault()
{ {
Value = DefaultValue; Value = DefaultValue;
if constexpr (std::is_enum_v<T>)
SnapToNearestAccessibleValue(false);
} }
template<typename T, bool isHidden> template<typename T, bool isHidden>
@ -696,6 +699,51 @@ void ConfigDef<T, isHidden>::GetLocaleStrings(std::vector<std::string_view>& loc
} }
} }
template<typename T, bool isHidden>
void ConfigDef<T, isHidden>::SnapToNearestAccessibleValue(bool searchUp)
{
if constexpr (std::is_enum_v<T>)
{
if (EnumTemplateReverse.empty() || InaccessibleValues.empty())
return;
if (EnumTemplateReverse.size() == InaccessibleValues.size())
{
assert(false && "All enum values are marked inaccessible and the nearest accessible value cannot be determined.");
return;
}
auto it = EnumTemplateReverse.find(Value);
if (it == EnumTemplateReverse.end())
{
assert(false && "Enum value does not exist in the template.");
return;
}
// Skip the enum value if it's marked as inaccessible.
while (InaccessibleValues.find(it->first) != InaccessibleValues.end())
{
if (searchUp)
{
++it;
if (it == EnumTemplateReverse.end())
it = EnumTemplateReverse.begin();
}
else
{
if (it == EnumTemplateReverse.begin())
it = EnumTemplateReverse.end();
--it;
}
}
Value = it->first;
}
}
std::filesystem::path Config::GetConfigPath() std::filesystem::path Config::GetConfigPath()
{ {
return GetUserPath() / "config.toml"; return GetUserPath() / "config.toml";

View file

@ -20,6 +20,7 @@ public:
virtual std::string GetDefinition(bool withSection = false) const = 0; virtual std::string GetDefinition(bool withSection = false) const = 0;
virtual std::string ToString(bool strWithQuotes = true) const = 0; virtual std::string ToString(bool strWithQuotes = true) const = 0;
virtual void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const = 0; virtual void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const = 0;
virtual void SnapToNearestAccessibleValue(bool searchUp) = 0;
}; };
#define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>> #define CONFIG_LOCALE std::unordered_map<ELanguage, std::tuple<std::string, std::string>>
@ -158,7 +159,8 @@ public:
CONFIG_LOCALE* Locale{}; CONFIG_LOCALE* Locale{};
T DefaultValue{}; T DefaultValue{};
T Value{ DefaultValue }; T Value{ DefaultValue };
std::unordered_map<std::string, T>* EnumTemplate; std::set<T> InaccessibleValues{};
std::unordered_map<std::string, T>* EnumTemplate{};
std::map<T, std::string> EnumTemplateReverse{}; std::map<T, std::string> EnumTemplateReverse{};
CONFIG_ENUM_LOCALE(T)* EnumLocale{}; CONFIG_ENUM_LOCALE(T)* EnumLocale{};
std::function<void(ConfigDef<T, isHidden>*)> Callback; std::function<void(ConfigDef<T, isHidden>*)> Callback;
@ -183,25 +185,20 @@ public:
~ConfigDef(); ~ConfigDef();
bool IsHidden() override; bool IsHidden() override;
void ReadValue(toml::v3::ex::parse_result& toml) override; void ReadValue(toml::v3::ex::parse_result& toml) override;
void MakeDefault() override; void MakeDefault() override;
std::string_view GetSection() const override; std::string_view GetSection() const override;
std::string_view GetName() const override; std::string_view GetName() const override;
std::string GetNameLocalised(ELanguage language) const override; std::string GetNameLocalised(ELanguage language) const override;
std::string GetDescription(ELanguage language) const override; std::string GetDescription(ELanguage language) const override;
bool IsDefaultValue() const override; bool IsDefaultValue() const override;
const void* GetValue() const override; const void* GetValue() const override;
std::string GetValueLocalised(ELanguage language) const override; std::string GetValueLocalised(ELanguage language) const override;
std::string GetValueDescription(ELanguage language) const override; std::string GetValueDescription(ELanguage language) const override;
std::string GetDefinition(bool withSection = false) const override; std::string GetDefinition(bool withSection = false) const override;
std::string ToString(bool strWithQuotes = true) const override; std::string ToString(bool strWithQuotes = true) const override;
void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const override; void GetLocaleStrings(std::vector<std::string_view>& localeStrings) const override;
void SnapToNearestAccessibleValue(bool searchUp) override;
operator T() const operator T() const
{ {