Ensure that all resources that will be used are properly updated and removed from the pool to avoid invalid re-use

This commit is contained in:
gdkchan 2018-12-09 22:10:14 -03:00
parent b7c54a13d4
commit f7f017e428

View file

@ -168,14 +168,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
if (_cache.TryGetValue(key, out CacheBucket bucket))
{
AcquireResource(bucket);
value = bucket.Value;
RemoveFromSortedCache(bucket.CacheNode);
bucket.UpdateCacheNode(_sortedCache.AddLast(bucket.CacheNode.Value));
RemoveFromResourcePool(bucket);
return true;
}
@ -189,6 +185,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
if (_cache.TryGetValue(key, out CacheBucket bucket) && bucket.PoolKey.Equals(poolKey))
{
//Value on key is already compatible, we don't need to do anything.
AcquireResource(bucket);
value = bucket.Value;
return true;
@ -218,6 +216,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
if (_cache.TryGetValue(key, out CacheBucket bucket))
{
AcquireResource(bucket);
size = bucket.Size;
return true;
@ -232,6 +232,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{
if (_cache.TryGetValue(key, out CacheBucket bucket))
{
AcquireResource(bucket);
size = bucket.Size;
value = bucket.Value;
@ -244,6 +246,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
return false;
}
private void AcquireResource(CacheBucket bucket)
{
RemoveFromSortedCache(bucket.CacheNode);
bucket.UpdateCacheNode(_sortedCache.AddLast(bucket.CacheNode.Value));
RemoveFromResourcePool(bucket);
}
private void ClearCacheIfNeeded()
{
long timestamp = PerformanceCounter.ElapsedMilliseconds;