Skip to content

Commit

Permalink
Add "Use strong CRC for texture dump" option.
Browse files Browse the repository at this point in the history
When this option is on, textures dumped with alternative strong CRC.

Dumps with strong CRC are stored in "strong_crc" subfolder of dump folder.

Hires texture load is changed:
if HD texture with RiceCRC is not found, the plugin tries to load HD texture with alternative strong CRC.
  • Loading branch information
gonetz committed Feb 25, 2024
1 parent 7b03990 commit ad5d46c
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void Config::resetToDefaults()
textureFilter.txCacheCompression = 1;
textureFilter.txSaveCache = 1;
textureFilter.txDump = 0;
textureFilter.txStrongCRC = 0;

textureFilter.txEnhancedTextureFileStorage = 0;
textureFilter.txHiresTextureFileStorage = 0;
Expand Down Expand Up @@ -207,6 +208,8 @@ const char* Config::hotkeyIniName(u32 _idx)
return "hkForceGammaCorrection";
case Config::HotKey::hkInaccurateTexCords:
return "hkInaccurateTexCords";
case Config::HotKey::hkStrongCRC:
return "hkStrongCRC";
}
return nullptr;
}
Expand Down Expand Up @@ -245,6 +248,8 @@ const char* Config::enabledHotkeyIniName(u32 _idx)
return "hkForceGammaCorrectionEnabled";
case Config::HotKey::hkInaccurateTexCords:
return "hkInaccurateTexCordsEnabled";
case Config::HotKey::hkStrongCRC:
return "hkStrongCRCEnabled";
}
return nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct Config
u32 txCacheCompression; // Zip textures cache
u32 txSaveCache; // Save texture cache to hard disk
u32 txDump; // Dump textures
u32 txStrongCRC; // Dump textures with alternative (strong) CRC

u32 txEnhancedTextureFileStorage; // Use file storage instead of memory cache for enhanced textures.
u32 txHiresTextureFileStorage; // Use file storage instead of memory cache for hires textures.
Expand Down Expand Up @@ -239,6 +240,7 @@ struct Config
hkOsdRenderingResolution,
hkForceGammaCorrection,
hkInaccurateTexCords,
hkStrongCRC,
hkTotal
};

