diff --git a/plugins/GSdx/GS.h b/plugins/GSdx/GS.h index 352e38da44..ef73ea85f5 100644 --- a/plugins/GSdx/GS.h +++ b/plugins/GSdx/GS.h @@ -769,9 +769,9 @@ REG64_(GIFReg, TEST) uint32 _PAD1:13; uint32 _PAD2:32; REG_END2 - __forceinline bool DoFirstPass() {return !ATE || ATST != 0;} // not all pixels fail automatically - __forceinline bool DoSecondPass() {return ATE && ATST != 1 && AFAIL != 0;} // pixels may fail, write fb/z - __forceinline bool NoSecondPass() {return ATE && ATST != 1 && AFAIL == 0;} // pixels may fail, no output + __forceinline bool DoFirstPass() {return !ATE || ATST != ATST_NEVER;} // not all pixels fail automatically + __forceinline bool DoSecondPass() {return ATE && ATST != ATST_ALWAYS && AFAIL != AFAIL_KEEP;} // pixels may fail, write fb/z + __forceinline bool NoSecondPass() {return ATE && ATST != ATST_ALWAYS && AFAIL == AFAIL_KEEP;} // pixels may fail, no output REG_END2 REG64_(GIFReg, TEX0) diff --git a/plugins/GSdx/GSClut.h b/plugins/GSdx/GSClut.h index 6303b81221..e4301ac6fd 100644 --- a/plugins/GSdx/GSClut.h +++ b/plugins/GSdx/GSClut.h @@ -71,7 +71,7 @@ __declspec(align(16)) class GSClut : public GSAlignedClass<16> template void WriteCLUT16_CSM2(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT); template void WriteCLUT16S_CSM2(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT); - void WriteCLUT_NULL(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT) {} + void WriteCLUT_NULL(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT) {ASSERT(0);} // xenosaga 3 static void WriteCLUT_T32_I8_CSM1(const uint32* RESTRICT src, uint16* RESTRICT clut); static void WriteCLUT_T32_I4_CSM1(const uint32* RESTRICT src, uint16* RESTRICT clut); diff --git a/plugins/GSdx/GSDevice10.cpp b/plugins/GSdx/GSDevice10.cpp index 8f5d709387..29e584d8a1 100644 --- a/plugins/GSdx/GSDevice10.cpp +++ b/plugins/GSdx/GSDevice10.cpp @@ -86,8 +86,8 @@ bool GSDevice10::Create(GSWnd* wnd, bool vsync) scd.SampleDesc.Quality = 0; scd.Windowed = TRUE; - uint32 flags = 0; - flags = D3D10_CREATE_DEVICE_SINGLETHREADED; //disables thread safety, should be fine (speedup) + uint32 flags = D3D10_CREATE_DEVICE_SINGLETHREADED; //disables thread safety, should be fine (speedup) + #ifdef DEBUG flags |= D3D10_CREATE_DEVICE_DEBUG; #endif @@ -113,8 +113,6 @@ bool GSDevice10::Create(GSWnd* wnd, bool vsync) } } - // hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &scd, &m_swapchain, &m_dev); - if(FAILED(hr)) return false; // convert diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index 4ab7429375..679b5016ec 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -86,8 +86,8 @@ bool GSDevice11::Create(GSWnd* wnd, bool vsync) scd.SampleDesc.Quality = 0; scd.Windowed = TRUE; - uint32 flags = 0; - flags = D3D11_CREATE_DEVICE_SINGLETHREADED; //disables thread safety, should be fine (speedup) + uint32 flags = D3D11_CREATE_DEVICE_SINGLETHREADED; //disables thread safety, should be fine (speedup) + #ifdef DEBUG flags |= D3D11_CREATE_DEVICE_DEBUG; #endif diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 0889fb51e1..5971220633 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -969,29 +969,6 @@ void GSDevice9::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4 } } -// FIXME: D3DXCompileShaderFromResource of d3dx9 v37 (march 2008) calls GetFullPathName on id for some reason and then crashes - -static HRESULT LoadShader(uint32 id, LPCSTR& data, uint32& size) -{ - CComPtr shader, error; - - HRSRC hRes = FindResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), RT_RCDATA); - - if(!hRes) return E_FAIL; - - size = SizeofResource(theApp.GetModuleHandle(), hRes); - - if(size == 0) return E_FAIL; - - HGLOBAL hResData = LoadResource(theApp.GetModuleHandle(), hRes); - - if(!hResData) return E_FAIL; - - data = (LPCSTR)LockResource(hResData); - - return S_OK; -} - HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il) { vector m; @@ -1002,16 +979,7 @@ HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO CComPtr shader, error; - // FIXME: hr = D3DXCompileShaderFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), &m[0], NULL, entry.c_str(), target, 0, &shader, &error, NULL); - - LPCSTR data; - uint32 size; - - hr = LoadShader(id, data, size); - - if(FAILED(hr)) return E_FAIL; - - hr = D3DXCompileShader(data, size, &m[0], NULL, entry.c_str(), m_shader.vs.c_str(), 0, &shader, &error, NULL); + hr = D3DXCompileShaderFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), &m[0], NULL, entry.c_str(), m_shader.vs.c_str(), 0, &shader, &error, NULL); if(SUCCEEDED(hr)) { @@ -1047,6 +1015,10 @@ HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO { flags |= D3DXSHADER_AVOID_FLOW_CONTROL; } + else + { + flags |= D3DXSHADER_SKIPVALIDATION; + } vector m; @@ -1056,16 +1028,7 @@ HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO CComPtr shader, error; - // FIXME: hr = D3DXCompileShaderFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), &m[0], NULL, entry.c_str(), target, flags, &shader, &error, NULL); - - LPCSTR data; - uint32 size; - - hr = LoadShader(id, data, size); - - if(FAILED(hr)) return E_FAIL; - - hr = D3DXCompileShader(data, size, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), 0, &shader, &error, NULL); + hr = D3DXCompileShaderFromResource(theApp.GetModuleHandle(), MAKEINTRESOURCE(id), &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), flags, &shader, &error, NULL); if(SUCCEEDED(hr)) { diff --git a/plugins/GSdx/GSRenderer.cpp b/plugins/GSdx/GSRenderer.cpp index f1030ee321..a191366f9c 100644 --- a/plugins/GSdx/GSRenderer.cpp +++ b/plugins/GSdx/GSRenderer.cpp @@ -709,7 +709,10 @@ bool GSRenderer::IsLinear() bool mmin = TEX1.IsMinLinear(); bool mmag = TEX1.IsMagLinear(); - if(mmag == mmin) return mmag; + if(mmag == mmin || TEX1.MXL == 0) // MXL == 0 => MMIN ignored, tested it on ps2 + { + return mmag; + } if(!TEX1.LCM && !PRIM->FST) // if FST => assume Q = 1.0f (should not, but Q is very often bogus, 0 or DEN) { @@ -761,7 +764,7 @@ bool GSRenderer::IsOpaque() amin = amax = 0x80; } } - else if(context->ALPHA.C == 1) + else if(context->ALPHA.C == 2) { amin = amax = context->ALPHA.FIX; } diff --git a/plugins/GSdx/GSRendererDX.h b/plugins/GSdx/GSRendererDX.h index 887e202f22..7ff1187eca 100644 --- a/plugins/GSdx/GSRendererDX.h +++ b/plugins/GSdx/GSRendererDX.h @@ -199,7 +199,6 @@ public: if(context->TEST.ATE) { - ps_sel.ate = 1; ps_sel.atst = context->TEST.ATST; switch(ps_sel.atst) @@ -215,6 +214,10 @@ public: break; } } + else + { + ps_sel.atst = ATST_ALWAYS; + } if(tex) { diff --git a/plugins/GSdx/GSRendererHW.h b/plugins/GSdx/GSRendererHW.h index 9e8459c500..41cc49b4db 100644 --- a/plugins/GSdx/GSRendererHW.h +++ b/plugins/GSdx/GSRendererHW.h @@ -624,7 +624,7 @@ protected: { if(TryAlphaTest(fm, zm)) { - context->TEST.ATE = 0; + context->TEST.ATST = ATST_ALWAYS; } } diff --git a/plugins/GSdx/GSTextureFX.h b/plugins/GSdx/GSTextureFX.h index 8e97f8d0a6..eaaf562e9a 100644 --- a/plugins/GSdx/GSTextureFX.h +++ b/plugins/GSdx/GSTextureFX.h @@ -174,7 +174,6 @@ public: uint32 aem:1; uint32 tfx:3; uint32 tcc:1; - uint32 ate:1; uint32 atst:3; uint32 fog:1; uint32 clr1:1; @@ -187,7 +186,7 @@ public: uint32 key; }; - operator uint32() {return key & 0x7fffff;} + operator uint32() {return key & 0x3fffff;} PSSelector() : key(0) {} }; diff --git a/plugins/GSdx/GSTextureFX10.cpp b/plugins/GSdx/GSTextureFX10.cpp index b221f9e069..b822ee691a 100644 --- a/plugins/GSdx/GSTextureFX10.cpp +++ b/plugins/GSdx/GSTextureFX10.cpp @@ -197,7 +197,7 @@ void GSTextureFX10::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample if(i == m_ps.end()) { - string str[14]; + string str[13]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -206,13 +206,12 @@ void GSTextureFX10::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample str[4] = format("%d", sel.aem); str[5] = format("%d", sel.tfx); str[6] = format("%d", sel.tcc); - str[7] = format("%d", sel.ate); - str[8] = format("%d", sel.atst); - str[9] = format("%d", sel.fog); - str[10] = format("%d", sel.clr1); - str[11] = format("%d", sel.fba); - str[12] = format("%d", sel.aout); - str[13] = format("%d", sel.ltf); + str[7] = format("%d", sel.atst); + str[8] = format("%d", sel.fog); + str[9] = format("%d", sel.clr1); + str[10] = format("%d", sel.fba); + str[11] = format("%d", sel.aout); + str[12] = format("%d", sel.ltf); D3D10_SHADER_MACRO macro[] = { @@ -223,13 +222,12 @@ void GSTextureFX10::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample {"PS_AEM", str[4].c_str()}, {"PS_TFX", str[5].c_str()}, {"PS_TCC", str[6].c_str()}, - {"PS_ATE", str[7].c_str()}, - {"PS_ATST", str[8].c_str()}, - {"PS_FOG", str[9].c_str()}, - {"PS_CLR1", str[10].c_str()}, - {"PS_FBA", str[11].c_str()}, - {"PS_AOUT", str[12].c_str()}, - {"PS_LTF", str[13].c_str()}, + {"PS_ATST", str[7].c_str()}, + {"PS_FOG", str[8].c_str()}, + {"PS_CLR1", str[9].c_str()}, + {"PS_FBA", str[10].c_str()}, + {"PS_AOUT", str[11].c_str()}, + {"PS_LTF", str[12].c_str()}, {NULL, NULL}, }; diff --git a/plugins/GSdx/GSTextureFX11.cpp b/plugins/GSdx/GSTextureFX11.cpp index 8ad8cf6cf6..95e815c198 100644 --- a/plugins/GSdx/GSTextureFX11.cpp +++ b/plugins/GSdx/GSTextureFX11.cpp @@ -199,7 +199,7 @@ void GSTextureFX11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample if(i == m_ps.end()) { - string str[14]; + string str[13]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -208,13 +208,12 @@ void GSTextureFX11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample str[4] = format("%d", sel.aem); str[5] = format("%d", sel.tfx); str[6] = format("%d", sel.tcc); - str[7] = format("%d", sel.ate); - str[8] = format("%d", sel.atst); - str[9] = format("%d", sel.fog); - str[10] = format("%d", sel.clr1); - str[11] = format("%d", sel.fba); - str[12] = format("%d", sel.aout); - str[13] = format("%d", sel.ltf); + str[7] = format("%d", sel.atst); + str[8] = format("%d", sel.fog); + str[9] = format("%d", sel.clr1); + str[10] = format("%d", sel.fba); + str[11] = format("%d", sel.aout); + str[12] = format("%d", sel.ltf); D3D11_SHADER_MACRO macro[] = { @@ -225,13 +224,12 @@ void GSTextureFX11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSample {"PS_AEM", str[4].c_str()}, {"PS_TFX", str[5].c_str()}, {"PS_TCC", str[6].c_str()}, - {"PS_ATE", str[7].c_str()}, - {"PS_ATST", str[8].c_str()}, - {"PS_FOG", str[9].c_str()}, - {"PS_CLR1", str[10].c_str()}, - {"PS_FBA", str[11].c_str()}, - {"PS_AOUT", str[12].c_str()}, - {"PS_LTF", str[13].c_str()}, + {"PS_ATST", str[7].c_str()}, + {"PS_FOG", str[8].c_str()}, + {"PS_CLR1", str[9].c_str()}, + {"PS_FBA", str[10].c_str()}, + {"PS_AOUT", str[11].c_str()}, + {"PS_LTF", str[12].c_str()}, {NULL, NULL}, }; diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index 87c6849a56..83a01d2565 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -177,7 +177,7 @@ void GSTextureFX9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSampler if(i == m_ps.end()) { - string str[13]; + string str[12]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -186,12 +186,11 @@ void GSTextureFX9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSampler str[4] = format("%d", sel.aem); str[5] = format("%d", sel.tfx); str[6] = format("%d", sel.tcc); - str[7] = format("%d", sel.ate); - str[8] = format("%d", sel.atst); - str[9] = format("%d", sel.fog); - str[10] = format("%d", sel.clr1); - str[11] = format("%d", sel.rt); - str[12] = format("%d", sel.ltf); + str[7] = format("%d", sel.atst); + str[8] = format("%d", sel.fog); + str[9] = format("%d", sel.clr1); + str[10] = format("%d", sel.rt); + str[11] = format("%d", sel.ltf); D3DXMACRO macro[] = { @@ -202,12 +201,11 @@ void GSTextureFX9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSampler {"PS_AEM", str[4].c_str()}, {"PS_TFX", str[5].c_str()}, {"PS_TCC", str[6].c_str()}, - {"PS_ATE", str[7].c_str()}, - {"PS_ATST", str[8].c_str()}, - {"PS_FOG", str[9].c_str()}, - {"PS_CLR1", str[10].c_str()}, - {"PS_RT", str[11].c_str()}, - {"PS_LTF", str[12].c_str()}, + {"PS_ATST", str[7].c_str()}, + {"PS_FOG", str[8].c_str()}, + {"PS_CLR1", str[9].c_str()}, + {"PS_RT", str[10].c_str()}, + {"PS_LTF", str[11].c_str()}, {NULL, NULL}, }; diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index 4e9236228a..b5b91643a5 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -148,7 +148,7 @@ bool GSUtil::CheckSSE() bool GSUtil::IsDirect3D10Available() { - if(HMODULE hModule = LoadLibrary(_T("d3d10.dll"))) + if(HMODULE hModule = LoadLibrary(_T("d3d10_1.dll"))) { FreeLibrary(hModule); diff --git a/plugins/GSdx/GSdx_vs2010.vcxproj b/plugins/GSdx/GSdx_vs2010.vcxproj index d6fe2960c1..e10b7f43a0 100644 --- a/plugins/GSdx/GSdx_vs2010.vcxproj +++ b/plugins/GSdx/GSdx_vs2010.vcxproj @@ -1319,6 +1319,7 @@ + @@ -1444,6 +1445,7 @@ + diff --git a/plugins/GSdx/GSdx_vs2010.vcxproj.filters b/plugins/GSdx/GSdx_vs2010.vcxproj.filters index 4ca7e0481a..c78db539e9 100644 --- a/plugins/GSdx/GSdx_vs2010.vcxproj.filters +++ b/plugins/GSdx/GSdx_vs2010.vcxproj.filters @@ -198,6 +198,9 @@ Source Files + + Source Files + Source Files @@ -518,6 +521,9 @@ Header Files + + Header Files + Header Files diff --git a/plugins/GSdx/res/tfx.fx b/plugins/GSdx/res/tfx.fx index 630fda80c8..803e853bb9 100644 --- a/plugins/GSdx/res/tfx.fx +++ b/plugins/GSdx/res/tfx.fx @@ -27,8 +27,7 @@ #define PS_AEM 0 #define PS_TFX 0 #define PS_TCC 1 -#define PS_ATE 0 -#define PS_ATST 4 +#define PS_ATST 1 #define PS_FOG 0 #define PS_CLR1 0 #define PS_FBA 0 @@ -100,15 +99,6 @@ float4 sample_p(float u) return Palette.Sample(PaletteSampler, u); } -#if SHADER_MODEL >= 0x401 - -float4 gather_c(float2 uv) -{ - return Texture.Gather(TextureSampler, uv, int2(0, 0)); -} - -#endif - #elif SHADER_MODEL <= 0x300 #ifndef VS_BPPZ @@ -126,7 +116,6 @@ float4 gather_c(float2 uv) #define PS_AEM 0 #define PS_TFX 0 #define PS_TCC 0 -#define PS_ATE 0 #define PS_ATST 4 #define PS_FOG 0 #define PS_CLR1 0 @@ -304,23 +293,15 @@ float4x4 sample_4c(float4 uv) return c; } -float4 sample_4a(float4 uv, float2 st) +float4 sample_4a(float4 uv) { float4 c; -/* - #if SHADER_MODEL >= 0x401 && PS_FMT == FMT_8 && PS_LTF && PS_WMS < 2 && PS_WMT < 2 - - c = gather_c(st); // the order of samples returned might not be the same as ours - - #else -*/ + c.x = sample_c(uv.xy).a; c.y = sample_c(uv.zy).a; c.z = sample_c(uv.xw).a; c.w = sample_c(uv.zw).a; -/* - #endif -*/ + #if SHADER_MODEL <= 0x300 if(PS_RT) c *= 128.0f / 255; #endif @@ -379,19 +360,19 @@ float4 sample(float2 st, float q) if(PS_FMT == FMT_8H) { - c = sample_4p(sample_4a(uv, st.xy)); + c = sample_4p(sample_4a(uv)); } else if(PS_FMT == FMT_4HL) { - c = sample_4p(fmod(sample_4a(uv, st.xy), 1.0f / 16)); + c = sample_4p(fmod(sample_4a(uv), 1.0f / 16)); } else if(PS_FMT == FMT_4HH) { - c = sample_4p(fmod(sample_4a(uv, st.xy) * 16, 1.0f / 16)); + c = sample_4p(fmod(sample_4a(uv) * 16, 1.0f / 16)); } else if(PS_FMT == FMT_8) { - c = sample_4p(sample_4a(uv, st.xy)); + c = sample_4p(sample_4a(uv)); } else { @@ -476,30 +457,31 @@ float4 tfx(float4 t, float4 c) void atst(float4 c) { - if(PS_ATE) + float a = trunc(c.a * 255); + + if(PS_ATST == 0) // never { - float a = trunc(c.a * 255); - - if(PS_ATST == 0) - { - discard; - } - else if(PS_ATST == 2 || PS_ATST == 3) // l, le - { - clip(AREF - a); - } - else if(PS_ATST == 4) // e - { - clip(0.5f - abs(a - AREF)); - } - else if(PS_ATST == 5 || PS_ATST == 6) // ge, g - { - clip(a - AREF); - } - else if(PS_ATST == 7) // ne - { - clip(abs(a - AREF) - 0.5f); - } + discard; + } + else if(PS_ATST == 1) // always + { + // nothing to do + } + else if(PS_ATST == 2 || PS_ATST == 3) // l, le + { + clip(AREF - a); + } + else if(PS_ATST == 4) // e + { + clip(0.5f - abs(a - AREF)); + } + else if(PS_ATST == 5 || PS_ATST == 6) // ge, g + { + clip(a - AREF); + } + else if(PS_ATST == 7) // ne + { + clip(abs(a - AREF) - 0.5f); } }