TextureCache: Make a better Anisotropic setter.

This commit is contained in:
Fernando Sahmkow 2021-10-30 01:52:11 +02:00
parent 6c97ab571a
commit 5230378709
4 changed files with 21 additions and 24 deletions

View file

@ -1201,7 +1201,14 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const TSCEntry& config) {
glSamplerParameterfv(handle, GL_TEXTURE_BORDER_COLOR, config.BorderColor().data()); glSamplerParameterfv(handle, GL_TEXTURE_BORDER_COLOR, config.BorderColor().data());
if (GLAD_GL_ARB_texture_filter_anisotropic || GLAD_GL_EXT_texture_filter_anisotropic) { if (GLAD_GL_ARB_texture_filter_anisotropic || GLAD_GL_EXT_texture_filter_anisotropic) {
glSamplerParameterf(handle, GL_TEXTURE_MAX_ANISOTROPY, config.MaxAnisotropy()); const f32 setting_anisotropic =
static_cast<f32>(1U << Settings::values.max_anisotropy.GetValue());
const f32 game_anisotropic = std::clamp(config.MaxAnisotropy(), 1.0f, 16.0f);
const bool aument_anisotropic =
game_anisotropic > 1.0f || config.mipmap_filter == TextureMipmapFilter::Linear;
const f32 max_anisotropy =
aument_anisotropic ? std::max(game_anisotropic, setting_anisotropic) : game_anisotropic;
glSamplerParameterf(handle, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropy);
} else { } else {
LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_anisotropic is required"); LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_anisotropic is required");
} }

View file

@ -1448,7 +1448,14 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t
LOG_WARNING(Render_Vulkan, "VK_EXT_sampler_filter_minmax is required"); LOG_WARNING(Render_Vulkan, "VK_EXT_sampler_filter_minmax is required");
} }
// Some games have samplers with garbage. Sanitize them here. // Some games have samplers with garbage. Sanitize them here.
const float max_anisotropy = std::clamp(tsc.MaxAnisotropy(), 1.0f, 16.0f); const f32 setting_anisotropic =
static_cast<f32>(1U << Settings::values.max_anisotropy.GetValue());
const f32 game_anisotropic = std::clamp(tsc.MaxAnisotropy(), 1.0f, 16.0f);
const bool aument_anisotropic =
game_anisotropic > 1.0f || tsc.mipmap_filter == TextureMipmapFilter::Linear;
const f32 max_anisotropy =
aument_anisotropic ? std::max(game_anisotropic, setting_anisotropic) : game_anisotropic;
sampler = device.GetLogical().CreateSampler(VkSamplerCreateInfo{ sampler = device.GetLogical().CreateSampler(VkSamplerCreateInfo{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = pnext, .pNext = pnext,

View file

@ -6,7 +6,6 @@
#include <array> #include <array>
#include "common/cityhash.h" #include "common/cityhash.h"
#include "common/settings.h"
#include "video_core/textures/texture.h" #include "video_core/textures/texture.h"
using Tegra::Texture::TICEntry; using Tegra::Texture::TICEntry;
@ -51,22 +50,6 @@ constexpr std::array<float, 256> SRGB_CONVERSION_LUT = {
0.917104f, 0.929242f, 0.941493f, 0.953859f, 0.966338f, 1.000000f, 1.000000f, 1.000000f, 0.917104f, 0.929242f, 0.941493f, 0.953859f, 0.966338f, 1.000000f, 1.000000f, 1.000000f,
}; };
unsigned SettingsMinimumAnisotropy() noexcept {
switch (static_cast<Anisotropy>(Settings::values.max_anisotropy.GetValue())) {
default:
case Anisotropy::Default:
return 1U;
case Anisotropy::Filter2x:
return 2U;
case Anisotropy::Filter4x:
return 4U;
case Anisotropy::Filter8x:
return 8U;
case Anisotropy::Filter16x:
return 16U;
}
}
} // Anonymous namespace } // Anonymous namespace
std::array<float, 4> TSCEntry::BorderColor() const noexcept { std::array<float, 4> TSCEntry::BorderColor() const noexcept {
@ -78,7 +61,7 @@ std::array<float, 4> TSCEntry::BorderColor() const noexcept {
} }
float TSCEntry::MaxAnisotropy() const noexcept { float TSCEntry::MaxAnisotropy() const noexcept {
return static_cast<float>(std::max(1U << max_anisotropy, SettingsMinimumAnisotropy())); return static_cast<float>(1U << max_anisotropy);
} }
} // namespace Tegra::Texture } // namespace Tegra::Texture

View file

@ -130,22 +130,22 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>2x (WILL BREAK THINGS)</string> <string>2x</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>4x (WILL BREAK THINGS)</string> <string>4x</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>8x (WILL BREAK THINGS)</string> <string>8x</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>16x (WILL BREAK THINGS)</string> <string>16x</string>
</property> </property>
</item> </item>
</widget> </widget>