zzogl-pg: Turn all the TRANSMIT_HOSTLOCAL macros into functions.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2761 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-03-21 06:22:55 +00:00
parent c697f6e6da
commit 6db10003de
2 changed files with 557 additions and 481 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,173 +5,241 @@
#include "Mem.h"
#define DSTPSM gs.dstbuf.psm
extern int tempX, tempY;
extern int pitch, area, fracX;
extern int nSize;
extern u8* pstart;
// transfers whole rows
#define TRANSMIT_HOSTLOCAL_Y_(psm, T, widthlimit, endY) { \
assert( (nSize%widthlimit) == 0 && widthlimit <= 4 ); \
if( (gs.imageEndX-gs.trxpos.dx)%widthlimit ) { \
/*GS_LOG("Bad Transmission! %d %d, psm: %d\n", gs.trxpos.dx, gs.imageEndX, DSTPSM);*/ \
for(; i < endY; ++i) { \
for(; j < gs.imageEndX && nSize > 0; j += 1, nSize -= 1, pbuf += 1) { \
/* write as many pixel at one time as possible */ \
writePixel##psm##_0(pstart, j%2048, i%2048, pbuf[0], gs.dstbuf.bw); \
} \
} \
} \
for(; i < endY; ++i) { \
for(; j < gs.imageEndX && nSize > 0; j += widthlimit, nSize -= widthlimit, pbuf += widthlimit) { \
/* write as many pixel at one time as possible */ \
if( nSize < widthlimit ) goto End; \
writePixel##psm##_0(pstart, j%2048, i%2048, pbuf[0], gs.dstbuf.bw); \
\
if( widthlimit > 1 ) { \
writePixel##psm##_0(pstart, (j+1)%2048, i%2048, pbuf[1], gs.dstbuf.bw); \
\
if( widthlimit > 2 ) { \
writePixel##psm##_0(pstart, (j+2)%2048, i%2048, pbuf[2], gs.dstbuf.bw); \
\
if( widthlimit > 3 ) { \
writePixel##psm##_0(pstart, (j+3)%2048, i%2048, pbuf[3], gs.dstbuf.bw); \
} \
} \
} \
} \
\
if( j >= gs.imageEndX ) { assert(j == gs.imageEndX); j = gs.trxpos.dx; } \
else { assert( gs.imageTransfer == -1 || nSize*sizeof(T)/4 == 0 ); goto End; } \
} \
} \
template <class T>
static __forceinline bool TransmitHostLocalY_(_writePixel_0 wp, u32 widthlimit, u32 endY, const T *pbuf)
{
assert( (nSize%widthlimit) == 0 && widthlimit <= 4 );
if ((gs.imageEndX-gs.trxpos.dx) % widthlimit)
{
// GS_LOG("Bad Transmission! %d %d, psm: %d\n", gs.trxpos.dx, gs.imageEndX, DSTPSM);
for(; tempY < endY; ++tempY)
{
for(; tempX < gs.imageEndX && nSize > 0; tempX += 1, nSize -= 1, pbuf += 1)
{
/* write as many pixel at one time as possible */
wp(pstart, tempX%2048, tempY%2048, pbuf[0], gs.dstbuf.bw);
}
}
}
for(; tempY < endY; ++tempY)
{
for(; tempX < gs.imageEndX && nSize > 0; tempX += widthlimit, nSize -= widthlimit, pbuf += widthlimit)
{
/* write as many pixel at one time as possible */
if( nSize < widthlimit ) return false;
wp(pstart, tempX%2048, tempY%2048, pbuf[0], gs.dstbuf.bw);
if( widthlimit > 1 )
{
wp(pstart, (tempX+1)%2048, tempY%2048, pbuf[1], gs.dstbuf.bw);
if( widthlimit > 2 )
{
wp(pstart, (tempX+2)%2048, tempY%2048, pbuf[2], gs.dstbuf.bw);
if( widthlimit > 3 )
{
wp(pstart, (tempX+3)%2048, tempY%2048, pbuf[3], gs.dstbuf.bw);
}
}
}
}
if ( tempX >= gs.imageEndX )
{
assert(tempX == gs.imageEndX);
tempX = gs.trxpos.dx;
}
else
{
assert( gs.imageTransfer == -1 || nSize*sizeof(T)/4 == 0 );
return false;
}
}
return true;
}
// transmit until endX, don't check size since it has already been prevalidated
#define TRANSMIT_HOSTLOCAL_X_(psm, T, widthlimit, blockheight, startX) { \
for(int tempi = 0; tempi < blockheight; ++tempi) { \
for(j = startX; j < gs.imageEndX; j++, pbuf++) { \
writePixel##psm##_0(pstart, j%2048, (i+tempi)%2048, pbuf[0], gs.dstbuf.bw); \
} \
pbuf += pitch-fracX; \
} \
} \
//template <class T>
//static __forceinline void TransmitHostLocalX_(_writePixel_0 wp, u32 widthlimit, u32 blockheight, u32 startX)
//{
// for(int tempi = 0; tempi < blockheight; ++tempi)
// {
// for(j = startX; j < gs.imageEndX; j++, pbuf++)
// {
// wp(pstart, j%2048, (i+tempi)%2048, pbuf[0], gs.dstbuf.bw);
// }
// pbuf += pitch - fracX;
// }
//}
template <class T>
static __forceinline bool TransmitHostLocalX_(_writePixel_0 wp, u32 widthlimit, u32 blockheight, u32 startX, const T *pbuf)
{
for(int tempi = 0; tempi < blockheight; ++tempi)
{
for(tempX = startX; tempX < gs.imageEndX; tempX++, pbuf++)
{
wp(pstart, tempX%2048, (tempY+tempi)%2048, pbuf[0], gs.dstbuf.bw);
}
pbuf += pitch - fracX;
}
return true;
}
// transfers whole rows
#define TRANSMIT_HOSTLOCAL_Y_24(psm, T, widthlimit, endY) { \
if( widthlimit != 8 || ((gs.imageEndX-gs.trxpos.dx)%widthlimit) ) { \
/*GS_LOG("Bad Transmission! %d %d, psm: %d\n", gs.trxpos.dx, gs.imageEndX, DSTPSM);*/ \
for(; i < endY; ++i) { \
for(; j < gs.imageEndX && nSize > 0; j += 1, nSize -= 1, pbuf += 3) { \
writePixel##psm##_0(pstart, j%2048, i%2048, *(u32*)(pbuf), gs.dstbuf.bw); \
} \
\
if( j >= gs.imageEndX ) { assert(gs.imageTransfer == -1 || j == gs.imageEndX); j = gs.trxpos.dx; } \
else { assert( gs.imageTransfer == -1 || nSize == 0 ); goto End; } \
} \
} \
else { \
assert( /*(nSize%widthlimit) == 0 &&*/ widthlimit == 8 ); \
for(; i < endY; ++i) { \
for(; j < gs.imageEndX && nSize > 0; j += widthlimit, nSize -= widthlimit, pbuf += 3*widthlimit) { \
if( nSize < widthlimit ) goto End; \
/* write as many pixel at one time as possible */ \
writePixel##psm##_0(pstart, j%2048, i%2048, *(u32*)(pbuf+0), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+1)%2048, i%2048, *(u32*)(pbuf+3), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+2)%2048, i%2048, *(u32*)(pbuf+6), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+3)%2048, i%2048, *(u32*)(pbuf+9), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+4)%2048, i%2048, *(u32*)(pbuf+12), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+5)%2048, i%2048, *(u32*)(pbuf+15), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+6)%2048, i%2048, *(u32*)(pbuf+18), gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+7)%2048, i%2048, *(u32*)(pbuf+21), gs.dstbuf.bw); \
} \
\
if( j >= gs.imageEndX ) { assert(gs.imageTransfer == -1 || j == gs.imageEndX); j = gs.trxpos.dx; } \
else { \
if( nSize < 0 ) { \
/* extracted too much */ \
assert( (nSize%3)==0 && nSize > -24 ); \
j += nSize/3; \
nSize = 0; \
} \
assert( gs.imageTransfer == -1 || nSize == 0 ); \
goto End; \
} \
} \
} \
} \
template <class T>
static __forceinline bool TransmitHostLocalY_24(_writePixel_0 wp, u32 widthlimit, u32 endY, const T *pbuf)
{
if (widthlimit != 8 || ((gs.imageEndX-gs.trxpos.dx)%widthlimit))
{
//GS_LOG("Bad Transmission! %d %d, psm: %d\n", gs.trxpos.dx, gs.imageEndX, DSTPSM);
for(; tempY < endY; ++tempY)
{
for(; tempX < gs.imageEndX && nSize > 0; tempX += 1, nSize -= 1, pbuf += 3)
{
wp(pstart, tempX%2048, tempY%2048, *(u32*)(pbuf), gs.dstbuf.bw);
}
if( tempX >= gs.imageEndX )
{
assert(gs.imageTransfer == -1 || tempX == gs.imageEndX);
tempX = gs.trxpos.dx;
}
else
{
assert( gs.imageTransfer == -1 || nSize == 0 );
return false;
}
}
}
else
{
assert( /*(nSize%widthlimit) == 0 &&*/ widthlimit == 8 );
for(; tempY < endY; ++tempY)
{
for(; tempX < gs.imageEndX && nSize > 0; tempX += widthlimit, nSize -= widthlimit, pbuf += 3*widthlimit)
{
if (nSize < widthlimit) return false;
/* write as many pixel at one time as possible */
wp(pstart, tempX%2048, tempY%2048, *(u32*)(pbuf+0), gs.dstbuf.bw);
wp(pstart, (tempX+1)%2048, tempY%2048, *(u32*)(pbuf+3), gs.dstbuf.bw);
wp(pstart, (tempX+2)%2048, tempY%2048, *(u32*)(pbuf+6), gs.dstbuf.bw);
wp(pstart, (tempX+3)%2048, tempY%2048, *(u32*)(pbuf+9), gs.dstbuf.bw);
wp(pstart, (tempX+4)%2048, tempY%2048, *(u32*)(pbuf+12), gs.dstbuf.bw);
wp(pstart, (tempX+5)%2048, tempY%2048, *(u32*)(pbuf+15), gs.dstbuf.bw);
wp(pstart, (tempX+6)%2048, tempY%2048, *(u32*)(pbuf+18), gs.dstbuf.bw);
wp(pstart, (tempX+7)%2048, tempY%2048, *(u32*)(pbuf+21), gs.dstbuf.bw);
}
if (tempX >= gs.imageEndX)
{
assert(gs.imageTransfer == -1 || tempX == gs.imageEndX);
tempX = gs.trxpos.dx;
}
else
{
if ( nSize < 0 )
{
/* extracted too much */
assert( (nSize%3)==0 && nSize > -24 );
tempX += nSize/3;
nSize = 0;
}
assert( gs.imageTransfer == -1 || nSize == 0 );
return false;
}
}
}
return true;
}
// transmit until endX, don't check size since it has already been prevalidated
#define TRANSMIT_HOSTLOCAL_X_24(psm, T, widthlimit, blockheight, startX) { \
for(int tempi = 0; tempi < blockheight; ++tempi) { \
for(j = startX; j < gs.imageEndX; j++, pbuf += 3) { \
writePixel##psm##_0(pstart, j%2048, (i+tempi)%2048, *(u32*)pbuf, gs.dstbuf.bw); \
} \
pbuf += 3*(pitch-fracX); \
} \
} \
template <class T>
static __forceinline bool TransmitHostLocalX_24(_writePixel_0 wp, u32 widthlimit, u32 blockheight, u32 startX, const T *pbuf)
{
for(int tempi = 0; tempi < blockheight; ++tempi)
{
for(tempX = startX; tempX < gs.imageEndX; tempX++, pbuf += 3)
{
wp(pstart, tempX%2048, (tempY+tempi)%2048, *(u32*)pbuf, gs.dstbuf.bw);
}
pbuf += 3*(pitch-fracX);
}
return true;
}
// meant for 4bit transfers
#define TRANSMIT_HOSTLOCAL_Y_4(psm, T, widthlimit, endY) { \
for(; i < endY; ++i) { \
for(; j < gs.imageEndX && nSize > 0; j += widthlimit, nSize -= widthlimit) { \
/* write as many pixel at one time as possible */ \
writePixel##psm##_0(pstart, j%2048, i%2048, *pbuf&0x0f, gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+1)%2048, i%2048, *pbuf>>4, gs.dstbuf.bw); \
pbuf++; \
if( widthlimit > 2 ) { \
writePixel##psm##_0(pstart, (j+2)%2048, i%2048, *pbuf&0x0f, gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+3)%2048, i%2048, *pbuf>>4, gs.dstbuf.bw); \
pbuf++; \
\
if( widthlimit > 4 ) { \
writePixel##psm##_0(pstart, (j+4)%2048, i%2048, *pbuf&0x0f, gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+5)%2048, i%2048, *pbuf>>4, gs.dstbuf.bw); \
pbuf++; \
\
if( widthlimit > 6 ) { \
writePixel##psm##_0(pstart, (j+6)%2048, i%2048, *pbuf&0x0f, gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+7)%2048, i%2048, *pbuf>>4, gs.dstbuf.bw); \
pbuf++; \
} \
} \
} \
} \
\
if( j >= gs.imageEndX ) { j = gs.trxpos.dx; } \
else { assert( gs.imageTransfer == -1 || (nSize/32) == 0 ); goto End; } \
} \
} \
template <class T>
static __forceinline bool TransmitHostLocalY_4(_writePixel_0 wp, u32 widthlimit, u32 endY, const T *pbuf)
{
for(; tempY < endY; ++tempY)
{
for(; tempX < gs.imageEndX && nSize > 0; tempX += widthlimit, nSize -= widthlimit)
{
/* write as many pixel at one time as possible */
wp(pstart, tempX%2048, tempY%2048, *pbuf&0x0f, gs.dstbuf.bw);
wp(pstart, (tempX+1)%2048, tempY%2048, *pbuf>>4, gs.dstbuf.bw);
pbuf++;
if ( widthlimit > 2 )
{
wp(pstart, (tempX+2)%2048, tempY%2048, *pbuf&0x0f, gs.dstbuf.bw);
wp(pstart, (tempX+3)%2048, tempY%2048, *pbuf>>4, gs.dstbuf.bw);
pbuf++;
if( widthlimit > 4 )
{
wp(pstart, (tempX+4)%2048, tempY%2048, *pbuf&0x0f, gs.dstbuf.bw);
wp(pstart, (tempX+5)%2048, tempY%2048, *pbuf>>4, gs.dstbuf.bw);
pbuf++;
if( widthlimit > 6 )
{
wp(pstart, (tempX+6)%2048, tempY%2048, *pbuf&0x0f, gs.dstbuf.bw);
wp(pstart, (tempX+7)%2048, tempY%2048, *pbuf>>4, gs.dstbuf.bw);
pbuf++;
}
}
}
}
if ( tempX >= gs.imageEndX )
{
tempX = gs.trxpos.dx;
}
else
{
assert( gs.imageTransfer == -1 || (nSize/32) == 0 );
return false;
}
}
return true;
}
// transmit until endX, don't check size since it has already been prevalidated
#define TRANSMIT_HOSTLOCAL_X_4(psm, T, widthlimit, blockheight, startX) { \
for(int tempi = 0; tempi < blockheight; ++tempi) { \
for(j = startX; j < gs.imageEndX; j+=2, pbuf++) { \
writePixel##psm##_0(pstart, j%2048, (i+tempi)%2048, pbuf[0]&0x0f, gs.dstbuf.bw); \
writePixel##psm##_0(pstart, (j+1)%2048, (i+tempi)%2048, pbuf[0]>>4, gs.dstbuf.bw); \
} \
pbuf += (pitch-fracX)/2; \
} \
} \
template <class T>
static __forceinline bool TransmitHostLocalX_4(_writePixel_0 wp, u32 widthlimit, u32 blockheight, u32 startX, const T *pbuf)
{
for(int tempi = 0; tempi < blockheight; ++tempi)
{
for(tempX = startX; tempX < gs.imageEndX; tempX+=2, pbuf++)
{
wp(pstart, tempX%2048, (tempY+tempi)%2048, pbuf[0]&0x0f, gs.dstbuf.bw);
wp(pstart, (tempX+1)%2048, (tempY+tempi)%2048, pbuf[0]>>4, gs.dstbuf.bw);
}
pbuf += (pitch-fracX)/2;
}
return true;
}
#define TRANSMIT_HOSTLOCAL_X(th, psm, T, widthlimit, blockheight, startX) \
TRANSMIT_HOSTLOCAL_X##th(psm, T, widthlimit, blockheight, startX)
#define TRANSMIT_HOSTLOCAL_Y(th, psm, T, widthlimit, endY) \
TRANSMIT_HOSTLOCAL_Y##th(psm,T,widthlimit,endY)
// calculate pitch in source buffer
static __forceinline u32 TransPitch(u32 pitch, u32 size)
{
return pitch * size / 8;
}
static __forceinline u32 TransPitch2(u32 pitch, u32 size)
{
if (size == 4) return pitch / 2;
if (size == 24) return pitch * 3;
return pitch;
}
#endif // MEM_TRANSMIT_H_INCLUDED