diff --git a/plugins/GSdx/GS.h b/plugins/GSdx/GS.h index 561cd09130..239b8f769c 100644 --- a/plugins/GSdx/GS.h +++ b/plugins/GSdx/GS.h @@ -24,6 +24,7 @@ #define PLUGIN_VERSION 0 #define VM_SIZE 4194304 +#define HALF_VM_SIZE (VM_SIZE / 2) #define PAGE_SIZE 8192 #define BLOCK_SIZE 256 #define COLUMN_SIZE 64 diff --git a/plugins/GSdx/GSDrawScanline.cpp b/plugins/GSdx/GSDrawScanline.cpp index 3cf739d071..169dcf73eb 100644 --- a/plugins/GSdx/GSDrawScanline.cpp +++ b/plugins/GSdx/GSDrawScanline.cpp @@ -532,7 +532,7 @@ void GSDrawScanline::DrawScanline(int pixels, int left, int top, const GSVertexS if(sel.zb) { - za = fza_base->y + fza_offset->y; + za = (fza_base->y + fza_offset->y) % HALF_VM_SIZE; if(sel.prim != GS_SPRITE_CLASS) { @@ -1130,7 +1130,7 @@ void GSDrawScanline::DrawScanline(int pixels, int left, int top, const GSVertexS if(sel.fb) { - fa = fza_base->x + fza_offset->x; + fa = (fza_base->x + fza_offset->x) % HALF_VM_SIZE; if(sel.rfb) { @@ -1646,7 +1646,7 @@ void GSDrawScanline::DrawScanline(int pixels, int left, int top, const GSVertexS if(sel.zb) { - za = fza_base->y + fza_offset->y; + za = (fza_base->y + fza_offset->y) % HALF_VM_SIZE; if(sel.prim != GS_SPRITE_CLASS) { @@ -2249,7 +2249,7 @@ void GSDrawScanline::DrawScanline(int pixels, int left, int top, const GSVertexS if(sel.fb) { - fa = fza_base->x + fza_offset->x; + fa = (fza_base->x + fza_offset->x) % HALF_VM_SIZE; if(sel.rfb) { diff --git a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx.cpp b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx.cpp index 2b3daf0794..250432ff2b 100644 --- a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx.cpp +++ b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx.cpp @@ -607,6 +607,7 @@ void GSDrawScanlineCodeGenerator::TestZ(const Xmm& temp1, const Xmm& temp2) mov(ebp, ptr[esi + 4]); add(ebp, ptr[edi + 4]); + and(ebp, HALF_VM_SIZE - 1); // GSVector4i zs = zi; @@ -2292,6 +2293,7 @@ void GSDrawScanlineCodeGenerator::ReadFrame() mov(ebx, ptr[esi]); add(ebx, ptr[edi]); + and(ebx, HALF_VM_SIZE - 1); if(!m_sel.rfb) { @@ -2903,4 +2905,4 @@ void GSDrawScanlineCodeGenerator::ReadTexel(const Xmm& dst, const Xmm& addr, uin else vpinsrd(dst, src, i); } -#endif \ No newline at end of file +#endif diff --git a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx2.cpp b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx2.cpp index 4bcb7261a8..9c8d4e776c 100644 --- a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx2.cpp +++ b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.avx2.cpp @@ -608,6 +608,7 @@ void GSDrawScanlineCodeGenerator::TestZ(const Ymm& temp1, const Ymm& temp2) mov(ebp, ptr[esi + 4]); add(ebp, ptr[edi + 4]); + and(ebp, HALF_VM_SIZE - 1); // GSVector8i zs = zi; @@ -2257,6 +2258,7 @@ void GSDrawScanlineCodeGenerator::ReadFrame() mov(ebx, ptr[esi]); add(ebx, ptr[edi]); + and(ebx, HALF_VM_SIZE - 1); if(!m_sel.rfb) { @@ -2952,4 +2954,4 @@ void GSDrawScanlineCodeGenerator::ReadTexel(const Ymm& dst, const Ymm& addr, uin } -#endif \ No newline at end of file +#endif diff --git a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.cpp b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.cpp index 93f4deaa0e..42c4b74ae9 100644 --- a/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.cpp +++ b/plugins/GSdx/GSDrawScanlineCodeGenerator.x86.cpp @@ -611,6 +611,7 @@ void GSDrawScanlineCodeGenerator::TestZ(const Xmm& temp1, const Xmm& temp2) mov(ebp, ptr[esi + 4]); add(ebp, ptr[edi + 4]); + and(ebp, HALF_VM_SIZE - 1); // GSVector4i zs = zi; @@ -2360,6 +2361,7 @@ void GSDrawScanlineCodeGenerator::ReadFrame() mov(ebx, ptr[esi]); add(ebx, ptr[edi]); + and(ebx, HALF_VM_SIZE - 1); if(!m_sel.rfb) { diff --git a/plugins/GSdx/GSLocalMemory.h b/plugins/GSdx/GSLocalMemory.h index 44c578802e..78981c5087 100644 --- a/plugins/GSdx/GSLocalMemory.h +++ b/plugins/GSdx/GSLocalMemory.h @@ -319,7 +319,7 @@ public: static __forceinline uint32 PixelAddress32(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 5) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 5) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 11) + pageOffset32[bp & 0x1f][y & 0x1f][x & 0x3f]; return word; @@ -327,7 +327,7 @@ public: static __forceinline uint32 PixelAddress16(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 6) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 12) + pageOffset16[bp & 0x1f][y & 0x3f][x & 0x3f]; return word; @@ -335,7 +335,7 @@ public: static __forceinline uint32 PixelAddress16S(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 6) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 12) + pageOffset16S[bp & 0x1f][y & 0x3f][x & 0x3f]; return word; @@ -345,7 +345,7 @@ public: { // ASSERT((bw & 1) == 0); // allowed for mipmap levels - uint32 page = (bp >> 5) + (y >> 6) * (bw >> 1) + (x >> 7); + uint32 page = ((bp >> 5) + (y >> 6) * (bw >> 1) + (x >> 7)) % MAX_PAGES; uint32 word = (page << 13) + pageOffset8[bp & 0x1f][y & 0x3f][x & 0x7f]; return word; @@ -355,7 +355,7 @@ public: { // ASSERT((bw & 1) == 0); // allowed for mipmap levels - uint32 page = (bp >> 5) + (y >> 7) * (bw >> 1) + (x >> 7); + uint32 page = ((bp >> 5) + (y >> 7) * (bw >> 1) + (x >> 7)) % MAX_PAGES; uint32 word = (page << 14) + pageOffset4[bp & 0x1f][y & 0x7f][x & 0x7f]; return word; @@ -363,7 +363,7 @@ public: static __forceinline uint32 PixelAddress32Z(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 5) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 5) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 11) + pageOffset32Z[bp & 0x1f][y & 0x1f][x & 0x3f]; return word; @@ -371,7 +371,7 @@ public: static __forceinline uint32 PixelAddress16Z(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 6) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 12) + pageOffset16Z[bp & 0x1f][y & 0x3f][x & 0x3f]; return word; @@ -379,7 +379,7 @@ public: static __forceinline uint32 PixelAddress16SZ(int x, int y, uint32 bp, uint32 bw) { - uint32 page = (bp >> 5) + (y >> 6) * bw + (x >> 6); + uint32 page = ((bp >> 5) + (y >> 6) * bw + (x >> 6)) % MAX_PAGES; uint32 word = (page << 12) + pageOffset16SZ[bp & 0x1f][y & 0x3f][x & 0x3f]; return word;