Merge pull request #718 from PCSX2/depth-color-direct-write

Depth color direct write
This commit is contained in:
Gregory Hainaut 2015-08-10 15:50:48 +02:00
commit 98c74879bf
6 changed files with 38 additions and 19 deletions

View File

@ -444,11 +444,13 @@ void GSDevice11::Dispatch(uint32 x, uint32 y, uint32 z)
void GSDevice11::ClearRenderTarget(GSTexture* t, const GSVector4& c)
{
if (!t) return;
m_ctx->ClearRenderTargetView(*(GSTexture11*)t, c.v);
}
void GSDevice11::ClearRenderTarget(GSTexture* t, uint32 c)
{
if (!t) return;
GSVector4 color = GSVector4::rgba32(c) * (1.0f / 255);
m_ctx->ClearRenderTargetView(*(GSTexture11*)t, color.v);
@ -456,11 +458,13 @@ void GSDevice11::ClearRenderTarget(GSTexture* t, uint32 c)
void GSDevice11::ClearDepth(GSTexture* t, float c)
{
if (!t) return;
m_ctx->ClearDepthStencilView(*(GSTexture11*)t, D3D11_CLEAR_DEPTH, c, 0);
}
void GSDevice11::ClearStencil(GSTexture* t, uint8 c)
{
if (!t) return;
m_ctx->ClearDepthStencilView(*(GSTexture11*)t, D3D11_CLEAR_STENCIL, 0, c);
}

View File

@ -649,11 +649,13 @@ void GSDevice9::EndScene()
void GSDevice9::ClearRenderTarget(GSTexture* t, const GSVector4& c)
{
if (!t) return;
ClearRenderTarget(t, (c * 255 + 0.5f).zyxw().rgba32());
}
void GSDevice9::ClearRenderTarget(GSTexture* rt, uint32 c)
{
if (!rt) return;
CComPtr<IDirect3DSurface9> surface;
m_dev->GetRenderTarget(0, &surface);
m_dev->SetRenderTarget(0, *(GSTexture9*)rt);
@ -663,6 +665,7 @@ void GSDevice9::ClearRenderTarget(GSTexture* rt, uint32 c)
void GSDevice9::ClearDepth(GSTexture* t, float c)
{
if (!t) return;
CComPtr<IDirect3DSurface9> dssurface;
m_dev->GetDepthStencilSurface(&dssurface);
m_dev->SetDepthStencilSurface(*(GSTexture9*)t);
@ -672,6 +675,7 @@ void GSDevice9::ClearDepth(GSTexture* t, float c)
void GSDevice9::ClearStencil(GSTexture* t, uint8 c)
{
if (!t) return;
CComPtr<IDirect3DSurface9> dssurface;
m_dev->GetDepthStencilSurface(&dssurface);
m_dev->SetDepthStencilSurface(*(GSTexture9*)t);

View File

@ -426,6 +426,8 @@ void GSDeviceOGL::DrawIndexedPrimitive(int offset, int count)
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
{
if (!t) return;
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
if (T->HasBeenCleaned() && !T->IsBackbuffer())
return;
@ -463,12 +465,16 @@ void GSDeviceOGL::ClearRenderTarget(GSTexture* t, const GSVector4& c)
void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c)
{
if (!t) return;
GSVector4 color = GSVector4::rgba32(c) * (1.0f / 255);
ClearRenderTarget(t, color);
}
void GSDeviceOGL::ClearRenderTarget_i(GSTexture* t, int32 c)
{
if (!t) return;
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
GL_PUSH("Clear RTi %d", T->GetID());
@ -501,6 +507,8 @@ void GSDeviceOGL::ClearRenderTarget_i(GSTexture* t, int32 c)
void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
{
if (!t) return;
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
GL_PUSH("Clear Depth %d", T->GetID());
@ -524,6 +532,8 @@ void GSDeviceOGL::ClearDepth(GSTexture* t, float c)
void GSDeviceOGL::ClearStencil(GSTexture* t, uint8 c)
{
if (!t) return;
GSTextureOGL* T = static_cast<GSTextureOGL*>(t);
GL_PUSH("Clear Stencil %d", T->GetID());

View File

@ -47,8 +47,8 @@ void GSRendererDX::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sourc
GSDrawingEnvironment& env = m_env;
GSDrawingContext* context = m_context;
const GSVector2i& rtsize = ds->GetSize();
const GSVector2& rtscale = ds->GetScale();
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
bool DATE = m_context->TEST.DATE && context->FRAME.PSM != PSM_PSMCT24;

View File

@ -340,10 +340,11 @@ void GSRendererHW::Draw()
// It is allowed to use the depth and rt at the same location. However at least 1 must
// be disabled.
// 1/ GoW uses a Cd blending on a 24 bits buffer (no alpha)
// 2/ SuperMan really draw the same value in both buffer...
// 2/ SuperMan really draws (0,0,0,0) color and a (0) 32-bits depth
// 3/ 50cents really draws (0,0,0,128) color and a (0) 24 bits depth
// Note: FF DoC has both buffer at same location but disable the depth test (write?) with ZTE = 0
const bool no_rt = (context->ALPHA.IsCd() && PRIM->ABE && (context->FRAME.PSM == 1)) ||
(context->FRAME.FBP == context->ZBUF.ZBP && !PRIM->TME && !context->ZBUF.ZMSK && !context->FRAME.FBMSK && context->TEST.ZTE);
const bool no_rt = (context->ALPHA.IsCd() && PRIM->ABE && (context->FRAME.PSM == 1));
const bool no_ds = !no_rt && (context->FRAME.FBP == context->ZBUF.ZBP && !PRIM->TME && !context->ZBUF.ZMSK && !context->FRAME.FBMSK && context->TEST.ZTE);
GIFRegTEX0 TEX0;
@ -358,9 +359,10 @@ void GSRendererHW::Draw()
TEX0.TBW = context->FRAME.FBW;
TEX0.PSM = context->ZBUF.PSM;
GSTextureCache::Target* ds = m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::DepthStencil, context->DepthWrite());
GSTextureCache::Target* ds = no_ds ? NULL : m_tc->LookupTarget(TEX0, m_width, m_height, GSTextureCache::DepthStencil, context->DepthWrite());
GSTexture* ds_tex = ds ? ds->m_texture : NULL;
if((!rt && !no_rt) || !ds)
if(!(rt || no_rt) || !(ds || no_ds))
{
GL_POP();
ASSERT(0);
@ -461,7 +463,7 @@ void GSRendererHW::Draw()
{
s = format("%05d_f%lld_rz0_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM);
ds->m_texture->Save(root_hw+s);
ds_tex->Save(root_hw+s);
}
s_n++;
@ -472,7 +474,7 @@ void GSRendererHW::Draw()
#endif
}
if(m_hacks.m_oi && !(this->*m_hacks.m_oi)(rt_tex, ds->m_texture, tex))
if(m_hacks.m_oi && !(this->*m_hacks.m_oi)(rt_tex, ds_tex, tex))
{
s_n += 1; // keep counter sync
GL_POP();
@ -539,7 +541,7 @@ void GSRendererHW::Draw()
//
DrawPrims(rt_tex, ds->m_texture, tex);
DrawPrims(rt_tex, ds_tex, tex);
//
@ -560,7 +562,7 @@ void GSRendererHW::Draw()
m_tc->InvalidateVideoMemType(GSTextureCache::DepthStencil, context->FRAME.Block());
}
if(zm != 0xffffffff)
if(zm != 0xffffffff && ds)
{
ds->m_valid = ds->m_valid.runion(r);
@ -594,7 +596,7 @@ void GSRendererHW::Draw()
{
s = format("%05d_f%lld_rz1_%05x_%d.bmp", s_n, frame, context->ZBUF.Block(), context->ZBUF.PSM);
ds->m_texture->Save(root_hw+s);
ds_tex->Save(root_hw+s);
}
s_n++;
@ -1222,7 +1224,7 @@ bool GSRendererHW::OI_SuperManReturns(GSTexture* rt, GSTexture* ds, GSTextureCac
GSDrawingContext* ctx = m_context;
GSVertex* v = &m_vertex.buff[0];
if (!(ctx->FRAME.FBP == ctx->ZBUF.ZBP && !PRIM->TME && !ctx->ZBUF.ZMSK && !ctx->FRAME.FBMSK))
if (!(ctx->FRAME.FBP == ctx->ZBUF.ZBP && !PRIM->TME && !ctx->ZBUF.ZMSK && !ctx->FRAME.FBMSK && m_vt.m_eq.rgba == 0xFFFF))
return true;
// Please kill those crazy devs!
@ -1231,10 +1233,9 @@ bool GSRendererHW::OI_SuperManReturns(GSTexture* rt, GSTexture* ds, GSTextureCac
ASSERT((v->RGBAQ.A << 24 | v->RGBAQ.B << 16 | v->RGBAQ.G << 8 | v->RGBAQ.R) == (int)v->XYZ.Z);
// Do a direct write
double depth = (double)v->XYZ.Z * exp2(-32.0f);
m_dev->ClearDepth(ds, (float)depth);
m_dev->ClearRenderTarget(rt, GSVector4(m_vt.m_min.c));
m_tc->InvalidateVideoMemType(GSTextureCache::RenderTarget, ctx->ZBUF.Block());
m_tc->InvalidateVideoMemType(GSTextureCache::DepthStencil, ctx->FRAME.Block());
return false;
}

View File

@ -559,12 +559,12 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
{
GL_PUSH("GL Draw from %d in %d (Depth %d)",
tex && tex->m_texture ? tex->m_texture->GetID() : 0,
rt ? rt->GetID() : -1, ds->GetID());
rt ? rt->GetID() : -1, ds ? ds->GetID() : -1);
GSTexture* hdr_rt = NULL;
const GSVector2i& rtsize = ds->GetSize();
const GSVector2& rtscale = ds->GetScale();
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
bool DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
bool DATE_GL42 = false;