GS: Move shader enums to dedicated file

This commit is contained in:
TellowKrinkle
2026-04-08 10:42:36 +02:00
committed by lightningterror
parent acb29963ba
commit 38bd7b0402
13 changed files with 104 additions and 90 deletions
+1
View File
@@ -544,6 +544,7 @@ set(pcsx2GSHeaders
GS/Renderers/Common/GSFastList.h
GS/Renderers/Common/GSFunctionMap.h
GS/Renderers/Common/GSRenderer.h
GS/Renderers/Common/GSShaderEnums.h
GS/Renderers/Common/GSTexture.h
GS/Renderers/Common/GSVertex.h
GS/Renderers/Common/GSVertexTrace.h
+9 -9
View File
@@ -1121,17 +1121,17 @@ std::string GSHWDrawConfig::GetPSDateName(u32 date)
}
}
std::string GSHWDrawConfig::GetPSAlphaTestName(u32 atst)
std::string GSHWDrawConfig::GetPSAlphaTestName(PS_ATST atst)
{
switch (static_cast<GSHWDrawConfig::PSAlphaTest>(atst))
switch (atst)
{
case GSHWDrawConfig::PSAlphaTest::PS_ATST_NONE: return "NONE";
case GSHWDrawConfig::PSAlphaTest::PS_ATST_LEQUAL: return "LEQUAL";
case GSHWDrawConfig::PSAlphaTest::PS_ATST_GEQUAL: return "GEQUAL";
case GSHWDrawConfig::PSAlphaTest::PS_ATST_EQUAL: return "EQUAL";
case GSHWDrawConfig::PSAlphaTest::PS_ATST_NOTEQUAL: return "NOTEQUAL";
default: return std::to_string(atst);
case PS_ATST::NONE: return "NONE";
case PS_ATST::LEQUAL: return "LEQUAL";
case PS_ATST::GEQUAL: return "GEQUAL";
case PS_ATST::EQUAL: return "EQUAL";
case PS_ATST::NOTEQUAL: return "NOTEQUAL";
};
return "UNKNOWN";
}
std::string GSHWDrawConfig::GetPSDstFmtName(u32 dstfmt)
@@ -1333,7 +1333,7 @@ void GSHWDrawConfig::DumpPSSelector(std::ostream& out, const PSSelector& ps, con
out << indent << "fog: " << static_cast<u32>(ps.fog) << std::endl;
out << indent << "iip: " << static_cast<u32>(ps.iip) << std::endl;
out << indent << "date: " << static_cast<u32>(ps.date) << " # " << GetPSDateName(static_cast<u32>(ps.date)) << std::endl;
out << indent << "atst: " << static_cast<u32>(ps.atst) << " # " << GetPSAlphaTestName(static_cast<u32>(ps.atst)) << std::endl;
out << indent << "atst: " << static_cast<u32>(ps.atst) << " # " << GetPSAlphaTestName(ps.atst) << std::endl;
out << indent << "afail: " << static_cast<u32>(ps.afail) << " # " << GSUtil::GetAFAILName(static_cast<u32>(ps.afail)) << std::endl;
out << indent << "fst: " << static_cast<u32>(ps.fst) << std::endl;
out << indent << "tfx: " << static_cast<u32>(ps.tfx) << std::endl;
+7 -31
View File
@@ -7,6 +7,7 @@
#include "common/WindowInfo.h"
#include "GS/GS.h"
#include "GS/Renderers/Common/GSFastList.h"
#include "GS/Renderers/Common/GSShaderEnums.h"
#include "GS/Renderers/Common/GSTexture.h"
#include "GS/Renderers/Common/GSVertex.h"
#include "GS/GSAlignedClass.h"
@@ -300,13 +301,9 @@ struct alignas(16) GSHWDrawConfig
Line,
Triangle,
};
enum class VSExpand: u8
{
None,
Point,
Line,
Sprite,
};
using VSExpand = GSShader::VSExpand;
using PS_ATST = GSShader::PS_ATST;
using PS_AFAIL = GSShader::PS_AFAIL;
#pragma pack(push, 1)
struct VSSelector
{
@@ -330,28 +327,7 @@ struct alignas(16) GSHWDrawConfig
__fi bool UseExpandIndexBuffer() const { return (expand == VSExpand::Point || expand == VSExpand::Sprite); }
};
static_assert(sizeof(VSSelector) == 1, "VSSelector is a single byte");
#pragma pack(pop)
enum PSAlphaTest
{
PS_ATST_NONE = 0,
PS_ATST_LEQUAL = 1,
PS_ATST_GEQUAL = 2,
PS_ATST_EQUAL = 3,
PS_ATST_NOTEQUAL = 4
};
// Identical with the usual GS enum except for the RGB_ONLY_DSB
enum PSAfail
{
PS_AFAIL_KEEP = 0,
PS_AFAIL_FB_ONLY = 1,
PS_AFAIL_ZB_ONLY = 2,
PS_AFAIL_RGB_ONLY = 3,
PS_AFAIL_RGB_ONLY_DSB = 4 // RGB only with dual source blend.
};
#pragma pack(push, 4)
struct PSSelector
{
// Performance note: there are too many shader combinations
@@ -375,8 +351,8 @@ struct alignas(16) GSHWDrawConfig
u32 iip : 1;
// Pixel test
u32 date : 3;
u32 atst : 3;
u32 afail : 3;
PS_ATST atst : 3;
PS_AFAIL afail : 3;
u32 ztst : 2;
// Color sampling
u32 fst : 1; // Investigate to do it on the VS
@@ -842,7 +818,7 @@ struct alignas(16) GSHWDrawConfig
// Dumping
static std::string GetTopologyName(u32 topology);
static std::string GetVSExpandName(u32 vsexpand);
static std::string GetPSAlphaTestName(u32 dstfmt);
static std::string GetPSAlphaTestName(PS_ATST dstfmt);
static std::string GetPSDstFmtName(u32 dstfmt);
static std::string GetPSDepthFmtName(u32 depthfmt);
static std::string GetPSBlendABDName(u32 abd);
+39
View File
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
// Enums that are used by shaders, to be included by both C++ and shader code
// Assume that cstdint types are available, but don't actually include the header (it's not available in shaders)
// (Currently only used by Metal)
#pragma once
namespace GSShader {
enum class VSExpand : uint8_t
{
None = 0,
Point = 1,
Line = 2,
Sprite = 3,
};
enum class PS_ATST : uint32_t
{
NONE = 0,
LEQUAL = 1,
GEQUAL = 2,
EQUAL = 3,
NOTEQUAL = 4
};
// Identical with the usual GS enum except for the RGB_ONLY_DSB
enum class PS_AFAIL : uint32_t
{
KEEP = 0,
FB_ONLY = 1,
ZB_ONLY = 2,
RGB_ONLY = 3,
RGB_ONLY_DSB = 4 // RGB only with dual source blend.
};
} // namespace GSShader
+20 -17
View File
@@ -12,6 +12,9 @@
#include "common/StringUtil.h"
#include <bit>
using PS_ATST = GSShader::PS_ATST;
using PS_AFAIL = GSShader::PS_AFAIL;
GSRendererHW::GSRendererHW()
: GSRenderer()
{
@@ -7856,7 +7859,7 @@ bool GSRendererHW::CanUseTexIsFB(const GSTextureCache::Target* rt, const GSTextu
return false;
}
void GSRendererHW::GetAlphaTestConfigPS(const u32 atst, const u8 aref, const bool invert_test, u32& ps_atst_out, float& aref_out)
void GSRendererHW::GetAlphaTestConfigPS(const u32 atst, const u8 aref, const bool invert_test, PS_ATST& ps_atst_out, float& aref_out)
{
static const u32 inverted_atst[] = {
ATST_ALWAYS,
@@ -7875,32 +7878,32 @@ void GSRendererHW::GetAlphaTestConfigPS(const u32 atst, const u8 aref, const boo
{
case ATST_LESS:
aref_out = static_cast<float>(aref) - small_val;
ps_atst_out = GSHWDrawConfig::PS_ATST_LEQUAL;
ps_atst_out = PS_ATST::LEQUAL;
break;
case ATST_LEQUAL:
aref_out = static_cast<float>(aref) - small_val + 1.0f;
ps_atst_out = GSHWDrawConfig::PS_ATST_LEQUAL;
ps_atst_out = PS_ATST::LEQUAL;
break;
case ATST_GEQUAL:
aref_out = static_cast<float>(aref) - small_val;
ps_atst_out = GSHWDrawConfig::PS_ATST_GEQUAL;
ps_atst_out = PS_ATST::GEQUAL;
break;
case ATST_GREATER:
aref_out = static_cast<float>(aref) - small_val + 1.0f;
ps_atst_out = GSHWDrawConfig::PS_ATST_GEQUAL;
ps_atst_out = PS_ATST::GEQUAL;
break;
case ATST_EQUAL:
aref_out = static_cast<float>(aref);
ps_atst_out = GSHWDrawConfig::PS_ATST_EQUAL;
ps_atst_out = PS_ATST::EQUAL;
break;
case ATST_NOTEQUAL:
aref_out = static_cast<float>(aref);
ps_atst_out = GSHWDrawConfig::PS_ATST_NOTEQUAL;
ps_atst_out = PS_ATST::NOTEQUAL;
break;
case ATST_NEVER:
case ATST_ALWAYS:
default:
ps_atst_out = GSHWDrawConfig::PS_ATST_NONE;
ps_atst_out = PS_ATST::NONE;
break;
}
}
@@ -7919,7 +7922,7 @@ void GSRendererHW::EmulateAlphaTest(DATEOptions& date_options)
GL_PUSH("HW: Alpha test config (1)");
// Temp pixel shader constants for the setup.
u32 ps_atst;
PS_ATST ps_atst;
float ps_aref;
u32 atst = m_cached_ctx.TEST.ATST;
@@ -7976,7 +7979,7 @@ void GSRendererHW::EmulateAlphaTest(DATEOptions& date_options)
GetAlphaTestConfigPS(atst, aref, false, ps_atst, ps_aref);
m_conf.ps.atst = ps_atst;
m_conf.cb_ps.FogColor_AREF.a = ps_aref;
m_conf.ps.afail = GSHWDrawConfig::PS_AFAIL_KEEP;
m_conf.ps.afail = PS_AFAIL::KEEP;
m_conf.alpha_test = GSHWDrawConfig::AlphaTestMode::KEEP;
return;
}
@@ -8043,7 +8046,7 @@ void GSRendererHW::EmulateAlphaTest(DATEOptions& date_options)
GetAlphaTestConfigPS(atst, aref, false, ps_atst, ps_aref);
m_conf.ps.atst = ps_atst;
m_conf.cb_ps.FogColor_AREF.a = ps_aref;
m_conf.ps.afail = afail;
m_conf.ps.afail = static_cast<PS_AFAIL>(afail);
m_conf.ps.color_feedback |= afail_needs_rt;
m_conf.ps.depth_feedback |= afail_needs_depth;
@@ -8086,7 +8089,7 @@ void GSRendererHW::EmulateAlphaTest(DATEOptions& date_options)
GetAlphaTestConfigPS(atst, aref, false, ps_atst, ps_aref);
m_conf.ps.atst = ps_atst;
m_conf.cb_ps.FogColor_AREF.a = ps_aref;
m_conf.ps.afail = GSHWDrawConfig::PS_AFAIL_RGB_ONLY_DSB;
m_conf.ps.afail = PS_AFAIL::RGB_ONLY_DSB;
m_conf.ps.no_color1 = false;
// Swap stencil DATE for PrimID DATE, for both Z on and off cases.
@@ -8113,7 +8116,7 @@ void GSRendererHW::EmulateAlphaTest(DATEOptions& date_options)
GetAlphaTestConfigPS(atst, aref, false, ps_atst, ps_aref);
m_conf.ps.atst = ps_atst;
m_conf.cb_ps.FogColor_AREF.a = ps_aref;
m_conf.ps.afail = GSHWDrawConfig::PS_AFAIL_KEEP;
m_conf.ps.afail = PS_AFAIL::KEEP;
m_conf.alpha_test = GSHWDrawConfig::AlphaTestMode::PASS_THEN_FAIL;
}
}
@@ -8132,7 +8135,7 @@ void GSRendererHW::EmulateAlphaTestSecondPass()
const u32 aref = m_cached_ctx.TEST.AREF;
// Temp variables for PS config.
u32 ps_atst;
PS_ATST ps_atst;
float ps_aref;
std::memcpy(&m_conf.alpha_second_pass.ps, &m_conf.ps, sizeof(m_conf.ps));
@@ -8156,7 +8159,7 @@ void GSRendererHW::EmulateAlphaTestSecondPass()
m_conf.alpha_second_pass.enable = true;
m_conf.alpha_second_pass.ps.atst = ps_atst;
m_conf.alpha_second_pass.ps_aref = ps_aref;
m_conf.alpha_second_pass.ps.afail = GSHWDrawConfig::PS_AFAIL_KEEP;
m_conf.alpha_second_pass.ps.afail = PS_AFAIL::KEEP;
}
// Setup for RBG_ONLY dual source blend selection
@@ -8213,7 +8216,7 @@ void GSRendererHW::EmulateAlphaTestSecondPass()
m_conf.alpha_second_pass.enable = true;
m_conf.alpha_second_pass.ps.atst = ps_atst;
m_conf.alpha_second_pass.ps_aref = ps_aref;
m_conf.alpha_second_pass.ps.afail = GSHWDrawConfig::PS_AFAIL_KEEP;
m_conf.alpha_second_pass.ps.afail = PS_AFAIL::KEEP;
}
}
@@ -10073,4 +10076,4 @@ void GSRendererHW::CleanupDepthAsRTFeedback()
g_gs_device->Recycle(m_conf.ds_as_rt);
m_conf.ds_as_rt = nullptr;
}
}
}
+4 -1
View File
@@ -92,6 +92,9 @@ private:
bool TextureCoversWithoutGapsNotEqual();
bool Is8PixelReverseSprite(const GSVertex& v0, const GSVertex& v1);
using PS_ATST = GSShader::PS_ATST;
using PS_AFAIL = GSShader::PS_AFAIL;
enum class CLUTDrawTestResult
{
NotCLUTDraw,
@@ -144,7 +147,7 @@ private:
const TextureMinMaxResult& tmm);
void EmulateZbuffer(const GSTextureCache::Target* ds);
static void GetAlphaTestConfigPS(const u32 atst, const u8 aref, const bool invert_test, u32& ps_atst_out, float& aref_out);
static void GetAlphaTestConfigPS(const u32 atst, const u8 aref, const bool invert_test, PS_ATST& ps_atst_out, float& aref_out);
void EmulateAlphaTest(DATEOptions& date_options);
void EmulateAlphaTestSecondPass();
+1 -1
View File
@@ -202,7 +202,7 @@ public:
bool iip : 1;
bool fst : 1;
bool point_size : 1;
GSMTLExpandType expand : 2;
GSShader::VSExpand expand : 2;
};
u8 key;
};
+11 -16
View File
@@ -747,6 +747,12 @@ static void setFnConstantI(MTLFunctionConstantValues* fc, unsigned int value, GS
[fc setConstantValue:&value type:MTLDataTypeUInt atIndex:constant];
}
template <typename T, std::enable_if_t<std::is_enum_v<T>, bool> = true>
static void setFnConstantI(MTLFunctionConstantValues* fc, T value, GSMTLFnConstants constant)
{
setFnConstantI(fc, static_cast<std::underlying_type_t<T>>(value), constant);
}
template <typename Fn>
static void OnMainThread(Fn&& fn)
{
@@ -1051,15 +1057,15 @@ bool GSDeviceMTL::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
{
VSSelector sel;
sel.key = i;
if (sel.point_size && sel.expand != GSMTLExpandType::None)
if (sel.point_size && sel.expand != GSShader::VSExpand::None)
continue;
setFnConstantB(m_fn_constants, sel.fst, GSMTLConstantIndex_FST);
setFnConstantB(m_fn_constants, sel.iip, GSMTLConstantIndex_IIP);
setFnConstantB(m_fn_constants, sel.point_size, GSMTLConstantIndex_VS_POINT_SIZE);
NSString* shader = @"vs_main";
if (sel.expand != GSMTLExpandType::None)
if (sel.expand != GSShader::VSExpand::None)
{
setFnConstantI(m_fn_constants, static_cast<u32>(sel.expand), GSMTLConstantIndex_VS_EXPAND_TYPE);
setFnConstantI(m_fn_constants, sel.expand, GSMTLConstantIndex_VS_EXPAND_TYPE);
shader = @"vs_main_expand";
}
m_hw_vs[i] = LoadShader(shader);
@@ -1799,17 +1805,6 @@ static MTLBlendOperation ConvertBlendOp(GSDevice::BlendOp generic)
}
}
static GSMTLExpandType ConvertVSExpand(GSHWDrawConfig::VSExpand generic)
{
switch (generic)
{
case GSHWDrawConfig::VSExpand::None: return GSMTLExpandType::None;
case GSHWDrawConfig::VSExpand::Point: return GSMTLExpandType::Point;
case GSHWDrawConfig::VSExpand::Line: return GSMTLExpandType::Line;
case GSHWDrawConfig::VSExpand::Sprite: return GSMTLExpandType::Sprite;
}
}
void GSDeviceMTL::MRESetHWPipelineState(GSHWDrawConfig::VSSelector vssel, GSHWDrawConfig::PSSelector pssel, GSHWDrawConfig::BlendState blend, GSHWDrawConfig::ColorMaskSelector cms)
{
PipelineSelectorExtrasMTL extras(blend, m_current_render.color_target, cms, m_current_render.depth_target, m_current_render.stencil_target);
@@ -1831,7 +1826,7 @@ void GSDeviceMTL::MRESetHWPipelineState(GSHWDrawConfig::VSSelector vssel, GSHWDr
vssel_mtl.fst = vssel.fst;
vssel_mtl.iip = vssel.iip;
vssel_mtl.point_size = vssel.point_size;
vssel_mtl.expand = ConvertVSExpand(vssel.expand);
vssel_mtl.expand = vssel.expand;
id<MTLFunction> vs = m_hw_vs[vssel_mtl.key];
id<MTLFunction> ps;
@@ -1906,7 +1901,7 @@ void GSDeviceMTL::MRESetHWPipelineState(GSHWDrawConfig::VSSelector vssel, GSHWDr
MRCOwned<MTLRenderPipelineDescriptor*> pdesc = MRCTransfer([MTLRenderPipelineDescriptor new]);
if (vssel_mtl.point_size)
[pdesc setInputPrimitiveTopology:MTLPrimitiveTopologyClassPoint];
if (vssel_mtl.expand == GSMTLExpandType::None)
if (vssel_mtl.expand == GSShader::VSExpand::None)
[pdesc setVertexDescriptor:m_hw_vertex];
else
[pdesc setInputPrimitiveTopology:MTLPrimitiveTopologyClassTriangle];
+1 -8
View File
@@ -3,6 +3,7 @@
#pragma once
#include <simd/simd.h>
#include "../Common/GSShaderEnums.h"
enum GSMTLBufferIndices
{
@@ -148,14 +149,6 @@ enum GSMTLAttributes
GSMTLAttributeIndexF,
};
enum class GSMTLExpandType : unsigned char
{
None = 0,
Point = 1,
Line = 2,
Sprite = 3,
};
enum GSMTLFnConstants
{
GSMTLConstantIndex_CAS_SHARPEN_ONLY,
+5 -5
View File
@@ -71,7 +71,7 @@ constant bool PS_MANUAL_LOD [[function_constant(GSMTLConstantIndex_PS_MA
constant bool PS_REGION_RECT [[function_constant(GSMTLConstantIndex_PS_REGION_RECT)]];
constant uint PS_SCANMSK [[function_constant(GSMTLConstantIndex_PS_SCANMSK)]];
constant GSMTLExpandType VS_EXPAND_TYPE = static_cast<GSMTLExpandType>(VS_EXPAND_TYPE_RAW);
constant GSShader::VSExpand VS_EXPAND_TYPE = static_cast<GSShader::VSExpand>(VS_EXPAND_TYPE_RAW);
#if defined(__METAL_MACOS__) && __METAL_VERSION__ >= 220
#define PRIMID_SUPPORT 1
@@ -219,9 +219,9 @@ vertex MainVSOut vs_main_expand(
{
switch (VS_EXPAND_TYPE)
{
case GSMTLExpandType::None:
case GSShader::VSExpand::None:
return vs_main_run(load_vertex(vertices[vid]), cb);
case GSMTLExpandType::Point:
case GSShader::VSExpand::Point:
{
MainVSOut point = vs_main_run(load_vertex(vertices[vid >> 2]), cb);
if (vid & 1)
@@ -230,7 +230,7 @@ vertex MainVSOut vs_main_expand(
point.p.y += cb.point_size.y;
return point;
}
case GSMTLExpandType::Line:
case GSShader::VSExpand::Line:
{
uint vid_base = vid >> 2;
bool is_bottom = vid & 2;
@@ -252,7 +252,7 @@ vertex MainVSOut vs_main_expand(
return point;
}
case GSMTLExpandType::Sprite:
case GSShader::VSExpand::Sprite:
{
uint vid_base = vid >> 1;
bool is_bottom = vid & 2;
+2 -2
View File
@@ -4813,8 +4813,8 @@ VkShaderModule GSDeviceVK::GetTFXFragmentShader(const GSHWDrawConfig::PSSelector
AddMacro(ss, "PS_AEM", sel.aem);
AddMacro(ss, "PS_TFX", sel.tfx);
AddMacro(ss, "PS_TCC", sel.tcc);
AddMacro(ss, "PS_ATST", sel.atst);
AddMacro(ss, "PS_AFAIL", sel.afail);
AddMacro(ss, "PS_ATST", static_cast<u32>(sel.atst));
AddMacro(ss, "PS_AFAIL", static_cast<u32>(sel.afail));
AddMacro(ss, "PS_FOG", sel.fog);
AddMacro(ss, "PS_BLEND_HW", sel.blend_hw);
AddMacro(ss, "PS_A_MASKED", sel.a_masked);
+1
View File
@@ -773,6 +773,7 @@
<ClInclude Include="GS\GSBlock.h" />
<ClInclude Include="GS\GSCapture.h" />
<ClInclude Include="GS\GSClut.h" />
<ClInclude Include="GS\Renderers\Common\GSShaderEnums.h" />
<ClInclude Include="GS\Renderers\Common\GSDevice.h" />
<ClInclude Include="GS\Renderers\DX11\GSDevice11.h" />
<ClInclude Include="GS\Renderers\OpenGL\GSDeviceOGL.h">
+3
View File
@@ -2027,6 +2027,9 @@
<ClInclude Include="GS\Renderers\Common\GSDevice.h">
<Filter>System\Ps2\GS\Renderers\Common</Filter>
</ClInclude>
<ClInclude Include="GS\Renderers\Common\GSShaderEnums.h">
<Filter>System\Ps2\GS\Renderers\Common</Filter>
</ClInclude>
<ClInclude Include="GS\Renderers\Common\GSTexture.h">
<Filter>System\Ps2\GS\Renderers\Common</Filter>
</ClInclude>