Skip to content

Commit

Permalink
GS/HW: Adjust point sampler behavior.
Browse files Browse the repository at this point in the history
VK/GL: Get rid of it completely as it doesn't seem needed anymore.
DX: Only enable it with combination with GPU Palette Conversion enabled as that's when the issue occurs.
  • Loading branch information
lightningterror committed Jul 9, 2024
1 parent d68f1aa commit b84787f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 26 deletions.
9 changes: 0 additions & 9 deletions bin/resources/shaders/opengl/tfx_fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ vec4 sample_c(vec2 uv)
return texelFetch(TextureSampler, ivec2(uv), 0);
#else

#if PS_POINT_SAMPLER
// Weird issue with ATI/AMD cards,
// it looks like they add 127/128 of a texel to sampling coordinates
// occasionally causing point sampling to erroneously round up.
// I'm manually adjusting coordinates to the centre of texels here,
// though the centre is just paranoia, the top left corner works fine.
// As of 2018 this issue is still present.
uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;
#endif
#if !PS_ADJS && !PS_ADJT
uv *= STScale;
#else
Expand Down
10 changes: 1 addition & 9 deletions bin/resources/shaders/vulkan/tfx.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,7 @@ vec4 sample_c(vec2 uv)
#elif PS_REGION_RECT
return texelFetch(Texture, ivec2(uv), 0);
#else
#if PS_POINT_SAMPLER
// Weird issue with ATI/AMD cards,
// it looks like they add 127/128 of a texel to sampling coordinates
// occasionally causing point sampling to erroneously round up.
// I'm manually adjusting coordinates to the centre of texels here,
// though the centre is just paranoia, the top left corner works fine.
// As of 2018 this issue is still present.
uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;
#endif

#if !PS_ADJS && !PS_ADJT
uv *= STScale;
#else
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/HW/GSRendererHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5010,7 +5010,7 @@ __ri void GSRendererHW::EmulateTextureSampler(const GSTextureCache::Target* rt,
m_conf.ps.tcc = m_cached_ctx.TEX0.TCC;

m_conf.ps.ltf = bilinear && shader_emulated_sampler;
m_conf.ps.point_sampler = g_gs_device->Features().broken_point_sampler && !target_region && (!bilinear || shader_emulated_sampler);
m_conf.ps.point_sampler = g_gs_device->Features().broken_point_sampler && GSConfig.GPUPaletteConversion && !target_region && (!bilinear || shader_emulated_sampler);

const int tw = static_cast<int>(1 << m_cached_ctx.TEX0.TW);
const int th = static_cast<int>(1 << m_cached_ctx.TEX0.TH);
Expand Down
7 changes: 3 additions & 4 deletions pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ bool GSDeviceOGL::CreateTextureFX()

bool GSDeviceOGL::CheckFeatures(bool& buggy_pbo)
{
bool vendor_id_amd = false;
//bool vendor_id_amd = false;
bool vendor_id_nvidia = false;
//bool vendor_id_intel = false;

Expand All @@ -615,7 +615,7 @@ bool GSDeviceOGL::CheckFeatures(bool& buggy_pbo)
std::strstr(vendor, "ATI"))
{
Console.WriteLn(Color_StrongRed, "OGL: AMD GPU detected.");
vendor_id_amd = true;
//vendor_id_amd = true;
}
else if (std::strstr(vendor, "NVIDIA Corporation"))
{
Expand Down Expand Up @@ -712,7 +712,7 @@ bool GSDeviceOGL::CheckFeatures(bool& buggy_pbo)
Console.Warning("Not using PBOs for texture downloads, this may reduce performance.");

// optional features based on context
m_features.broken_point_sampler = vendor_id_amd;
m_features.broken_point_sampler = false;
m_features.primitive_id = true;

m_features.framebuffer_fetch = GLAD_GL_EXT_shader_framebuffer_fetch;
Expand Down Expand Up @@ -1377,7 +1377,6 @@ std::string GSDeviceOGL::GetPSSource(const PSSelector& sel)
+ fmt::format("#define PS_COLCLIP {}\n", sel.colclip)
+ fmt::format("#define PS_DATE {}\n", sel.date)
+ fmt::format("#define PS_TCOFFSETHACK {}\n", sel.tcoffsethack)
+ fmt::format("#define PS_POINT_SAMPLER {}\n", sel.point_sampler)
+ fmt::format("#define PS_REGION_RECT {}\n", sel.region_rect)
+ fmt::format("#define PS_BLEND_A {}\n", sel.blend_a)
+ fmt::format("#define PS_BLEND_B {}\n", sel.blend_b)
Expand Down
3 changes: 1 addition & 2 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2575,7 +2575,7 @@ bool GSDeviceVK::CheckFeatures()
m_features.framebuffer_fetch =
m_optional_extensions.vk_ext_rasterization_order_attachment_access && !GSConfig.DisableFramebufferFetch;
m_features.texture_barrier = GSConfig.OverrideTextureBarriers != 0;
m_features.broken_point_sampler = isAMD;
m_features.broken_point_sampler = false;

// geometryShader is needed because gl_PrimitiveID is part of the Geometry SPIR-V Execution Model.
m_features.primitive_id = m_device_features.geometryShader;
Expand Down Expand Up @@ -4722,7 +4722,6 @@ VkShaderModule GSDeviceVK::GetTFXFragmentShader(const GSHWDrawConfig::PSSelector
AddMacro(ss, "PS_COLCLIP", sel.colclip);
AddMacro(ss, "PS_DATE", sel.date);
AddMacro(ss, "PS_TCOFFSETHACK", sel.tcoffsethack);
AddMacro(ss, "PS_POINT_SAMPLER", sel.point_sampler);
AddMacro(ss, "PS_REGION_RECT", sel.region_rect);
AddMacro(ss, "PS_BLEND_A", sel.blend_a);
AddMacro(ss, "PS_BLEND_B", sel.blend_b);
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/ShaderCacheVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

/// Version number for GS and other shaders. Increment whenever any of the contents of the
/// shaders change, to invalidate the cache.
static constexpr u32 SHADER_CACHE_VERSION = 52;
static constexpr u32 SHADER_CACHE_VERSION = 53;

0 comments on commit b84787f

Please sign in to comment.