d3d9: Clean up some scaling handling.
This commit is contained in:
parent
1072028ef5
commit
d18164bd4d
2 changed files with 32 additions and 9 deletions
|
@ -55,6 +55,8 @@ namespace DX9 {
|
||||||
|
|
||||||
// Changes more frequent than this will be considered "frequent" and prevent texture scaling.
|
// Changes more frequent than this will be considered "frequent" and prevent texture scaling.
|
||||||
#define TEXCACHE_FRAME_CHANGE_FREQUENT 6
|
#define TEXCACHE_FRAME_CHANGE_FREQUENT 6
|
||||||
|
// Note: only used when hash backoff is disabled.
|
||||||
|
#define TEXCACHE_FRAME_CHANGE_FREQUENT_REGAIN_TRUST 33
|
||||||
|
|
||||||
#define TEXCACHE_MAX_TEXELS_SCALED (256*256) // Per frame
|
#define TEXCACHE_MAX_TEXELS_SCALED (256*256) // Per frame
|
||||||
|
|
||||||
|
@ -246,6 +248,13 @@ void TextureCacheDX9::Invalidate(u32 addr, int size, GPUInvalidationType type) {
|
||||||
gpuStats.numTextureInvalidations++;
|
gpuStats.numTextureInvalidations++;
|
||||||
// Start it over from 0 (unless it's safe.)
|
// Start it over from 0 (unless it's safe.)
|
||||||
iter->second.numFrames = type == GPU_INVALIDATE_SAFE ? 256 : 0;
|
iter->second.numFrames = type == GPU_INVALIDATE_SAFE ? 256 : 0;
|
||||||
|
if (type == GPU_INVALIDATE_SAFE) {
|
||||||
|
u32 diff = gpuStats.numFlips - iter->second.lastFrame;
|
||||||
|
// We still need to mark if the texture is frequently changing, even if it's safely changing.
|
||||||
|
if (diff < TEXCACHE_FRAME_CHANGE_FREQUENT) {
|
||||||
|
iter->second.status |= TexCacheEntry::STATUS_CHANGE_FREQUENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
iter->second.framesUntilNextFullHash = 0;
|
iter->second.framesUntilNextFullHash = 0;
|
||||||
} else if (!iter->second.framebuffer) {
|
} else if (!iter->second.framebuffer) {
|
||||||
iter->second.invalidHint++;
|
iter->second.invalidHint++;
|
||||||
|
@ -1251,13 +1260,17 @@ void TextureCacheDX9::SetTexture(bool force) {
|
||||||
fullhash = QuickTexHash(texaddr, bufw, w, h, format, entry);
|
fullhash = QuickTexHash(texaddr, bufw, w, h, format, entry);
|
||||||
if (fullhash != entry->fullhash) {
|
if (fullhash != entry->fullhash) {
|
||||||
hashFail = true;
|
hashFail = true;
|
||||||
} else if (entry->GetHashStatus() != TexCacheEntry::STATUS_HASHING && entry->numFrames > TexCacheEntry::FRAMES_REGAIN_TRUST) {
|
} else {
|
||||||
// Reset to STATUS_HASHING.
|
|
||||||
if (g_Config.bTextureBackoffCache) {
|
if (g_Config.bTextureBackoffCache) {
|
||||||
|
if (entry->GetHashStatus() != TexCacheEntry::STATUS_HASHING && entry->numFrames > TexCacheEntry::FRAMES_REGAIN_TRUST) {
|
||||||
|
// Reset to STATUS_HASHING.
|
||||||
entry->SetHashStatus(TexCacheEntry::STATUS_HASHING);
|
entry->SetHashStatus(TexCacheEntry::STATUS_HASHING);
|
||||||
}
|
|
||||||
entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT;
|
entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT;
|
||||||
}
|
}
|
||||||
|
} else if (entry->numFrames > TEXCACHE_FRAME_CHANGE_FREQUENT_REGAIN_TRUST) {
|
||||||
|
entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashFail) {
|
if (hashFail) {
|
||||||
|
@ -1458,15 +1471,25 @@ void TextureCacheDX9::SetTexture(bool force) {
|
||||||
scaleFactor = g_Config.iTexScalingLevel;
|
scaleFactor = g_Config.iTexScalingLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rachet down scale factor in low-memory mode.
|
||||||
|
if (lowMemoryMode_) {
|
||||||
|
// Keep it even, though, just in case of npot troubles.
|
||||||
|
scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Don't scale the PPGe texture.
|
// Don't scale the PPGe texture.
|
||||||
if (entry->addr > 0x05000000 && entry->addr < 0x08800000)
|
if (entry->addr > 0x05000000 && entry->addr < 0x08800000)
|
||||||
scaleFactor = 1;
|
scaleFactor = 1;
|
||||||
|
if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0) {
|
||||||
|
// Remember for later that we /wanted/ to scale this texture.
|
||||||
|
entry->status |= TexCacheEntry::STATUS_TO_SCALE;
|
||||||
|
scaleFactor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (scaleFactor != 1 && (entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0) {
|
if (scaleFactor != 1) {
|
||||||
if (texelsScaledThisFrame_ >= TEXCACHE_MAX_TEXELS_SCALED) {
|
if (texelsScaledThisFrame_ >= TEXCACHE_MAX_TEXELS_SCALED) {
|
||||||
entry->status |= TexCacheEntry::STATUS_TO_SCALE;
|
entry->status |= TexCacheEntry::STATUS_TO_SCALE;
|
||||||
scaleFactor = 1;
|
scaleFactor = 1;
|
||||||
// INFO_LOG(G3D, "Skipped scaling for now..");
|
|
||||||
} else {
|
} else {
|
||||||
entry->status &= ~TexCacheEntry::STATUS_TO_SCALE;
|
entry->status &= ~TexCacheEntry::STATUS_TO_SCALE;
|
||||||
texelsScaledThisFrame_ += w * h;
|
texelsScaledThisFrame_ += w * h;
|
||||||
|
@ -1489,7 +1512,7 @@ void TextureCacheDX9::SetTexture(bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mipmapping is only enabled when texture scaling is disabled.
|
// Mipmapping is only enabled when texture scaling is disabled.
|
||||||
if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) {
|
if (maxLevel > 0 && scaleFactor == 1) {
|
||||||
for (u32 i = 1; i <= maxLevel; i++) {
|
for (u32 i = 1; i <= maxLevel; i++) {
|
||||||
LoadTextureLevel(*entry, i, maxLevel, replaceImages, scaleFactor, dstFmt);
|
LoadTextureLevel(*entry, i, maxLevel, replaceImages, scaleFactor, dstFmt);
|
||||||
}
|
}
|
||||||
|
@ -1840,7 +1863,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, int maxL
|
||||||
pool = D3DPOOL_DEFAULT;
|
pool = D3DPOOL_DEFAULT;
|
||||||
usage = D3DUSAGE_DYNAMIC; // TODO: Switch to using a staging texture?
|
usage = D3DUSAGE_DYNAMIC; // TODO: Switch to using a staging texture?
|
||||||
}
|
}
|
||||||
int levels = g_Config.iTexScalingLevel == 1 ? maxLevel + 1 : 1;
|
int levels = scaleFactor == 1 ? maxLevel + 1 : 1;
|
||||||
HRESULT hr = pD3Ddevice->CreateTexture(w, h, levels, usage, (D3DFORMAT)D3DFMT(dstFmt), pool, &texture, NULL);
|
HRESULT hr = pD3Ddevice->CreateTexture(w, h, levels, usage, (D3DFORMAT)D3DFMT(dstFmt), pool, &texture, NULL);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
INFO_LOG(G3D, "Failed to create D3D texture");
|
INFO_LOG(G3D, "Failed to create D3D texture");
|
||||||
|
|
|
@ -1619,7 +1619,7 @@ void TextureCache::SetTexture(bool force) {
|
||||||
LoadTextureLevel(*entry, 0, replaceImages, scaleFactor, dstFmt);
|
LoadTextureLevel(*entry, 0, replaceImages, scaleFactor, dstFmt);
|
||||||
|
|
||||||
// Mipmapping only enable when texture scaling disable
|
// Mipmapping only enable when texture scaling disable
|
||||||
if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) {
|
if (maxLevel > 0 && scaleFactor == 1) {
|
||||||
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
||||||
if (badMipSizes) {
|
if (badMipSizes) {
|
||||||
// WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format);
|
// WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue