GS:HW: Reduce primid max value.

Large values may cause errors in primid DATE on Mesa OpenGL.
This commit is contained in:
TJnotJT
2026-09-04 01:37:00 +02:00
committed by lightningterror
parent 9120e6fb6a
commit bd9b6daaad
10 changed files with 58 additions and 26 deletions
+8 -8
View File
@@ -662,9 +662,9 @@ float ps_primid_image_init_0(PS_INPUT input) : SV_Target
{
float c;
if ((127.5f / 255.0f) < sample_c(input.t).a) // < 0x80 pass (== 0x80 should not pass)
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
@@ -674,9 +674,9 @@ float ps_primid_image_init_1(PS_INPUT input) : SV_Target
{
float c;
if (sample_c(input.t).a < (127.5f / 255.0f)) // >= 0x80 pass
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
@@ -686,9 +686,9 @@ float ps_primid_image_init_2(PS_INPUT input) : SV_Target
{
float c;
if ((254.5f / 255.0f) < sample_c(input.t).a) // < 0x80 pass (== 0x80 should not pass)
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
@@ -698,9 +698,9 @@ float ps_primid_image_init_3(PS_INPUT input) : SV_Target
{
float c;
if (sample_c(input.t).a < (254.5f / 255.0f)) // >= 0x80 pass
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
+5 -5
View File
@@ -627,23 +627,23 @@ void ps_yuv()
void main()
{
o_col0 = vec4(0x7FFFFFFF);
o_col0 = vec4(PRIMID_MAX);
#ifdef ps_primid_image_init_0
if((127.5f / 255.0f) < sample_c().a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_1
if(sample_c().a < (127.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_2
if((254.5f / 255.0f) < sample_c().a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_3
if(sample_c().a < (254.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
}
#endif
+5 -5
View File
@@ -640,23 +640,23 @@ void ps_yuv()
void main()
{
o_col0 = vec4(0x7FFFFFFF);
o_col0 = vec4(PRIMID_MAX);
#ifdef ps_primid_image_init_0
if((127.5f / 255.0f) < sample_c(v_tex).a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_1
if(sample_c(v_tex).a < (127.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_2
if((254.5f / 255.0f) < sample_c(v_tex).a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_3
if(sample_c(v_tex).a < (254.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
}
#endif
+11
View File
@@ -63,4 +63,15 @@ enum class PS_ROV_DEPTH : uint32_t
READ_ONLY = 2,
};
#if defined(__METAL_VERSION__)
#define CONSTANT constant
#else
#define CONSTANT
#endif
static constexpr CONSTANT int PRIMID_MAX = (1 << 24) - 1;
static constexpr CONSTANT int PRIMID_MIN = -1;
#undef CONSTANT
} // namespace GSShader
+4
View File
@@ -249,6 +249,8 @@ bool GSDevice11::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
ShaderMacro sm_ps;
sm_ps.AddMacro("PIXEL_SHADER", 1);
sm_ps.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm_ps.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm_ps.AddMacro("HAS_BILN", static_cast<int>(shader.Biln()));
sm_ps.AddMacro("HAS_STENCIL_OUTPUT", static_cast<int>(shader.StencilOutput()));
sm_ps.AddMacro("HAS_INTEGER_OUTPUT", static_cast<int>(shader.IntegerOutputBpp() != 0));
@@ -582,6 +584,8 @@ bool GSDevice11::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
const std::string entry_point_macro = WrapEntryPointMacro(entry_point);
ShaderMacro sm_ps;
sm_ps.AddMacro("PIXEL_SHADER", 1);
sm_ps.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm_ps.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm_ps.AddMacro(entry_point_macro.c_str(), 1);
m_date.primid_init_ps[i] = m_shader_cache.GetPixelShader(m_dev.get(), *convert_hlsl, sm_ps.GetPtr(), entry_point.c_str());
if (!m_date.primid_init_ps[i])
+4
View File
@@ -2877,6 +2877,8 @@ bool GSDevice12::CompileConvertPipelines()
ShaderMacro sm;
sm.AddMacro("PIXEL_SHADER", 1);
sm.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm.AddMacro("HAS_BILN", static_cast<int>(shader.Biln()));
sm.AddMacro("HAS_STENCIL_OUTPUT", static_cast<int>(shader.StencilOutput()));
sm.AddMacro("HAS_INTEGER_OUTPUT", static_cast<int>(shader.IntegerOutputBpp() != 0));
@@ -2930,6 +2932,8 @@ bool GSDevice12::CompileConvertPipelines()
ShaderMacro sm;
sm.AddMacro("PIXEL_SHADER", "1");
sm.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm.AddMacro(entry_point_macro.c_str(), "1");
ComPtr<ID3DBlob> ps(m_shader_cache.GetPixelShader(*source, sm.GetPtr(), entry_point.c_str()));
+4 -4
View File
@@ -112,22 +112,22 @@ fragment void ps_datm0(float4 p [[position]], DirectReadTextureIn<float> tex)
fragment float4 ps_primid_init_datm1(float4 p [[position]], DirectReadTextureIn<float> tex)
{
return tex.read(p).a < (127.5f / 255.f) ? -1 : FLT_MAX;
return tex.read(p).a < (127.5f / 255.f) ? GSShader::PRIMID_MIN : GSShader::PRIMID_MAX;
}
fragment float4 ps_primid_init_datm0(float4 p [[position]], DirectReadTextureIn<float> tex)
{
return tex.read(p).a > (127.5f / 255.f) ? -1 : FLT_MAX;
return tex.read(p).a > (127.5f / 255.f) ? GSShader::PRIMID_MIN : GSShader::PRIMID_MAX;
}
fragment float4 ps_primid_rta_init_datm1(float4 p [[position]], DirectReadTextureIn<float> tex)
{
return tex.read(p).a < (254.5f / 255.f) ? -1 : FLT_MAX;
return tex.read(p).a < (254.5f / 255.f) ? GSShader::PRIMID_MIN : GSShader::PRIMID_MAX;
}
fragment float4 ps_primid_rta_init_datm0(float4 p [[position]], DirectReadTextureIn<float> tex)
{
return tex.read(p).a > (254.5f / 255.f) ? -1 : FLT_MAX;
return tex.read(p).a > (254.5f / 255.f) ? GSShader::PRIMID_MIN : GSShader::PRIMID_MAX;
}
fragment float4 ps_rta_correction(ConvertShaderData data [[stage_in]], ConvertPSRes res)
+7 -1
View File
@@ -432,6 +432,8 @@ bool GSDeviceOGL::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
const char* name = shader.EntryPoint();
std::string macro;
macro += fmt::format("#define PRIMID_MAX {}\n", GSShader::PRIMID_MAX);
macro += fmt::format("#define PRIMID_MIN {}\n", GSShader::PRIMID_MIN);
macro += fmt::format("#define HAS_BILN {}\n", static_cast<int>(shader.Biln()));
macro += fmt::format("#define HAS_STENCIL_OUTPUT {}\n", static_cast<int>(shader.StencilOutput()));
macro += fmt::format("#define HAS_INTEGER_OUTPUT {}\n", static_cast<int>(shader.IntegerOutputBpp() != 0));
@@ -609,9 +611,13 @@ bool GSDeviceOGL::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
for (size_t i = 0; i < std::size(m_date.primid_ps); i++)
{
std::string macro;
macro += fmt::format("#define PRIMID_MAX {}\n", GSShader::PRIMID_MAX);
macro += fmt::format("#define PRIMID_MIN {}\n", GSShader::PRIMID_MIN);
const std::string ps(GetShaderSource(
fmt::format("ps_primid_image_init_{}", i),
GL_FRAGMENT_SHADER, *convert_glsl));
GL_FRAGMENT_SHADER, *convert_glsl, macro));
m_shader_cache.GetProgram(&m_date.primid_ps[i], m_convert.vs, ps);
m_date.primid_ps[i].SetFormattedName("PrimID Destination Alpha Init %d", i);
}
+9 -2
View File
@@ -4200,6 +4200,8 @@ bool GSDeviceVK::CompileConvertPipelines()
gpb.SetColorWriteMask(0, shader.Mask());
std::string macro;
macro += fmt::format("#define PRIMID_MAX {}\n", GSShader::PRIMID_MAX);
macro += fmt::format("#define PRIMID_MIN {}\n", GSShader::PRIMID_MIN);
macro += fmt::format("#define HAS_BILN {}\n", static_cast<int>(shader.Biln()));
macro += fmt::format("#define HAS_STENCIL_OUTPUT {}\n", static_cast<int>(shader.StencilOutput()));
macro += fmt::format("#define HAS_INTEGER_OUTPUT {}\n", static_cast<int>(shader.IntegerOutputBpp() != 0));
@@ -4267,9 +4269,14 @@ bool GSDeviceVK::CompileConvertPipelines()
for (u32 datm = 0; datm < 4; datm++)
{
std::string macro;
macro += fmt::format("#define PRIMID_MAX {}\n", GSShader::PRIMID_MAX);
macro += fmt::format("#define PRIMID_MIN {}\n", GSShader::PRIMID_MIN);
const std::string source_with_header = macro + *source;
const std::string entry_point(StringUtil::StdStringFromFormat("ps_primid_image_init_%d", datm));
VkShaderModule ps =
GetUtilityFragmentShader(*source, entry_point.c_str());
VkShaderModule ps = GetUtilityFragmentShader(source_with_header, entry_point.c_str());
if (ps == VK_NULL_HANDLE)
return false;
+1 -1
View File
@@ -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 = 111; // Last changed in PR 14824 (1)
static constexpr u32 SHADER_CACHE_VERSION = 112; // Last changed in PR 14824 (2)