TextureCache: Allow the backends to return nullptr for textures.

This commit is contained in:
degasus 2015-11-21 10:41:05 +01:00
parent fc00598785
commit c9dc5fb376
1 changed files with 67 additions and 52 deletions

View File

@ -265,6 +265,8 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::DoPartialTextureUpdates(Tex
newconfig.height = h; newconfig.height = h;
newconfig.rendertarget = true; newconfig.rendertarget = true;
TCacheEntryBase* newentry = AllocateTexture(newconfig); TCacheEntryBase* newentry = AllocateTexture(newconfig);
if (newentry)
{
newentry->SetGeneralParameters(entry_to_update->addr, entry_to_update->size_in_bytes, entry_to_update->format); newentry->SetGeneralParameters(entry_to_update->addr, entry_to_update->size_in_bytes, entry_to_update->format);
newentry->SetDimensions(entry_to_update->native_width, entry_to_update->native_height, 1); newentry->SetDimensions(entry_to_update->native_width, entry_to_update->native_height, 1);
newentry->SetHashes(entry_to_update->base_hash, entry_to_update->hash); newentry->SetHashes(entry_to_update->base_hash, entry_to_update->hash);
@ -281,6 +283,7 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::DoPartialTextureUpdates(Tex
textures_by_address.emplace(key, entry_to_update); textures_by_address.emplace(key, entry_to_update);
} }
} }
}
srcrect.right = entry->config.width; srcrect.right = entry->config.width;
srcrect.bottom = entry->config.height; srcrect.bottom = entry->config.height;
dstrect.left = x * entry_to_update->config.width / entry_to_update->native_width; dstrect.left = x * entry_to_update->config.width / entry_to_update->native_width;
@ -544,6 +547,8 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::Load(const u32 stage)
config.layers = FramebufferManagerBase::GetEFBLayers(); config.layers = FramebufferManagerBase::GetEFBLayers();
TCacheEntryBase *decoded_entry = AllocateTexture(config); TCacheEntryBase *decoded_entry = AllocateTexture(config);
if (decoded_entry)
{
decoded_entry->SetGeneralParameters(address, texture_size, full_format); decoded_entry->SetGeneralParameters(address, texture_size, full_format);
decoded_entry->SetDimensions(entry->native_width, entry->native_height, 1); decoded_entry->SetDimensions(entry->native_width, entry->native_height, 1);
decoded_entry->SetHashes(base_hash, full_hash); decoded_entry->SetHashes(base_hash, full_hash);
@ -554,6 +559,7 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::Load(const u32 stage)
textures_by_address.emplace((u64)address, decoded_entry); textures_by_address.emplace((u64)address, decoded_entry);
return ReturnEntry(stage, decoded_entry); return ReturnEntry(stage, decoded_entry);
} }
}
// Search the texture cache for normal textures by hash // Search the texture cache for normal textures by hash
// //
@ -611,6 +617,21 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::Load(const u32 stage)
} }
} }
// how many levels the allocated texture shall have
const u32 texLevels = hires_tex ? (u32)hires_tex->m_levels.size() : tex_levels;
// create the entry/texture
TCacheEntryConfig config;
config.width = width;
config.height = height;
config.levels = texLevels;
TCacheEntryBase* entry = AllocateTexture(config);
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
if (!entry)
return nullptr;
if (!hires_tex) if (!hires_tex)
{ {
if (!(texformat == GX_TF_RGBA8 && from_tmem)) if (!(texformat == GX_TF_RGBA8 && from_tmem))
@ -625,18 +646,6 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::Load(const u32 stage)
} }
} }
// how many levels the allocated texture shall have
const u32 texLevels = hires_tex ? (u32)hires_tex->m_levels.size() : tex_levels;
// create the entry/texture
TCacheEntryConfig config;
config.width = width;
config.height = height;
config.levels = texLevels;
TCacheEntryBase* entry = AllocateTexture(config);
GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
iter = textures_by_address.emplace((u64)address, entry); iter = textures_by_address.emplace((u64)address, entry);
if (g_ActiveConfig.iSafeTextureCache_ColorSamples == 0 || if (g_ActiveConfig.iSafeTextureCache_ColorSamples == 0 ||
std::max(texture_size, palette_size) <= (u32)g_ActiveConfig.iSafeTextureCache_ColorSamples * 8) std::max(texture_size, palette_size) <= (u32)g_ActiveConfig.iSafeTextureCache_ColorSamples * 8)
@ -1120,6 +1129,8 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFo
TCacheEntryBase* entry = AllocateTexture(config); TCacheEntryBase* entry = AllocateTexture(config);
if (entry)
{
entry->SetGeneralParameters(dstAddr, 0, dstFormat); entry->SetGeneralParameters(dstAddr, 0, dstFormat);
entry->SetDimensions(tex_w, tex_h, 1); entry->SetDimensions(tex_w, tex_h, 1);
@ -1141,6 +1152,7 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFo
textures_by_address.emplace((u64)dstAddr, entry); textures_by_address.emplace((u64)dstAddr, entry);
} }
}
} }
TextureCacheBase::TCacheEntryBase* TextureCacheBase::AllocateTexture(const TCacheEntryConfig& config) TextureCacheBase::TCacheEntryBase* TextureCacheBase::AllocateTexture(const TCacheEntryConfig& config)
@ -1155,6 +1167,9 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::AllocateTexture(const TCach
else else
{ {
entry = g_texture_cache->CreateTexture(config); entry = g_texture_cache->CreateTexture(config);
if (!entry)
return nullptr;
INCSTAT(stats.numTexturesCreated); INCSTAT(stats.numTexturesCreated);
} }