GSdx: FXAA 3.10, page up key activates it

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4828 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gabest11 2011-07-25 11:16:01 +00:00
parent 0b09b84526
commit bfbf403bf4
21 changed files with 2169 additions and 35 deletions

View File

@ -36,6 +36,7 @@ GPURenderer::GPURenderer(GSDevice* dev)
m_dither = theApp.GetConfig("dithering", 1);
m_aspectratio = theApp.GetConfig("AspectRatio", 1);
m_vsync = !!theApp.GetConfig("vsync", 0);
m_fxaa = !!theApp.GetConfig("fxaa", 0);
m_scale = m_mem.GetScale();
#ifdef _WINDOWS
@ -116,6 +117,11 @@ bool GPURenderer::Merge()
m_dev->Merge(st, sr, dr, s, 1, 1, GSVector4(0, 0, 0, 1));
if(m_fxaa)
{
m_dev->FXAA();
}
return true;
}
@ -235,6 +241,9 @@ LRESULT GPURenderer::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
case VK_NEXT:
m_aspectratio = (m_aspectratio + 1) % 3;
return 0;
case VK_PRIOR:
m_fxaa = !m_fxaa;
return 0;
}
}

View File

@ -35,6 +35,7 @@ protected:
int m_dither;
int m_aspectratio;
bool m_vsync;
bool m_fxaa;
GSVector2i m_scale;
virtual void ResetDevice() {}

View File

