Skip to content

Commit

Permalink
Implemented CACHE IXIN/IHIN and LLD/SCD instructions.
Browse files Browse the repository at this point in the history
Optimized LDL/LDR/SDL/SDR instructions.
Optimized ULW/USW/ULD/USD instruction macros.
Optimized AND/OR/XOR/NOR/ORI/XORI with 32-bit operands.
Updated Mupen64Plus RSP HLE plugin.
Updated xxHash to v0.6.5.
Other minor fixes.
  • Loading branch information
Extrems committed Oct 30, 2022
1 parent 75c0d1a commit c73cf02
Show file tree
Hide file tree
Showing 16 changed files with 1,234 additions and 472 deletions.
10 changes: 0 additions & 10 deletions glN64_GX/CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
#else
# include "../main/winlnxdefs.h"
#endif // __LINUX__
#define XXH_PRIVATE_API
#define XXH_FORCE_MEMORY_ACCESS 2
#define XXH_FORCE_NATIVE_FORMAT 1
#define XXH_FORCE_ALIGN_CHECK 0
#include "../main/xxhash.h"

#define CRC32_POLYNOMIAL 0x04C11DB7

Expand Down Expand Up @@ -99,8 +94,3 @@ DWORD CRC_CalculatePalette( DWORD crc, void *buffer, DWORD count )

return crc ^ orig;
}

DWORD Hash_Calculate( DWORD hash, void *buffer, DWORD count )
{
return XXH32(buffer, count, hash);
}
10 changes: 8 additions & 2 deletions glN64_GX/CRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
#else
# include "../main/winlnxdefs.h"
#endif // __LINUX__
#define XXH_INLINE_ALL
#define XXH_FORCE_NATIVE_FORMAT 1
#include "../main/xxhash.h"

void CRC_BuildTable();

DWORD CRC_Calculate( DWORD crc, void *buffer, DWORD count );
DWORD CRC_CalculatePalette( DWORD crc, void *buffer, DWORD count );

DWORD Hash_Calculate( DWORD hash, void *buffer, DWORD count );

inline DWORD Hash_Calculate( DWORD hash, void *buffer, DWORD count )
{
return XXH32(buffer, count, hash);
}
36 changes: 18 additions & 18 deletions glN64_GX/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void TextureCache_Init()
cache.dummy->clampT = 1;
cache.dummy->clampWidth = 2;
cache.dummy->clampHeight = 2;
cache.dummy->crc = 0;
cache.dummy->hash = 0;
cache.dummy->format = 0;
cache.dummy->size = 0;
cache.dummy->frameBufferTexture = FALSE;
Expand Down Expand Up @@ -1500,9 +1500,9 @@ void TextureCache_Load( CachedTexture *texInfo )
#endif // !__GX__
}

u32 TextureCache_CalculateCRC( u32 t, u32 width, u32 height )
u32 TextureCache_CalculateHash( u32 t, u32 width, u32 height )
{
u32 crc;
u32 hash;
u32 y, /*i,*/ bpl, lineBytes, line;
u64 *src;

Expand All @@ -1513,21 +1513,21 @@ u32 TextureCache_CalculateCRC( u32 t, u32 width, u32 height )
if (gSP.textureTile[t]->size == G_IM_SIZ_32b)
line <<= 1;

crc = 0xFFFFFFFF;
hash = 0;
for (y = 0; y < height; y++)
{
src = (u64*)&TMEM[(gSP.textureTile[t]->tmem + line * y) & 0x1FF];
crc = Hash_Calculate( crc, src, bpl );
hash = Hash_Calculate( hash, src, bpl );
}

if ((gDP.otherMode.textureLUT != G_TT_NONE) || (gSP.textureTile[t]->format == G_IM_FMT_CI))
{
if (gSP.textureTile[t]->size == G_IM_SIZ_4b)
crc = Hash_Calculate( crc, &TMEM[0x100 + (gSP.textureTile[t]->palette << 4)], 128 );
hash = Hash_Calculate( hash, &TMEM[0x100 + (gSP.textureTile[t]->palette << 4)], 128 );
else if ((gSP.textureTile[t]->size == G_IM_SIZ_8b) || (gSP.textureTile[t]->size == G_IM_SIZ_16b))
crc = Hash_Calculate( crc, &TMEM[0x100], 2048 );
hash = Hash_Calculate( hash, &TMEM[0x100], 2048 );
}
return crc;
return hash;
}

