diff --git a/plugins/GSdx/GSDirtyRect.cpp b/plugins/GSdx/GSDirtyRect.cpp index 4276d0d47e..422fad5f22 100644 --- a/plugins/GSdx/GSDirtyRect.cpp +++ b/plugins/GSdx/GSDirtyRect.cpp @@ -75,7 +75,9 @@ GSVector4i GSDirtyRectList::GetDirtyRectAndClear(const GIFRegTEX0& TEX0, const G clear(); - return r.rintersect(GSVector4i(0, 0, size.x, size.y)); + GSVector2i bs = GSLocalMemory::m_psm[TEX0.PSM].bs; + + return r.ralign(bs).rintersect(GSVector4i(0, 0, size.x, size.y)); } return GSVector4i::zero(); diff --git a/plugins/GSdx/GSLocalMemory.cpp b/plugins/GSdx/GSLocalMemory.cpp index 004aae25ff..a13bdef939 100644 --- a/plugins/GSdx/GSLocalMemory.cpp +++ b/plugins/GSdx/GSLocalMemory.cpp @@ -1720,26 +1720,7 @@ void GSLocalMemory::ReadTextureBlock16SZ(uint32 bp, uint8* dst, int dstpitch, co /////////////////// -void GSLocalMemory::ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP) -{ - readTexture rtx = m_psm[TEX0.PSM].rtx; - readTexel rt = m_psm[TEX0.PSM].rt; - GSVector2i bs = m_psm[TEX0.PSM].bs; - - if(r.width() < bs.x || r.height() < bs.y - || (r.left & (bs.x - 1)) || (r.top & (bs.y - 1)) - || (r.right & (bs.x - 1)) || (r.bottom & (bs.y - 1)) - || CLAMP.WMS == 3 || CLAMP.WMT == 3) - { - ReadTexture(r, dst, dstpitch, TEX0, TEXA, CLAMP, rt, rtx); - } - else - { - (this->*rtx)(r, dst, dstpitch, TEX0, TEXA); - } -} - -void GSLocalMemory::ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP) +void GSLocalMemory::ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) { readTexture rtx = m_psm[TEX0.PSM].rtx; readTexel rt = m_psm[TEX0.PSM].rt; @@ -1749,7 +1730,7 @@ void GSLocalMemory::ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, || (r.left & (bs.x - 1)) || (r.top & (bs.y - 1)) || (r.right & (bs.x - 1)) || (r.bottom & (bs.y - 1))) { - ReadTextureNC(r, dst, dstpitch, TEX0, TEXA, rt, rtx); + ReadTexture(r, dst, dstpitch, TEX0, TEXA, rt, rtx); } else { @@ -1936,50 +1917,7 @@ void GSLocalMemory::ReadTexture16SZNP(const GSVector4i& r, uint8* dst, int dstpi /////////////////// -void GSLocalMemory::ReadTextureNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP) -{ - readTexture rtx = m_psm[TEX0.PSM].rtxNP; - readTexel rt = m_psm[TEX0.PSM].rtNP; - GSVector2i bs = m_psm[TEX0.PSM].bs; - - if(r.width() < bs.x || r.height() < bs.y - || (r.left & (bs.x - 1)) || (r.top & (bs.y - 1)) - || (r.right & (bs.x - 1)) || (r.bottom & (bs.y - 1)) - || CLAMP.WMS == 3 || CLAMP.WMT == 3) - { - uint32 psm = TEX0.PSM; - - switch(psm) - { - case PSM_PSMT8: - case PSM_PSMT8H: - case PSM_PSMT4: - case PSM_PSMT4HL: - case PSM_PSMT4HH: - psm = TEX0.CPSM; - break; - } - - switch(psm) - { - default: - case PSM_PSMCT32: - case PSM_PSMCT24: - ReadTexture(r, dst, dstpitch, TEX0, TEXA, CLAMP, rt, rtx); - break; - case PSM_PSMCT16: - case PSM_PSMCT16S: - ReadTexture(r, dst, dstpitch, TEX0, TEXA, CLAMP, rt, rtx); - break; - } - } - else - { - (this->*rtx)(r, dst, dstpitch, TEX0, TEXA); - } -} - -void GSLocalMemory::ReadTextureNPNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP) +void GSLocalMemory::ReadTextureNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) { readTexture rtx = m_psm[TEX0.PSM].rtxNP; readTexel rt = m_psm[TEX0.PSM].rtNP; @@ -2007,11 +1945,11 @@ void GSLocalMemory::ReadTextureNPNC(const GSVector4i& r, uint8* dst, int dstpitc default: case PSM_PSMCT32: case PSM_PSMCT24: - ReadTextureNC(r, dst, dstpitch, TEX0, TEXA, rt, rtx); + ReadTexture(r, dst, dstpitch, TEX0, TEXA, rt, rtx); break; case PSM_PSMCT16: case PSM_PSMCT16S: - ReadTextureNC(r, dst, dstpitch, TEX0, TEXA, rt, rtx); + ReadTexture(r, dst, dstpitch, TEX0, TEXA, rt, rtx); break; } } @@ -2106,266 +2044,9 @@ void GSLocalMemory::ReadTextureBlock4HHP(uint32 bp, uint8* dst, int dstpitch, co // template -void GSLocalMemory::ReadTexture(const GSVector4i& r2, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP, readTexel rt, readTexture rtx) +void GSLocalMemory::ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, readTexel rt, readTexture rtx) { - // TODO: this is a mess, make it more simple - - GSVector4i r = r2; - - uint32 wms = CLAMP.WMS, wmt = CLAMP.WMT; - uint32 minu = CLAMP.MINU, maxu = CLAMP.MAXU; - uint32 minv = CLAMP.MINV, maxv = CLAMP.MAXV; - - GSVector2i bs = m_psm[TEX0.PSM].bs; - - int bsxm = bs.x - 1; - int bsym = bs.y - 1; - - if(wms == 3 || wmt == 3) - { - if(wms == 3 && wmt == 3) - { - int w = minu + 1; - int h = minv + 1; - - w = (w + bsxm) & ~bsxm; - h = (h + bsym) & ~bsym; - - if(w % bs.x == 0 && maxu % bs.x == 0 && h % bs.y == 0 && maxv % bs.y == 0) - { -// printf("!!! 1 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - - T* buff = (T*)_aligned_malloc(w * h * sizeof(T), 16); - - (this->*rtx)(GSVector4i(maxu, maxv, maxu + w, maxv + h), (uint8*)buff, w * sizeof(T), TEX0, TEXA); - - dst -= r.left * sizeof(T); - -// int left = (r.left + minu) & ~minu; -// int right = r.right & ~minu; - - for(int y = r.top; y < r.bottom; y++, dst += dstpitch) - { - T* src = &buff[(y & minv) * w]; - - int x = r.left; -/* - for(; x < left; x++) - { - ((T*)dst)[x] = src[x & minu]; - } - - for(; x < right; x += minu + 1) - { - memcpy(&((T*)dst)[x], src, sizeof(T) * (minu + 1)); - } -*/ - for(; x < r.right; x++) - { - ((T*)dst)[x] = src[x & minu]; - } - } - - _aligned_free(buff); - - return; - } - } - - if(wms == 2) - { - int left = r.left; - r.left = min(r.right, max(r.left, (int)minu)); - r.right = max(r.left, min(r.right, (int)maxu + 1)); - dst += (r.left - left) * sizeof(T); - } - - if(wmt == 2) - { - int top = r.top; - r.top = min(r.bottom, max(r.top, (int)minv)); - r.bottom = max(r.top, min(r.bottom, (int)maxv + 1)); - dst += (r.top - top) * dstpitch; - } - - if(wms == 3 && wmt != 3) - { - int w = ((minu + 1) + bsxm) & ~bsxm; - - if(w % bs.x == 0 && maxu % bs.x == 0) - { -// printf("!!! 2 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - int top = r.top & ~bsym; - int bottom = (r.bottom + bsym) & ~bsym; - - int h = bottom - top; - - T* buff = (T*)_aligned_malloc(w * h * sizeof(T), 16); - - (this->*rtx)(GSVector4i(maxu, top, maxu + w, top + h), (uint8*)buff, w * sizeof(T), TEX0, TEXA); - - dst -= r.left * sizeof(T); - -// int left = (r.left + minu) & ~minu; -// int right = r.right & ~minu; - - for(int y = r.top; y < r.bottom; y++, dst += dstpitch) - { - T* src = &buff[(y - top) * w]; - - int x = r.left; -/* - for(; x < left; x++) - { - ((T*)dst)[x] = src[x & minu]; - } - - for(; x < right; x += minu + 1) - { - memcpy(&((T*)dst)[x], src, sizeof(T) * (minu + 1)); - } -*/ - for(; x < r.right; x++) - { - ((T*)dst)[x] = src[x & minu]; - } - } - - _aligned_free(buff); - - return; - } - } - - if(wms != 3 && wmt == 3) - { - int h = (minv + 1 + bsym) & ~bsym; - - if(h % bs.y == 0 && maxv % bs.y == 0) - { -// printf("!!! 3 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - int left = r.left & ~bsxm; - int right = (r.right + bsxm) & ~bsxm; - - int w = right - left; - - T* buff = (T*)_aligned_malloc(w * h * sizeof(T), 16); - - (this->*rtx)(GSVector4i(left, maxv, left + w, maxv + h), (uint8*)buff, w * sizeof(T), TEX0, TEXA); - - for(int y = r.top; y < r.bottom; y++, dst += dstpitch) - { - T* src = &buff[(y & minv) * w + (r.left - left)]; - - memcpy(dst, src, sizeof(T) * r.width()); - } - - _aligned_free(buff); - - return; - } - } - - switch(wms) - { - default: for(int x = r.left; x < r.right; x++) m_xtbl[x] = x; break; - case 3: for(int x = r.left; x < r.right; x++) m_xtbl[x] = (x & minu) | maxu; break; - } - - switch(wmt) - { - default: for(int y = r.top; y < r.bottom; y++) m_ytbl[y] = y; break; - case 3: for(int y = r.top; y < r.bottom; y++) m_ytbl[y] = (y & minv) | maxv; break; - } - -// printf("!!! 4 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - - for(int y = r.top; y < r.bottom; y++, dst += dstpitch) - for(int x = r.left, i = 0; x < r.right; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(m_xtbl[x], m_ytbl[y], TEX0, TEXA); - } - else - { - // find a block-aligned rect that fits between r and the region clamped area (if any) - - GSVector4i r1 = r; - GSVector4i r2 = r; - - r1.left = (r1.left + bsxm) & ~bsxm; - r1.top = (r1.top + bsym) & ~bsym; - r1.right = r1.right & ~bsxm; - r1.bottom = r1.bottom & ~bsym; - - if(wms == 2 && minu < maxu) - { - r2.left = minu & ~bsxm; - r2.right = (maxu + bsxm) & ~bsxm; - } - - if(wmt == 2 && minv < maxv) - { - r2.top = minv & ~bsym; - r2.bottom = (maxv + bsym) & ~bsym; - } - - GSVector4i cr = r1.rintersect(r2); - - bool aligned = ((DWORD_PTR)(dst + (cr.left - r.left) * sizeof(T)) & 0xf) == 0; - - if(cr.rempty() || !aligned) - { - // TODO: expand r to block size, read into temp buffer, copy to r (like above) - -if(!aligned) printf("unaligned memory pointer passed to ReadTexture\n"); - -// printf("!!! 5 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - - for(int y = r.top; y < r.bottom; y++, dst += dstpitch) - for(int x = r.left, i = 0; x < r.right; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(x, y, TEX0, TEXA); - } - else - { -// printf("!!! 6 wms = %d, wmt = %d, %3x %3x %3x %3x, %d %d - %d %d\n", wms, wmt, minu, maxu, minv, maxv, r.left, r.top, r.right, r.bottom); - - for(int y = r.top; y < cr.top; y++, dst += dstpitch) - for(int x = r.left, i = 0; x < r.right; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(x, y, TEX0, TEXA); - - if(!cr.rempty()) - { - (this->*rtx)(cr, dst + (cr.left - r.left) * sizeof(T), dstpitch, TEX0, TEXA); - } - - for(int y = cr.top; y < cr.bottom; y++, dst += dstpitch) - { - for(int x = r.left, i = 0; x < cr.left; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(x, y, TEX0, TEXA); - for(int x = cr.right, i = x - r.left; x < r.right; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(x, y, TEX0, TEXA); - } - - for(int y = cr.bottom; y < r.bottom; y++, dst += dstpitch) - for(int x = r.left, i = 0; x < r.right; x++, i++) - ((T*)dst)[i] = (T)(this->*rt)(x, y, TEX0, TEXA); - } - } -} - -template -void GSLocalMemory::ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, readTexel rt, readTexture rtx) -{ - GSVector2i bs = m_psm[TEX0.PSM].bs; - - int bsxm = bs.x - 1; - int bsym = bs.y - 1; - - GSVector4i cr; - - cr.left = (r.left + bsxm) & ~bsxm; - cr.top = (r.top + bsym) & ~bsym; - cr.right = r.right & ~bsxm; - cr.bottom = r.bottom & ~bsym; + GSVector4i cr = r.ralign(m_psm[TEX0.PSM].bs); bool aligned = ((DWORD_PTR)(dst + (cr.left - r.left) * sizeof(T)) & 0xf) == 0; @@ -2373,7 +2054,8 @@ void GSLocalMemory::ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, { // TODO: expand r to block size, read into temp buffer, copy to r (like above) -if(!aligned) printf("unaligned memory pointer passed to ReadTexture\n"); +if(!aligned) +printf("unaligned memory pointer passed to ReadTexture\n"); for(int y = r.top; y < r.bottom; y++, dst += dstpitch) for(int x = r.left, i = 0; x < r.right; x++, i++) diff --git a/plugins/GSdx/GSLocalMemory.h b/plugins/GSdx/GSLocalMemory.h index 1a966ae603..f690fafa2a 100644 --- a/plugins/GSdx/GSLocalMemory.h +++ b/plugins/GSdx/GSLocalMemory.h @@ -795,8 +795,7 @@ public: void ReadTexture16Z(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const; void ReadTexture16SZ(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const; - void ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP); - void ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP); + void ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA); void ReadTextureBlock32(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const; void ReadTextureBlock24(uint32 bp, uint8* dst, int dstpitch, const GIFRegTEXA& TEXA) const; @@ -824,8 +823,7 @@ public: void ReadTexture16ZNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const; void ReadTexture16SZNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA) const; - void ReadTextureNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP); - void ReadTextureNPNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP); + void ReadTextureNP(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA); // pal ? 8 : 32 @@ -845,8 +843,7 @@ public: static uint32 m_xtbl[1024], m_ytbl[1024]; - template void ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GIFRegCLAMP& CLAMP, readTexel rt, readTexture rtx); - template void ReadTextureNC(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, readTexel rt, readTexture rtx); + template void ReadTexture(const GSVector4i& r, uint8* dst, int dstpitch, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, readTexel rt, readTexture rtx); // diff --git a/plugins/GSdx/GSRendererHW10.cpp b/plugins/GSdx/GSRendererHW10.cpp index 69bf582df4..4423d582e5 100644 --- a/plugins/GSdx/GSRendererHW10.cpp +++ b/plugins/GSdx/GSRendererHW10.cpp @@ -324,28 +324,27 @@ void GSRendererHW10::Draw(int prim, GSTexture* rt, GSTexture* ds, GSTextureCache ps_sel.clr1 = om_bsel.abe && om_bsel.a == 1 && om_bsel.b == 2 && om_bsel.d == 1; ps_sel.fba = context->FBA.FBA; ps_sel.aout = context->FRAME.PSM == PSM_PSMCT16 || context->FRAME.PSM == PSM_PSMCT16S || (context->FRAME.FBMSK & 0xff000000) == 0x7f000000 ? 1 : 0; + ps_sel.ltf = m_filter == 2 ? context->TEX1.IsLinear() : m_filter; GSTextureFX10::PSSamplerSelector ps_ssel; - ps_ssel.min = m_filter == 2 ? (context->TEX1.MMIN & 1) : m_filter; - ps_ssel.mag = m_filter == 2 ? (context->TEX1.MMAG & 1) : m_filter; ps_ssel.tau = 0; ps_ssel.tav = 0; + ps_ssel.ltf = ps_sel.ltf; GSTextureFX10::PSConstantBuffer ps_cb; - ps_cb.FogColor = GSVector4(env.FOGCOL.FCR, env.FOGCOL.FCG, env.FOGCOL.FCB, 0) / 255.0f; + ps_cb.FogColorAREF = GSVector4((int)env.FOGCOL.FCR, (int)env.FOGCOL.FCG, (int)env.FOGCOL.FCB, (int)context->TEST.AREF) / 255; ps_cb.TA0 = (float)(int)env.TEXA.TA0 / 255; ps_cb.TA1 = (float)(int)env.TEXA.TA1 / 255; - ps_cb.AREF = (float)(int)context->TEST.AREF / 255; if(context->TEST.ATST == 2 || context->TEST.ATST == 5) { - ps_cb.AREF -= 0.9f/256; + ps_cb.FogColorAREF.a -= 0.9f / 255; } else if(context->TEST.ATST == 3 || context->TEST.ATST == 6) { - ps_cb.AREF += 0.9f/256; + ps_cb.FogColorAREF.a += 0.9f / 255; } if(tex) @@ -400,7 +399,6 @@ void GSRendererHW10::Draw(int prim, GSTexture* rt, GSTexture* ds, GSTextureCache float h = (float)tex->m_texture->GetHeight(); ps_cb.WH = GSVector2(w, h); - ps_cb.rWrH = GSVector2(1.0f / w, 1.0f / h); ps_cb.HalfTexel = GSVector4(-0.5f / w, -0.5f / h, +0.5f / w, +0.5f / h); } else diff --git a/plugins/GSdx/GSRendererHW9.cpp b/plugins/GSdx/GSRendererHW9.cpp index 3b90ca47a8..b4b0877352 100644 --- a/plugins/GSdx/GSRendererHW9.cpp +++ b/plugins/GSdx/GSRendererHW9.cpp @@ -298,28 +298,27 @@ void GSRendererHW9::Draw(int prim, GSTexture* rt, GSTexture* ds, GSTextureCache: ps_sel.fog = PRIM->FGE; ps_sel.clr1 = om_bsel.abe && om_bsel.a == 1 && om_bsel.b == 2 && om_bsel.d == 1; ps_sel.rt = tex && tex->m_rendered; + ps_sel.ltf = m_filter == 2 ? context->TEX1.IsLinear() : m_filter; GSTextureFX9::PSSamplerSelector ps_ssel; - ps_ssel.min = m_filter == 2 ? (context->TEX1.MMIN & 1) : m_filter; - ps_ssel.mag = m_filter == 2 ? (context->TEX1.MMAG & 1) : m_filter; ps_ssel.tau = 0; ps_ssel.tav = 0; + ps_ssel.ltf = ps_sel.ltf; GSTextureFX9::PSConstantBuffer ps_cb; - ps_cb.FogColor = GSVector4(env.FOGCOL.FCR, env.FOGCOL.FCG, env.FOGCOL.FCB, 0) / 255.0f; + ps_cb.FogColorAREF = GSVector4((int)env.FOGCOL.FCR, (int)env.FOGCOL.FCG, (int)env.FOGCOL.FCB, (int)context->TEST.AREF) / 255; ps_cb.TA0 = (float)(int)env.TEXA.TA0 / 255; ps_cb.TA1 = (float)(int)env.TEXA.TA1 / 255; - ps_cb.AREF = (float)(int)context->TEST.AREF / 255; if(context->TEST.ATST == 2 || context->TEST.ATST == 5) { - ps_cb.AREF -= 0.9f/256; + ps_cb.FogColorAREF.a -= 0.9f / 255; } else if(context->TEST.ATST == 3 || context->TEST.ATST == 6) { - ps_cb.AREF += 0.9f/256; + ps_cb.FogColorAREF.a += 0.9f / 255; } if(tex) @@ -374,7 +373,6 @@ void GSRendererHW9::Draw(int prim, GSTexture* rt, GSTexture* ds, GSTextureCache: float h = (float)tex->m_texture->GetHeight(); ps_cb.WH = GSVector2(w, h); - ps_cb.rWrH = GSVector2(1.0f / w, 1.0f / h); ps_cb.HalfTexel = GSVector4(-0.5f / w, -0.5f / h, +0.5f / w, +0.5f / h); } else diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index 2b78701155..d9e0d732b6 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -114,15 +114,11 @@ GSTexture* GSRendererSW::GetOutput(int i) } } - GIFRegCLAMP CLAMP; - - CLAMP.WMS = CLAMP.WMT = 1; - // TODO static uint8* buff = (uint8*)_aligned_malloc(1024 * 1024 * 4, 16); static int pitch = 1024 * 4; - m_mem.ReadTexture(r, buff, pitch, TEX0, m_env.TEXA, CLAMP); + m_mem.ReadTexture(r, buff, pitch, TEX0, m_env.TEXA); m_texture[i]->Update(r, buff, pitch); diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 43a6587019..07d10931f8 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -260,21 +260,21 @@ GSTextureCache::GSCachedTexture* GSTextureCache::GetTexture() for(list::iterator i = m_tex.begin(); i != m_tex.end(); i++) { - t = *i; + GSCachedTexture* t2 = *i; - if(GSUtil::HasSharedBits(t->m_TEX0.TBP0, t->m_TEX0.PSM, TEX0.TBP0, TEX0.PSM)) + if((((t2->m_TEX0.u32[0] ^ TEX0.u32[0]) & 0xffefffff) | ((t2->m_TEX0.u32[1] ^ TEX0.u32[1]) & 3)) != 0) // TBP0 TBW (PSM & ~1) TW TH { - if(TEX0.PSM == t->m_TEX0.PSM && TEX0.TBW == t->m_TEX0.TBW - && TEX0.TW == t->m_TEX0.TW && TEX0.TH == t->m_TEX0.TH - && (pal == 0 || TEX0.CPSM == t->m_TEX0.CPSM && GSVector4i::compare(t->m_clut, clut, pal * sizeof(clut[0])))) - { - m_tex.splice(m_tex.begin(), m_tex, i); - - break; - } + continue; } - t = NULL; + if(!(pal == 0 || t2->m_TEX0.CPSM == TEX0.CPSM && GSVector4i::compare(t2->m_clut, clut, pal * sizeof(clut[0])))) + { + continue; + } + + t = t2; + + m_tex.splice(m_tex.begin(), m_tex, i); } if(t == NULL) @@ -367,6 +367,8 @@ GSTextureCache::GSCachedTexture* GSTextureCache::GetTexture() t->Update(); + m_tex_used = true; + return t; } @@ -595,9 +597,11 @@ void GSTextureCache::InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const void GSTextureCache::IncAge() { - RecycleByAge(m_tex, 2); + RecycleByAge(m_tex, m_tex_used ? 2 : 30); RecycleByAge(m_rt); RecycleByAge(m_ds); + + m_tex_used = false; } // GSTextureCache::GSSurface @@ -704,7 +708,7 @@ void GSTextureCache::GSCachedTexture::Update() { // in dx9 managed textures can be written directly, less copying is faster, but still not as fast as dx10's UpdateResource - m_renderer->m_mem.ReadTextureNPNC(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + m_renderer->m_mem.ReadTextureNP(r, bits, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA); m_texture->Unmap(); } @@ -714,7 +718,7 @@ void GSTextureCache::GSCachedTexture::Update() pitch = ((r.width() + 3) & ~3) * 4; - m_renderer->m_mem.ReadTextureNPNC(r, buff, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA, m_renderer->m_context->CLAMP); + m_renderer->m_mem.ReadTextureNP(r, buff, pitch, m_renderer->m_context->TEX0, m_renderer->m_env.TEXA); m_texture->Update(r, buff, pitch); } diff --git a/plugins/GSdx/GSTextureCache.h b/plugins/GSdx/GSTextureCache.h index 66daec1834..34bef246ca 100644 --- a/plugins/GSdx/GSTextureCache.h +++ b/plugins/GSdx/GSTextureCache.h @@ -72,7 +72,6 @@ public: bool GetDirtyRect(GSVector4i& r); public: - GIFRegCLAMP m_CLAMP; uint32* m_clut; // * GSVector4i m_valid; int m_bpp; @@ -96,6 +95,8 @@ protected: list m_ds; list m_tex; + bool m_tex_used; + template void RecycleByAge(list& l, int maxage = 60) { for(list::iterator i = l.begin(); i != l.end(); ) diff --git a/plugins/GSdx/GSTextureCache10.cpp b/plugins/GSdx/GSTextureCache10.cpp index ebc31259f3..e3c902d1e1 100644 --- a/plugins/GSdx/GSTextureCache10.cpp +++ b/plugins/GSdx/GSTextureCache10.cpp @@ -55,12 +55,7 @@ void GSTextureCache10::GSRenderTargetHW10::Update() TEXA.TA0 = 0; TEXA.TA1 = 0x80; - GIFRegCLAMP CLAMP; - - CLAMP.WMS = 0; - CLAMP.WMT = 0; - - m_renderer->m_mem.ReadTexture(r, buff, pitch, m_TEX0, TEXA, CLAMP); + m_renderer->m_mem.ReadTexture(r, buff, pitch, m_TEX0, TEXA); // s->m_perfmon.Put(GSPerfMon::Unswizzle, w * h * 4); @@ -182,7 +177,6 @@ bool GSTextureCache10::GSCachedTextureHW10::Create() // m_renderer->m_perfmon.Put(GSPerfMon::WriteTexture, 1); m_TEX0 = m_renderer->m_context->TEX0; - m_CLAMP = m_renderer->m_context->CLAMP; uint32 psm = m_TEX0.PSM; @@ -240,7 +234,6 @@ bool GSTextureCache10::GSCachedTextureHW10::Create(GSRenderTarget* rt) // m_renderer->m_perfmon.Put(GSPerfMon::ConvertRT2T, 1); m_TEX0 = m_renderer->m_context->TEX0; - m_CLAMP = m_renderer->m_context->CLAMP; m_rendered = true; int tw = 1 << m_TEX0.TW; diff --git a/plugins/GSdx/GSTextureCache9.cpp b/plugins/GSdx/GSTextureCache9.cpp index 2b98621de5..3c65349fdf 100644 --- a/plugins/GSdx/GSTextureCache9.cpp +++ b/plugins/GSdx/GSTextureCache9.cpp @@ -57,12 +57,7 @@ void GSTextureCache9::GSRenderTarget9::Update() TEXA.TA0 = 0; TEXA.TA1 = 0x80; - GIFRegCLAMP CLAMP; - - CLAMP.WMS = 0; - CLAMP.WMT = 0; - - m_renderer->m_mem.ReadTexture(r, bits, pitch, m_TEX0, TEXA, CLAMP); + m_renderer->m_mem.ReadTexture(r, bits, pitch, m_TEX0, TEXA); t->Unmap(); @@ -181,7 +176,6 @@ bool GSTextureCache9::GSCachedTexture9::Create() // m_renderer->m_perfmon.Put(GSPerfMon::WriteTexture, 1); m_TEX0 = m_renderer->m_context->TEX0; - m_CLAMP = m_renderer->m_context->CLAMP; uint32 psm = m_TEX0.PSM; @@ -239,7 +233,6 @@ bool GSTextureCache9::GSCachedTexture9::Create(GSRenderTarget* rt) // m_renderer->m_perfmon.Put(GSPerfMon::ConvertRT2T, 1); m_TEX0 = m_renderer->m_context->TEX0; - m_CLAMP = m_renderer->m_context->CLAMP; m_rendered = true; int tw = 1 << m_TEX0.TW; diff --git a/plugins/GSdx/GSTextureCacheSW.cpp b/plugins/GSdx/GSTextureCacheSW.cpp index 524521e5ec..ca7144a438 100644 --- a/plugins/GSdx/GSTextureCacheSW.cpp +++ b/plugins/GSdx/GSTextureCacheSW.cpp @@ -46,8 +46,7 @@ const GSTextureCacheSW::GSTexture* GSTextureCacheSW::Lookup(const GIFRegTEX0& TE { GSTexture* t2 = (*i).first; - // if(t2->m_TEX0.TBP0 != TEX0.TBP0 || t2->m_TEX0.TBW != TEX0.TBW || t2->m_TEX0.PSM != TEX0.PSM || t2->m_TEX0.TW != TEX0.TW || t2->m_TEX0.TH != TEX0.TH) - if(((t2->m_TEX0.u32[0] ^ TEX0.u32[0]) | ((t2->m_TEX0.u32[1] ^ TEX0.u32[1]) & 3)) != 0) + if(((t2->m_TEX0.u32[0] ^ TEX0.u32[0]) | ((t2->m_TEX0.u32[1] ^ TEX0.u32[1]) & 3)) != 0) // TBP0 TBW PSM TW TH { continue; } diff --git a/plugins/GSdx/GSTextureFX10.cpp b/plugins/GSdx/GSTextureFX10.cpp index 0dec170dcc..60d79f75dc 100644 --- a/plugins/GSdx/GSTextureFX10.cpp +++ b/plugins/GSdx/GSTextureFX10.cpp @@ -213,7 +213,7 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl if(i == m_ps.end()) { - string str[13]; + string str[14]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -228,6 +228,7 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl str[10] = format("%d", sel.clr1); str[11] = format("%d", sel.fba); str[12] = format("%d", sel.aout); + str[13] = format("%d", sel.ltf); D3D10_SHADER_MACRO macro[] = { @@ -244,6 +245,7 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl {"CLR1", str[10].c_str()}, {"FBA", str[11].c_str()}, {"AOUT", str[12].c_str()}, + {"LTF", str[13].c_str()}, {NULL, NULL}, }; @@ -280,11 +282,7 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl memset(&sd, 0, sizeof(sd)); - sd.Filter = D3D10_ENCODE_BASIC_FILTER( - (ssel.min ? D3D10_FILTER_TYPE_LINEAR : D3D10_FILTER_TYPE_POINT), - (ssel.mag ? D3D10_FILTER_TYPE_LINEAR : D3D10_FILTER_TYPE_POINT), - D3D10_FILTER_TYPE_POINT, - false); + sd.Filter = ssel.ltf ? D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT : D3D10_FILTER_MIN_MAG_MIP_POINT; sd.AddressU = ssel.tau ? D3D10_TEXTURE_ADDRESS_WRAP : D3D10_TEXTURE_ADDRESS_CLAMP; sd.AddressV = ssel.tav ? D3D10_TEXTURE_ADDRESS_WRAP : D3D10_TEXTURE_ADDRESS_CLAMP; diff --git a/plugins/GSdx/GSTextureFX10.h b/plugins/GSdx/GSTextureFX10.h index cc8653ca7e..3377acd1fd 100644 --- a/plugins/GSdx/GSTextureFX10.h +++ b/plugins/GSdx/GSTextureFX10.h @@ -77,7 +77,11 @@ public: __declspec(align(16)) struct PSConstantBuffer { - GSVector4 FogColor; + GSVector4 FogColorAREF; + GSVector4 HalfTexel; + GSVector2 WH; + float TA0; + float TA1; float MINU; float MINV; float MAXU; @@ -86,13 +90,6 @@ public: uint32 VMSK; uint32 UFIX; uint32 VFIX; - float TA0; - float TA1; - float AREF; - float _pad[1]; - GSVector2 WH; - GSVector2 rWrH; - GSVector4 HalfTexel; struct PSConstantBuffer() {memset(this, 0, sizeof(*this));} @@ -106,16 +103,14 @@ public: GSVector4i b2 = b[2]; GSVector4i b3 = b[3]; GSVector4i b4 = b[4]; - GSVector4i b5 = b[5]; - if(!((a[0] == b0) & (a[1] == b1) & (a[2] == b2) & (a[3] == b3) & (a[4] == b4) & (a[5] == b5)).alltrue()) + if(!((a[0] == b0) & (a[1] == b1) & (a[2] == b2) & (a[3] == b3) & (a[4] == b4)).alltrue()) { a[0] = b0; a[1] = b1; a[2] = b2; a[3] = b3; a[4] = b4; - a[5] = b5; return true; } @@ -124,6 +119,19 @@ public: } }; + union GSSelector + { + struct + { + uint32 iip:1; + uint32 prim:2; + }; + + uint32 key; + + operator uint32() {return key & 0x7;} + }; + union PSSelector { struct @@ -141,24 +149,12 @@ public: uint32 clr1:1; uint32 fba:1; uint32 aout:1; + uint32 ltf:1; }; uint32 key; - operator uint32() {return key & 0x1fffff;} - }; - - union GSSelector - { - struct - { - uint32 iip:1; - uint32 prim:2; - }; - - uint32 key; - - operator uint32() {return key & 0x7;} + operator uint32() {return key & 0x3fffff;} }; union PSSamplerSelector @@ -167,13 +163,12 @@ public: { uint32 tau:1; uint32 tav:1; - uint32 min:1; - uint32 mag:1; + uint32 ltf:1; }; uint32 key; - operator uint32() {return key & 0xf;} + operator uint32() {return key & 0x7;} }; union OMDepthStencilSelector diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index 7abf2a550c..31f27b0983 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -180,7 +180,7 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample if(i == m_ps.end()) { - string str[12]; + string str[13]; str[0] = format("%d", sel.fst); str[1] = format("%d", sel.wms); @@ -194,6 +194,7 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample str[9] = format("%d", sel.fog); str[10] = format("%d", sel.clr1); str[11] = format("%d", sel.rt); + str[12] = format("%d", sel.ltf); D3DXMACRO macro[] = { @@ -209,6 +210,7 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample {"FOG", str[9].c_str()}, {"CLR1", str[10].c_str()}, {"RT", str[11].c_str()}, + {"LTF", str[12].c_str()}, {NULL, NULL}, }; @@ -227,10 +229,10 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample if(sel.tfx != 4) { - bool b = sel.bpp < 3 && sel.wms < 3 && sel.wmt < 3; - - ssel.min = b; - ssel.mag = b; + if(!(sel.bpp < 3 && sel.wms < 3 && sel.wmt < 3)) + { + ssel.ltf = 0; + } hash_map::const_iterator i = m_ps_ss.find(ssel); @@ -244,8 +246,8 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample memset(ss, 0, sizeof(*ss)); - ss->FilterMin[0] = ssel.min ? D3DTEXF_LINEAR : D3DTEXF_POINT; - ss->FilterMag[0] = ssel.mag ? D3DTEXF_LINEAR : D3DTEXF_POINT; + ss->FilterMin[0] = ssel.ltf ? D3DTEXF_LINEAR : D3DTEXF_POINT; + ss->FilterMag[0] = ssel.ltf ? D3DTEXF_LINEAR : D3DTEXF_POINT; ss->FilterMin[1] = D3DTEXF_POINT; ss->FilterMag[1] = D3DTEXF_POINT; diff --git a/plugins/GSdx/GSTextureFX9.h b/plugins/GSdx/GSTextureFX9.h index 54fbb258ca..e3e1b5823e 100644 --- a/plugins/GSdx/GSTextureFX9.h +++ b/plugins/GSdx/GSTextureFX9.h @@ -53,7 +53,11 @@ public: struct PSConstantBuffer { - GSVector4 FogColor; + GSVector4 FogColorAREF; + GSVector4 HalfTexel; + GSVector2 WH; + float TA0; + float TA1; float MINU; float MINV; float MAXU; @@ -62,13 +66,6 @@ public: uint32 VMSK; uint32 UFIX; uint32 VFIX; - float TA0; - float TA1; - float AREF; - float _pad[1]; - GSVector2 WH; - GSVector2 rWrH; - GSVector4 HalfTexel; }; union PSSelector @@ -87,11 +84,12 @@ public: uint32 fog:1; uint32 clr1:1; uint32 rt:1; + uint32 ltf:1; }; uint32 key; - operator uint32() {return key & 0xfffff;} + operator uint32() {return key & 0x1fffff;} }; union PSSamplerSelector @@ -100,13 +98,12 @@ public: { uint32 tau:1; uint32 tav:1; - uint32 min:1; - uint32 mag:1; + uint32 ltf:1; }; uint32 key; - operator uint32() {return key & 0xf;} + operator uint32() {return key & 0x7;} }; union OMDepthStencilSelector diff --git a/plugins/GSdx/GSdx_vs2008.vcproj b/plugins/GSdx/GSdx_vs2008.vcproj index e71c4955e4..ba86150a75 100644 --- a/plugins/GSdx/GSdx_vs2008.vcproj +++ b/plugins/GSdx/GSdx_vs2008.vcproj @@ -1398,6 +1398,14 @@ + + +