mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-20 17:51:13 +02:00
Optimize texture cache code
This commit is contained in:
@@ -53,11 +53,6 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
private ulong MaxTextureSizeCapacity = 2 * GiB;
|
private ulong MaxTextureSizeCapacity = 2 * GiB;
|
||||||
private const ulong MinTextureSizeCapacity = 512 * MiB;
|
private const ulong MinTextureSizeCapacity = 512 * MiB;
|
||||||
private const ulong DefaultTextureSizeCapacity = 1 * GiB;
|
private const ulong DefaultTextureSizeCapacity = 1 * GiB;
|
||||||
private const ulong TextureSizeCapacity4GiB = 2 * GiB;
|
|
||||||
private const ulong TextureSizeCapacity6GiB = 4 * GiB;
|
|
||||||
private const ulong TextureSizeCapacity8GiB = 6 * GiB;
|
|
||||||
private const ulong TextureSizeCapacity10GiB = 10 * GiB;
|
|
||||||
private const ulong TextureSizeCapacity12GiB = 12 * GiB;
|
|
||||||
|
|
||||||
private const float MemoryScaleFactor = 0.50f;
|
private const float MemoryScaleFactor = 0.50f;
|
||||||
private ulong _maxCacheMemoryUsage = DefaultTextureSizeCapacity;
|
private ulong _maxCacheMemoryUsage = DefaultTextureSizeCapacity;
|
||||||
@@ -82,25 +77,18 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// <param name="cpuMemorySize">The amount of physical CPU Memory available on the device.</param>
|
/// <param name="cpuMemorySize">The amount of physical CPU Memory available on the device.</param>
|
||||||
public void Initialize(GpuContext context, ulong cpuMemorySize)
|
public void Initialize(GpuContext context, ulong cpuMemorySize)
|
||||||
{
|
{
|
||||||
var cpuMemorySizeGiB = cpuMemorySize / GiB;
|
ulong cpuMemorySizeGiB = cpuMemorySize / GiB;
|
||||||
var MaximumGpuMemoryGiB = context.Capabilities.MaximumGpuMemory / GiB;
|
ulong MaximumGpuMemoryGiB = context.Capabilities.MaximumGpuMemory / GiB;
|
||||||
|
ulong TextureSizeCapacity = cpuMemorySize - (2 * GiB);
|
||||||
|
|
||||||
if (context.Capabilities.MaximumGpuMemory == 0)
|
MaxTextureSizeCapacity =
|
||||||
{
|
context.Capabilities.MaximumGpuMemory == 0 || cpuMemorySizeGiB < 6 && MaximumGpuMemoryGiB < 6
|
||||||
MaxTextureSizeCapacity = DefaultTextureSizeCapacity;
|
? DefaultTextureSizeCapacity
|
||||||
}
|
: cpuMemorySizeGiB < 10
|
||||||
else
|
? TextureSizeCapacity
|
||||||
MaxTextureSizeCapacity = cpuMemorySizeGiB switch
|
: cpuMemorySize;
|
||||||
{
|
|
||||||
< 6 when MaximumGpuMemoryGiB < 6 => DefaultTextureSizeCapacity,
|
|
||||||
< 6 => TextureSizeCapacity4GiB,
|
|
||||||
6 => TextureSizeCapacity6GiB,
|
|
||||||
8 => TextureSizeCapacity8GiB,
|
|
||||||
10 => TextureSizeCapacity10GiB,
|
|
||||||
_ => TextureSizeCapacity12GiB
|
|
||||||
};
|
|
||||||
|
|
||||||
var cacheMemory = (ulong)(context.Capabilities.MaximumGpuMemory * MemoryScaleFactor);
|
ulong cacheMemory = (ulong)(context.Capabilities.MaximumGpuMemory * MemoryScaleFactor);
|
||||||
|
|
||||||
_maxCacheMemoryUsage = Math.Clamp(cacheMemory, MinTextureSizeCapacity, MaxTextureSizeCapacity);
|
_maxCacheMemoryUsage = Math.Clamp(cacheMemory, MinTextureSizeCapacity, MaxTextureSizeCapacity);
|
||||||
|
|
||||||
@@ -177,10 +165,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void RemoveLeastUsedTexture()
|
private void RemoveLeastUsedTexture()
|
||||||
{
|
{
|
||||||
if (_textures.First != null)
|
Texture oldestTexture = _textures.First?.Value;
|
||||||
{
|
|
||||||
Texture oldestTexture = _textures.First.Value;
|
|
||||||
|
|
||||||
|
if (oldestTexture != null)
|
||||||
|
{
|
||||||
_totalSize -= oldestTexture.Size;
|
_totalSize -= oldestTexture.Size;
|
||||||
|
|
||||||
if (!oldestTexture.CheckModified(false))
|
if (!oldestTexture.CheckModified(false))
|
||||||
@@ -206,11 +194,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
/// <param name="texture">The texture to be removed from the cache</param>
|
/// <param name="texture">The texture to be removed from the cache</param>
|
||||||
/// <param name="flush">True to remove the texture if it was on the cache</param>
|
/// <param name="flush">True to remove the texture if it was on the cache</param>
|
||||||
/// <returns>True if the texture was found and removed, false otherwise</returns>
|
/// <returns>True if the texture was found and removed, false otherwise</returns>
|
||||||
public bool Remove(Texture texture, bool flush)
|
public void Remove(Texture texture, bool flush)
|
||||||
{
|
{
|
||||||
if (texture.CacheNode == null)
|
if (texture.CacheNode == null)
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove our reference to this texture.
|
// Remove our reference to this texture.
|
||||||
@@ -225,7 +213,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
|
|
||||||
texture.CacheNode = null;
|
texture.CacheNode = null;
|
||||||
|
|
||||||
return texture.DecrementReferenceCount();
|
texture.DecrementReferenceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -241,10 +229,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||||||
{
|
{
|
||||||
return entry.Texture;
|
return entry.Texture;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
_shortCacheLookup.Remove(descriptor);
|
||||||
_shortCacheLookup.Remove(descriptor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user