I hate D3D.

32-bit depth buffers for D3D9 users if available.  Lots of code shuffling for reasons I don't even remember.  Stuff.  Pretty much just the 32-bit depth buffers.  That's good though, you don't have to envy D3D10 users half as much now.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3002 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
sudonim1 2010-05-14 14:05:39 +00:00
parent 70a247674d
commit c7aa146489
12 changed files with 224 additions and 106 deletions

View File

@ -31,9 +31,6 @@
#define MAX_PAGES 512
#define MAX_BLOCKS 16384
//#define DISABLE_BITMASKING
//#define DISABLE_COLCLAMP
#include "GSVector.h"
#pragma pack(push, 1)

View File

@ -111,6 +111,7 @@ public:
virtual void StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, const GSVector4& dr, int shader = 0, bool linear = true) {}
virtual void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1) {}
virtual void PSSetShaderResource(int i, GSTexture* sr) {}
virtual void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL) {}
GSTexture* GetCurrent();

View File

@ -632,9 +632,9 @@ void GSDevice11::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt,
// ps
PSSetShader(ps, ps_cb);
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, NULL);
PSSetShaderResources(st, NULL);
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt, NULL);
PSSetShader(ps, ps_cb);
//
@ -718,8 +718,8 @@ void GSDevice11::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1 (&iaV
GSTexture* rt2 = rt->IsMSAA() ? Resolve(rt) : rt;
PSSetShaderResources(rt2, NULL);
PSSetShader(m_convert.ps[datm ? 2 : 3], NULL);
PSSetSamplerState(m_convert.pt, NULL);
PSSetShader(m_convert.ps[datm ? 2 : 3], NULL);
//
@ -853,20 +853,31 @@ void GSDevice11::GSSetShader(ID3D11GeometryShader* gs)
void GSDevice11::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
{
ID3D11ShaderResourceView* srv0 = NULL;
ID3D11ShaderResourceView* srv1 = NULL;
PSSetShaderResource(0, sr0);
PSSetShaderResource(1, sr1);
PSSetShaderResource(2, NULL);
}
if(sr0) srv0 = *(GSTexture11*)sr0;
if(sr1) srv1 = *(GSTexture11*)sr1;
void GSDevice11::PSSetShaderResource(int i, GSTexture* sr)
{
ID3D11ShaderResourceView* srv = NULL;
if (sr) srv = *(GSTexture11*)sr;
if(m_state.ps_srv[0] != srv0 || m_state.ps_srv[1] != srv1)
if (m_state.ps_srv[i] != srv) {
m_state.ps_srv[i] = srv;
m_srv_changed = true;
}
}
void GSDevice11::PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1, ID3D11SamplerState* ss2)
{
if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1 || m_state.ps_ss[2] != ss2)
{
m_state.ps_srv[0] = srv0;
m_state.ps_srv[1] = srv1;
m_state.ps_ss[0] = ss0;
m_state.ps_ss[1] = ss1;
m_state.ps_ss[2] = ss2;
ID3D11ShaderResourceView* srvs[] = {srv0, srv1};
m_ctx->PSSetShaderResources(0, 2, srvs);
m_ss_changed = true;
}
}
@ -879,6 +890,16 @@ void GSDevice11::PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb)
m_ctx->PSSetShader(ps, NULL, 0);
}
if (m_srv_changed) {
m_ctx->PSSetShaderResources(0, 3, m_state.ps_srv);
m_srv_changed = false;
}
if (m_ss_changed) {
m_ctx->PSSetSamplers(0, 3, m_state.ps_ss);
m_ss_changed = false;
}
if(m_state.ps_cb != ps_cb)
{
m_state.ps_cb = ps_cb;
@ -887,19 +908,6 @@ void GSDevice11::PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb)
}
}
void GSDevice11::PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1)
{
if(m_state.ps_ss[0] != ss0 || m_state.ps_ss[1] != ss1)
{
m_state.ps_ss[0] = ss0;
m_state.ps_ss[1] = ss1;
ID3D11SamplerState* sss[] = {ss0, ss1};
m_ctx->PSSetSamplers(0, 2, sss);
}
}
void GSDevice11::OMSetDepthStencilState(ID3D11DepthStencilState* dss, uint8 sref)
{
if(m_state.dss != dss || m_state.sref != sref)

View File

@ -65,6 +65,8 @@ class GSDevice11 : public GSDeviceDX
CComPtr<ID3D11Buffer> m_vb;
CComPtr<ID3D11Buffer> m_vb_old;
bool m_srv_changed, m_ss_changed;
struct
{
ID3D11Buffer* vb;
@ -74,10 +76,10 @@ class GSDevice11 : public GSDeviceDX
ID3D11VertexShader* vs;
ID3D11Buffer* vs_cb;
ID3D11GeometryShader* gs;
ID3D11ShaderResourceView* ps_srv[2];
ID3D11ShaderResourceView* ps_srv[3];
ID3D11PixelShader* ps;
ID3D11Buffer* ps_cb;
ID3D11SamplerState* ps_ss[2];
ID3D11SamplerState* ps_ss[3];
GSVector2i viewport;
GSVector4i scissor;
ID3D11DepthStencilState* dss;
@ -132,6 +134,7 @@ public: // TODO
CComPtr<ID3D11Buffer> m_ps_cb;
hash_map<uint32, CComPtr<ID3D11SamplerState> > m_ps_ss;
CComPtr<ID3D11SamplerState> m_palette_ss;
CComPtr<ID3D11SamplerState> m_rt_ss;
hash_map<uint32, CComPtr<ID3D11DepthStencilState> > m_om_dss;
hash_map<uint32, CComPtr<ID3D11BlendState> > m_om_bs;
@ -178,8 +181,9 @@ public:
void VSSetShader(ID3D11VertexShader* vs, ID3D11Buffer* vs_cb);
void GSSetShader(ID3D11GeometryShader* gs);
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
void PSSetShaderResource(int i, GSTexture* sr);
void PSSetShader(ID3D11PixelShader* ps, ID3D11Buffer* ps_cb);
void PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1);
void PSSetSamplerState(ID3D11SamplerState* ss0, ID3D11SamplerState* ss1, ID3D11SamplerState* ss2 = NULL);
void OMSetDepthStencilState(ID3D11DepthStencilState* dss, uint8 sref);
void OMSetBlendState(ID3D11BlendState* bs, float bf);
void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL);
@ -190,6 +194,9 @@ public:
void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel);
void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix);
bool HasStencil() { return true; }
bool HasDepth32() { return true; }
ID3D11Device* operator->() {return m_dev;}
operator ID3D11Device*() {return m_dev;}
operator ID3D11DeviceContext*() {return m_ctx;}

