Skip to content

Commit

Permalink
Remove fast crc calculation - should be no longer needed
Browse files Browse the repository at this point in the history
Change lod method to use one similar to glide64's (thanks ratop46)
  • Loading branch information
death-droid committed Oct 7, 2012
1 parent 46c4f35 commit bc54add
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 167 deletions.
40 changes: 0 additions & 40 deletions Config.cpp
Expand Up @@ -429,9 +429,6 @@ void WriteConfiguration(void)
fprintf(f, "FulScreenHeight ");
fprintf(f, "%d\n", windowSetting.uFullScreenDisplayHeight);

fprintf(f, "FastTextureLoading ");
fprintf(f, "%d\n", defaultRomOptions.bFastTexCRC);

fprintf(f, "ForceTextureFilter ");
fprintf(f, "%d\n", (uint32)options.forceTextureFilter);

Expand Down Expand Up @@ -620,7 +617,6 @@ void ReadConfiguration(void)
defaultRomOptions.N64RenderToTextureEmuType = TXT_BUF_NONE;

defaultRomOptions.bNormalBlender = FALSE;
defaultRomOptions.bFastTexCRC=FALSE;
defaultRomOptions.bNormalCombiner = FALSE;
defaultRomOptions.bAccurateTextureMapping = TRUE;
defaultRomOptions.bInN64Resolution = FALSE;
Expand Down Expand Up @@ -690,7 +686,6 @@ void ReadConfiguration(void)
options.bCacheHiResTextures = ReadRegistryDwordVal("CacheHiResTextures");
options.bDumpTexturesToFiles = ReadRegistryDwordVal("DumpTexturesToFiles");
options.bDumpTexturesToFiles = FALSE; // Never starting the plugin with this option on
defaultRomOptions.bFastTexCRC = ReadRegistryDwordVal("FastTextureLoading");
options.DirectXDevice = ReadRegistryDwordVal("DirectXDevice");
options.DirectXDepthBufferSetting = ReadRegistryDwordVal("DirectXDepthBufferSetting");
options.DirectXAntiAliasingValue = ReadRegistryDwordVal("DirectXAntiAliasingValue");;
Expand All @@ -699,7 +694,6 @@ void ReadConfiguration(void)
options.FPSColor = ReadRegistryDwordVal("FPSColor");;
options.DirectXMaxAnisotropy = ReadRegistryDwordVal("DirectXMaxAnisotropy");;
options.colorQuality = ReadRegistryDwordVal("ColorQuality");
defaultRomOptions.bFastTexCRC = ReadRegistryDwordVal("FastTextureLoading");
defaultRomOptions.bAccurateTextureMapping = ReadRegistryDwordVal("AccurateTextureMapping");
defaultRomOptions.bInN64Resolution = ReadRegistryDwordVal("InN64Resolution");
defaultRomOptions.bSaveVRAM = ReadRegistryDwordVal("SaveVRAM");
Expand Down Expand Up @@ -752,7 +746,6 @@ void GenerateCurrentRomOptions()
currentRomOptions.screenUpdateSetting =g_curRomInfo.dwScreenUpdateSetting;
currentRomOptions.bNormalCombiner =g_curRomInfo.dwNormalCombiner;
currentRomOptions.bNormalBlender =g_curRomInfo.dwNormalBlender;
currentRomOptions.bFastTexCRC =g_curRomInfo.dwFastTextureCRC;
currentRomOptions.bAccurateTextureMapping =g_curRomInfo.dwAccurateTextureMapping;

options.enableHackForGames = NO_HACK_FOR_GAME;
Expand Down Expand Up @@ -907,8 +900,6 @@ void GenerateCurrentRomOptions()
else currentRomOptions.bNormalCombiner--;
if( currentRomOptions.bNormalBlender == 0 ) currentRomOptions.bNormalBlender = defaultRomOptions.bNormalBlender;
else currentRomOptions.bNormalBlender--;
if( currentRomOptions.bFastTexCRC == 0 ) currentRomOptions.bFastTexCRC = defaultRomOptions.bFastTexCRC;
else currentRomOptions.bFastTexCRC--;
if( currentRomOptions.bAccurateTextureMapping == 0 ) currentRomOptions.bAccurateTextureMapping = defaultRomOptions.bAccurateTextureMapping;
else currentRomOptions.bAccurateTextureMapping--;

