zzogl-pg: Fix a few game crashes in Windows. (Reverted a few misc changes in r2833.)

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2865 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-04-16 04:17:46 +00:00
parent 9f7032d0f6
commit 6d6eb253c6
1 changed files with 46 additions and 59 deletions

View File

@ -1875,7 +1875,6 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
{
FUNCLOG
int start, end, nClutOffset, clutsize;
const int TexWidth = GPU_TEXWIDTH * 4;
MemoryTarget_GetClutVariables (nClutOffset, clutsize, tex0);
MemoryTarget_GetMemAddress(start, end, tex0);
@ -1883,32 +1882,31 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
ZeroGS::CMemoryTarget* it = MemoryTarget_SearchExistTarget (start, end, nClutOffset, clutsize, tex0, forcevalidate);
if (it != NULL) return it;
// couldn't find, so create.
// couldn't find so create
CMemoryTarget* targ;
u32 fmt = GL_UNSIGNED_BYTE;
if (PSMT_ISHALF_STORAGE(tex0))
{
fmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
}
if (PSMT_ISHALF_STORAGE(tex0)) fmt = GL_UNSIGNED_SHORT_1_5_5_5_REV;
int widthmult = 1;
int channels = NumberOfChannels(tex0.psm);
if ((g_MaxTexHeight < 4096) && (end-start > g_MaxTexHeight)) widthmult = 2;
int channels = 1;
channels = NumberOfChannels(tex0.psm);
targ = MemoryTarget_ClearedTargetsSearch(fmt, widthmult, channels, end - start);
// fill local clut
if (PSMT_ISCLUT(tex0.psm))
{
assert( clutsize > 0 );
targ->cpsm = tex0.cpsm;
targ->clut.reserve(256*4); // no matter what
targ->clut.resize(clutsize);
if (PSMT_IS32BIT(tex0.cpsm)) // 32 bit
if (PSMT_IS32BIT(tex0.cpsm))
{
memcpy_amd(&targ->clut[0], g_pbyGSClut+nClutOffset, clutsize);
}
@ -1916,7 +1914,6 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
{
u16* pClutBuffer = (u16*)(g_pbyGSClut + nClutOffset);
u16* pclut = (u16*)&targ->clut[0];
int left = ((u32)nClutOffset & 2) ? 0 : ((nClutOffset&0x3ff)/2)+clutsize-512;
if( left > 0 ) clutsize -= left;
@ -1935,9 +1932,9 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
while(left > 0)
{
pclut[0] = pClutBuffer[0];
pclut++;
pClutBuffer += 2;
left -= 2;
pClutBuffer += 2;
pclut++;
}
}
}
@ -1973,37 +1970,28 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
}
#ifndef RELEASE_TO_PUBLIC
g_TransferredToGPU += TexWidth * channels * targ->height;
g_TransferredToGPU += GPU_TEXWIDTH * channels * 4 * targ->height;
#endif
// fill with data
if( targ->ptex->memptr == NULL )
{
targ->ptex->memptr = (u8*)_aligned_malloc(TexWidth * targ->realheight, 16);
targ->ptex->memptr = (u8*)_aligned_malloc(4 * GPU_TEXWIDTH * targ->realheight, 16);
assert(targ->ptex->ref > 0 );
}
memcpy_amd(targ->ptex->memptr, g_pbyGSMemory + TexWidth * targ->realy, TexWidth * targ->height);
memcpy_amd(targ->ptex->memptr, g_pbyGSMemory + 4 * GPU_TEXWIDTH * targ->realy, 4 * GPU_TEXWIDTH * targ->height);
vector<u8> texdata;
u8* ptexdata = NULL;
const int cur_width = GPU_TEXWIDTH * channels * widthmult;
if (PSMT_ISCLUT(tex0.psm))
{
int new_size = cur_width * (targ->realheight + widthmult - 1)/widthmult;
if (PSMT_IS32BIT(tex0.cpsm))
new_size *= 4;
else
new_size *= 2;
texdata.resize(new_size);
texdata.resize( (tex0.cpsm <= 1?4:2) *GPU_TEXWIDTH*channels*widthmult*(targ->realheight+widthmult-1)/widthmult);
ptexdata = &texdata[0];
u8* psrc = (u8*)(g_pbyGSMemory + 4 * GPU_TEXWIDTH * targ->realy);
if (PSMT_IS32BIT(tex0.cpsm)) // 32bit
if (PSMT_IS32BIT(tex0.cpsm))
{
u32* pclut = (u32*)&targ->clut[0];
u32* pdst = (u32*)ptexdata;
@ -2020,26 +2008,25 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
}
else
{
if ((tex0.psm == PSMT16Z) || (tex0.psm == PSMT16SZ))
if (tex0.psm == PSMT16Z || tex0.psm == PSMT16SZ)
{
int new_size = cur_width * (targ->realheight + widthmult - 1)/widthmult;
texdata.resize(4*GPU_TEXWIDTH*channels*widthmult*(targ->realheight+widthmult-1)/widthmult
#if defined(ZEROGS_SSE2)
// reserve additional elements for alignment if SSE2 used.
+ 15 // reserve additional elements for alignment if SSE2 used.
// better do it now, so less resizing would be needed
new_size += 15;
#endif
texdata.resize(new_size);
);
ptexdata = &texdata[0];
// needs to be 8 bit, use xmm for unpacking
u16* dst = (u16*)ptexdata;
u16* src = (u16*)(g_pbyGSMemory + TexWidth * targ->realy);
u16* src = (u16*)(g_pbyGSMemory + 4 * GPU_TEXWIDTH * targ->realy);
#if defined(ZEROGS_SSE2)
if (((u32)(uptr)dst)%16 != 0)
{
// This is not an unusual situation, when vector<u8> does not 16bit alignment, that is destructive for SSE2
// This is not unusual situation, when vector<u8> does not 16bit alignment, that is destructive for SSE2
// instruction movdqa [%eax], xmm0
// The idea would be resise vector to 15 elements, that set ptxedata to aligned position.
// Later we would move eax by 16, so only we should verify is first element align
@ -2080,7 +2067,7 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
if (targ->ptex->tex == 0) glGenTextures(1, &targ->ptex->tex);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, targ->ptex->tex);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, (fmt == GL_UNSIGNED_BYTE) ? 4 : GL_RGB5_A1, GPU_TEXWIDTH * channels * widthmult,
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, fmt==GL_UNSIGNED_BYTE?4:GL_RGB5_A1, GPU_TEXWIDTH*channels*widthmult,
(targ->realheight+widthmult-1)/widthmult, 0, GL_RGBA, fmt, ptexdata);
int realheight = targ->realheight;
@ -2096,7 +2083,7 @@ ZeroGS::CMemoryTarget* ZeroGS::CMemoryTargetMngr::GetMemoryTarget(const tex0Info
if (listTargets.size() == 0)
{
ERROR_LOG("Failed to create %dx%x texture\n", GPU_TEXWIDTH*channels*widthmult, (realheight+widthmult-1)/widthmult);
//channels = 1;
channels = 1;
return NULL;
}
DestroyOldest();