View File

@ -50,6 +50,15 @@ GSDevice9::~GSDevice9()
if(m_state.ps_cb) _aligned_free(m_state.ps_cb);
}
static bool TestDepthFormat(CComPtr<IDirect3D9> &d3d, D3DFORMAT format)
{
if (FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, format)))
return false;
if (FAILED(d3d->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, format)))
return false;
return true;
}
bool GSDevice9::Create(GSWnd* wnd)
{
if(!__super::Create(wnd))
@ -57,8 +66,6 @@ bool GSDevice9::Create(GSWnd* wnd)
return false;
}
HRESULT hr;
// dd
// Unreferenced
@ -84,13 +91,14 @@ bool GSDevice9::Create(GSWnd* wnd)
if(!m_d3d) return false;
hr = m_d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8);
if(FAILED(hr)) return false;
hr = m_d3d->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_D24S8);
if(FAILED(hr)) return false;
if (TestDepthFormat(m_d3d, D3DFMT_D32F_LOCKABLE))
m_depth_format = D3DFMT_D32F_LOCKABLE;
else if (TestDepthFormat(m_d3d, D3DFMT_D32))
m_depth_format = D3DFMT_D32;
else if (TestDepthFormat(m_d3d, D3DFMT_D24S8))
m_depth_format = D3DFMT_D24S8;
else
return false;
memset(&m_d3dcaps, 0, sizeof(m_d3dcaps));
@ -138,7 +146,7 @@ bool GSDevice9::Create(GSWnd* wnd)
DWORD quality[2] = {0, 0};
if(SUCCEEDED(m_d3d->CheckDeviceMultiSampleType(m_d3dcaps.AdapterOrdinal, m_d3dcaps.DeviceType, D3DFMT_A8R8G8B8, TRUE, (D3DMULTISAMPLE_TYPE)i, &quality[0])) && quality[0] > 0
&& SUCCEEDED(m_d3d->CheckDeviceMultiSampleType(m_d3dcaps.AdapterOrdinal, m_d3dcaps.DeviceType, D3DFMT_D24S8, TRUE, (D3DMULTISAMPLE_TYPE)i, &quality[1])) && quality[1] > 0)
&& SUCCEEDED(m_d3d->CheckDeviceMultiSampleType(m_d3dcaps.AdapterOrdinal, m_d3dcaps.DeviceType, m_depth_format, TRUE, (D3DMULTISAMPLE_TYPE)i, &quality[1])) && quality[1] > 0)
{
m_msaa_desc.Count = i;
m_msaa_desc.Quality = std::min<DWORD>(quality[0] - 1, quality[1] - 1);
@ -556,7 +564,7 @@ GSTexture* GSDevice9::CreateRenderTarget(int w, int h, bool msaa, int format)
GSTexture* GSDevice9::CreateDepthStencil(int w, int h, bool msaa, int format)
{
return __super::CreateDepthStencil(w, h, msaa, format ? format : D3DFMT_D24S8);
return __super::CreateDepthStencil(w, h, msaa, format ? format : m_depth_format);
}
GSTexture* GSDevice9::CreateTexture(int w, int h, int format)
@ -683,9 +691,9 @@ void GSDevice9::StretchRect(GSTexture* st, const GSVector4& sr, GSTexture* dt, c
// ps
PSSetShader(ps, ps_cb, ps_cb_len);
PSSetSamplerState(linear ? &m_convert.ln : &m_convert.pt);
PSSetShaderResources(st, NULL);
PSSetShader(ps, ps_cb, ps_cb_len);
//
@ -886,24 +894,19 @@ void GSDevice9::VSSetShader(IDirect3DVertexShader9* vs, const float* vs_cb, int
void GSDevice9::PSSetShaderResources(GSTexture* sr0, GSTexture* sr1)
{
IDirect3DTexture9* srv0 = NULL;
IDirect3DTexture9* srv1 = NULL;
PSSetShaderResource(0, sr0);
PSSetShaderResource(1, sr1);
PSSetShaderResource(2, NULL);
}
if(sr0) srv0 = *(GSTexture9*)sr0;
if(sr1) srv1 = *(GSTexture9*)sr1;
void GSDevice9::PSSetShaderResource(int i, GSTexture* sr)
{
IDirect3DTexture9* srv = NULL;
if (sr) srv = *(GSTexture9*)sr;
if(m_state.ps_srvs[0] != srv0)
{
m_state.ps_srvs[0] = srv0;
m_dev->SetTexture(0, srv0);
}
if(m_state.ps_srvs[1] != srv1)
{
m_state.ps_srvs[1] = srv1;
m_dev->SetTexture(1, srv1);
if (m_state.ps_srvs[i] != srv) {
m_state.ps_srvs[i] = srv;
m_dev->SetTexture(i, srv);
}
}
@ -948,10 +951,12 @@ void GSDevice9::PSSetSamplerState(Direct3DSamplerState9* ss)
m_dev->SetSamplerState(0, D3DSAMP_ADDRESSV, ss->AddressV);
m_dev->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_dev->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
m_dev->SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
m_dev->SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
m_dev->SetSamplerState(3, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(3, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(4, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(4, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
m_dev->SetSamplerState(0, D3DSAMP_MINFILTER, ss->FilterMin[0]);
m_dev->SetSamplerState(0, D3DSAMP_MAGFILTER, ss->FilterMag[0]);
m_dev->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
@ -960,6 +965,8 @@ void GSDevice9::PSSetSamplerState(Direct3DSamplerState9* ss)
m_dev->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
m_dev->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_POINT);
m_dev->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
m_dev->SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_POINT);
m_dev->SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
}
}

View File

@ -83,6 +83,7 @@ class GSDevice9 : public GSDeviceDX
CComPtr<IDirect3DVertexBuffer9> m_vb;
CComPtr<IDirect3DVertexBuffer9> m_vb_old;
bool m_lost;
D3DFORMAT m_depth_format;
struct
{
@ -93,7 +94,7 @@ class GSDevice9 : public GSDeviceDX
IDirect3DVertexShader9* vs;
float* vs_cb;
int vs_cb_len;
IDirect3DTexture9* ps_srvs[2];
IDirect3DTexture9* ps_srvs[3];
IDirect3DPixelShader9* ps;
float* ps_cb;
int ps_cb_len;
@ -191,6 +192,7 @@ public:
void IASetPrimitiveTopology(D3DPRIMITIVETYPE topology);
void VSSetShader(IDirect3DVertexShader9* vs, const float* vs_cb, int vs_cb_len);
void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1);
void PSSetShaderResource(int i, GSTexture* sr);
void PSSetShader(IDirect3DPixelShader9* ps, const float* ps_cb, int ps_cb_len);
void PSSetSamplerState(Direct3DSamplerState9* ss);
void OMSetDepthStencilState(Direct3DDepthStencilState9* dss);
@ -208,4 +210,7 @@ public:
void SetupGS(GSSelector sel) {}
void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel);
void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix);
bool HasStencil() { return m_depth_format == D3DFMT_D24S8; }
bool HasDepth32() { return m_depth_format != D3DFMT_D24S8; }
};

View File

@ -75,12 +75,13 @@ public:
uint32 tme:1;
uint32 fst:1;
uint32 logz:1;
uint32 rtcopy:1;
};
uint32 key;
};
operator uint32() {return key & 0x1f;}
operator uint32() {return key & 0x3f;}
VSSelector() : key(0) {}
};
@ -171,12 +172,13 @@ public:
uint32 rt:1;
uint32 ltf:1;
uint32 colclip:2;
uint32 date:2;
};
uint32 key;
};
operator uint32() {return key & 0xffffff;}
operator uint32() {return key & 0x3ffffff;}
PSSelector() : key(0) {}
};
@ -284,4 +286,7 @@ public:
virtual void SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix) = 0;
virtual void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1 (&iaVertices)[4], bool datm)=0;
virtual bool HasStencil() = 0;
virtual bool HasDepth32() = 0;
};

