Pass video info to texture replacements.

This commit is contained in:
Unknown W. Brackets 2016-05-01 08:54:43 -07:00
parent f5b93bc6f0
commit c20075b0e0
5 changed files with 56 additions and 17 deletions

View File

@ -280,18 +280,18 @@ static bool WriteTextureToPNG(png_imagep image, const std::string &filename, int
}
#endif
void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, int scaleFactor, ReplacedTextureFormat fmt) {
void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int w, int h) {
_assert_msg_(G3D, enabled_, "Replacement not enabled");
if (!g_Config.bSaveNewTextures) {
// Ignore.
return;
}
if (addr > 0x05000000 && addr < 0x08800000) {
if (replacedInfo.addr > 0x05000000 && replacedInfo.addr < 0x08800000) {
// Don't save the PPGe texture.
return;
}
std::string hashfile = LookupHashFile(cachekey, hash, level);
std::string hashfile = LookupHashFile(replacedInfo.cachekey, replacedInfo.hash, level);
const std::string filename = basePath_ + hashfile;
const std::string saveFilename = basePath_ + NEW_TEXTURE_DIR + hashfile;
@ -301,7 +301,7 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con
return;
}
ReplacementCacheKey replacementKey(cachekey, hash);
ReplacementCacheKey replacementKey(replacedInfo.cachekey, replacedInfo.hash);
auto it = savedCache_.find(replacementKey);
if (it != savedCache_.end() && File::Exists(saveFilename)) {
// We've already saved this texture. Let's only save if it's bigger (e.g. scaled now.)
@ -311,19 +311,19 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con
}
// Only save the hashed portion of the PNG.
int lookupW = w / scaleFactor;
int lookupH = h / scaleFactor;
if (LookupHashRange(addr, lookupW, lookupH)) {
w = lookupW * scaleFactor;
h = lookupH * scaleFactor;
int lookupW = w / replacedInfo.scaleFactor;
int lookupH = h / replacedInfo.scaleFactor;
if (LookupHashRange(replacedInfo.addr, lookupW, lookupH)) {
w = lookupW * replacedInfo.scaleFactor;
h = lookupH * replacedInfo.scaleFactor;
}
#ifdef USING_QT_UI
ERROR_LOG(G3D, "Replacement texture saving not implemented for Qt");
#else
if (fmt != ReplacedTextureFormat::F_8888) {
if (replacedInfo.fmt != ReplacedTextureFormat::F_8888) {
saveBuf.resize((pitch * h) / sizeof(u16));
switch (fmt) {
switch (replacedInfo.fmt) {
case ReplacedTextureFormat::F_5650:
ConvertRGBA565ToRGBA8888(saveBuf.data(), (const u16 *)data, (pitch * h) / sizeof(u16));
break;
@ -348,7 +348,7 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con
}
data = saveBuf.data();
if (fmt != ReplacedTextureFormat::F_8888_BGRA) {
if (replacedInfo.fmt != ReplacedTextureFormat::F_8888_BGRA) {
// We doubled our pitch.
pitch *= 2;
}
@ -366,7 +366,7 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con
if (png.warning_or_error >= 2) {
ERROR_LOG(COMMON, "Saving screenshot to PNG produced errors.");
} else if (success) {
NOTICE_LOG(G3D, "Saving texture for replacement: %08x / %dx%d", hash, w, h);
NOTICE_LOG(G3D, "Saving texture for replacement: %08x / %dx%d", replacedInfo.hash, w, h);
}
#endif

View File

@ -127,6 +127,16 @@ protected:
friend TextureReplacer;
};
struct ReplacedTextureDecodeInfo {
u64 cachekey;
u32 hash;
u32 addr;
bool isVideo;
bool isFinal;
int scaleFactor;
ReplacedTextureFormat fmt;
};
class TextureReplacer {
public:
TextureReplacer();
@ -143,7 +153,7 @@ public:
ReplacedTexture &FindReplacement(u64 cachekey, u32 hash, int w, int h);
void NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, int scaleFactor, ReplacedTextureFormat fmt);
void NotifyTextureDecoded(const ReplacedTextureDecodeInfo &replacedInfo, const void *data, int pitch, int level, int w, int h);
protected:
bool LoadIni();

View File

@ -1674,8 +1674,17 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &re
}
if (replacer.Enabled()) {
ReplacedTextureDecodeInfo replacedInfo;
replacedInfo.cachekey = entry.CacheKey();
replacedInfo.hash = entry.fullhash;
replacedInfo.addr = entry.addr;
replacedInfo.isVideo = videos_.find(entry.addr & 0x3FFFFFFF) != videos_.end();
replacedInfo.isFinal = (entry.status & TexCacheEntry::STATUS_TO_SCALE) == 0;
replacedInfo.scaleFactor = scaleFactor;
replacedInfo.fmt = FromD3D9Format(dstFmt);
int bpp = dstFmt == D3DFMT_A8R8G8B8 ? 4 : 2;
replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash, entry.addr, pixelData, w * bpp, level, w, h, scaleFactor, FromD3D9Format(dstFmt));
replacer.NotifyTextureDecoded(replacedInfo, pixelData, w * bpp, level, w, h);
}
}

View File

@ -1812,8 +1812,17 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &repla
}
if (replacer.Enabled()) {
ReplacedTextureDecodeInfo replacedInfo;
replacedInfo.cachekey = entry.CacheKey();
replacedInfo.hash = entry.fullhash;
replacedInfo.addr = entry.addr;
replacedInfo.isVideo = videos_.find(entry.addr & 0x3FFFFFFF) != videos_.end();
replacedInfo.isFinal = (entry.status & TexCacheEntry::STATUS_TO_SCALE) == 0;
replacedInfo.scaleFactor = scaleFactor;
replacedInfo.fmt = FromGLESFormat(dstFmt, useBGRA);
int bpp = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash,entry.addr, pixelData, (useUnpack ? bufw : w) * bpp, level, w, h, scaleFactor, FromGLESFormat(dstFmt, useBGRA));
replacer.NotifyTextureDecoded(replacedInfo, pixelData, (useUnpack ? bufw : w) * bpp, level, w, h);
}
}

View File

@ -1329,6 +1329,17 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) {
}
lastBoundTexture = entry->vkTex;
ReplacedTextureDecodeInfo replacedInfo;
if (replacer.Enabled() && !replaced.Valid()) {
replacedInfo.cachekey = cachekey;
replacedInfo.hash = entry->fullhash;
replacedInfo.addr = texaddr;
replacedInfo.isVideo = videos_.find(texaddr & 0x3FFFFFFF) != videos_.end();
replacedInfo.isFinal = (entry->status & TexCacheEntry::STATUS_TO_SCALE) == 0;
replacedInfo.scaleFactor = scaleFactor;
replacedInfo.fmt = FromVulkanFormat(actualFmt);
}
if (entry->vkTex) {
// Upload the texture data.
for (int i = 0; i <= maxLevel; i++) {
@ -1348,7 +1359,7 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) {
} else {
LoadTextureLevel(*entry, (uint8_t *)data, stride, i, scaleFactor, dstFmt);
if (replacer.Enabled()) {
replacer.NotifyTextureDecoded(cachekey, entry->fullhash, texaddr, data, stride, i, mipWidth, mipHeight, scaleFactor, FromVulkanFormat(actualFmt));
replacer.NotifyTextureDecoded(replacedInfo, data, stride, i, mipWidth, mipHeight);
}
}
entry->vkTex->texture_->UploadMip(i, mipWidth, mipHeight, texBuf, bufferOffset, stride / bpp);