From 282e04bffb4962dcc1d8aee2cb0fd2a1a45c86e6 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 16 Nov 2021 23:07:17 +0100 Subject: TextureCache: Add automatic anisotropic filtering and refactor code. --- src/common/settings.h | 2 +- src/video_core/renderer_opengl/gl_texture_cache.cpp | 8 +------- src/video_core/renderer_vulkan/vk_texture_cache.cpp | 8 +------- src/video_core/textures/texture.cpp | 15 ++++++++++++++- src/yuzu/configuration/configure_graphics_advanced.ui | 5 +++++ 5 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/common/settings.h b/src/common/settings.h index c7610ef1c..42f8b4a7d 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -515,7 +515,7 @@ struct Values { #endif FullscreenMode::Borderless, FullscreenMode::Exclusive, "fullscreen_mode"}; RangedSetting aspect_ratio{0, 0, 3, "aspect_ratio"}; - RangedSetting max_anisotropy{0, 0, 4, "max_anisotropy"}; + RangedSetting max_anisotropy{0, 0, 5, "max_anisotropy"}; Setting use_speed_limit{true, "use_speed_limit"}; RangedSetting speed_limit{100, 0, 9999, "speed_limit"}; Setting use_disk_shader_cache{true, "use_disk_shader_cache"}; diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index c2668fee6..1d3f193af 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -1201,13 +1201,7 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const TSCEntry& config) { glSamplerParameterfv(handle, GL_TEXTURE_BORDER_COLOR, config.BorderColor().data()); if (GLAD_GL_ARB_texture_filter_anisotropic || GLAD_GL_EXT_texture_filter_anisotropic) { - const f32 setting_anisotropic = - static_cast(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; + const f32 max_anisotropy = std::clamp(config.MaxAnisotropy(), 1.0f, 16.0f); glSamplerParameterf(handle, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropy); } else { LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_anisotropic is required"); diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 7db561ca0..daf26f380 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -1448,13 +1448,7 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const Tegra::Texture::TSCEntry& t LOG_WARNING(Render_Vulkan, "VK_EXT_sampler_filter_minmax is required"); } // Some games have samplers with garbage. Sanitize them here. - const f32 setting_anisotropic = - static_cast(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; + const f32 max_anisotropy = std::clamp(tsc.MaxAnisotropy(), 1.0f, 16.0f); sampler = device.GetLogical().CreateSampler(VkSamplerCreateInfo{ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, diff --git a/src/video_core/textures/texture.cpp b/src/video_core/textures/texture.cpp index b2d5bb03e..ba066f98f 100644 --- a/src/video_core/textures/texture.cpp +++ b/src/video_core/textures/texture.cpp @@ -6,6 +6,7 @@ #include #include "common/cityhash.h" +#include "common/settings.h" #include "video_core/textures/texture.h" using Tegra::Texture::TICEntry; @@ -61,7 +62,19 @@ std::array TSCEntry::BorderColor() const noexcept { } float TSCEntry::MaxAnisotropy() const noexcept { - return static_cast(1U << max_anisotropy); + if (max_anisotropy == 0 && mipmap_filter != TextureMipmapFilter::Linear) { + return 1.0f; + } + const auto anisotropic_settings = Settings::values.max_anisotropy.GetValue(); + u32 new_max_anisotropic{}; + if (anisotropic_settings == 0) { + const auto anisotropic_based_onscale = Settings::values.resolution_info.up_scale >> + Settings::values.resolution_info.down_shift; + new_max_anisotropic = std::max(anisotropic_based_onscale + 1U, 1U); + } else { + new_max_anisotropic = Settings::values.max_anisotropy.GetValue(); + } + return static_cast(1U << std::min(max_anisotropy + anisotropic_settings - 1, 31U)); } } // namespace Tegra::Texture diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index cbbcd45a0..96de0b3d1 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui @@ -123,6 +123,11 @@ + + + Automatic + + Default -- cgit v1.2.3