@ -64,7 +64,7 @@ GSSource : public CBaseFilter, private CCritSec, public IGSSource
vector<CMediaType> m_mts;
public:
GSSourceOutputPin(const GSVector2i& size, REFERENCE_TIME atpf, CBaseFilter* pFilter, CCritSec* pLock, HRESULT& hr, int m_colorspace)
GSSourceOutputPin(const GSVector2i& size, REFERENCE_TIME atpf, CBaseFilter* pFilter, CCritSec* pLock, HRESULT& hr, int colorspace)
: CBaseOutputPin("GSSourceOutputPin", pFilter, pLock, &hr, L"Output")
, m_size(size)
{
@ -79,24 +79,8 @@ GSSource : public CBaseFilter, private CCritSec, public IGSSource
vih.bmiHeader.biWidth = m_size.x;
vih.bmiHeader.biHeight = m_size.y;
// RGB32 (priority)
if ( m_colorspace == 1 )
{
mt.subtype = MEDIASUBTYPE_RGB32;
mt.lSampleSize = m_size.x * m_size.y * 4;
vih.bmiHeader.biCompression = BI_RGB;
vih.bmiHeader.biPlanes = 1;
vih.bmiHeader.biBitCount = 32;
vih.bmiHeader.biSizeImage = m_size.x * m_size.y * 4;
mt.SetFormat((uint8*)&vih, sizeof(vih));
m_mts.push_back(mt);
}
// YUY2
else
{
mt.subtype = MEDIASUBTYPE_YUY2;
mt.lSampleSize = m_size.x * m_size.y * 2;
@ -107,7 +91,6 @@ GSSource : public CBaseFilter, private CCritSec, public IGSSource
mt.SetFormat((uint8*)&vih, sizeof(vih));
m_mts.push_back(mt);
}
// RGB32
@ -120,7 +103,8 @@ GSSource : public CBaseFilter, private CCritSec, public IGSSource
vih.bmiHeader.biSizeImage = m_size.x * m_size.y * 4;
mt.SetFormat((uint8*)&vih, sizeof(vih));
m_mts.push_back(mt);
if(colorspace == 1) m_mts.insert(m_mts.begin(), mt);
else m_mts.push_back(mt);
}
HRESULT GSSourceOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
@ -189,14 +173,14 @@ GSSource : public CBaseFilter, private CCritSec, public IGSSource
public:
GSSource(int w, int h, int fps, IUnknown* pUnk, HRESULT& hr, int m_colorspace)
GSSource(int w, int h, int fps, IUnknown* pUnk, HRESULT& hr, int colorspace)
: CBaseFilter(NAME("GSSource"), pUnk, this, __uuidof(this), &hr)
, m_output(NULL)
, m_size(w, h)
, m_atpf(10000000i64 / fps)
, m_now(0)
{
m_output = new GSSourceOutputPin(m_size, m_atpf, this, this, hr, m_colorspace);
m_output = new GSSourceOutputPin(m_size, m_atpf, this, this, hr, colorspace);
// FIXME
if(fps == 60) m_atpf = 166834; // = 10000000i64 / 59.94
@ -420,8 +404,6 @@ bool GSCapture::BeginCapture(int fps)
m_size.x = (dlg.m_width + 7) & ~7;
m_size.y = (dlg.m_height + 7) & ~7;
m_colorspace = dlg.m_colorspace;
wstring fn(dlg.m_filename.begin(), dlg.m_filename.end());
//
@ -439,7 +421,7 @@ bool GSCapture::BeginCapture(int fps)
return false;
}
m_src = new GSSource(m_size.x, m_size.y, fps, NULL, hr, m_colorspace);
m_src = new GSSource(m_size.x, m_size.y, fps, NULL, hr, dlg.m_colorspace);
if (dlg.m_enc==0)
{

View File

@ -33,8 +33,6 @@ class GSCapture : protected GSCritSec
bool m_capturing;
GSVector2i m_size;
int m_colorspace;
#ifdef _WINDOWS
CComPtr<IGraphBuilder> m_graph;

View File

@ -31,6 +31,7 @@ GSDevice::GSDevice()
, m_merge(NULL)
, m_weavebob(NULL)
, m_blend(NULL)
, m_fxaa(NULL)
, m_1x1(NULL)
, m_frame(0)
{
@ -45,6 +46,7 @@ GSDevice::~GSDevice()
delete m_merge;
delete m_weavebob;
delete m_blend;
delete m_fxaa;
delete m_1x1;
}
@ -65,12 +67,14 @@ bool GSDevice::Reset(int w, int h)
delete m_merge;
delete m_weavebob;
delete m_blend;
delete m_fxaa;
delete m_1x1;
m_backbuffer = NULL;
m_merge = NULL;
m_weavebob = NULL;
m_blend = NULL;
m_fxaa = NULL;
m_1x1 = NULL;
m_current = NULL; // current is special, points to other textures, no need to delete
@ -198,7 +202,7 @@ GSTexture* GSDevice::GetCurrent()
void GSDevice::Merge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, const GSVector2i& fs, bool slbg, bool mmod, const GSVector4& c)
{
if(!m_merge || !(m_merge->GetSize() == fs))
if(m_merge == NULL || m_merge->GetSize() != fs)
{
Recycle(m_merge);
@ -243,7 +247,7 @@ void GSDevice::Merge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, const GSVec
void GSDevice::Interlace(const GSVector2i& ds, int field, int mode, float yoffset)
{
if(!m_weavebob || !(m_weavebob->GetSize() == ds))
if(m_weavebob == NULL || m_weavebob->GetSize() != ds)
{
delete m_weavebob;
@ -260,7 +264,7 @@ void GSDevice::Interlace(const GSVector2i& ds, int field, int mode, float yoffse
{
// blend
if(!m_blend || !(m_blend->GetSize() == ds))
if(m_blend == NULL || m_blend->GetSize() != ds)
{
delete m_blend;
@ -288,6 +292,28 @@ void GSDevice::Interlace(const GSVector2i& ds, int field, int mode, float yoffse
}
}
void GSDevice::FXAA()
{
GSVector2i s = m_current->GetSize();
if(m_fxaa == NULL || m_fxaa->GetSize() != s)
{
delete m_fxaa;
m_fxaa = CreateRenderTarget(s.x, s.y, false);
}
if(m_fxaa != NULL)
{
GSVector4 sr(0, 0, 1, 1);
GSVector4 dr(0, 0, s.x, s.y);
StretchRect(m_current, sr, m_fxaa, dr, 7, false);
DoFXAA(m_fxaa, m_current);
}
}
bool GSDevice::ResizeTexture(GSTexture** t, int w, int h)
{
if(t == NULL) {ASSERT(0); return false;}

View File

@ -46,6 +46,15 @@ public:
InterlaceConstantBuffer() {memset(this, 0, sizeof(*this));}
};
class FXAAConstantBuffer
{
public:
GSVector4 rcpFrame;
GSVector4 rcpFrameOpt;
FXAAConstantBuffer() {memset(this, 0, sizeof(*this));}
};
#pragma pack(pop)
class GSDevice : public GSAlignedClass<32>
@ -60,6 +69,7 @@ protected:
GSTexture* m_merge;
GSTexture* m_weavebob;
GSTexture* m_blend;
GSTexture* m_fxaa;
GSTexture* m_1x1;
GSTexture* m_current;
struct {size_t stride, start, count, limit;} m_vertices;
@ -70,6 +80,7 @@ protected:
virtual void DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVector4* dr, bool slbg, bool mmod, const GSVector4& c) = 0;
virtual void DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset) = 0;
virtual void DoFXAA(GSTexture* st, GSTexture* dt) {}
public:
GSDevice();
@ -119,6 +130,7 @@ public:
void Merge(GSTexture* st[2], GSVector4* sr, GSVector4* dr, const GSVector2i& fs, bool slbg, bool mmod, const GSVector4& c);
void Interlace(const GSVector2i& ds, int field, int mode, float yoffset);
void FXAA();
bool ResizeTexture(GSTexture** t, int w, int h);

View File

@ -203,6 +203,18 @@ bool GSDevice11::Create(GSWnd* wnd)
hr = CompileShader(IDR_INTERLACE_FX, format("ps_main%d", i), NULL, &m_interlace.ps[i]);
}
// fxaa
memset(&bd, 0, sizeof(bd));
bd.ByteWidth = sizeof(FXAAConstantBuffer);
bd.Usage = D3D11_USAGE_DEFAULT;
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
hr = m_dev->CreateBuffer(&bd, NULL, &m_fxaa.cb);
hr = CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
//
memset(&rd, 0, sizeof(rd));
@ -611,6 +623,26 @@ void GSDevice11::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool line
StretchRect(st, sr, dt, dr, m_interlace.ps[shader], m_interlace.cb, linear);
}
void GSDevice11::DoFXAA(GSTexture* st, GSTexture* dt)
{
GSVector2i s = dt->GetSize();
GSVector4 sr(0, 0, 1, 1);
GSVector4 dr(0, 0, s.x, s.y);
FXAAConstantBuffer cb;
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, 0, NULL, &cb, 0, 0);
StretchRect(st, sr, dt, dr, m_fxaa.ps, m_fxaa.cb, true);
//st->Save("c:\\temp1\\1.bmp");
//dt->Save("c:\\temp1\\2.bmp");
}
void GSDevice11::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm)
{
const GSVector2i& size = rt->GetSize();

View File

@ -36,6 +36,7 @@ class GSDevice11 : public GSDeviceDX
void DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVector4* dr, bool slbg, bool mmod, const GSVector4& c);
void DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset = 0);
void DoFXAA(GSTexture* st, GSTexture* dt);
//
@ -77,7 +78,7 @@ public: // TODO
{
CComPtr<ID3D11InputLayout> il;
CComPtr<ID3D11VertexShader> vs;
CComPtr<ID3D11PixelShader> ps[7];
CComPtr<ID3D11PixelShader> ps[8];
CComPtr<ID3D11SamplerState> ln;
CComPtr<ID3D11SamplerState> pt;
CComPtr<ID3D11DepthStencilState> dss;
@ -97,6 +98,12 @@ public: // TODO
CComPtr<ID3D11Buffer> cb;
} m_interlace;
struct
{
CComPtr<ID3D11PixelShader> ps;
CComPtr<ID3D11Buffer> cb;
} m_fxaa;
struct
{
CComPtr<ID3D11DepthStencilState> dss;

View File

@ -282,6 +282,10 @@ bool GSDevice9::Create(GSWnd* wnd)
CompileShader(IDR_INTERLACE_FX, format("ps_main%d", i), NULL, &m_interlace.ps[i]);
}
// fxaa
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
// create shader layout
VSSelector sel;
@ -800,6 +804,21 @@ void GSDevice9::DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linea
StretchRect(st, sr, dt, dr, m_interlace.ps[shader], (const float*)&cb, 1, linear);
}
void GSDevice9::DoFXAA(GSTexture* st, GSTexture* dt)
{
GSVector2i s = dt->GetSize();
GSVector4 sr(0, 0, 1, 1);
GSVector4 dr(0, 0, s.x, s.y);
FXAAConstantBuffer cb;
cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f);
cb.rcpFrameOpt = GSVector4::zero();
StretchRect(st, sr, dt, dr, m_fxaa.ps, (const float*)&cb, 2, true);
}
void GSDevice9::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm)
{
const GSVector2i& size = rt->GetSize();

View File

@ -71,6 +71,7 @@ class GSDevice9 : public GSDeviceDX
void DoMerge(GSTexture* st[2], GSVector4* sr, GSTexture* dt, GSVector4* dr, bool slbg, bool mmod, const GSVector4& c);
void DoInterlace(GSTexture* st, GSTexture* dt, int shader, bool linear, float yoffset = 0);
void DoFXAA(GSTexture* st, GSTexture* dt);
//
@ -112,7 +113,7 @@ public: // TODO
{
CComPtr<IDirect3DVertexDeclaration9> il;
CComPtr<IDirect3DVertexShader9> vs;
CComPtr<IDirect3DPixelShader9> ps[7];
CComPtr<IDirect3DPixelShader9> ps[8];
Direct3DSamplerState9 ln;
Direct3DSamplerState9 pt;
Direct3DDepthStencilState9 dss;
@ -130,6 +131,11 @@ public: // TODO
CComPtr<IDirect3DPixelShader9> ps[4];
} m_interlace;
struct
{
CComPtr<IDirect3DPixelShader9> ps;
} m_fxaa;
struct
{
Direct3DDepthStencilState9 dss;

View File

@ -36,6 +36,7 @@ GSRenderer::GSRenderer()
m_vsync = !!theApp.GetConfig("vsync", 0);
m_aa1 = !!theApp.GetConfig("aa1", 0);
m_mipmap = !!theApp.GetConfig("mipmap", 1);
m_fxaa = !!theApp.GetConfig("fxaa", 0);
s_n = 0;
s_dump = !!theApp.GetConfig("dump", 0);
@ -262,6 +263,11 @@ bool GSRenderer::Merge(int field)
m_dev->Interlace(ds, field ^ field2, mode, tex[1] ? tex[1]->GetScale().y : tex[0]->GetScale().y);
}
if(m_fxaa)
{
m_dev->FXAA();
}
}
return true;
@ -522,6 +528,10 @@ void GSRenderer::KeyEvent(GSKeyEventData* e)
m_mipmap = !m_mipmap;
printf("GSdx: (Software) mipmapping is now %s.\n", m_mipmap ? "enabled" : "disabled");
return;
case VK_PRIOR:
m_fxaa = !m_fxaa;
printf("GSdx: fxaa is now %s.\n", m_fxaa ? "enabled" : "disabled");
return;
}
#else

