diff --git a/bin/resources/shaders/common/fxaa.fx b/bin/resources/shaders/common/fxaa.fx index a4611c771d..3fb2b93862 100644 --- a/bin/resources/shaders/common/fxaa.fx +++ b/bin/resources/shaders/common/fxaa.fx @@ -31,11 +31,6 @@ layout(std140, binding = 14) uniform cb14 Texture2D Texture : register(t0); SamplerState TextureSampler : register(s0); -cbuffer cb0 -{ - float4 _rcpFrame : register(c0); -}; - struct VS_INPUT { float4 p : POSITION; @@ -131,11 +126,6 @@ float RGBLuminance(float3 color) return dot(color.rgb, lumCoeff); } -#if (FXAA_GLSL_130 == 0) -#define PixelSize float2(_rcpFrame.x, _rcpFrame.y) -#endif - - float3 RGBGammaToLinear(float3 color, float gamma) { color = FxaaSat(color); @@ -502,6 +492,7 @@ float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0) tex.tex = Texture; tex.smpl = TextureSampler; + float2 PixelSize; Texture.GetDimensions(PixelSize.x, PixelSize.y); FxaaColor = FxaaPixelShader(uv0, tex, 1.0/PixelSize.xy, FxaaSubpixMax, FxaaEdgeThreshold, FxaaEdgeThresholdMin); diff --git a/bin/resources/shaders/opengl/common_header.glsl b/bin/resources/shaders/opengl/common_header.glsl index b26e59bbf3..e7efce9cf2 100644 --- a/bin/resources/shaders/opengl/common_header.glsl +++ b/bin/resources/shaders/opengl/common_header.glsl @@ -44,15 +44,6 @@ out gl_PerVertex { // Performance note, some drivers (nouveau) will validate all Constant Buffers // even if only one was updated. -#ifdef FRAGMENT_SHADER -layout(std140, binding = 6) uniform cb15 -{ - int EMODA; - int EMODC; - ivec2 pad_cb15; -}; -#endif - #if defined(VERTEX_SHADER) || defined(GEOMETRY_SHADER) layout(std140, binding = 1) uniform cb20 { @@ -69,7 +60,7 @@ layout(std140, binding = 1) uniform cb20 #endif #if defined(VERTEX_SHADER) || defined(FRAGMENT_SHADER) -layout(std140, binding = 2) uniform cb21 +layout(std140, binding = 0) uniform cb21 { vec3 FogColor; float AREF; diff --git a/bin/resources/shaders/opengl/convert.glsl b/bin/resources/shaders/opengl/convert.glsl index a7858be8fa..f567a14fb1 100644 --- a/bin/resources/shaders/opengl/convert.glsl +++ b/bin/resources/shaders/opengl/convert.glsl @@ -388,6 +388,8 @@ void ps_mod256() #endif #ifdef ps_yuv +uniform ivec2 EMOD; + void ps_yuv() { vec4 i = sample_c(); @@ -404,7 +406,7 @@ void ps_yuv() float Cr = float(0xE0)/255.0f * yuv.y + float(0x80)/255.0f; float Cb = float(0xE0)/255.0f * yuv.z + float(0x80)/255.0f; - switch(EMODA) { + switch(EMOD.x) { case 0: o.a = i.a; break; @@ -419,7 +421,7 @@ void ps_yuv() break; } - switch(EMODC) { + switch(EMOD.y) { case 0: o.rgb = i.rgb; break; diff --git a/bin/resources/shaders/opengl/interlace.glsl b/bin/resources/shaders/opengl/interlace.glsl index 88107cf5bb..4b3a02b798 100644 --- a/bin/resources/shaders/opengl/interlace.glsl +++ b/bin/resources/shaders/opengl/interlace.glsl @@ -9,11 +9,8 @@ in SHADER #ifdef FRAGMENT_SHADER -layout(std140, binding = 4) uniform cb11 -{ - vec2 ZrH; - float hH; -}; +uniform vec2 ZrH; +uniform float hH; layout(location = 0) out vec4 SV_Target0; diff --git a/bin/resources/shaders/opengl/merge.glsl b/bin/resources/shaders/opengl/merge.glsl index 70eb4e1287..3adea54f58 100644 --- a/bin/resources/shaders/opengl/merge.glsl +++ b/bin/resources/shaders/opengl/merge.glsl @@ -9,10 +9,7 @@ in SHADER #ifdef FRAGMENT_SHADER -layout(std140, binding = 3) uniform cb10 -{ - vec4 BGColor; -}; +uniform vec4 BGColor; layout(location = 0) out vec4 SV_Target0; diff --git a/bin/shaders/GS.fx b/bin/shaders/GS.fx index 44ef66debc..7da52e35cf 100644 --- a/bin/shaders/GS.fx +++ b/bin/shaders/GS.fx @@ -49,11 +49,8 @@ in SHADER layout(location = 0) out vec4 SV_Target0; -layout(std140, binding = 14) uniform cb14 -{ - vec2 _xyFrame; - vec4 _rcpFrame; -}; +uniform vec2 _xyFrame; +uniform vec4 _rcpFrame; #else diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index 4b4d363aab..cfdb131b9c 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -97,15 +97,6 @@ public: ExternalFXConstantBuffer() { memset(this, 0, sizeof(*this)); } }; -class FXAAConstantBuffer -{ -public: - GSVector4 rcpFrame; - GSVector4 rcpFrameOpt; - - FXAAConstantBuffer() { memset(this, 0, sizeof(*this)); } -}; - class ShadeBoostConstantBuffer { public: diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 3be5b88564..8835949164 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -351,16 +351,6 @@ bool GSDevice11::Create(const WindowInfo& wi) m_dev->CreateBuffer(&bd, nullptr, m_shaderfx.cb.put()); - // Fxaa - - memset(&bd, 0, sizeof(bd)); - - bd.ByteWidth = sizeof(FXAAConstantBuffer); - bd.Usage = D3D11_USAGE_DEFAULT; - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - - m_dev->CreateBuffer(&bd, nullptr, m_fxaa.cb.put()); - // memset(&rd, 0, sizeof(rd)); @@ -954,9 +944,7 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex) const GSVector4 sRect(0, 0, 1, 1); const GSVector4 dRect(0, 0, s.x, s.y); - FXAAConstantBuffer cb; - - if (m_fxaa.ps == nullptr) + if (!m_fxaa_ps) { try { @@ -964,7 +952,7 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex) if (shader.has_value()) { ShaderMacro sm(m_shader.model); - CreateShader(*shader, "fxaa.fx", nullptr, "ps_main", sm.GetPtr(), m_fxaa.ps.put()); + CreateShader(*shader, "fxaa.fx", nullptr, "ps_main", sm.GetPtr(), m_fxaa_ps.put()); } } catch (GSRecoverableError) @@ -973,12 +961,7 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex) } } - cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f); - cb.rcpFrameOpt = GSVector4::zero(); - - m_ctx->UpdateSubresource(m_fxaa.cb.get(), 0, nullptr, &cb, 0, 0); - - StretchRect(sTex, sRect, dTex, dRect, m_fxaa.ps.get(), m_fxaa.cb.get(), true); + StretchRect(sTex, sRect, dTex, dRect, m_fxaa_ps.get(), nullptr, true); //sTex->Save("c:\\temp1\\1.bmp"); //dTex->Save("c:\\temp1\\2.bmp"); diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.h b/pcsx2/GS/Renderers/DX11/GSDevice11.h index 3264af94f5..78c2f79fd8 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.h +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.h @@ -193,11 +193,7 @@ private: wil::com_ptr_nothrow cb; } m_shaderfx; - struct - { - wil::com_ptr_nothrow ps; - wil::com_ptr_nothrow cb; - } m_fxaa; + wil::com_ptr_nothrow m_fxaa_ps; struct { diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp index 01936b42de..367ea5bebd 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp @@ -32,12 +32,8 @@ u64 g_vertex_upload_byte = 0; u64 g_uniform_upload_byte = 0; #endif -static constexpr u32 g_merge_cb_index = 3; -static constexpr u32 g_interlace_cb_index = 4; -static constexpr u32 g_fx_cb_index = 14; -static constexpr u32 g_convert_index = 5; static constexpr u32 g_vs_cb_index = 1; -static constexpr u32 g_ps_cb_index = 2; +static constexpr u32 g_ps_cb_index = 0; static constexpr u32 VERTEX_BUFFER_SIZE = 32 * 1024 * 1024; static constexpr u32 INDEX_BUFFER_SIZE = 16 * 1024 * 1024; @@ -110,24 +106,9 @@ GSDeviceOGL::~GSDeviceOGL() m_vertex_stream_buffer.reset(); m_index_stream_buffer.reset(); - // Clean m_merge_obj - delete m_merge_obj.cb; - - // Clean m_interlace - delete m_interlace.cb; - // Clean m_convert delete m_convert.dss; delete m_convert.dss_write; - delete m_convert.cb; - - // Clean m_fxaa - delete m_fxaa.cb; - -#ifndef PCSX2_CORE - // Clean m_shaderfx - delete m_shaderfx.cb; -#endif // Clean m_date delete m_date.dss; @@ -375,8 +356,6 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) { GL_PUSH("GSDeviceOGL::Convert"); - m_convert.cb = new GSUniformBufferOGL("Misc UBO", g_convert_index, sizeof(MiscConstantBuffer)); - // these all share the same vertex shader const auto shader = Host::ReadResourceFileToString("shaders/opengl/convert.glsl"); if (!shader.has_value()) @@ -394,6 +373,9 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) if (!m_shader_cache.GetProgram(&m_convert.ps[i], m_convert.vs, {}, ps)) return false; m_convert.ps[i].SetFormattedName("Convert pipe %s", name); + + if (static_cast(i) == ShaderConvert::YUV) + m_convert.ps[i].RegisterUniform("EMOD"); } PSSamplerSelector point; @@ -415,10 +397,6 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) { GL_PUSH("GSDeviceOGL::Merge"); - static const float default_merge_cb[4] = {}; - m_merge_obj.cb = new GSUniformBufferOGL("Merge UBO", g_merge_cb_index, sizeof(MergeConstantBuffer)); - m_merge_obj.cb->upload(default_merge_cb); - const auto shader = Host::ReadResourceFileToString("shaders/opengl/merge.glsl"); if (!shader.has_value()) return false; @@ -429,6 +407,7 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) if (!m_shader_cache.GetProgram(&m_merge_obj.ps[i], m_convert.vs, {}, ps)) return false; m_merge_obj.ps[i].SetFormattedName("Merge pipe %zu", i); + m_merge_obj.ps[i].RegisterUniform("BGColor"); } } @@ -438,10 +417,6 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) { GL_PUSH("GSDeviceOGL::Interlace"); - m_interlace.cb = new GSUniformBufferOGL("Interlace UBO", g_interlace_cb_index, sizeof(InterlaceConstantBuffer)); - InterlaceConstantBuffer interlace_cb; - m_interlace.cb->upload(&interlace_cb); - const auto shader = Host::ReadResourceFileToString("shaders/opengl/interlace.glsl"); if (!shader.has_value()) return false; @@ -452,6 +427,8 @@ bool GSDeviceOGL::Create(const WindowInfo& wi) if (!m_shader_cache.GetProgram(&m_interlace.ps[i], m_convert.vs, {}, ps)) return false; m_interlace.ps[i].SetFormattedName("Merge pipe %zu", i); + m_interlace.ps[i].RegisterUniform("ZrH"); + m_interlace.ps[i].RegisterUniform("hH"); } } @@ -1323,15 +1300,6 @@ void GSDeviceOGL::DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, OMSetColorMaskState(); ClearRenderTarget(dTex, c); - // Upload constant to select YUV algo - if (feedback_write_2 || feedback_write_1) - { - // Write result to feedback loop - m_misc_cb_cache.EMOD_AC.x = EXTBUF.EMODA; - m_misc_cb_cache.EMOD_AC.y = EXTBUF.EMODC; - m_convert.cb->cache_upload(&m_misc_cb_cache); - } - if (sTex[1] && (PMODE.SLBG == 0 || feedback_write_2_but_blend_bg)) { // 2nd output is enabled and selected. Copy it to destination so we can blend it with 1st output @@ -1339,6 +1307,14 @@ void GSDeviceOGL::DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, StretchRect(sTex[1], sRect[1], dTex, dRect[1], ShaderConvert::COPY); } + // Upload constant to select YUV algo + if (feedback_write_2 || feedback_write_1) + { + // Write result to feedback loop + m_convert.ps[static_cast(ShaderConvert::YUV)].Bind(); + m_convert.ps[static_cast(ShaderConvert::YUV)].Uniform2i(0, EXTBUF.EMODA, EXTBUF.EMODC); + } + // Save 2nd output if (feedback_write_2) // FIXME I'm not sure dRect[1] is always correct StretchRect(dTex, full_r, sTex[2], dRect[1], ShaderConvert::YUV); @@ -1356,7 +1332,8 @@ void GSDeviceOGL::DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, if (PMODE.MMOD == 1) { // Blend with a constant alpha - m_merge_obj.cb->cache_upload(&c.v); + m_merge_obj.ps[1].Bind(); + m_merge_obj.ps[1].Uniform4fv(0, c.v); StretchRect(sTex[0], sRect[0], dTex, dRect[0], m_merge_obj.ps[1], m_MERGE_BLEND, OMColorMaskSelector()); } else @@ -1381,12 +1358,9 @@ void GSDeviceOGL::DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool const GSVector4 sRect(0, 0, 1, 1); const GSVector4 dRect(0.0f, yoffset, s.x, s.y + yoffset); - InterlaceConstantBuffer cb; - - cb.ZrH = GSVector2(0, 1.0f / s.y); - cb.hH = s.y / 2; - - m_interlace.cb->cache_upload(&cb); + m_interlace.ps[shader].Bind(); + m_interlace.ps[shader].Uniform2f(0, 0, 1.0f / s.y); + m_interlace.ps[shader].Uniform1f(1, s.y / 2); StretchRect(sTex, sRect, dTex, dRect, m_interlace.ps[shader], linear); } @@ -1456,10 +1430,13 @@ void GSDeviceOGL::DoExternalFX(GSTexture* sTex, GSTexture* dTex) shader << fshader.rdbuf(); - m_shaderfx.cb = new GSUniformBufferOGL("eFX UBO", g_fx_cb_index, sizeof(ExternalFXConstantBuffer)); const std::string ps(GetShaderSource("ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, shader.str(), config.str())); if (!m_shaderfx.ps.Compile(m_convert.vs, {}, ps) || !m_shaderfx.ps.Link()) return; + + m_shaderfx.ps.RegisterUniform("_xyFrame"); + m_shaderfx.ps.RegisterUniform("_rcpFrame"); + m_shaderfx.ps.RegisterUniform("_rcpFrameOpt"); } GL_PUSH("DoExternalFX"); @@ -1471,13 +1448,10 @@ void GSDeviceOGL::DoExternalFX(GSTexture* sTex, GSTexture* dTex) const GSVector4 sRect(0, 0, 1, 1); const GSVector4 dRect(0, 0, s.x, s.y); - ExternalFXConstantBuffer cb; - - cb.xyFrame = GSVector2((float)s.x, (float)s.y); - cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f); - cb.rcpFrameOpt = GSVector4::zero(); - - m_shaderfx.cb->cache_upload(&cb); + m_shaderfx.ps.Bind(); + m_shaderfx.ps.Uniform2f(0, (float)s.x, (float)s.y); + m_shaderfx.ps.Uniform4f(1, 1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f); + m_shaderfx.ps.Uniform4f(2, 0.0f, 0.0f, 0.0f, 0.0f); StretchRect(sTex, sRect, dTex, dRect, m_shaderfx.ps, true); #endif diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h index edbe6465df..accaa0ddd5 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h @@ -183,13 +183,6 @@ public: using OMDepthStencilSelector = GSHWDrawConfig::DepthStencilSelector; using OMColorMaskSelector = GSHWDrawConfig::ColorMaskSelector; - struct alignas(32) MiscConstantBuffer - { - GSVector4i EMOD_AC; - - MiscConstantBuffer() { memset(this, 0, sizeof(*this)); } - }; - struct ProgramSelector { VSSelector vs; @@ -247,13 +240,11 @@ private: struct { GL::Program ps[2]; // program object - GSUniformBufferOGL* cb; // uniform buffer object } m_merge_obj; struct { GL::Program ps[4]; // program object - GSUniformBufferOGL* cb; // uniform buffer object } m_interlace; struct @@ -264,20 +255,17 @@ private: GLuint pt; // sampler object GSDepthStencilOGL* dss; GSDepthStencilOGL* dss_write; - GSUniformBufferOGL* cb; } m_convert; struct { GL::Program ps; - GSUniformBufferOGL* cb; } m_fxaa; #ifndef PCSX2_CORE struct { GL::Program ps; - GSUniformBufferOGL* cb; } m_shaderfx; #endif @@ -309,7 +297,6 @@ private: GSHWDrawConfig::VSConstantBuffer m_vs_cb_cache; GSHWDrawConfig::PSConstantBuffer m_ps_cb_cache; - MiscConstantBuffer m_misc_cb_cache; std::unique_ptr m_font; AlignedBuffer m_download_buffer;