View File

@ -66,30 +66,39 @@ public:
GSDrawingEnvironment& env = m_env;
GSDrawingContext* context = m_context;
const GSVector2i& rtsize = rt->GetSize();
const GSVector2& rtscale = rt->GetScale();
bool DATE = m_context->TEST.DATE && context->FRAME.PSM != PSM_PSMCT24;
GSTexture *rtcopy = NULL;
assert(m_dev != NULL);
GSDeviceDX& dev = (GSDeviceDX&)*m_dev;
//
if(m_context->TEST.DATE)
if(DATE)
{
const GSVector2i& size = rt->GetSize();
if (dev.HasStencil()) {
GSVector4 s = GSVector4(rtscale.x / rtsize.x, rtscale.y / rtsize.y);
GSVector4 o = GSVector4(-1.0f, 1.0f);
GSVector4 s = GSVector4(rt->GetScale().x / size.x, rt->GetScale().y / size.y);
GSVector4 o = GSVector4(-1.0f, 1.0f);
GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy());
GSVector4 dst = src * 2.0f + o.xxxx();
GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + o.xxyy()) * s.xyxy()).sat(o.zzyy());
GSVector4 dst = src * 2.0f + o.xxxx();
GSVertexPT1 vertices[] =
{
{GSVector4(dst.x, -dst.y, 0.5f, 1.0f), GSVector2(src.x, src.y)},
{GSVector4(dst.z, -dst.y, 0.5f, 1.0f), GSVector2(src.z, src.y)},
{GSVector4(dst.x, -dst.w, 0.5f, 1.0f), GSVector2(src.x, src.w)},
{GSVector4(dst.z, -dst.w, 0.5f, 1.0f), GSVector2(src.z, src.w)},
};
GSVertexPT1 vertices[] =
{
{GSVector4(dst.x, -dst.y, 0.5f, 1.0f), GSVector2(src.x, src.y)},
{GSVector4(dst.z, -dst.y, 0.5f, 1.0f), GSVector2(src.z, src.y)},
{GSVector4(dst.x, -dst.w, 0.5f, 1.0f), GSVector2(src.x, src.w)},
{GSVector4(dst.z, -dst.w, 0.5f, 1.0f), GSVector2(src.z, src.w)},
};
dev.SetupDATE(rt, ds, vertices, m_context->TEST.DATM );
dev.SetupDATE(rt, ds, vertices, m_context->TEST.DATM);
} else {
rtcopy = m_dev->CreateRenderTarget(rtsize.x, rtsize.y, false, rt->GetFormat());
// I'll use VertexTrace when I consider it more trustworthy
m_dev->CopyRect(rt, rtcopy, GSVector4i(rtsize).zwxy());
}
}
//
@ -110,11 +119,6 @@ public:
om_dssel.ztst = ZTST_ALWAYS;
}
if(context->FRAME.PSM != PSM_PSMCT24)
{
om_dssel.date = context->TEST.DATE;
}
if(m_fba)
{
om_dssel.fba = context->FBA.FBA;
@ -156,7 +160,8 @@ public:
vs_sel.tme = PRIM->TME;
vs_sel.fst = PRIM->FST;
vs_sel.logz = m_logz ? 1 : 0;
vs_sel.logz = dev.HasDepth32() ? 0 : m_logz ? 1 : 0;
vs_sel.rtcopy = !!rtcopy;
// The real GS appears to do no masking based on the Z buffer format and writing larger Z values
// than the buffer supports seems to be an error condition on the real GS, causing it to crash.
@ -193,12 +198,12 @@ public:
GSDeviceDX::VSConstantBuffer vs_cb;
float sx = 2.0f * rt->GetScale().x / (rt->GetWidth() << 4);
float sy = 2.0f * rt->GetScale().y / (rt->GetHeight() << 4);
float sx = 2.0f * rtscale.x / (rtsize.x << 4);
float sy = 2.0f * rtscale.y / (rtsize.y << 4);
float ox = (float)(int)context->XYOFFSET.OFX;
float oy = (float)(int)context->XYOFFSET.OFY;
float ox2 = 2.0f * m_pixelcenter.x / rt->GetWidth();
float oy2 = 2.0f * m_pixelcenter.y / rt->GetHeight();
float ox2 = 2.0f * m_pixelcenter.x / rtsize.x;
float oy2 = 2.0f * m_pixelcenter.y / rtsize.y;
//This hack subtracts around half a pixel from OFX and OFY. (Cannot do this directly,
//because DX10 and DX9 have a different pixel center.)
@ -231,6 +236,14 @@ public:
GSDeviceDX::PSSamplerSelector ps_ssel;
GSDeviceDX::PSConstantBuffer ps_cb;
if(DATE)
{
if (dev.HasStencil())
om_dssel.date = 1;
else
ps_sel.date = 1 + context->TEST.DATM;
}
if (env.COLCLAMP.CLAMP == 0) {
ps_sel.colclip = 1;
}
@ -316,10 +329,12 @@ public:
// rs
GSVector4i scissor = GSVector4i(GSVector4(rt->GetScale()).xyxy() * context->scissor.in).rintersect(GSVector4i(rt->GetSize()).zwxy());
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * context->scissor.in).rintersect(GSVector4i(rtsize).zwxy());
dev.OMSetRenderTargets(rt, ds, &scissor);
dev.PSSetShaderResources(tex ? tex->m_texture : NULL, tex ? tex->m_palette : NULL);
dev.PSSetShaderResource(0, tex ? tex->m_texture : NULL);
dev.PSSetShaderResource(1, tex ? tex->m_palette : NULL);
dev.PSSetShaderResource(2, rtcopy);
uint8 afix = context->ALPHA.FIX;
@ -418,6 +433,8 @@ public:
dev.EndScene();
m_dev->Recycle(rtcopy);
if(om_dssel.fba) UpdateFBA(rt);
}
};

