From a804801a1b148a357314c15c3a10388f98aece00 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 25 Nov 2024 13:23:39 +1000 Subject: [PATCH] GPU/HW: Support filtering with texture cache --- src/core/gpu_hw_shadergen.cpp | 59 +++++++++++++++++++-------------- src/core/shader_cache_version.h | 2 +- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index e85738c17..64cdcb1ef 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -822,11 +822,34 @@ uint2 FloatToIntegerCoords(float2 coords) return uint2((UPSCALED == 0 || FORCE_ROUND_TEXCOORDS != 0) ? roundEven(coords) : floor(coords)); } -#if !PAGE_TEXTURE +#if PAGE_TEXTURE + +float4 SampleFromPageTexture(float2 coords) +{ + // Cached textures. + uint2 icoord = ApplyTextureWindow(FloatToIntegerCoords(coords)); +#if UPSCALED + float2 fpart = frac(coords); + coords = (float2(icoord) + fpart); +#else + // Drop fractional part. + coords = float2(icoord); +#endif + + // Normalize. + coords = coords * (1.0f / 256.0f); + return SAMPLE_TEXTURE(samp0, coords); +} + +#endif + +#if !PAGE_TEXTURE || TEXTURE_FILTERING float4 SampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords) { - #if PALETTE + #if PAGE_TEXTURE + return SampleFromPageTexture(coords); + #elif PALETTE uint2 icoord = ApplyTextureWindow(FloatToIntegerCoords(coords)); uint2 vicoord; @@ -875,26 +898,7 @@ float4 SampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords) #endif } -#else - -float4 SampleFromPageTexture(float2 coords) -{ - // Cached textures. - uint2 icoord = ApplyTextureWindow(FloatToIntegerCoords(coords)); -#if UPSCALED - float2 fpart = frac(coords); - coords = (float2(icoord) + fpart); -#else - // Drop fractional part. - coords = float2(icoord); -#endif - - // Normalize. - coords = coords * (1.0f / 256.0f); - return SAMPLE_TEXTURE(samp0, coords); -} - -#endif +#endif // !PAGE_TEXTURE || TEXTURE_FILTERING #endif // TEXTURED )"; @@ -902,6 +906,9 @@ float4 SampleFromPageTexture(float2 coords) const u32 num_fragment_outputs = use_rov ? 0 : (use_dual_source ? 2 : 1); if (textured && page_texture) { + if (texture_filtering != GPUTextureFilter::Nearest) + WriteBatchTextureFilter(ss, texture_filtering); + if (uv_limits) { DeclareFragmentEntryPoint(ss, 1, 1, {{"nointerpolation", "float4 v_uv_limits"}}, true, num_fragment_outputs, @@ -960,7 +967,7 @@ float4 SampleFromPageTexture(float2 coords) #if TEXTURED float4 texcol; - #if PAGE_TEXTURE + #if PAGE_TEXTURE && !TEXTURE_FILTERING #if UV_LIMITS texcol = SampleFromPageTexture(clamp(v_tex0, v_uv_limits.xy, v_uv_limits.zw)); #else @@ -971,7 +978,11 @@ float4 SampleFromPageTexture(float2 coords) ialpha = 1.0; #elif TEXTURE_FILTERING - FilteredSampleFromVRAM(v_texpage, v_tex0, v_uv_limits, texcol, ialpha); + #if PAGE_TEXTURE + FilteredSampleFromVRAM(int2(0, 0), v_tex0, v_uv_limits, texcol, ialpha); + #else + FilteredSampleFromVRAM(v_texpage, v_tex0, v_uv_limits, texcol, ialpha); + #endif if (ialpha < 0.5) discard; #else diff --git a/src/core/shader_cache_version.h b/src/core/shader_cache_version.h index 89fec6d32..95a2b141b 100644 --- a/src/core/shader_cache_version.h +++ b/src/core/shader_cache_version.h @@ -5,4 +5,4 @@ #include "common/types.h" -static constexpr u32 SHADER_CACHE_VERSION = 21; +static constexpr u32 SHADER_CACHE_VERSION = 22;