Skip to content

Commit

Permalink
GPU/HW: Support filtering with texture cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 25, 2024
1 parent 0ae8fcc commit a804801
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
59 changes: 35 additions & 24 deletions src/core/gpu_hw_shadergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -875,33 +898,17 @@ 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
)";

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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/shader_cache_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

#include "common/types.h"

static constexpr u32 SHADER_CACHE_VERSION = 21;
static constexpr u32 SHADER_CACHE_VERSION = 22;

0 comments on commit a804801

Please sign in to comment.