View File

@ -22,6 +22,10 @@
#include "stdafx.h"
#include "GSState.h"
//#define DISABLE_BITMASKING
//#define DISABLE_COLCLAMP
//#define DISABLE_DATE
GSState::GSState()
: m_mt(false)
, m_irq(NULL)
@ -805,6 +809,9 @@ template<int i> void GSState::GIFRegHandlerTEST(GIFReg* r)
}
m_env.CTXT[i].TEST = (GSVector4i)r->TEST;
#ifdef DISABLE_DATE
m_env.CTXT[i].TEST.DATE = 0;
#endif
}
void GSState::GIFRegHandlerPABE(GIFReg* r)

View File

@ -66,6 +66,10 @@ bool GSDevice11::CreateTextureFX()
if(FAILED(hr)) return false;
hr = m_dev->CreateSamplerState(&sd, &m_rt_ss);
if(FAILED(hr)) return false;
// create layout
VSSelector sel;
@ -90,17 +94,19 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
if(i == m_vs.end())
{
string str[3];
string str[4];
str[0] = format("%d", sel.bppz);
str[1] = format("%d", sel.tme);
str[2] = format("%d", sel.fst);
str[3] = format("%d", sel.rtcopy);
D3D11_SHADER_MACRO macro[] =
{
{"VS_BPPZ", str[0].c_str()},
{"VS_TME", str[1].c_str()},
{"VS_FST", str[2].c_str()},
{"VS_RTCOPY", str[3].c_str()},
{NULL, NULL},
};
@ -175,7 +181,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
if(i == m_ps.end())
{
string str[14];
string str[15];
str[0] = format("%d", sel.fst);
str[1] = format("%d", sel.wms);
@ -191,6 +197,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
str[11] = format("%d", sel.aout);
str[12] = format("%d", sel.ltf);
str[13] = format("%d", sel.colclip);
str[14] = format("%d", sel.date);
D3D11_SHADER_MACRO macro[] =
{
@ -208,6 +215,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
{"PS_AOUT", str[11].c_str()},
{"PS_LTF", str[12].c_str()},
{"PS_COLCLIP", str[13].c_str()},
{"PS_DATE", str[14].c_str()},
{NULL, NULL},
};
@ -227,8 +235,6 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
ctx->UpdateSubresource(m_ps_cb, 0, NULL, cb, 0, 0);
}
PSSetShader(i->second, m_ps_cb);
ID3D11SamplerState* ss0 = NULL;
ID3D11SamplerState* ss1 = NULL;
@ -272,7 +278,9 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
}
}
PSSetSamplerState(ss0, ss1);
PSSetSamplerState(ss0, ss1, sel.date ? m_rt_ss : NULL);
PSSetShader(i->second, m_ps_cb);
}
void GSDevice11::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, uint8 afix)

