From 94cad4a61afd34a8fa7e7ef57ce98f7a5bedd144 Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Tue, 12 Feb 2013 10:57:48 +0000 Subject: [PATCH] GSdx: New hack from KrossX lets users configure their own texture coordinate offset via hacks dialog. This can be used to fine tune correction of upscale glitches versus the problems that come with it. I guess this is able to correct nearly all ghosting and bad text issues games can have! Thanks for this nice patch, KrossX :) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5556 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GSDeviceDX.h | 3 +++ plugins/GSdx/GSRendererDX.cpp | 15 ++++++++++----- plugins/GSdx/GSRendererDX.h | 4 +++- plugins/GSdx/GSRendererDX11.cpp | 21 ++++++++++----------- plugins/GSdx/GSRendererDX9.cpp | 16 +++++++--------- plugins/GSdx/GSSettingsDlg.cpp | 30 ++++++++++++++++++++++++++++-- plugins/GSdx/GSTextureFX11.cpp | 8 +++++--- plugins/GSdx/GSTextureFX9.cpp | 8 +++++--- plugins/GSdx/GSdx.rc | 26 ++++++++++++++++---------- plugins/GSdx/res/tfx.fx | 13 +++++++++---- plugins/GSdx/resource.h | 10 ++++++++-- 11 files changed, 104 insertions(+), 50 deletions(-) diff --git a/plugins/GSdx/GSDeviceDX.h b/plugins/GSdx/GSDeviceDX.h index 76f2911f8a..e49a4d2e31 100644 --- a/plugins/GSdx/GSDeviceDX.h +++ b/plugins/GSdx/GSDeviceDX.h @@ -96,6 +96,8 @@ public: GSVector4 MinF_TA; GSVector4i MskFix; + GSVector4 TC_OffsetHack; + struct PSConstantBuffer() { FogColor_AREF = GSVector4::zero(); @@ -175,6 +177,7 @@ public: uint32 colclip:2; uint32 date:2; uint32 spritehack:1; + uint32 tcoffsethack:1; uint32 point_sampler:1; }; diff --git a/plugins/GSdx/GSRendererDX.cpp b/plugins/GSdx/GSRendererDX.cpp index 1349e76c41..36713b6ee6 100644 --- a/plugins/GSdx/GSRendererDX.cpp +++ b/plugins/GSdx/GSRendererDX.cpp @@ -31,8 +31,12 @@ GSRendererDX::GSRendererDX(GSTextureCache* tc, const GSVector2& pixelcenter) m_fba = !!theApp.GetConfig("fba", 1); UserHacks_AlphaHack = !!theApp.GetConfig("UserHacks_AlphaHack", 0) && !!theApp.GetConfig("UserHacks", 0); - UserHacks_WildHack = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_WildHack", 0) : 0; + UserHacks_WildHack = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_WildHack", 0) : 0; UserHacks_AlphaStencil = !!theApp.GetConfig("UserHacks_AlphaStencil", 0) && !!theApp.GetConfig("UserHacks", 0); + + UserHacks_TCOffset = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_TCOffset", 0) : 0; + UserHacks_TCO_x = (UserHacks_TCOffset & 0xFFFF) / -1000.0f; + UserHacks_TCO_y = ((UserHacks_TCOffset >> 16) & 0xFFFF) / -1000.0f; } GSRendererDX::~GSRendererDX() @@ -287,10 +291,7 @@ void GSRendererDX::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sourc ps_sel.wms = context->CLAMP.WMS; ps_sel.wmt = context->CLAMP.WMT; - if (tex->m_palette) - ps_sel.fmt = cpsm.fmt | 4; - else - ps_sel.fmt = cpsm.fmt; + ps_sel.fmt = tex->m_palette? cpsm.fmt | 4 : cpsm.fmt; ps_sel.aem = env.TEXA.AEM; ps_sel.tfx = context->TEX0.TFX; ps_sel.tcc = context->TEX0.TCC; @@ -319,6 +320,10 @@ void GSRendererDX::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sourc ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw(); ps_cb.MskFix = GSVector4i(context->CLAMP.MINU, context->CLAMP.MINV, context->CLAMP.MAXU, context->CLAMP.MAXV); + // TC Offset Hack + ps_sel.tcoffsethack = !!UserHacks_TCOffset; + ps_cb.TC_OffsetHack = GSVector4(UserHacks_TCO_x, UserHacks_TCO_y).xyxy() / WH.xyxy(); + GSVector4 clamp(ps_cb.MskFix); GSVector4 ta(env.TEXA & GSVector4i::x000000ff()); diff --git a/plugins/GSdx/GSRendererDX.h b/plugins/GSdx/GSRendererDX.h index cd1587c806..5325433ee4 100644 --- a/plugins/GSdx/GSRendererDX.h +++ b/plugins/GSdx/GSRendererDX.h @@ -37,7 +37,9 @@ protected: virtual void SetupIA() = 0; virtual void UpdateFBA(GSTexture* rt) {} - int UserHacks_WildHack; + unsigned int UserHacks_WildHack; + unsigned int UserHacks_TCOffset; + float UserHacks_TCO_x, UserHacks_TCO_y; public: GSRendererDX(GSTextureCache* tc, const GSVector2& pixelcenter = GSVector2(0, 0)); diff --git a/plugins/GSdx/GSRendererDX11.cpp b/plugins/GSdx/GSRendererDX11.cpp index 380956ac89..cd44665eb2 100644 --- a/plugins/GSdx/GSRendererDX11.cpp +++ b/plugins/GSdx/GSRendererDX11.cpp @@ -45,17 +45,16 @@ void GSRendererDX11::SetupIA() if(dev->IAMapVertexBuffer(&ptr, sizeof(GSVertex), m_vertex.next)) { - GSVector4i::storent(ptr, m_vertex.buff, sizeof(GSVertex) * m_vertex.next); - - if(UserHacks_WildHack && !isPackedUV_HackFlag) - { - GSVertex* RESTRICT d = (GSVertex*)ptr; - - for(unsigned int i = 0; i < m_vertex.next; i++, d++) - if(PRIM->TME && PRIM->FST) - d->UV &= UserHacks_WildHack == 1 ? 0x3FEF3FEF : 0x3FF73FF7; - } - + GSVector4i::storent(ptr, m_vertex.buff, sizeof(GSVertex) * m_vertex.next); + + if(UserHacks_WildHack && !isPackedUV_HackFlag) + { + GSVertex* RESTRICT d = (GSVertex*)ptr; + + for(unsigned int i = 0; i < m_vertex.next; i++, d++) + if(PRIM->TME && PRIM->FST) d->UV &= 0x3FEF3FEF; + } + dev->IAUnmapVertexBuffer(); } diff --git a/plugins/GSdx/GSRendererDX9.cpp b/plugins/GSdx/GSRendererDX9.cpp index 437a526e14..c56218bef4 100644 --- a/plugins/GSdx/GSRendererDX9.cpp +++ b/plugins/GSdx/GSRendererDX9.cpp @@ -199,15 +199,13 @@ void GSRendererDX9::SetupIA() { if(PRIM->FST) { - if(UserHacks_WildHack && !isPackedUV_HackFlag) - { - t = GSVector4(GSVector4i::load(UserHacks_WildHack == 1? - s->UV & 0x3FEF3FEF : s->UV & 0x3FF73FF7).upl16()); - - //printf("GSDX: %08X | D3D9(%d) %s\n", s->UV & 0x3FEF3FEF, m_vertex.next, i == 0 ? "*" : ""); - } - else - t = GSVector4(GSVector4i::load(s->UV).upl16()); + if(UserHacks_WildHack && !isPackedUV_HackFlag) + { + t = GSVector4(GSVector4i::load(s->UV & 0x3FEF3FEF).upl16()); + //printf("GSDX: %08X | D3D9(%d) %s\n", s->UV & 0x3FEF3FEF, m_vertex.next, i == 0 ? "*" : ""); + } + else + t = GSVector4(GSVector4i::load(s->UV).upl16()); } else { diff --git a/plugins/GSdx/GSSettingsDlg.cpp b/plugins/GSdx/GSSettingsDlg.cpp index 65588c797a..b93aef9a16 100644 --- a/plugins/GSdx/GSSettingsDlg.cpp +++ b/plugins/GSdx/GSSettingsDlg.cpp @@ -522,6 +522,11 @@ void GSHacksDlg::OnInit() SendMessage(GetDlgItem(m_hWnd, IDC_SKIPDRAWHACK), UDM_SETRANGE, 0, MAKELPARAM(1000, 0)); SendMessage(GetDlgItem(m_hWnd, IDC_SKIPDRAWHACK), UDM_SETPOS, 0, MAKELPARAM(theApp.GetConfig("UserHacks_SkipDraw", 0), 0)); + SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETX), UDM_SETRANGE, 0, MAKELPARAM(10000, 0)); + SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETX), UDM_SETPOS, 0, MAKELPARAM(theApp.GetConfig("UserHacks_TCOffset", 0) & 0xFFFF, 0)); + + SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETY), UDM_SETRANGE, 0, MAKELPARAM(10000, 0)); + SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETY), UDM_SETPOS, 0, MAKELPARAM((theApp.GetConfig("UserHacks_TCOffset", 0) >> 16) & 0xFFFF, 0)); // Hacks descriptions SetWindowText(GetDlgItem(m_hWnd, IDC_HACK_DESCRIPTION), "Hover over an item to get a description."); @@ -537,6 +542,7 @@ bool GSHacksDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) case WM_SETCURSOR: { const char *helpstr = ""; + bool updateText = true; POINT pos; GetCursorPos(&pos); @@ -597,12 +603,26 @@ bool GSHacksDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) "CrcHacksExclusions=all\n" "CrcHacksExclusions=0x0F0C4A9C, 0x0EE5646B, 0x7ACF7E03"; break; + + case IDC_TCOFFSETX: + case IDC_TCOFFSETX2: + case IDC_STATIC_TCOFFSETX: + case IDC_TCOFFSETY: + case IDC_TCOFFSETY2: + case IDC_STATIC_TCOFFSETY: + helpstr = "Texture Coordinates Offset Hack\n\n" + "Offset for the ST/UV texture coordinates. Fixes some odd texture issues and might fix some post processing alignment too.\n\n" + " 0500 0500, fixes Persona 3 minimap, helps Haunting Ground.\n" + " 0000 1000, fixes Xenosaga hair edges (DX10+ Issue)\n"; + break; + default: - helpstr = "Hover over an item to get a description."; + updateText = false; break; } - SetWindowText(GetDlgItem(m_hWnd, IDC_HACK_DESCRIPTION), helpstr); + if(updateText) + SetWindowText(GetDlgItem(m_hWnd, IDC_HACK_DESCRIPTION), helpstr); } break; @@ -623,6 +643,12 @@ bool GSHacksDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) theApp.SetConfig("UserHacks_AggressiveCRC", (int)IsDlgButtonChecked(m_hWnd, IDC_AGGRESSIVECRC)); theApp.SetConfig("UserHacks_AlphaStencil", (int)IsDlgButtonChecked(m_hWnd, IDC_ALPHASTENCIL)); theApp.SetConfig("UserHacks_DisableCrcHacks", (int)IsDlgButtonChecked(m_hWnd, IDC_CHECK_DISABLE_ALL_HACKS)); + + unsigned int TCOFFSET = SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETX), UDM_GETPOS, 0, 0) & 0xFFFF; + TCOFFSET |= (SendMessage(GetDlgItem(m_hWnd, IDC_TCOFFSETY), UDM_GETPOS, 0, 0) & 0xFFFF) << 16; + + theApp.SetConfig("UserHacks_TCOffset", TCOFFSET); + EndDialog(m_hWnd, id); } break; } diff --git a/plugins/GSdx/GSTextureFX11.cpp b/plugins/GSdx/GSTextureFX11.cpp index 689248c13b..d51ec6ec0d 100644 --- a/plugins/GSdx/GSTextureFX11.cpp +++ b/plugins/GSdx/GSTextureFX11.cpp @@ -177,7 +177,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe if(i == m_ps.end()) { - string str[17]; + string str[18]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -195,7 +195,8 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe str[13] = format("%d", sel.colclip); str[14] = format("%d", sel.date); str[15] = format("%d", sel.spritehack); - str[16] = format("%d", sel.point_sampler); + str[16] = format("%d", sel.tcoffsethack); + str[17] = format("%d", sel.point_sampler); D3D11_SHADER_MACRO macro[] = { @@ -215,7 +216,8 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe {"PS_COLCLIP", str[13].c_str()}, {"PS_DATE", str[14].c_str()}, {"PS_SPRITEHACK", str[15].c_str()}, - {"PS_POINT_SAMPLER", str[16].c_str()}, + {"PS_TCOFFSETHACK", str[16].c_str()}, + {"PS_POINT_SAMPLER", str[17].c_str()}, {NULL, NULL}, }; diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index 132228ff89..a929458a82 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -135,7 +135,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel if(i == m_ps.end()) { - string str[16]; + string str[17]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -152,7 +152,8 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel str[12] = format("%d", sel.colclip); str[13] = format("%d", sel.date); str[14] = format("%d", sel.spritehack); - str[15] = format("%d", sel.point_sampler); + str[15] = format("%d", sel.tcoffsethack); + str[16] = format("%d", sel.point_sampler); D3DXMACRO macro[] = { @@ -171,7 +172,8 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel {"PS_COLCLIP", str[12].c_str()}, {"PS_DATE", str[13].c_str()}, {"PS_SPRITEHACK", str[14].c_str()}, - {"PS_POINT_SAMPLER", str[15].c_str()}, + {"PS_TCOFFSETHACK", str[15].c_str()}, + {"PS_POINT_SAMPLER", str[16].c_str()}, {NULL, NULL}, }; diff --git a/plugins/GSdx/GSdx.rc b/plugins/GSdx/GSdx.rc index a5b602546f..0b293f825e 100644 --- a/plugins/GSdx/GSdx.rc +++ b/plugins/GSdx/GSdx.rc @@ -74,28 +74,34 @@ IDB_LOGO10 BITMAP "res\\logo10.bmp" // Dialog // -IDD_HACKS DIALOGEX 0, 0, 315, 203 +IDD_HACKS DIALOGEX 0, 0, 315, 236 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Hacks Configuration" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - DEFPUSHBUTTON "OK",IDOK,258,182,50,14 - GROUPBOX "Hack",IDC_STATIC,7,7,76,165,0,WS_EX_TRANSPARENT - GROUPBOX "Description",IDC_STATIC,85,7,223,165 + DEFPUSHBUTTON "OK",IDOK,258,215,50,14 + GROUPBOX "Hack",IDC_STATIC,7,7,86,201,0,WS_EX_TRANSPARENT + GROUPBOX "Description",IDC_STATIC,96,7,212,201 LTEXT "MSAA",IDC_STATIC_MSAA,14,20,20,8 LTEXT "Skipdraw",IDC_STATIC_SKIPDRAW,14,37,30,8 - EDITTEXT IDC_SKIPDRAWHACKEDIT,45,35,24,14,ES_RIGHT | ES_AUTOHSCROLL - CONTROL "",IDC_SKIPDRAWHACK,"msctls_updown32",UDS_SETBUDDYINT | UDS_AUTOBUDDY | UDS_ARROWKEYS,68,35,10,14 + EDITTEXT IDC_SKIPDRAWHACKEDIT,53,35,35,14,ES_RIGHT | ES_AUTOHSCROLL + CONTROL "",IDC_SKIPDRAWHACK,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,88,35,10,14 CONTROL "Alpha",IDC_ALPHAHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,54,34,10 CONTROL "Half-pixel Offset",IDC_OFFSETHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,71,65,10 CONTROL "Sprite",IDC_SPRITEHACK,"Button",BS_AUTO3STATE | WS_TABSTOP,14,88,35,10 - LTEXT "USE AT YOUR OWN RISK!",IDC_STATIC,7,182,84,8,WS_DISABLED - COMBOBOX IDC_MSAACB,35,18,44,63,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "USE AT YOUR OWN RISK!",IDC_STATIC,7,218,84,11,WS_DISABLED + COMBOBOX IDC_MSAACB,35,18,54,63,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "WildArmsOffset",IDC_WILDHACK,"Button",BS_AUTO3STATE | WS_TABSTOP,14,105,64,10 - LTEXT "TEXT_GOES_HERE",IDC_HACK_DESCRIPTION,92,20,209,145 + LTEXT "TEXT_GOES_HERE",IDC_HACK_DESCRIPTION,102,20,199,183 CONTROL "Aggressive-CRC",IDC_AGGRESSIVECRC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,122,66,10 CONTROL "Alpha Stencil",IDC_ALPHASTENCIL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,139,66,10 CONTROL "Disable CRCs",IDC_CHECK_DISABLE_ALL_HACKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,156,58,10 + LTEXT "TC Offset X",IDC_STATIC_TCOFFSETX,14,173,37,8 + EDITTEXT IDC_TCOFFSETX2,53,171,35,14,ES_RIGHT | ES_AUTOHSCROLL + CONTROL "",IDC_TCOFFSETX,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,87,171,11,14 + EDITTEXT IDC_TCOFFSETY2,53,188,35,14,ES_RIGHT | ES_AUTOHSCROLL + CONTROL "",IDC_TCOFFSETY,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,86,188,11,14 + LTEXT "TC Offset Y",IDC_STATIC_TCOFFSETY,14,190,37,8 END IDD_SHADEBOOST DIALOGEX 0, 0, 316, 129 @@ -262,7 +268,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 308 TOPMARGIN, 7 - BOTTOMMARGIN, 196 + BOTTOMMARGIN, 229 END IDD_SHADEBOOST, DIALOG diff --git a/plugins/GSdx/res/tfx.fx b/plugins/GSdx/res/tfx.fx index 7d56b29866..f78f9ebe7f 100644 --- a/plugins/GSdx/res/tfx.fx +++ b/plugins/GSdx/res/tfx.fx @@ -37,6 +37,7 @@ #define PS_COLCLIP 0 #define PS_DATE 0 #define PS_SPRITEHACK 0 +#define PS_TCOFFSETHACK 0 #define PS_POINT_SAMPLER 0 #endif @@ -101,6 +102,7 @@ cbuffer cb1 float2 MinF; float2 TA; uint4 MskFix; + float4 TC_OffsetHack; }; float4 sample_c(float2 uv) @@ -202,6 +204,8 @@ float4 ps_params[7]; #define MinF ps_params[4].xy #define TA ps_params[4].zw +#define TC_OffsetHack ps_params[5] + float4 sample_c(float2 uv) { return tex2D(Texture, uv); @@ -365,10 +369,11 @@ float4x4 sample_4p(float4 u) float4 sample(float2 st, float q) { - if(!PS_FST) - { - st /= q; - } + if(!PS_FST) st /= q; + + #if PS_TCOFFSETHACK + st += TC_OffsetHack.xy; + #endif float4 t; float4x4 c; diff --git a/plugins/GSdx/resource.h b/plugins/GSdx/resource.h index 70062a104c..a4b56979f5 100644 --- a/plugins/GSdx/resource.h +++ b/plugins/GSdx/resource.h @@ -80,7 +80,13 @@ #define IDC_AGGRESSIVECRC 2076 #define IDC_CHECK_DISABLE_ALL_HACKS 2077 #define IDC_ALPHASTENCIL 2078 -#define IDC_ADAPTER 2078 +#define IDC_ADAPTER 2079 +#define IDC_STATIC_TCOFFSETX 2080 +#define IDC_STATIC_TCOFFSETY 2081 +#define IDC_TCOFFSETX 2082 +#define IDC_TCOFFSETX2 2083 +#define IDC_TCOFFSETY 2084 +#define IDC_TCOFFSETY2 2085 #define IDC_COLORSPACE 3000 #define IDR_CONVERT_FX 10000 #define IDR_TFX_FX 10001 @@ -99,7 +105,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 10012 #define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 2079 +#define _APS_NEXT_CONTROL_VALUE 2086 #define _APS_NEXT_SYMED_VALUE 5000 #endif #endif