Expand Down Expand Up @@ -950,7 +941,6 @@ void Ini_GetRomOptions(LPGAMESETTING pGameSetting)
pGameSetting->bTxtSizeMethod2 = IniSections[i].bTxtSizeMethod2;
pGameSetting->bEnableTxtLOD = IniSections[i].bEnableTxtLOD;

pGameSetting->dwFastTextureCRC = IniSections[i].dwFastTextureCRC;
pGameSetting->bEmulateClear = IniSections[i].bEmulateClear;
pGameSetting->bForceScreenClear = IniSections[i].bForceScreenClear;
pGameSetting->dwAccurateTextureMapping = IniSections[i].dwAccurateTextureMapping;
Expand Down Expand Up @@ -985,12 +975,6 @@ void Ini_StoreRomOptions(LPGAMESETTING pGameSetting)
bIniIsChanged=true;
}

if( IniSections[i].dwFastTextureCRC !=pGameSetting->dwFastTextureCRC )
{
IniSections[i].dwFastTextureCRC =pGameSetting->dwFastTextureCRC ;
bIniIsChanged=true;
}

if( IniSections[i].bEmulateClear !=pGameSetting->bEmulateClear )
{
IniSections[i].bEmulateClear =pGameSetting->bEmulateClear ;
Expand Down Expand Up @@ -1259,13 +1243,6 @@ ToolTipMsg ttmsg[] = {
"\nWhen a game is not running, it is the default value (for all games), available values are on/off.\n"
"When a game is running, it is the game setting. Three available setting are on/off/as default."
},
{
IDC_FAST_TEX_CRC,
"Fast texture loading",
"Uses a faster CRC algorithm to speed up texture loading and CRC computation.\n"
"\nWhen a game is not running, it is the default value (for all games), available values are on/off.\n"
"When a game is running, it is the game setting. Three available setting are on/off/as default."
},
{
IDC_ACCURATE_TEXTURE_MAPPING,
"Accurate Texture Mapping",
Expand Down Expand Up @@ -1843,7 +1820,6 @@ BOOL ReadIniFile()
newsection.bForceScreenClear = FALSE;
newsection.bDisableBlender = FALSE;
newsection.bForceDepthBuffer = FALSE;
newsection.dwFastTextureCRC = 0;
newsection.dwAccurateTextureMapping = 0;
newsection.dwNormalBlender = 0;
newsection.dwNormalCombiner = 0;
Expand Down Expand Up @@ -1915,9 +1891,6 @@ BOOL ReadIniFile()
if (lstrcmpi(left(readinfo,22), "AccurateTextureMapping")==0)
IniSections[sectionno].dwAccurateTextureMapping = strtol(right(readinfo,1),NULL,10);

if (lstrcmpi(left(readinfo,14), "FastTextureCRC")==0)
IniSections[sectionno].dwFastTextureCRC = strtol(right(readinfo,1),NULL,10);

if (lstrcmpi(left(readinfo,12), "EmulateClear")==0)
IniSections[sectionno].bEmulateClear = strtol(right(readinfo,1),NULL,10);

Expand Down Expand Up @@ -2074,9 +2047,6 @@ void OutputSectionDetails(uint32 i, FILE * fh)
if (IniSections[i].dwAccurateTextureMapping != 0)
fprintf(fh, "AccurateTextureMapping=%d\n", IniSections[i].dwAccurateTextureMapping);

if (IniSections[i].dwFastTextureCRC != 0)
fprintf(fh, "FastTextureCRC=%d\n", IniSections[i].dwFastTextureCRC);

if (IniSections[i].dwNormalBlender != 0)
fprintf(fh, "NormalAlphaBlender=%d\n", IniSections[i].dwNormalBlender);

Expand Down Expand Up @@ -2205,7 +2175,6 @@ int FindIniEntry(uint32 dwCRC1, uint32 dwCRC2, uint8 nCountryID, LPCTSTR szName)
newsection.bForceScreenClear = FALSE;
newsection.bDisableBlender = FALSE;
newsection.bForceDepthBuffer = FALSE;
newsection.dwFastTextureCRC = 0;
newsection.dwAccurateTextureMapping = 0;
newsection.dwNormalBlender = 0;
newsection.dwNormalCombiner = 0;
Expand Down Expand Up @@ -3091,7 +3060,6 @@ LRESULT APIENTRY DefaultSettingDialogProc(HWND hDlg, unsigned message, LONG wPar

SendDlgItemMessage(hDlg, IDC_ALPHA_BLENDER, BM_SETCHECK, defaultRomOptions.bNormalBlender? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hDlg, IDC_NORMAL_COMBINER, BM_SETCHECK, defaultRomOptions.bNormalCombiner ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hDlg, IDC_FAST_TEX_CRC, BM_SETCHECK, defaultRomOptions.bFastTexCRC ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hDlg, IDC_ACCURATE_TEXTURE_MAPPING, BM_SETCHECK, defaultRomOptions.bAccurateTextureMapping ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hDlg, IDC_IN_N64_RESOLUTION, BM_SETCHECK, defaultRomOptions.bInN64Resolution ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hDlg, IDC_SAVE_VRAM, BM_SETCHECK, defaultRomOptions.bSaveVRAM ? BST_CHECKED : BST_UNCHECKED, 0);
Expand Down Expand Up @@ -3174,7 +3142,6 @@ LRESULT APIENTRY DefaultSettingDialogProc(HWND hDlg, unsigned message, LONG wPar
break;
case IDOK:
defaultRomOptions.bNormalBlender = (SendDlgItemMessage(hDlg, IDC_ALPHA_BLENDER, BM_GETCHECK, 0, 0) == BST_CHECKED);
defaultRomOptions.bFastTexCRC = (SendDlgItemMessage(hDlg, IDC_FAST_TEX_CRC, BM_GETCHECK, 0, 0) == BST_CHECKED);
defaultRomOptions.bNormalCombiner = (SendDlgItemMessage(hDlg, IDC_NORMAL_COMBINER, BM_GETCHECK, 0, 0) == BST_CHECKED);
defaultRomOptions.bAccurateTextureMapping = (SendDlgItemMessage(hDlg, IDC_ACCURATE_TEXTURE_MAPPING, BM_GETCHECK, 0, 0) == BST_CHECKED);
defaultRomOptions.N64FrameBufferEmuType = SendDlgItemMessage(hDlg, IDC_FRAME_BUFFER_SETTING, CB_GETCURSEL, 0, 0);
Expand Down Expand Up @@ -3218,10 +3185,6 @@ LRESULT APIENTRY RomSettingProc(HWND hDlg, unsigned message, LONG wParam, LONG l
SendDlgItemMessage(hDlg, IDC_NORMAL_COMBINER, BM_SETSTYLE, BS_AUTO3STATE, TRUE);
SendDlgItemMessage(hDlg, IDC_NORMAL_COMBINER, BM_SETCHECK, state, 0);

state = g_curRomInfo.dwFastTextureCRC ==2 ? BST_CHECKED : (g_curRomInfo.dwFastTextureCRC ==1?BST_UNCHECKED:BST_INDETERMINATE);
SendDlgItemMessage(hDlg, IDC_FAST_TEX_CRC, BM_SETSTYLE, BS_AUTO3STATE, TRUE);
SendDlgItemMessage(hDlg, IDC_FAST_TEX_CRC, BM_SETCHECK, state, 0);

state = g_curRomInfo.dwAccurateTextureMapping ==2 ? BST_CHECKED : (g_curRomInfo.dwAccurateTextureMapping ==1?BST_UNCHECKED:BST_INDETERMINATE);
SendDlgItemMessage(hDlg, IDC_ACCURATE_TEXTURE_MAPPING, BM_SETSTYLE, BS_AUTO3STATE, TRUE);
SendDlgItemMessage(hDlg, IDC_ACCURATE_TEXTURE_MAPPING, BM_SETCHECK, state, 0);
Expand Down Expand Up @@ -3337,9 +3300,6 @@ LRESULT APIENTRY RomSettingProc(HWND hDlg, unsigned message, LONG wParam, LONG l
state = SendDlgItemMessage(hDlg, IDC_ALPHA_BLENDER, BM_GETCHECK, 0, 0);
g_curRomInfo.dwNormalBlender = (state==BST_CHECKED?2:(state==BST_UNCHECKED?1:0));

state = SendDlgItemMessage(hDlg, IDC_FAST_TEX_CRC, BM_GETCHECK, 0, 0);
g_curRomInfo.dwFastTextureCRC = (state==BST_CHECKED?2:(state==BST_UNCHECKED?1:0));

state = SendDlgItemMessage(hDlg, IDC_NORMAL_COMBINER, BM_GETCHECK, 0, 0);
g_curRomInfo.dwNormalCombiner = (state==BST_CHECKED?2:(state==BST_UNCHECKED?1:0));

Expand Down
1 change: 0 additions & 1 deletion Config.h
Expand Up @@ -237,7 +237,6 @@ typedef struct {
uint32 screenUpdateSetting;
BOOL bNormalCombiner;
BOOL bNormalBlender;
BOOL bFastTexCRC;
BOOL bAccurateTextureMapping;
BOOL bInN64Resolution;
BOOL bDoubleSizeForSmallTxtrBuf;
Expand Down
150 changes: 37 additions & 113 deletions Device/FrameBuffer.cpp
Expand Up @@ -585,129 +585,53 @@ uint32 CalculateRDRAMCRC(void *pPhysicalAddress, uint32 left, uint32 top, uint32
dwAsmCRC = 0;
dwAsmdwBytesPerLine = ((width<<size)+1)/2;

if( currentRomOptions.bFastTexCRC && !options.bLoadHiResTextures && (height>=32 || (dwAsmdwBytesPerLine>>2)>=16))
{
uint32 realWidthInDWORD = dwAsmdwBytesPerLine>>2;
uint32 xinc = realWidthInDWORD / FAST_CRC_CHECKING_INC_X;
if( xinc < FAST_CRC_MIN_X_INC )
{
xinc = min(FAST_CRC_MIN_X_INC, width);
}
if( xinc > FAST_CRC_MAX_X_INC )
{
xinc = FAST_CRC_MAX_X_INC;
}
try{
dwAsmdwBytesPerLine = ((width<<size)+1)/2;

uint32 yinc = height / FAST_CRC_CHECKING_INC_Y;
if( yinc < FAST_CRC_MIN_Y_INC )
{
yinc = min(FAST_CRC_MIN_Y_INC, height);
}
if( yinc > FAST_CRC_MAX_Y_INC )
{
yinc = FAST_CRC_MAX_Y_INC;
}
pAsmStart = (uint8*)(pPhysicalAddress);
pAsmStart += (top * pitchInBytes) + (((left<<size)+1)>>1);

uint32 pitch = pitchInBytes>>2;
register uint32 *pStart = (uint32*)(pPhysicalAddress);
pStart += (top * pitch) + (((left<<size)+1)>>3);

/*
uint32 x,y;
for (y = 0; y < height; y+=yinc) // Do every nth line?
{
for (x = 0; x < realWidthInDWORD; x+=xinc)
{
dwAsmCRC += *(pStart+x);
dwAsmCRC ^= x;
}
pStart += pitch;
dwAsmCRC ^= y;
}
*/
dwAsmHeight = height - 1;
dwAsmPitch = pitchInBytes;


__asm
__asm
{
push esi;
mov esi, DWORD PTR [xinc];
mov ebx, DWORD PTR [pStart];
mov eax,0; // EAX = the CRC
mov edx,0x0;
loop1:
cmp edx, height;
jae endloop1;
mov ecx, 0x0;
loop2:
add eax, ecx;
cmp ecx, DWORD PTR [realWidthInDWORD]
jae endloop2;
push eax
push ebx
push ecx
push edx
push esi

rol eax, 4
add eax, DWORD PTR [ebx][ecx*4];
mov ecx, pAsmStart; // = pStart
mov edx, 0 // The CRC
mov eax, dwAsmHeight // = y
l2: mov ebx, dwAsmdwBytesPerLine // = x
sub ebx, 4
l1: mov esi, [ecx+ebx]
xor esi, ebx
rol edx, 4
add edx, esi
sub ebx, 4
jge l1
xor esi, eax
add edx, esi
add ecx, dwAsmPitch
dec eax
jge l2

mov dwAsmCRC, edx

add ecx, esi;
jmp loop2;
endloop2:
xor eax, edx;
add edx, DWORD PTR [yinc];
add ebx, DWORD PTR [pitch];
jmp loop1;
endloop1:
mov DWORD PTR [dwAsmCRC], eax;
pop esi;
pop esi
pop edx
pop ecx
pop ebx
pop eax
}
}
else
catch(...)
{
try{
dwAsmdwBytesPerLine = ((width<<size)+1)/2;

pAsmStart = (uint8*)(pPhysicalAddress);
pAsmStart += (top * pitchInBytes) + (((left<<size)+1)>>1);

dwAsmHeight = height - 1;
dwAsmPitch = pitchInBytes;


__asm
{
push eax
push ebx
push ecx
push edx
push esi

mov ecx, pAsmStart; // = pStart
mov edx, 0 // The CRC
mov eax, dwAsmHeight // = y
l2: mov ebx, dwAsmdwBytesPerLine // = x
sub ebx, 4
l1: mov esi, [ecx+ebx]
xor esi, ebx
rol edx, 4
add edx, esi
sub ebx, 4
jge l1
xor esi, eax
add edx, esi
add ecx, dwAsmPitch
dec eax
jge l2

mov dwAsmCRC, edx

pop esi
pop edx
pop ecx
pop ebx
pop eax
}
}
catch(...)
{
TRACE0("Exception in texture CRC calculation");
}
TRACE0("Exception in texture CRC calculation");
}
return dwAsmCRC;
}
Expand Down
2 changes: 1 addition & 1 deletion Parser/RDP_Texture.h
Expand Up @@ -884,7 +884,7 @@ long synchronizedLastModified;

void PrepareTextures()
{
if( gRDP.textureIsChanged || !currentRomOptions.bFastTexCRC ||
if( gRDP.textureIsChanged ||
CRender::g_pRender->m_pColorCombiner->m_pDecodedMux->m_ColorTextureFlag[0] ||
CRender::g_pRender->m_pColorCombiner->m_pDecodedMux->m_ColorTextureFlag[1] )
{
Expand Down
6 changes: 4 additions & 2 deletions Render/RenderBase.cpp
Expand Up @@ -728,10 +728,12 @@ void ComputeLOD()
dt = sqrtf((s0-s1)*(s0-s1)+(t0-t1)*(t0-t1));

float lod = dt/d;
int ilod = (int)lod;
double intptr;
float frac = log10f(lod)/log10f(2.0f);
//DEBUGGER_IF_DUMP(pauseAtNext,{DebuggerAppendMsg("LOD frac = %f", frac);});
frac = (lod / powf(2.0f,floorf(frac)));
frac = frac - floorf(frac);
int lod_tile = min((int)(log10f((float)ilod)/log10f(2.0f)), gRSP.curTile + floorf(frac))
frac = max((float)modf(lod / pow(2.,lod_tile),&intptr), gRDP.primLODMin / 255.0f);
//DEBUGGER_IF_DUMP(pauseAtNext,{DebuggerAppendMsg("LOD = %f, frac = %f", lod, frac);});
gRDP.LODFrac = (uint32)(frac*255);
CRender::g_pRender->SetCombinerAndBlender();
Expand Down

0 comments on commit bc54add

Please sign in to comment.