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

View File

@ -265,6 +265,8 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::DoPartialTextureUpdates(Tex
newconfig.height = h;
newconfig.rendertarget = true;
TCacheEntryBase* newentry = AllocateTexture(newconfig);
if (newentry)
{
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->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);
}
}
}
srcrect.right = entry->config.width;
srcrect.bottom = entry->config.height;
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();
TCacheEntryBase *decoded_entry = AllocateTexture(config);
if (decoded_entry)
{
decoded_entry->SetGeneralParameters(address, texture_size, full_format);
decoded_entry->SetDimensions(entry->native_width, entry->native_height, 1);
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);
return ReturnEntry(stage, decoded_entry);
}
}
// 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 (!(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);
if (g_ActiveConfig.iSafeTextureCache_ColorSamples == 0 ||
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);
if (entry)
{
entry->SetGeneralParameters(dstAddr, 0, dstFormat);
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);
}
}
}
TextureCacheBase::TCacheEntryBase* TextureCacheBase::AllocateTexture(const TCacheEntryConfig& config)
@ -1155,6 +1167,9 @@ TextureCacheBase::TCacheEntryBase* TextureCacheBase::AllocateTexture(const TCach
else
{
entry = g_texture_cache->CreateTexture(config);
if (!entry)
return nullptr;
INCSTAT(stats.numTexturesCreated);
}