View File

@ -45,6 +45,7 @@ protected:
bool m_aa1;
bool m_mipmap;
bool m_framelimit;
bool m_fxaa;
virtual GSTexture* GetOutput(int i) = 0;

View File

@ -145,7 +145,7 @@ public:
else
{
//Breath of Fire Dragon Quarter triggers this in battles. Graphics are fine though.
ASSERT(0);
//ASSERT(0);
}
}
}

View File

@ -354,6 +354,20 @@ bool GSRendererSW::GetScanlineGlobalData(GSScanlineGlobalData& gd)
if(t == NULL) {ASSERT(0); return false;}
if(s_dump)// && m_context->TEX1.MXL > 0 && m_context->TEX1.MMIN >= 2 && m_context->TEX1.MMIN <= 5 && m_vt.m_lod.x > 0)
{
uint64 frame = m_perfmon.GetFrame();
string s;
if(s_save && s_n >= s_saven && PRIM->TME)
{
s = format("c:\\temp1\\_%05d_f%lld_tex32_%05x_%d.bmp", s_n, frame, (int)m_context->TEX0.TBP0, (int)m_context->TEX0.PSM);
t->Save(s);
}
}
gd.tex[0] = t->m_buff;
gd.sel.tw = t->m_tw - 3;

View File

@ -43,6 +43,7 @@ BEGIN
"#include ""res/convert.fx""\r\n"
"#include ""res/interlace.fx""\r\n"
"#include ""res/merge.fx""\r\0"
"#include ""res/fxaa.fx""\r\0"
END
#endif // APSTUDIO_INVOKED
@ -57,6 +58,7 @@ IDR_CONVERT_FX RCDATA "res\\convert.fx"
IDR_TFX_FX RCDATA "res\\tfx.fx"
IDR_MERGE_FX RCDATA "res\\merge.fx"
IDR_INTERLACE_FX RCDATA "res\\interlace.fx"
IDR_FXAA_FX RCDATA "res\\fxaa.fx"
/////////////////////////////////////////////////////////////////////////////
//
@ -310,6 +312,7 @@ END
#include "res/convert.fx"
#include "res/interlace.fx"
#include "res/merge.fx"
#include "res/fxaa.fx"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -1727,6 +1727,7 @@
</ItemGroup>
<ItemGroup>
<None Include="GSdx.def" />
<None Include="res\fxaa.fx" />
<None Include="res\logo10.bmp" />
<None Include="res\logo9.bmp" />
<None Include="res\convert.fx" />