Expand Down
2 changes: 1 addition & 1 deletion src/GLideNHQ/TxFilterExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef unsigned char boolean;
#define GZ_HIRESTEXCACHE 0x00800000
#define DUMP_TEXCACHE 0x01000000
#define DUMP_HIRESTEXCACHE 0x02000000
#define UNDEFINED_0 0x04000000
#define DUMP_STRONG_CRC 0x04000000
#define UNDEFINED_1 0x08000000
#define FORCE16BPP_HIRESTEX 0x10000000
#define FORCE16BPP_TEX 0x20000000
Expand Down
4 changes: 4 additions & 0 deletions src/GLideNUI/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ QString ConfigDialog::_hotkeyDescription(quint32 _idx) const
return tr("Toggle force gamma correction");
case Config::HotKey::hkInaccurateTexCords:
return tr("Toggle inaccurate texture coordinates");
case Config::HotKey::hkStrongCRC:
return tr("Toggle strong CRC for textures dump");
}
return tr("Unknown hotkey");
}
Expand Down Expand Up @@ -373,6 +375,7 @@ void ConfigDialog::_init(bool reInit, bool blockCustomSettings)
ui->texturePackGroupBox->setChecked(config.textureFilter.txHiresEnable != 0);
ui->alphaChannelCheckBox->setChecked(config.textureFilter.txHiresFullAlphaChannel != 0);
ui->alternativeCRCCheckBox->setChecked(config.textureFilter.txHresAltCRC != 0);
ui->strongCRCCheckBox->setChecked(config.textureFilter.txStrongCRC != 0);
ui->force16bppCheckBox->setChecked(config.textureFilter.txForce16bpp != 0);
ui->compressCacheCheckBox->setChecked(config.textureFilter.txCacheCompression != 0);
ui->saveTextureCacheCheckBox->setChecked(config.textureFilter.txSaveCache != 0);
Expand Down Expand Up @@ -689,6 +692,7 @@ void ConfigDialog::accept(bool justSave) {
config.textureFilter.txHiresEnable = ui->texturePackGroupBox->isChecked() ? 1 : 0;
config.textureFilter.txHiresFullAlphaChannel = ui->alphaChannelCheckBox->isChecked() ? 1 : 0;
config.textureFilter.txHresAltCRC = ui->alternativeCRCCheckBox->isChecked() ? 1 : 0;
config.textureFilter.txStrongCRC = ui->strongCRCCheckBox->isChecked() ? 1 : 0;

config.textureFilter.txCacheCompression = ui->compressCacheCheckBox->isChecked() ? 1 : 0;
config.textureFilter.txForce16bpp = ui->force16bppCheckBox->isChecked() ? 1 : 0;
Expand Down
3 changes: 3 additions & 0 deletions src/GLideNUI/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void _loadSettings(QSettings & settings)
config.textureFilter.txHiresEnable = settings.value("txHiresEnable", config.textureFilter.txHiresEnable).toInt();
config.textureFilter.txHiresFullAlphaChannel = settings.value("txHiresFullAlphaChannel", config.textureFilter.txHiresFullAlphaChannel).toInt();
config.textureFilter.txHresAltCRC = settings.value("txHresAltCRC", config.textureFilter.txHresAltCRC).toInt();
config.textureFilter.txStrongCRC = settings.value("txStrongCRC", config.textureFilter.txStrongCRC).toInt();
config.textureFilter.txForce16bpp = settings.value("txForce16bpp", config.textureFilter.txForce16bpp).toInt();
config.textureFilter.txCacheCompression = settings.value("txCacheCompression", config.textureFilter.txCacheCompression).toInt();
config.textureFilter.txSaveCache = settings.value("txSaveCache", config.textureFilter.txSaveCache).toInt();
Expand Down Expand Up @@ -252,6 +253,7 @@ void _writeSettingsToFile(const QString & filename)
settings.setValue("txHiresEnable", config.textureFilter.txHiresEnable);
settings.setValue("txHiresFullAlphaChannel", config.textureFilter.txHiresFullAlphaChannel);
settings.setValue("txHresAltCRC", config.textureFilter.txHresAltCRC);
settings.setValue("txStrongCRC", config.textureFilter.txStrongCRC);
settings.setValue("txForce16bpp", config.textureFilter.txForce16bpp);
settings.setValue("txCacheCompression", config.textureFilter.txCacheCompression);
settings.setValue("txSaveCache", config.textureFilter.txSaveCache);
Expand Down Expand Up @@ -550,6 +552,7 @@ void saveCustomRomSettings(const QString & _strIniFolder, const QString & _strSh
WriteCustomSetting(textureFilter, txHiresEnable);
WriteCustomSetting(textureFilter, txHiresFullAlphaChannel);
WriteCustomSetting(textureFilter, txHresAltCRC);
WriteCustomSetting(textureFilter, txStrongCRC);
WriteCustomSetting(textureFilter, txForce16bpp);
WriteCustomSetting(textureFilter, txCacheCompression);
WriteCustomSetting(textureFilter, txSaveCache);
Expand Down
10 changes: 10 additions & 0 deletions src/GLideNUI/configDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="strongCRCCheckBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This option enables alternative, strong CRC method instead of RiceCRC for texture dump. If you find some textures not dumped, try checking this option.&lt;/p&gt;&lt;p&gt;[Recommended: &lt;span style=&quot; font-style:italic;&quot;&gt;Mostly unchecked, unless RiceCRC fails&lt;/span&gt;]&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Strong CRC calculation (when RiceCRC fails)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hiresTexFileStorageCheckBox">
<property name="toolTip">
Expand Down
8 changes: 8 additions & 0 deletions src/TextureFilterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ u32 TextureFilterHandler::_getConfigOptions() const
options |= LET_TEXARTISTS_FLY;
if (config.hotkeys.enabledKeys[Config::HotKey::hkTexDump] != 0 || config.textureFilter.txDump)
options |= DUMP_TEX;
if (config.textureFilter.txStrongCRC)
options |= DUMP_STRONG_CRC;
if (config.textureFilter.txDeposterize)
options |= DEPOSTERIZE;
if (config.textureFilter.txEnhancedTextureFileStorage)
Expand Down Expand Up @@ -110,6 +112,12 @@ void TextureFilterHandler::init()
pTexDumpPath = txDumpPath;
}

if (config.textureFilter.txStrongCRC) {
::wcscpy(txDumpPath, pTexDumpPath);
gln_wcscat(txDumpPath, wst("/strong_crc"));
pTexDumpPath = txDumpPath;
}

m_inited = txfilter_init(maxTextureSize, // max texture width supported by hardware
maxTextureSize, // max texture height supported by hardware
32, // max texture bpp supported by hardware
Expand Down
26 changes: 18 additions & 8 deletions src/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ void TextureCache::_loadBackground(CachedTexture *pTexture)
free(pDest);
}

bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc)
bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc, u64 & _strongcrc)
{
if (config.textureFilter.txHiresEnable == 0 || !TFH.isInited())
return false;
Expand Down Expand Up @@ -1221,10 +1221,18 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 &
}

