Skip to content

Commit

Permalink
GS/DX11: Fix sampling from cleared targets
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jul 8, 2023
1 parent 475e90b commit 4290c16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
34 changes: 14 additions & 20 deletions pcsx2/GS/Renderers/DX11/GSDevice11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,17 +1282,13 @@ void GSDevice11::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*

// ps

PSSetShaderResources(sTex, nullptr);
PSSetShaderResource(0, sTex);
PSSetSamplerState(linear ? m_convert.ln.get() : m_convert.pt.get());
PSSetShader(ps, ps_cb);

//

DrawPrimitive();

//

PSSetShaderResources(nullptr, nullptr);
}

void GSDevice11::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, PresentShader shader, float shaderTime, bool linear)
Expand Down Expand Up @@ -1350,17 +1346,13 @@ void GSDevice11::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*

// ps

PSSetShaderResources(sTex, nullptr);
PSSetShaderResource(0, sTex);
PSSetSamplerState(linear ? m_convert.ln.get() : m_convert.pt.get());
PSSetShader(m_present.ps[static_cast<u32>(shader)].get(), m_present.ps_cb.get());

//

DrawPrimitive();

//

PSSetShaderResources(nullptr, nullptr);
}

void GSDevice11::UpdateCLUTTexture(GSTexture* sTex, float sScale, u32 offsetX, u32 offsetY, GSTexture* dTex, u32 dOffset, u32 dSize)
Expand Down Expand Up @@ -1813,7 +1805,7 @@ void GSDevice11::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vert
VSSetShader(m_convert.vs.get(), nullptr);

// ps
PSSetShaderResources(rt, nullptr);
PSSetShaderResource(0, rt);
PSSetSamplerState(m_convert.pt.get());
PSSetShader(m_convert.ps[static_cast<int>(datm ? ShaderConvert::DATM_1 : ShaderConvert::DATM_0)].get(), nullptr);

Expand Down Expand Up @@ -1993,16 +1985,9 @@ void GSDevice11::VSSetShader(ID3D11VertexShader* vs, ID3D11Buffer* vs_cb)
}
}

void GSDevice11::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
{
PSSetShaderResource(0, sr0);
PSSetShaderResource(1, sr1);
PSSetShaderResource(2, nullptr);
}

void GSDevice11::PSSetShaderResource(int i, GSTexture* sr)
{
m_state.ps_sr_views[i] = sr ? static_cast<ID3D11ShaderResourceView*>(*static_cast<GSTexture11*>(sr)) : nullptr;
m_state.ps_sr_views[i] = *static_cast<GSTexture11*>(sr);
}

void GSDevice11::PSSetSamplerState(ID3D11SamplerState* ss0)
Expand Down Expand Up @@ -2277,7 +2262,16 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
}
IASetPrimitiveTopology(topology);

PSSetShaderResources(config.tex, config.pal);
if (config.tex)
{
CommitClear(config.tex);
PSSetShaderResource(0, config.tex);
}
if (config.pal)
{
CommitClear(config.pal);
PSSetShaderResource(1, config.pal);
}

GSTexture* rt_copy = nullptr;
if (config.require_one_barrier || (config.tex && config.tex == config.rt)) // Used as "bind rt" flag when texture barrier is unsupported
Expand Down
1 change: 0 additions & 1 deletion pcsx2/GS/Renderers/DX11/GSDevice11.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ class GSDevice11 final : public GSDevice

void VSSetShader(ID3D11VertexShader* vs, ID3D11Buffer* vs_cb);

void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
void PSSetShaderResource(int i, GSTexture* sr);
void PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb);
void PSUpdateShaderState();
Expand Down

0 comments on commit 4290c16

Please sign in to comment.