GS/GL: Optimize shader copies states.

Don't set blend state and color mask when writing depth stencil only.
Blend state and color mask is used when writing to render target.

Don't set depth stencil state when writing render target only.
Depth stencil state is used when writing to depth stencil only.
This commit is contained in:
lightningterror
2026-03-01 10:08:25 +01:00
parent d178c451d8
commit b25211fd0a
2 changed files with 26 additions and 20 deletions
+25 -19
View File
@@ -1530,10 +1530,10 @@ void GSDeviceOGL::DoStretchRect(GSTexture* sTex, const GSVector4& sRect, GSTextu
if (draw_in_depth)
OMSetDepthStencilState(m_convert.dss_write);
else
OMSetDepthStencilState(m_convert.dss);
OMSetBlendState(alpha_blend, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);
OMSetColorMaskState(cms);
{
OMSetBlendState(alpha_blend, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);
OMSetColorMaskState(cms);
}
// ************************************
// Texture
@@ -1644,7 +1644,6 @@ void GSDeviceOGL::FilteredDownsampleTexture(GSTexture* sTex, GSTexture* dTex, u3
prog.Uniform1f(2, static_cast<float>(downsample_factor * downsample_factor));
prog.Uniform1f(3, (GSConfig.UserHacks_NativeScaling > GSNativeScaling::Aggressive) ? 2.0f : 1.0f);
OMSetDepthStencilState(m_convert.dss);
OMSetBlendState(false);
OMSetColorMaskState();
OMSetRenderTargets(dTex, nullptr);
@@ -1682,18 +1681,24 @@ void GSDeviceOGL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect
DrawPrimitive();
}
void GSDeviceOGL::DrawMultiStretchRects(
const MultiStretchRect* rects, u32 num_rects, GSTexture* dTex, ShaderConvert shader)
void GSDeviceOGL::DrawMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, GSTexture* dTex, ShaderConvert shader)
{
IASetVAO(m_vao);
IASetPrimitiveTopology(GL_TRIANGLE_STRIP);
OMSetDepthStencilState(HasDepthOutput(shader) ? m_convert.dss_write : m_convert.dss);
OMSetBlendState(false);
OMSetColorMaskState();
if (!dTex->IsDepthStencil())
OMSetRenderTargets(dTex, nullptr);
else
const bool draw_in_depth = dTex->IsDepthStencil();
if (draw_in_depth)
{
OMSetDepthStencilState(m_convert.dss_write);
OMSetRenderTargets(nullptr, dTex);
}
else
{
OMSetBlendState(false);
OMSetRenderTargets(dTex, nullptr);
}
m_convert.ps[static_cast<int>(shader)].Bind();
const GSVector2 ds(static_cast<float>(dTex->GetWidth()), static_cast<float>(dTex->GetHeight()));
@@ -1712,7 +1717,7 @@ void GSDeviceOGL::DrawMultiStretchRects(
continue;
}
DoMultiStretchRects(rects + first, count, ds);
DoMultiStretchRects(rects + first, count, ds, draw_in_depth);
last_tex = rects[i].src;
last_linear = rects[i].linear;
last_wmask = rects[i].wmask.wrgba;
@@ -1720,10 +1725,10 @@ void GSDeviceOGL::DrawMultiStretchRects(
count = 1;
}
DoMultiStretchRects(rects + first, count, ds);
DoMultiStretchRects(rects + first, count, ds, draw_in_depth);
}
void GSDeviceOGL::DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, const GSVector2& ds)
void GSDeviceOGL::DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, const GSVector2& ds, const bool draw_in_depth)
{
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
@@ -1775,7 +1780,10 @@ void GSDeviceOGL::DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rec
PSSetShaderResource(0, rects[0].src);
PSSetSamplerState(rects[0].linear ? m_convert.ln : m_convert.pt);
OMSetColorMaskState(rects[0].wmask);
if (!draw_in_depth)
OMSetColorMaskState(rects[0].wmask);
DrawIndexedPrimitive();
}
@@ -1942,8 +1950,6 @@ void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, SetDATM datm, const GS
// om
OMSetDepthStencilState(m_date.dss);
OMSetBlendState(false);
OMSetColorMaskState();
// ia
+1 -1
View File
@@ -335,7 +335,7 @@ public:
void FilteredDownsampleTexture(GSTexture* sTex, GSTexture* dTex, u32 downsample_factor, const GSVector2i& clamp_min, const GSVector4& dRect) override;
void DrawMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, GSTexture* dTex, ShaderConvert shader) override;
void DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, const GSVector2& ds);
void DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, const GSVector2& ds, const bool draw_in_depth);
void RenderHW(GSHWDrawConfig& config) override;
void SendHWDraw(const GSHWDrawConfig& config, bool one_barrier, bool full_barrier);