void TextureCache_ActivateTexture( u32 t, CachedTexture *texture )
Expand Down Expand Up @@ -1617,23 +1617,23 @@ void TextureCache_ActivateDummy( u32 t )
void TextureCache_UpdateBackground()
{
u32 numBytes = gSP.bgImage.width * gSP.bgImage.height << gSP.bgImage.size >> 1;
u32 crc;
u32 hash;

crc = Hash_Calculate( 0xFFFFFFFF, &RDRAM[gSP.bgImage.address], numBytes );
hash = Hash_Calculate( 0, &RDRAM[gSP.bgImage.address], numBytes );

if (gSP.bgImage.format == G_IM_FMT_CI)
{
if (gSP.bgImage.size == G_IM_SIZ_4b)
crc = Hash_Calculate( crc, &TMEM[0x100 + (gSP.bgImage.palette << 4)], 128 );
hash = Hash_Calculate( hash, &TMEM[0x100 + (gSP.bgImage.palette << 4)], 128 );
else if (gSP.bgImage.size == G_IM_SIZ_8b)
crc = Hash_Calculate( crc, &TMEM[0x100], 2048 );
hash = Hash_Calculate( hash, &TMEM[0x100], 2048 );
}

CachedTexture *current = cache.top;

while (current)
{
if ((current->crc == crc) &&
if ((current->hash == hash) &&
(current->width == gSP.bgImage.width) &&
(current->height == gSP.bgImage.height) &&
(current->format == gSP.bgImage.format) &&
Expand Down Expand Up @@ -1664,7 +1664,7 @@ void TextureCache_UpdateBackground()
#endif // !__GX__

cache.current[0]->address = gSP.bgImage.address;
cache.current[0]->crc = crc;
cache.current[0]->hash = hash;

cache.current[0]->format = gSP.bgImage.format;
cache.current[0]->size = gSP.bgImage.size;
Expand Down Expand Up @@ -1706,7 +1706,7 @@ void TextureCache_Update( u32 t )
{
CachedTexture *current;
//s32 i, j, k;
u32 crc, /*bpl, cacheNum,*/ maxTexels;
u32 hash, /*bpl, cacheNum,*/ maxTexels;
u32 tileWidth, maskWidth, loadWidth, lineWidth, clampWidth, height;
u32 tileHeight, maskHeight, loadHeight, lineHeight, clampHeight, width;

Expand Down Expand Up @@ -1848,15 +1848,15 @@ void TextureCache_Update( u32 t )
maskHeight = 1 << gSP.textureTile[t]->maskt;
}

crc = TextureCache_CalculateCRC( t, width, height );
hash = TextureCache_CalculateHash( t, width, height );

// if (!TextureCache_Verify())
// current = cache.top;

current = cache.top;
while (current)
{
if ((current->crc == crc) &&
if ((current->hash == hash) &&
// (current->address == gDP.textureImage.address) &&
// (current->palette == gSP.textureTile[t]->palette) &&
(current->width == width) &&
Expand Down Expand Up @@ -1902,7 +1902,7 @@ void TextureCache_Update( u32 t )
#endif // !__GX__

cache.current[t]->address = gDP.textureImage.address;
cache.current[t]->crc = crc;
cache.current[t]->hash = hash;

cache.current[t]->format = gSP.textureTile[t]->format;
cache.current[t]->size = gSP.textureTile[t]->size;
Expand Down
2 changes: 1 addition & 1 deletion glN64_GX/Textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct CachedTexture

GLuint glName;
u32 address;
u32 crc;
u32 hash;
// float fulS, fulT;
// WORD ulS, ulT, lrS, lrT;
float offsetS, offsetT;
Expand Down
Loading

1 comment on commit c73cf02

@Ntemis
Copy link

@Ntemis Ntemis commented on c73cf02 Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work thank you!!

Please sign in to comment.