_ricecrc = txfilter_checksum(addr, width, height, _pTexture->size, bpl, paladdr);
if (config.textureFilter.txStrongCRC)
_strongcrc = txfilter_checksum_strong(addr, width, height, _pTexture->size, bpl, paladdr);
GHQTexInfo ghqTexInfo;
// TODO: fix problem with zero texture dimensions on GLideNHQ side.
if (txfilter_hirestex(_pTexture->crc, _ricecrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo) &&
ghqTexInfo.width != 0 && ghqTexInfo.height != 0) {
auto hirestexFound = txfilter_hirestex(_pTexture->crc, _ricecrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo);
if (!hirestexFound) {
// Texture with RiceCRC was not found. Try alternative CRC.
if (_strongcrc == 0U)
_strongcrc = txfilter_checksum_strong(addr, width, height, _pTexture->size, bpl, paladdr);
hirestexFound = txfilter_hirestex(_pTexture->crc, _strongcrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo);
}
if (hirestexFound && ghqTexInfo.width != 0 && ghqTexInfo.height != 0) {
ghqTexInfo.format = gfxContext.convertInternalTextureFormat(ghqTexInfo.format);
Context::InitTextureParams params;
params.handle = _pTexture->name;
Expand Down Expand Up @@ -1390,7 +1398,8 @@ void doubleTexture(T* pTex, u32 width, u32 height)
void TextureCache::_loadFast(u32 _tile, CachedTexture *_pTexture)
{
u64 ricecrc = 0;
if (_loadHiresTexture(_tile, _pTexture, ricecrc))
u64 strongcrc = 0;
if (_loadHiresTexture(_tile, _pTexture, ricecrc, strongcrc))
return;

s32 mipLevel = 0;
Expand Down Expand Up @@ -1493,7 +1502,7 @@ void TextureCache::_loadFast(u32 _tile, CachedTexture *_pTexture)
txfilter_dmptx((u8*)m_tempTextureHolder.data(), tmptex.width, tmptex.height,
tmptex.width, (u16)u32(glInternalFormat),
N64FormatSize(_pTexture->format, _pTexture->size),
ricecrc);
config.textureFilter.txStrongCRC ? strongcrc : ricecrc);
}

bool bLoaded = false;
Expand Down Expand Up @@ -1591,7 +1600,8 @@ void TextureCache::_loadFast(u32 _tile, CachedTexture *_pTexture)
void TextureCache::_loadAccurate(u32 _tile, CachedTexture *_pTexture)
{
u64 ricecrc = 0;
if (_loadHiresTexture(_tile, _pTexture, ricecrc))
u64 strongcrc = 0;
if (_loadHiresTexture(_tile, _pTexture, ricecrc, strongcrc))
return;

bool force32bitFormat = false;
Expand Down Expand Up @@ -1669,7 +1679,7 @@ void TextureCache::_loadAccurate(u32 _tile, CachedTexture *_pTexture)
txfilter_dmptx((u8*)(m_tempTextureHolder.data() + texDataOffset), tmptex.width, tmptex.height,
tmptex.width, (u16)u32(glInternalFormat),
N64FormatSize(_pTexture->format, _pTexture->size),
ricecrc);
config.textureFilter.txStrongCRC ? strongcrc : ricecrc);
}

texDataOffset += tmptex.width * tmptex.height;
Expand Down Expand Up @@ -1728,7 +1738,7 @@ void TextureCache::_loadAccurate(u32 _tile, CachedTexture *_pTexture)
txfilter_dmptx((u8*)m_tempTextureHolder.data(), tmptex.width, tmptex.height,
tmptex.width, (u16)u32(glInternalFormat),
N64FormatSize(_pTexture->format, _pTexture->size),
ricecrc);
config.textureFilter.txStrongCRC ? strongcrc : ricecrc);
}

