Enable anisotropic filtering when the game requests it

This commit is contained in:
Pokechu22 2021-07-30 12:14:54 -07:00
parent 002a96adb0
commit 26a2e488ac
7 changed files with 17 additions and 19 deletions

View File

@ -336,10 +336,10 @@ ID3D11SamplerState* StateCache::Get(SamplerState state)
sampdc.MinLOD = state.tm1.min_lod / 16.f; sampdc.MinLOD = state.tm1.min_lod / 16.f;
sampdc.MipLODBias = state.tm0.lod_bias / 256.f; sampdc.MipLODBias = state.tm0.lod_bias / 256.f;
if (state.tm0.anisotropic_filtering) if (state.tm0.anisotropic_filtering != 0)
{ {
sampdc.Filter = D3D11_FILTER_ANISOTROPIC; sampdc.Filter = D3D11_FILTER_ANISOTROPIC;
sampdc.MaxAnisotropy = 1u << g_ActiveConfig.iMaxAnisotropy; sampdc.MaxAnisotropy = 1u << state.tm0.anisotropic_filtering;
} }
ComPtr<ID3D11SamplerState> res; ComPtr<ID3D11SamplerState> res;

View File

@ -128,10 +128,10 @@ static void GetD3DSamplerDesc(D3D12_SAMPLER_DESC* desc, const SamplerState& stat
desc->MipLODBias = static_cast<s32>(state.tm0.lod_bias) / 256.f; desc->MipLODBias = static_cast<s32>(state.tm0.lod_bias) / 256.f;
desc->ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; desc->ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
if (state.tm0.anisotropic_filtering) if (state.tm0.anisotropic_filtering != 0)
{ {
desc->Filter = D3D12_FILTER_ANISOTROPIC; desc->Filter = D3D12_FILTER_ANISOTROPIC;
desc->MaxAnisotropy = 1u << g_ActiveConfig.iMaxAnisotropy; desc->MaxAnisotropy = 1u << state.tm0.anisotropic_filtering;
} }
} }

View File

@ -102,10 +102,10 @@ void SamplerCache::SetParameters(GLuint sampler_id, const SamplerState& params)
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, params.tm0.lod_bias / 256.f); glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, params.tm0.lod_bias / 256.f);
} }
if (params.tm0.anisotropic_filtering && g_ogl_config.bSupportsAniso) if (params.tm0.anisotropic_filtering != 0 && g_ogl_config.bSupportsAniso)
{ {
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT,
static_cast<float>(1 << g_ActiveConfig.iMaxAnisotropy)); static_cast<float>(1 << params.tm0.anisotropic_filtering));
} }
} }

View File

@ -369,11 +369,11 @@ VkSampler ObjectCache::GetSampler(const SamplerState& info)
}; };
// Can we use anisotropic filtering with this sampler? // Can we use anisotropic filtering with this sampler?
if (info.tm0.anisotropic_filtering && g_vulkan_context->SupportsAnisotropicFiltering()) if (info.tm0.anisotropic_filtering != 0 && g_vulkan_context->SupportsAnisotropicFiltering())
{ {
// Cap anisotropy to device limits. // Cap anisotropy to device limits.
create_info.anisotropyEnable = VK_TRUE; create_info.anisotropyEnable = VK_TRUE;
create_info.maxAnisotropy = std::min(static_cast<float>(1 << g_ActiveConfig.iMaxAnisotropy), create_info.maxAnisotropy = std::min(static_cast<float>(1 << info.tm0.anisotropic_filtering),
g_vulkan_context->GetMaxSamplerAnisotropy()); g_vulkan_context->GetMaxSamplerAnisotropy());
} }

View File

@ -311,10 +311,15 @@ void SamplerState::Generate(const BPMemory& bp, u32 index)
}; };
tm0.wrap_u = filter_invalid_wrap(bp_tm0.wrap_s); tm0.wrap_u = filter_invalid_wrap(bp_tm0.wrap_s);
tm0.wrap_v = filter_invalid_wrap(bp_tm0.wrap_t); tm0.wrap_v = filter_invalid_wrap(bp_tm0.wrap_t);
if (bp_tm0.max_aniso == MaxAniso::Two)
tm0.anisotropic_filtering = 1;
else if (bp_tm0.max_aniso == MaxAniso::Four)
tm0.anisotropic_filtering = 2;
else
tm0.anisotropic_filtering = 0;
tm0.diag_lod = bp_tm0.diag_lod; tm0.diag_lod = bp_tm0.diag_lod;
tm0.anisotropic_filtering = false; // TODO: Respect BP anisotropic filtering mode tm0.lod_clamp = bp_tm0.lod_clamp; // TODO: What does this do?
tm0.lod_clamp = bp_tm0.lod_clamp; // TODO: What does this do?
} }
namespace RenderState namespace RenderState

View File

@ -199,7 +199,7 @@ struct SamplerState
BitField<7, 1, LODType> diag_lod; BitField<7, 1, LODType> diag_lod;
BitField<8, 16, s32> lod_bias; // multiplied by 256, higher precision than normal BitField<8, 16, s32> lod_bias; // multiplied by 256, higher precision than normal
BitField<24, 1, bool, u32> lod_clamp; // TODO: This isn't currently implemented BitField<24, 1, bool, u32> lod_clamp; // TODO: This isn't currently implemented
BitField<25, 1, bool, u32> anisotropic_filtering; // TODO: This doesn't use the BP one yet BitField<25, 4, u32> anisotropic_filtering;
u32 hex = 0; u32 hex = 0;
}; };
union TM1 union TM1

View File

@ -1078,11 +1078,7 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
state.tm0.mag_filter = FilterMode::Linear; state.tm0.mag_filter = FilterMode::Linear;
if (tm0.mipmap_filter != MipMode::None) if (tm0.mipmap_filter != MipMode::None)
state.tm0.mipmap_filter = FilterMode::Linear; state.tm0.mipmap_filter = FilterMode::Linear;
state.tm0.anisotropic_filtering = true; state.tm0.anisotropic_filtering = g_ActiveConfig.iMaxAnisotropy;
}
else
{
state.tm0.anisotropic_filtering = false;
} }
if (has_arbitrary_mips && tm0.mipmap_filter != MipMode::None) if (has_arbitrary_mips && tm0.mipmap_filter != MipMode::None)
@ -1093,9 +1089,6 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
// Correct this with the upscaling factor of custom textures. // Correct this with the upscaling factor of custom textures.
s32 lod_offset = std::log2(g_framebuffer_manager->GetEFBScale() / custom_tex_scale) * 256.f; s32 lod_offset = std::log2(g_framebuffer_manager->GetEFBScale() / custom_tex_scale) * 256.f;
state.tm0.lod_bias = std::clamp<s32>(state.tm0.lod_bias + lod_offset, -32768, 32767); state.tm0.lod_bias = std::clamp<s32>(state.tm0.lod_bias + lod_offset, -32768, 32767);
// Anisotropic also pushes mips farther away so it cannot be used either
state.tm0.anisotropic_filtering = false;
} }
g_gfx->SetSamplerState(index, state); g_gfx->SetSamplerState(index, state);