View File

@ -73,12 +73,13 @@ void GSDevice9::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
if(i == m_vs.end())
{
string str[4];
string str[5];
str[0] = format("%d", sel.bppz);
str[1] = format("%d", sel.tme);
str[2] = format("%d", sel.fst);
str[3] = format("%d", sel.logz);
str[4] = format("%d", sel.rtcopy);
D3DXMACRO macro[] =
{
@ -86,6 +87,7 @@ void GSDevice9::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
{"VS_TME", str[1].c_str()},
{"VS_FST", str[2].c_str()},
{"VS_LOGZ", str[3].c_str()},
{"VS_RTCOPY", str[4].c_str()},
{NULL, NULL},
};
@ -121,7 +123,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
{
if(GSTexture* t = CreateMskFix(size.z, cb->MskFix.x, cb->MskFix.z))
{
m_dev->SetTexture(2, *(GSTexture9*)t);
m_dev->SetTexture(3, *(GSTexture9*)t);
}
}
@ -129,7 +131,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
{
if(GSTexture* t = CreateMskFix(size.w, cb->MskFix.y, cb->MskFix.w))
{
m_dev->SetTexture(3, *(GSTexture9*)t);
m_dev->SetTexture(4, *(GSTexture9*)t);
}
}
}
@ -138,7 +140,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
if(i == m_ps.end())
{
string str[13];
string str[14];
str[0] = format("%d", sel.fst);
str[1] = format("%d", sel.wms);
@ -153,6 +155,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
str[10] = format("%d", sel.rt);
str[11] = format("%d", sel.ltf);
str[12] = format("%d", sel.colclip);
str[13] = format("%d", sel.date);
D3DXMACRO macro[] =
{
@ -169,6 +172,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel
{"PS_RT", str[10].c_str()},
{"PS_LTF", str[11].c_str()},
{"PS_COLCLIP", str[12].c_str()},
{"PS_DATE", str[13].c_str()},
{NULL, NULL},
};

View File

@ -35,6 +35,7 @@
#define PS_AOUT 0
#define PS_LTF 1
#define PS_COLCLIP 0
#define PS_DATE 0
#endif
struct VS_INPUT
@ -51,6 +52,9 @@ struct VS_OUTPUT
{
float4 p : SV_Position;
float4 t : TEXCOORD0;
#if VS_RTCOPY
float4 tp : TEXCOORD1;
#endif
float4 c : COLOR0;
};
@ -58,6 +62,9 @@ struct PS_INPUT
{
float4 p : SV_Position;
float4 t : TEXCOORD0;
#if PS_DATE > 0
float4 tp : TEXCOORD1;
#endif
float4 c : COLOR0;
};
@ -69,8 +76,10 @@ struct PS_OUTPUT
Texture2D<float4> Texture : register(t0);
Texture2D<float4> Palette : register(t1);
Texture2D<float4> RTCopy : register(t2);
SamplerState TextureSampler : register(s0);
SamplerState PaletteSampler : register(s1);
SamplerState RTCopySampler : register(s2);
cbuffer cb0
{
@ -101,6 +110,11 @@ float4 sample_p(float u)
return Palette.Sample(PaletteSampler, u);
}
float4 sample_rt(float2 uv)
{
return RTCopy.Sample(RTCopySampler, uv);
}
#elif SHADER_MODEL <= 0x300
#ifndef VS_BPPZ
@ -124,6 +138,7 @@ float4 sample_p(float u)
#define PS_RT 0
#define PS_LTF 0
#define PS_COLCLIP 0
#define PS_DATE 0
#endif
struct VS_INPUT
@ -138,19 +153,26 @@ struct VS_OUTPUT
{
float4 p : POSITION;
float4 t : TEXCOORD0;
#if VS_RTCOPY
float4 tp : TEXCOORD1;
#endif
float4 c : COLOR0;
};
struct PS_INPUT
{
float4 t : TEXCOORD0;
#if PS_DATE > 0
float4 tp : TEXCOORD1;
#endif
float4 c : COLOR0;
};
sampler Texture : register(s0);
sampler Palette : register(s1);
sampler1D UMSKFIX : register(s2);
sampler1D VMSKFIX : register(s3);
sampler RTCopy : register(s2);
sampler1D UMSKFIX : register(s3);
sampler1D VMSKFIX : register(s4);
float4 vs_params[3];
@ -178,6 +200,11 @@ float4 sample_p(float u)
return tex2D(Palette, u);
}
float4 sample_rt(float2 uv)
{
return tex2D(RTCopy, uv);
}
#endif
float4 wrapuv(float4 uv)
@ -458,6 +485,23 @@ float4 tfx(float4 t, float4 c)
return saturate(c);
}
void datst(PS_INPUT input)
{
#if PS_DATE > 0
float alpha = sample_rt(input.tp.xy).a;
#if SHADER_MODEL >= 0x400
float alpha0x80 = 128. / 255;
#else
float alpha0x80 = 1;
#endif
if (PS_DATE == 1 && alpha >= alpha0x80)
discard;
else if (PS_DATE == 2 && alpha < alpha0x80)
discard;
#endif
}
void atst(float4 c)
{
float a = trunc(c.a * 255);
@ -500,10 +544,12 @@ float4 fog(float4 c, float f)
float4 ps_color(PS_INPUT input)
{
datst(input);
float4 t = sample(input.t.xy, input.t.w);
float4 c = tfx(t, input.c);
atst(c);
c = fog(c, input.t.z);
@ -548,7 +594,10 @@ VS_OUTPUT vs_main(VS_INPUT input)
float4 p = float4(input.p, input.z, 0) - float4(0.05f, 0.05f, 0, 0);
output.p = p * VertexScale - VertexOffset;
#if VS_RTCOPY
output.tp = (p * VertexScale - VertexOffset) * float4(0.5, -0.5, 0, 0) + 0.5;
#endif
if(VS_TME)
{
if(VS_FST)
@ -687,6 +736,9 @@ VS_OUTPUT vs_main(VS_INPUT input)
float4 p = input.p - float4(0.05f, 0.05f, 0, 0);
output.p = p * VertexScale - VertexOffset;
#if VS_RTCOPY
output.tp = (p * VertexScale - VertexOffset) * float4(0.5, -0.5, 0, 0) + 0.5;
#endif
if(VS_LOGZ)
{