bool bLoaded = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct TextureCache
CachedTexture * _addTexture(u64 _crc64);
void _loadFast(u32 _tile, CachedTexture *_pTexture);
void _loadAccurate(u32 _tile, CachedTexture *_pTexture);
bool _loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc);
bool _loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 & _ricecrc, u64 & _strongcrc);
void _loadBackground(CachedTexture *pTexture);
bool _loadHiresBackground(CachedTexture *_pTexture, u64 & _ricecrc);
void _loadDepthTexture(CachedTexture * _pTexture, u16* _pDest);
Expand Down
11 changes: 11 additions & 0 deletions src/VI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "DebugDump.h"
#include "osal_keys.h"
#include "DisplayWindow.h"
#include "TextureFilterHandler.h"
#include "GLideNHQ/TxFilterExport.h"
#include <Graphics/Context.h>

Expand Down Expand Up @@ -131,6 +132,16 @@ static void checkHotkeys()
/* Turn on texture dump */
if (osal_is_key_pressed(config.hotkeys.enabledKeys[Config::hkTexDump], 0x0001))
textureCache().toggleDumpTex();

if (osal_is_key_pressed(config.hotkeys.enabledKeys[Config::hkStrongCRC], 0x0001)) {
if (config.textureFilter.txStrongCRC == 0)
dwnd().getDrawer().showMessage("Enable strong CRC for textures dump\n", Milliseconds(750));
else
dwnd().getDrawer().showMessage("Disable strong CRC for textures dump\n", Milliseconds(750));
config.textureFilter.txStrongCRC = !config.textureFilter.txStrongCRC;
TFH.shutdown();
TFH.init();
}
}

if (osal_is_key_pressed(config.hotkeys.enabledKeys[Config::hkTexCoordBounds], 0x0001)) {
Expand Down
7 changes: 7 additions & 0 deletions src/mupenplus/Config_mupenplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const char* _hotkeyDescription(u32 _idx)
return "Hotkey: toggle force gamma correction";
case Config::HotKey::hkInaccurateTexCords:
return "Hotkey: toggle inaccurate texture coordinates";
case Config::HotKey::hkStrongCRC:
return "Hotkey: toggle strong CRC for textures dump";
}
return "Unknown hotkey";
}
Expand Down Expand Up @@ -257,6 +259,8 @@ bool Config_SetDefault()
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "txDump", config.textureFilter.txDump, "Dump textures");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "txStrongCRC", config.textureFilter.txStrongCRC, "Use strong CRC for texture dump.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "txEnhancedTextureFileStorage", config.textureFilter.txEnhancedTextureFileStorage, "Use file storage instead of memory cache for enhanced textures.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "txHiresTextureFileStorage", config.textureFilter.txHiresTextureFileStorage, "Use file storage instead of memory cache for HD textures.");
Expand Down Expand Up @@ -473,6 +477,8 @@ void Config_LoadCustomConfig()
if (result == M64ERR_SUCCESS) config.textureFilter.txSaveCache = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "textureFilter\\txDump", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.textureFilter.txDump = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "textureFilter\\txStrongCRC", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.textureFilter.txStrongCRC = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "textureFilter\\txEnhancedTextureFileStorage", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.textureFilter.txEnhancedTextureFileStorage = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "textureFilter\\txHiresTextureFileStorage", value, sizeof(value));
Expand Down Expand Up @@ -569,6 +575,7 @@ void Config_LoadConfig()
config.textureFilter.txCacheCompression = ConfigGetParamBool(g_configVideoGliden64, "txCacheCompression");
config.textureFilter.txSaveCache = ConfigGetParamBool(g_configVideoGliden64, "txSaveCache");
config.textureFilter.txDump = ConfigGetParamBool(g_configVideoGliden64, "txDump");
config.textureFilter.txStrongCRC = ConfigGetParamBool(g_configVideoGliden64, "txStrongCRC");
config.textureFilter.txEnhancedTextureFileStorage = ConfigGetParamBool(g_configVideoGliden64, "txEnhancedTextureFileStorage");
config.textureFilter.txHiresTextureFileStorage = ConfigGetParamBool(g_configVideoGliden64, "txHiresTextureFileStorage");
config.textureFilter.txNoTextureFileStorage = ConfigGetParamBool(g_configVideoGliden64, "txNoTextureFileStorage");
Expand Down

0 comments on commit ad5d46c

Please sign in to comment.