View File

@ -671,6 +671,9 @@
<Filter>Baseclasses</Filter>
</None>
<None Include="GSdx.def" />
<None Include="res\fxaa.fx">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="GSdx.rc">

View File

@ -89,6 +89,19 @@ PS_OUTPUT ps_main0(PS_INPUT input)
return output;
}
PS_OUTPUT ps_main7(PS_INPUT input)
{
PS_OUTPUT output;
float4 c = sample_c(input.t);
c.a = dot(c.rgb, float3(0.299, 0.587, 0.114));
output.c = c;
return output;
}
float4 ps_crt(PS_INPUT input, int i)
{
float4 mask[4] =

1995
plugins/GSdx/res/fxaa.fx Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
#if SHADER_MODEL >= 0x400
Texture2D Texture;
@ -82,4 +83,5 @@ float4 ps_main3(float2 tex : TEXCOORD0) : COLOR
}
#endif
#endif

View File

@ -79,14 +79,14 @@
#define IDR_TFX_FX 10001
#define IDR_MERGE_FX 10002
#define IDR_INTERLACE_FX 10003
#define IDD_COINFIG2 10004
#define IDD_CONFIG2 10004
#define IDR_FXAA_FX 10005
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 10005
#define _APS_NEXT_RESOURCE_VALUE 10006
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 2050
#define _APS_NEXT_SYMED_VALUE 5000