2010-03-26 05:56:40 +00:00
|
|
|
/* ZeroGS KOSMOS
|
|
|
|
* Copyright (C) 2005-2006 zerofrog@gmail.com
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-26 05:56:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GS.h"
|
|
|
|
#include "Mem.h"
|
|
|
|
#include "Mem_Swizzle.h"
|
|
|
|
|
|
|
|
// special swizzle macros - which I converted to functions.
|
|
|
|
#ifdef ZEROGS_SSE2
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock32(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock32_sse2(dst, src, pitch, WriteMask);
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock16(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock16_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock8(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock8_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock4(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock4_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock32u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock32u_sse2(dst, src, pitch, WriteMask);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock16u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock16u_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock8u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock8u_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock4u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock4u_sse2(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-26 05:56:40 +00:00
|
|
|
#else
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock32(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock32_c(dst, src, pitch, WriteMask);
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock16(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock16_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock8(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock8_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock4(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock4_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock32u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock32_c(dst, src, pitch, WriteMask);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock16u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock16_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock8u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock8_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock4u(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
SwizzleBlock4_c(dst, src, pitch/*, WriteMask*/);
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void __fastcall SwizzleBlock32_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u32* d = &g_columnTable32[0][0];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (WriteMask == 0xffffffff)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
|
|
|
|
for (int i = 0; i < 8; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
((u32*)dst)[d[i]] = ((u32*)src)[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
|
|
|
|
for (int i = 0; i < 8; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
((u32*)dst)[d[i]] = (((u32*)dst)[d[i]] & ~WriteMask) | (((u32*)src)[i] & WriteMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__forceinline void __fastcall SwizzleBlock24_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u32* d = &g_columnTable32[0][0];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (WriteMask == 0x00ffffff)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
|
|
|
|
for (int i = 0; i < 8; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
((u32*)dst)[d[i]] = ((u32*)src)[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 8; j++, d += 8, src += srcpitch)
|
|
|
|
for (int i = 0; i < 8; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
((u32*)dst)[d[i]] = (((u32*)dst)[d[i]] & ~WriteMask) | (((u32*)src)[i] & WriteMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void __fastcall SwizzleBlock16_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u32* d = &g_columnTable16[0][0];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 8; j++, d += 16, src += srcpitch)
|
|
|
|
for (int i = 0; i < 16; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
((u16*)dst)[d[i]] = ((u16*)src)[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void __fastcall SwizzleBlock8_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u32* d = &g_columnTable8[0][0];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 16; j++, d += 16, src += srcpitch)
|
|
|
|
for (int i = 0; i < 16; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
dst[d[i]] = src[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void __fastcall SwizzleBlock4_c(u8* dst, u8* src, int srcpitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u32* d = &g_columnTable4[0][0];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int j = 0; j < 16; j++, d += 32, src += srcpitch)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < 32; i++)
|
2010-03-26 05:56:40 +00:00
|
|
|
{
|
|
|
|
u32 addr = d[i];
|
2010-05-01 20:33:53 +00:00
|
|
|
u8 c = (src[i>>1] >> ((i & 1) << 2)) & 0x0f;
|
|
|
|
u32 shift = (addr & 1) << 2;
|
2010-03-26 05:56:40 +00:00
|
|
|
dst[addr >> 1] = (dst[addr >> 1] & (0xf0 >> shift)) | (c << shift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-26 05:56:40 +00:00
|
|
|
#endif
|
2010-04-25 00:31:27 +00:00
|
|
|
__forceinline void SwizzleBlock24(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u8* pnewsrc = src;
|
|
|
|
u32* pblock = tempblock;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int by = 0; by < 7; ++by, pblock += 8, pnewsrc += pitch - 24)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int bx = 0; bx < 8; ++bx, pnewsrc += 3)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
pblock[bx] = *(u32*)pnewsrc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int bx = 0; bx < 7; ++bx, pnewsrc += 3)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
/* might be 1 byte out of bounds of GS memory */
|
|
|
|
pblock[bx] = *(u32*)pnewsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do 3 bytes for the last copy */
|
2010-05-01 20:33:53 +00:00
|
|
|
*((u8*)pblock + 28) = pnewsrc[0];
|
|
|
|
|
|
|
|
*((u8*)pblock + 29) = pnewsrc[1];
|
|
|
|
|
|
|
|
*((u8*)pblock + 30) = pnewsrc[2];
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0x00ffffff);
|
|
|
|
}
|
2010-03-26 05:56:40 +00:00
|
|
|
|
|
|
|
__forceinline void SwizzleBlock8H(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
u8* pnewsrc = src;
|
|
|
|
u32* pblock = tempblock;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
u32 u = *(u32*)pnewsrc;
|
2010-05-01 20:33:53 +00:00
|
|
|
pblock[0] = u << 24;
|
|
|
|
pblock[1] = u << 16;
|
|
|
|
pblock[2] = u << 8;
|
2010-04-25 00:31:27 +00:00
|
|
|
pblock[3] = u;
|
2010-05-01 20:33:53 +00:00
|
|
|
u = *(u32*)(pnewsrc + 4);
|
|
|
|
pblock[4] = u << 24;
|
|
|
|
pblock[5] = u << 16;
|
|
|
|
pblock[6] = u << 8;
|
2010-04-25 00:31:27 +00:00
|
|
|
pblock[7] = u;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0xff000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void SwizzleBlock4HH(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u8* pnewsrc = src;
|
|
|
|
u32* pblock = tempblock;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
u32 u = *(u32*)pnewsrc;
|
2010-05-01 20:33:53 +00:00
|
|
|
pblock[0] = u << 28;
|
|
|
|
pblock[1] = u << 24;
|
|
|
|
pblock[2] = u << 20;
|
|
|
|
pblock[3] = u << 16;
|
|
|
|
pblock[4] = u << 12;
|
|
|
|
pblock[5] = u << 8;
|
|
|
|
pblock[6] = u << 4;
|
2010-04-25 00:31:27 +00:00
|
|
|
pblock[7] = u;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0xf0000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void SwizzleBlock4HL(u8 *dst, u8 *src, int pitch, u32 WriteMask)
|
|
|
|
{
|
|
|
|
u8* pnewsrc = src;
|
|
|
|
u32* pblock = tempblock;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int by = 0; by < 8; ++by, pblock += 8, pnewsrc += pitch)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
|
|
|
u32 u = *(u32*)pnewsrc;
|
2010-05-01 20:33:53 +00:00
|
|
|
pblock[0] = u << 24;
|
|
|
|
pblock[1] = u << 20;
|
|
|
|
pblock[2] = u << 16;
|
|
|
|
pblock[3] = u << 12;
|
|
|
|
pblock[4] = u << 8;
|
|
|
|
pblock[5] = u << 4;
|
2010-04-25 00:31:27 +00:00
|
|
|
pblock[6] = u;
|
2010-05-01 20:33:53 +00:00
|
|
|
pblock[7] = u >> 4;
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
SwizzleBlock32((u8*)dst, (u8*)tempblock, 32, 0x0f000000);
|
|
|
|
}
|