Address feedback
This commit is contained in:
parent
f88a7a8596
commit
ca09e7f537
3 changed files with 25 additions and 43 deletions
|
@ -30,19 +30,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
ResourcePool<TKey, TValue>.CreateValue CreateValueCallback,
|
ResourcePool<TKey, TValue>.CreateValue CreateValueCallback,
|
||||||
ResourcePool<TKey, TValue>.DeleteValue DeleteValueCallback)
|
ResourcePool<TKey, TValue>.DeleteValue DeleteValueCallback)
|
||||||
{
|
{
|
||||||
if (CreateValueCallback == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(CreateValueCallback));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DeleteValueCallback == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(DeleteValueCallback));
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache = new Dictionary<long, CacheBucket>();
|
Cache = new Dictionary<long, CacheBucket>();
|
||||||
|
|
||||||
Pool = new ResourcePool<TKey, TValue>(CreateValueCallback, DeleteValueCallback);
|
Pool = new ResourcePool<TKey, TValue>(
|
||||||
|
CreateValueCallback ?? throw new ArgumentNullException(nameof(CreateValueCallback)),
|
||||||
|
DeleteValueCallback ?? throw new ArgumentNullException(nameof(DeleteValueCallback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Lock()
|
public void Lock()
|
||||||
|
@ -82,7 +74,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
{
|
{
|
||||||
Value = Bucket.Value;
|
Value = Bucket.Value;
|
||||||
|
|
||||||
Value.UpdateStamp();
|
Value.UpdateTimestamp();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
|
|
||||||
OGLStreamBuffer CachedBuffer = VboCache.CreateOrRecycle(Key, Params, (uint)DataSize);
|
OGLStreamBuffer CachedBuffer = VboCache.CreateOrRecycle(Key, Params, (uint)DataSize);
|
||||||
|
|
||||||
IntPtr Length = new IntPtr(DataSize);
|
CachedBuffer.SetData(DataSize, HostAddress);
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, CachedBuffer.Handle);
|
|
||||||
|
|
||||||
GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, Length, HostAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateIbo(long Key, int DataSize, IntPtr HostAddress)
|
public void CreateIbo(long Key, int DataSize, IntPtr HostAddress)
|
||||||
|
@ -114,11 +110,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
|
|
||||||
OGLStreamBuffer CachedBuffer = IboCache.CreateOrRecycle(Key, Params, (uint)DataSize);
|
OGLStreamBuffer CachedBuffer = IboCache.CreateOrRecycle(Key, Params, (uint)DataSize);
|
||||||
|
|
||||||
IntPtr Length = new IntPtr(DataSize);
|
CachedBuffer.SetData(DataSize, HostAddress);
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, CachedBuffer.Handle);
|
|
||||||
|
|
||||||
GL.BufferSubData(BufferTarget.ElementArrayBuffer, IntPtr.Zero, Length, HostAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetIndexArray(int Size, GalIndexFormat Format)
|
public void SetIndexArray(int Size, GalIndexFormat Format)
|
||||||
|
|
|
@ -14,14 +14,14 @@ namespace Ryujinx.Graphics
|
||||||
|
|
||||||
public bool IsUsed { get; private set; }
|
public bool IsUsed { get; private set; }
|
||||||
|
|
||||||
public void UpdateStamp()
|
public void UpdateTimestamp()
|
||||||
{
|
{
|
||||||
Timestamp = Environment.TickCount;
|
Timestamp = Environment.TickCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MarkAsUsed()
|
public void MarkAsUsed()
|
||||||
{
|
{
|
||||||
UpdateStamp();
|
UpdateTimestamp();
|
||||||
|
|
||||||
IsUsed = true;
|
IsUsed = true;
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,9 @@ namespace Ryujinx.Graphics
|
||||||
|
|
||||||
public delegate void DeleteValue(TValue Resource);
|
public delegate void DeleteValue(TValue Resource);
|
||||||
|
|
||||||
private List<(TKey, List<TValue>)> Entries;
|
private LinkedList<(TKey, LinkedList<TValue>)> Entries;
|
||||||
|
|
||||||
private Queue<(TValue, List<TValue>)> SortedCache;
|
private Queue<(TValue, LinkedList<TValue>)> SortedCache;
|
||||||
|
|
||||||
private CreateValue CreateValueCallback;
|
private CreateValue CreateValueCallback;
|
||||||
private DeleteValue DeleteValueCallback;
|
private DeleteValue DeleteValueCallback;
|
||||||
|
@ -55,16 +55,16 @@ namespace Ryujinx.Graphics
|
||||||
this.CreateValueCallback = CreateValueCallback;
|
this.CreateValueCallback = CreateValueCallback;
|
||||||
this.DeleteValueCallback = DeleteValueCallback;
|
this.DeleteValueCallback = DeleteValueCallback;
|
||||||
|
|
||||||
Entries = new List<(TKey, List<TValue>)>();
|
Entries = new LinkedList<(TKey, LinkedList<TValue>)>();
|
||||||
|
|
||||||
SortedCache = new Queue<(TValue, List<TValue>)>();
|
SortedCache = new Queue<(TValue, LinkedList<TValue>)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TValue CreateOrRecycle(TKey Params)
|
public TValue CreateOrRecycle(TKey Params)
|
||||||
{
|
{
|
||||||
List<TValue> Family = GetOrAddEntry(Params);
|
LinkedList<TValue> Siblings = GetOrAddEntry(Params);
|
||||||
|
|
||||||
foreach (TValue RecycledValue in Family)
|
foreach (TValue RecycledValue in Siblings)
|
||||||
{
|
{
|
||||||
if (!RecycledValue.IsUsed)
|
if (!RecycledValue.IsUsed)
|
||||||
{
|
{
|
||||||
|
@ -78,9 +78,9 @@ namespace Ryujinx.Graphics
|
||||||
|
|
||||||
Resource.MarkAsUsed();
|
Resource.MarkAsUsed();
|
||||||
|
|
||||||
Family.Add(Resource);
|
Siblings.AddLast(Resource);
|
||||||
|
|
||||||
SortedCache.Enqueue((Resource, Family));
|
SortedCache.Enqueue((Resource, Siblings));
|
||||||
|
|
||||||
return Resource;
|
return Resource;
|
||||||
}
|
}
|
||||||
|
@ -91,14 +91,12 @@ namespace Ryujinx.Graphics
|
||||||
|
|
||||||
for (int Count = 0; Count < MaxRemovalsPerRun; Count++)
|
for (int Count = 0; Count < MaxRemovalsPerRun; Count++)
|
||||||
{
|
{
|
||||||
if (!SortedCache.TryDequeue(out (TValue Resource, List<TValue> Family) Tuple))
|
if (!SortedCache.TryDequeue(out (TValue Resource, LinkedList<TValue> Siblings) Tuple))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TValue Resource = Tuple.Resource;
|
(TValue Resource, LinkedList <TValue> Siblings) = Tuple;
|
||||||
|
|
||||||
List<TValue> Family = Tuple.Family;
|
|
||||||
|
|
||||||
if (!Resource.IsUsed)
|
if (!Resource.IsUsed)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +104,7 @@ namespace Ryujinx.Graphics
|
||||||
|
|
||||||
if ((uint)TimeDelta > MaxTimeDelta)
|
if ((uint)TimeDelta > MaxTimeDelta)
|
||||||
{
|
{
|
||||||
if (!Family.Remove(Resource))
|
if (!Siblings.Remove(Resource))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
|
@ -117,13 +115,13 @@ namespace Ryujinx.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SortedCache.Enqueue((Resource, Family));
|
SortedCache.Enqueue((Resource, Siblings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TValue> GetOrAddEntry(TKey Params)
|
private LinkedList<TValue> GetOrAddEntry(TKey Params)
|
||||||
{
|
{
|
||||||
foreach ((TKey MyParams, List<TValue> Resources) in Entries)
|
foreach ((TKey MyParams, LinkedList<TValue> Resources) in Entries)
|
||||||
{
|
{
|
||||||
if (MyParams.IsCompatible(Params))
|
if (MyParams.IsCompatible(Params))
|
||||||
{
|
{
|
||||||
|
@ -131,11 +129,11 @@ namespace Ryujinx.Graphics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TValue> Family = new List<TValue>();
|
LinkedList<TValue> Siblings = new LinkedList<TValue>();
|
||||||
|
|
||||||
Entries.Add((Params, Family));
|
Entries.AddFirst((Params, Siblings));
|
||||||
|
|
||||||
return Family;
|
return Siblings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int RingDelta(int Old, int New)
|
private static int RingDelta(int Old, int New)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue