Skip to content

Commit

Permalink
GPU/ShaderGen: Use sample instead of load at 1x as well
Browse files Browse the repository at this point in the history
Consistency. Mali ends up ever-so-slightly faster with sample versus
texel loads, apparently.

Also fixes compile errors when using texture filtering on GLSL ES.
  • Loading branch information
stenzek committed Dec 13, 2024
1 parent db848d1 commit 8f19912
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/gpu_hw_shadergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ float4 SampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords)
#if !UPSCALED
uint2 icoord = ApplyTextureWindow(FloatToIntegerCoords(coords));
uint2 vicoord = (texpage.xy + icoord) & uint2(1023, 511);
return LOAD_TEXTURE(samp0, int2(vicoord), 0);
return SAMPLE_TEXTURE_LEVEL(samp0, float2(vicoord) * RCP_VRAM_SIZE, 0.0);
#else
// Coordinates are already upscaled, we need to downscale them to apply the texture
// window, then re-upscale/offset. We can't round here, because it could result in
Expand Down Expand Up @@ -979,7 +979,7 @@ float4 SampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords)
ialpha = 1.0;
#elif TEXTURE_FILTERING
#if PAGE_TEXTURE
FilteredSampleFromVRAM(int2(0, 0), v_tex0, v_uv_limits, texcol, ialpha);
FilteredSampleFromVRAM(VECTOR_BROADCAST(TEXPAGE_VALUE, 0u), v_tex0, v_uv_limits, texcol, ialpha);
#else
FilteredSampleFromVRAM(v_texpage, v_tex0, v_uv_limits, texcol, ialpha);
#endif
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 = 23;
static constexpr u32 SHADER_CACHE_VERSION = 24;
2 changes: 2 additions & 0 deletions src/util/shadergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */
ss << "#define LOAD_TEXTURE_BUFFER(name, index) texelFetch(name, index)\n";
ss << "#define BEGIN_ARRAY(type, size) type[size](\n";
ss << "#define END_ARRAY )\n";
ss << "#define VECTOR_BROADCAST(type, value) (type(value))\n";

ss << "float saturate(float value) { return clamp(value, 0.0, 1.0); }\n";
ss << "float2 saturate(float2 value) { return clamp(value, float2(0.0, 0.0), float2(1.0, 1.0)); }\n";
Expand Down Expand Up @@ -344,6 +345,7 @@ void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */
ss << "#define LOAD_TEXTURE_BUFFER(name, index) name.Load(index)\n";
ss << "#define BEGIN_ARRAY(type, size) {\n";
ss << "#define END_ARRAY }\n";
ss << "#define VECTOR_BROADCAST(type, value) ((type)(value))\n";
}

ss << "\n";
Expand Down

0 comments on commit 8f19912

Please sign in to comment.