From 2a06bb6e2cee616fb6899ea9c3a02785ed26df33 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 7 Apr 2023 16:40:37 +1000 Subject: [PATCH] GS/OGL: Use VS/GS selectors from base class --- bin/resources/shaders/opengl/tfx_vgs.glsl | 18 ++++---- pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp | 29 ++---------- pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h | 56 +---------------------- 3 files changed, 16 insertions(+), 87 deletions(-) diff --git a/bin/resources/shaders/opengl/tfx_vgs.glsl b/bin/resources/shaders/opengl/tfx_vgs.glsl index 0d3d77bd45..9e3f5e7823 100644 --- a/bin/resources/shaders/opengl/tfx_vgs.glsl +++ b/bin/resources/shaders/opengl/tfx_vgs.glsl @@ -46,12 +46,12 @@ void texture_coord() // Integer coordinate => normalized VSout.t_int.xy = uv * TextureScale; -#if VS_INT_FST == 1 - // Some games uses float coordinate for post-processing effect - VSout.t_int.zw = st / TextureScale; -#else +#if VS_FST // Integer coordinate => integral VSout.t_int.zw = uv; +#else + // Some games uses float coordinate for post-processing effect + VSout.t_int.zw = st / TextureScale; #endif } @@ -129,7 +129,7 @@ void out_vertex(in vec4 position, in vertex v) GSout.t_float = v.t_float; GSout.t_int = v.t_int; // Flat output -#if GS_POINT == 1 +#if GS_PRIM == 0 GSout.c = GSin[0].c; #else GSout.c = GSin[1].c; @@ -139,14 +139,14 @@ void out_vertex(in vec4 position, in vertex v) EmitVertex(); } -#if GS_POINT == 1 +#if GS_PRIM == 0 layout(points) in; #else layout(lines) in; #endif layout(triangle_strip, max_vertices = 4) out; -#if GS_POINT == 1 +#if GS_PRIM == 0 void gs_main() { @@ -172,7 +172,7 @@ void gs_main() EndPrimitive(); } -#elif GS_LINE == 1 +#elif GS_PRIM == 1 void gs_main() { @@ -203,7 +203,7 @@ void gs_main() EndPrimitive(); } -#else +#else // GS_PRIM == 3 void gs_main() { diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp index 1fa8087555..6c6acfbf01 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp @@ -1176,7 +1176,7 @@ std::string GSDeviceOGL::GetVSSource(VSSelector sel) { DevCon.WriteLn("Compiling new vertex shader with selector 0x%" PRIX64, sel.key); - std::string macro = fmt::format("#define VS_INT_FST {}\n", static_cast(sel.int_fst)) + std::string macro = fmt::format("#define VS_FST {}\n", static_cast(sel.fst)) + fmt::format("#define VS_IIP {}\n", static_cast(sel.iip)) + fmt::format("#define VS_POINT_SIZE {}\n", static_cast(sel.point_size)); @@ -1189,8 +1189,8 @@ std::string GSDeviceOGL::GetGSSource(GSSelector sel) { DevCon.WriteLn("Compiling new geometry shader with selector 0x%" PRIX64, sel.key); - std::string macro = fmt::format("#define GS_POINT {}\n", static_cast(sel.point)) - + fmt::format("#define GS_LINE {}\n", static_cast(sel.line)) + std::string macro = fmt::format("#define GS_PRIM {}\n", static_cast(sel.topology)) + + fmt::format("#define GS_EXPAND {}\n", static_cast(sel.expand)) + fmt::format("#define GS_IIP {}\n", static_cast(sel.iip)); std::string src = GenGlslHeader("gs_main", GL_GEOMETRY_SHADER, macro); @@ -2243,16 +2243,6 @@ void GSDeviceOGL::SetupOM(OMDepthStencilSelector dssel) OMSetDepthStencilState(m_om_dss[dssel.key]); } -static GSDeviceOGL::VSSelector convertSel(const GSHWDrawConfig::VSSelector sel, const GSHWDrawConfig::Topology topology) -{ - // Mali requires gl_PointSize written when rasterizing points. The spec seems to suggest this is okay. - GSDeviceOGL::VSSelector out; - out.int_fst = !sel.fst; - out.iip = sel.iip; - out.point_size = sel.point_size || (GLLoader::is_gles && topology == GSHWDrawConfig::Topology::Point); - return out; -} - // clang-format off static constexpr std::array s_gl_blend_factors = { { GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, @@ -2366,22 +2356,13 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config) } ProgramSelector psel; - psel.vs = convertSel(config.vs, config.topology); + psel.vs = config.vs; psel.ps.key_hi = config.ps.key_hi; psel.ps.key_lo = config.ps.key_lo; psel.gs.key = 0; psel.pad = 0; if (config.gs.expand) - { - psel.gs.iip = config.gs.iip; - switch (config.gs.topology) - { - case GSHWDrawConfig::GSTopology::Point: psel.gs.point = 1; break; - case GSHWDrawConfig::GSTopology::Line: psel.gs.line = 1; break; - case GSHWDrawConfig::GSTopology::Sprite: psel.gs.sprite = 1; break; - case GSHWDrawConfig::GSTopology::Triangle: ASSERT(0); break; - } - } + psel.gs.key = config.gs.key; SetupPipeline(psel); diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h index 54b054a07f..18936bbd47 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h @@ -120,60 +120,8 @@ public: class GSDeviceOGL final : public GSDevice { public: - struct VSSelector - { - union - { - struct - { - u8 int_fst : 1; - u8 iip : 1; - u8 point_size : 1; - u8 _free : 5; - }; - - u8 key; - }; - - VSSelector() - : key(0) - { - } - VSSelector(u8 k) - : key(k) - { - } - }; - - struct GSSelector - { - union - { - struct - { - u8 sprite : 1; - u8 point : 1; - u8 line : 1; - u8 iip : 1; - - u8 _free : 4; - }; - - u8 key; - }; - - operator u32() const { return key; } - - GSSelector() - : key(0) - { - } - GSSelector(u8 k) - : key(k) - { - } - }; - + using VSSelector = GSHWDrawConfig::VSSelector; + using GSSelector = GSHWDrawConfig::GSSelector; using PSSelector = GSHWDrawConfig::PSSelector; using PSSamplerSelector = GSHWDrawConfig::SamplerSelector; using OMDepthStencilSelector = GSHWDrawConfig::DepthStencilSelector;