Skip to content

Commit

Permalink
GS:OGL: Use blend min for primid destination alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
TellowKrinkle authored and lightningterror committed Sep 6, 2022
1 parent 8052382 commit 62f9b16
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 177 deletions.
17 changes: 17 additions & 0 deletions bin/resources/shaders/opengl/convert.glsl
Expand Up @@ -378,4 +378,21 @@ void ps_yuv()
}
#endif

#if defined(ps_stencil_image_init_0) || defined(ps_stencil_image_init_1)

void main()
{
SV_Target0 = vec4(0x7FFFFFFF);

#ifdef ps_stencil_image_init_0
if((127.5f / 255.0f) < sample_c().a) // < 0x80 pass (== 0x80 should not pass)
SV_Target0 = vec4(-1);
#endif
#ifdef ps_stencil_image_init_1
if(sample_c().a < (127.5f / 255.0f)) // >= 0x80 pass
SV_Target0 = vec4(-1);
#endif
}
#endif

#endif
53 changes: 9 additions & 44 deletions bin/resources/shaders/opengl/tfx_fs.glsl
Expand Up @@ -74,36 +74,12 @@ layout(binding = 1) uniform sampler2D PaletteSampler;
layout(binding = 2) uniform sampler2D RtSampler; // note 2 already use by the image below
#endif

#ifndef DISABLE_GL42_image
#if PS_DATE > 0
// Performance note: images mustn't be declared if they are unused. Otherwise it will
// require extra shader validation.

// FIXME how to declare memory access
layout(r32i, binding = 3) uniform iimage2D img_prim_min;
// WARNING:
// You can't enable it if you discard the fragment. The depth is still
// updated (shadow in Shin Megami Tensei Nocturne)
//
// early_fragment_tests must still be enabled in the first pass of the 2 passes algo
// First pass search the first primitive that will write the bad alpha value. Value
// won't be written if the fragment fails the depth test.
//
// In theory the best solution will be do
// 1/ copy the depth buffer
// 2/ do the full depth (current depth writes are disabled)
// 3/ restore the depth buffer for 2nd pass
// Of course, it is likely too costly.
#if PS_DATE == 1 || PS_DATE == 2
layout(early_fragment_tests) in;
#endif
#if PS_DATE == 3
layout(binding = 3) uniform sampler2D img_prim_min;

// I don't remember why I set this parameter but it is surely useless
//layout(pixel_center_integer) in vec4 gl_FragCoord;
#endif
#else
// use basic stencil
#endif

vec4 fetch_rt()
{
Expand Down Expand Up @@ -814,8 +790,7 @@ void ps_main()
discard;
#endif

#if PS_DATE != 0
#if ((PS_DATE & 3) == 1 || (PS_DATE & 3) == 2)
#if PS_DATE >= 5

#if PS_WRITE_RG == 1
// Pseudo 16 bits access.
Expand All @@ -833,25 +808,19 @@ void ps_main()
#endif

if (bad) {
#if PS_DATE >= 5 || defined(DISABLE_GL42_image)
discard;
#else
imageStore(img_prim_min, ivec2(gl_FragCoord.xy), ivec4(-1));
return;
#endif
}

#endif

#if PS_DATE == 3 && !defined(DISABLE_GL42_image)
int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy)).r;
#if PS_DATE == 3
int stencil_ceil = int(texelFetch(img_prim_min, ivec2(gl_FragCoord.xy), 0).r);
// Note gl_PrimitiveID == stencil_ceil will be the primitive that will update
// the bad alpha value so we must keep it.

if (gl_PrimitiveID > stencil_ceil) {
discard;
}
#endif
#endif

vec4 C = ps_color();
Expand Down Expand Up @@ -934,19 +903,15 @@ void ps_main()
#endif

// Get first primitive that will write a failling alpha value
#if PS_DATE == 1 && !defined(DISABLE_GL42_image)
#if PS_DATE == 1
// DATM == 0
// Pixel with alpha equal to 1 will failed (128-255)
if (C.a > 127.5f) {
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
}
SV_Target0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);
return;
#elif PS_DATE == 2 && !defined(DISABLE_GL42_image)
#elif PS_DATE == 2
// DATM == 1
// Pixel with alpha equal to 0 will failed (0-127)
if (C.a < 127.5f) {
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
}
SV_Target0 = (C.a < 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);
return;
#endif

Expand Down
2 changes: 0 additions & 2 deletions pcsx2/GS/GS.cpp
Expand Up @@ -1477,12 +1477,10 @@ void GSApp::Init()
m_default_configuration["OsdShowIndicators"] = "1";
m_default_configuration["OsdScale"] = "100";
m_default_configuration["override_GL_ARB_copy_image"] = "-1";
m_default_configuration["override_GL_ARB_clear_texture"] = "-1";
m_default_configuration["override_GL_ARB_clip_control"] = "-1";
m_default_configuration["override_GL_ARB_direct_state_access"] = "-1";
m_default_configuration["override_GL_ARB_draw_buffers_blend"] = "-1";
m_default_configuration["override_GL_ARB_gpu_shader5"] = "-1";
m_default_configuration["override_GL_ARB_shader_image_load_store"] = "-1";
m_default_configuration["override_GL_ARB_texture_barrier"] = "-1";
m_default_configuration["OverrideTextureBarriers"] = "-1";
m_default_configuration["OverrideGeometryShaders"] = "-1";
Expand Down
6 changes: 0 additions & 6 deletions pcsx2/GS/Renderers/OpenGL/GLLoader.cpp
Expand Up @@ -148,10 +148,8 @@ namespace GLLoader
bool has_dual_source_blend = false;
bool found_framebuffer_fetch = false;
bool found_geometry_shader = true; // we require GL3.3 so geometry must be supported by default
bool found_GL_ARB_clear_texture = false;
// DX11 GPU
bool found_GL_ARB_gpu_shader5 = false; // Require IvyBridge
bool found_GL_ARB_shader_image_load_store = false; // Intel IB. Nvidia/AMD miss Mesa implementation.
bool found_GL_ARB_texture_barrier = false;

static bool mandatory(const std::string& ext)
Expand Down Expand Up @@ -266,10 +264,6 @@ namespace GLLoader
{
// GL4.0
found_GL_ARB_gpu_shader5 = optional("GL_ARB_gpu_shader5");
// GL4.2
found_GL_ARB_shader_image_load_store = optional("GL_ARB_shader_image_load_store");
// GL4.4
found_GL_ARB_clear_texture = optional("GL_ARB_clear_texture");
// GL4.5
optional("GL_ARB_direct_state_access");
// Mandatory for the advance HW renderer effect. Unfortunately Mesa LLVMPIPE/SWR renderers doesn't support this extension.
Expand Down
2 changes: 0 additions & 2 deletions pcsx2/GS/Renderers/OpenGL/GLLoader.h
Expand Up @@ -43,7 +43,5 @@ namespace GLLoader
extern bool found_framebuffer_fetch;
extern bool found_geometry_shader;
extern bool found_GL_ARB_gpu_shader5;
extern bool found_GL_ARB_shader_image_load_store;
extern bool found_GL_ARB_clear_texture;
extern bool found_GL_ARB_texture_barrier;
} // namespace GLLoader

0 comments on commit 62f9b16

Please sign in to comment.