Skip to content

Commit

Permalink
GS/HW: Adjust point sampler behavior.
Browse files Browse the repository at this point in the history
VK/GL/Metal: 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.

Test: See if Metal breaks with no point sampler.

2
  • Loading branch information
lightningterror committed Jul 9, 2024
1 parent 294bb4d commit 75defbe
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 44 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
11 changes: 1 addition & 10 deletions bin/resources/shaders/vulkan/tfx.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ void main()
#define PS_FBMASK 0
#define PS_LTF 1
#define PS_TCOFFSETHACK 0
#define PS_POINT_SAMPLER 0
#define PS_SHUFFLE 0
#define PS_SHUFFLE_SAME 0
#define PS_PROCESS_BA 0
Expand Down Expand Up @@ -372,15 +371,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
3 changes: 1 addition & 2 deletions pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ static void OnMainThread(Fn&& fn)

MTLPixelFormat layer_px_fmt = [m_layer pixelFormat];

m_features.broken_point_sampler = [[m_dev.dev name] containsString:@"AMD"];
m_features.broken_point_sampler = false;
m_features.vs_expand = !GSConfig.DisableVertexShaderExpand;
m_features.primitive_id = m_dev.features.primid;
m_features.texture_barrier = true;
Expand Down Expand Up @@ -1861,7 +1861,6 @@ static GSMTLExpandType ConvertVSExpand(GSHWDrawConfig::VSExpand generic)
setFnConstantB(m_fn_constants, pssel.tex_is_fb, GSMTLConstantIndex_PS_TEX_IS_FB);
setFnConstantB(m_fn_constants, pssel.automatic_lod, GSMTLConstantIndex_PS_AUTOMATIC_LOD);
setFnConstantB(m_fn_constants, pssel.manual_lod, GSMTLConstantIndex_PS_MANUAL_LOD);
setFnConstantB(m_fn_constants, pssel.point_sampler, GSMTLConstantIndex_PS_POINT_SAMPLER);
setFnConstantB(m_fn_constants, pssel.region_rect, GSMTLConstantIndex_PS_REGION_RECT);
setFnConstantI(m_fn_constants, pssel.scanmsk, GSMTLConstantIndex_PS_SCANMSK);
auto newps = LoadShader(@"ps_main");
Expand Down
1 change: 0 additions & 1 deletion pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ enum GSMTLFnConstants
GSMTLConstantIndex_PS_TEX_IS_FB,
GSMTLConstantIndex_PS_AUTOMATIC_LOD,
GSMTLConstantIndex_PS_MANUAL_LOD,
GSMTLConstantIndex_PS_POINT_SAMPLER,
GSMTLConstantIndex_PS_REGION_RECT,
GSMTLConstantIndex_PS_SCANMSK,
};
11 changes: 0 additions & 11 deletions pcsx2/GS/Renderers/Metal/tfx.metal
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ constant bool PS_TALES_OF_ABYSS_HLE [[function_constant(GSMTLConstantIndex_PS_TA
constant bool PS_TEX_IS_FB [[function_constant(GSMTLConstantIndex_PS_TEX_IS_FB)]];
constant bool PS_AUTOMATIC_LOD [[function_constant(GSMTLConstantIndex_PS_AUTOMATIC_LOD)]];
constant bool PS_MANUAL_LOD [[function_constant(GSMTLConstantIndex_PS_MANUAL_LOD)]];
constant bool PS_POINT_SAMPLER [[function_constant(GSMTLConstantIndex_PS_POINT_SAMPLER)]];
constant bool PS_REGION_RECT [[function_constant(GSMTLConstantIndex_PS_REGION_RECT)]];
constant uint PS_SCANMSK [[function_constant(GSMTLConstantIndex_PS_SCANMSK)]];

Expand Down Expand Up @@ -324,16 +323,6 @@ struct PSMain
if (PS_REGION_RECT)
return read_tex(uint2(uv));

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 * cb.wh.zw) + 0.5) / cb.wh.zw;
}
if (!PS_ADJS && !PS_ADJT)
{
uv *= cb.st_scale;
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
9 changes: 4 additions & 5 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,14 +2568,14 @@ bool GSDeviceVK::CreateDeviceAndSwapChain()
bool GSDeviceVK::CheckFeatures()
{
const VkPhysicalDeviceLimits& limits = m_device_properties.limits;
const u32 vendorID = m_device_properties.vendorID;
const bool isAMD = (vendorID == 0x1002 || vendorID == 0x1022);
// const bool isNVIDIA = (vendorID == 0x10DE);
//const u32 vendorID = m_device_properties.vendorID;
//const bool isAMD = (vendorID == 0x1002 || vendorID == 0x1022);
//const bool isNVIDIA = (vendorID == 0x10DE);

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 75defbe

Please sign in to comment.