mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-29 15:06:09 +00:00
GPU: Relax locking on Buffer Cache (#3883)
I did this on ncbuffer2 when we were using it for LDN 3, but I noticed that it can apply to the current buffer manager too, and it's an easy performance win. The only buffer access that can come from another thread is the overlap search for buffers that have been unmapped. Everything else, including modifications, come from the main GPU thread. That means we only need to lock the range list when it's being modified, as that's the only time where we'll cause a race with the unmapped handler. This has a significant performance improvements in situations where FIFO is high, like the other two PRs. Joined together they give a nice boost (73.6 master -> 79 -> 83 fps in SMO).
This commit is contained in:
parent
cc51a03af9
commit
5a39d3c4a1
|
@ -22,6 +22,10 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
private readonly GpuContext _context;
|
private readonly GpuContext _context;
|
||||||
private readonly PhysicalMemory _physicalMemory;
|
private readonly PhysicalMemory _physicalMemory;
|
||||||
|
|
||||||
|
/// <remarks>
|
||||||
|
/// Only modified from the GPU thread. Must lock for add/remove.
|
||||||
|
/// Must lock for any access from other threads.
|
||||||
|
/// </remarks>
|
||||||
private readonly RangeList<Buffer> _buffers;
|
private readonly RangeList<Buffer> _buffers;
|
||||||
|
|
||||||
private Buffer[] _bufferOverlaps;
|
private Buffer[] _bufferOverlaps;
|
||||||
|
@ -200,12 +204,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
/// <param name="size">Size in bytes of the buffer</param>
|
/// <param name="size">Size in bytes of the buffer</param>
|
||||||
private void CreateBufferAligned(ulong address, ulong size)
|
private void CreateBufferAligned(ulong address, ulong size)
|
||||||
{
|
{
|
||||||
int overlapsCount;
|
int overlapsCount = _buffers.FindOverlapsNonOverlapping(address, size, ref _bufferOverlaps);
|
||||||
|
|
||||||
lock (_buffers)
|
|
||||||
{
|
|
||||||
overlapsCount = _buffers.FindOverlapsNonOverlapping(address, size, ref _bufferOverlaps);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (overlapsCount != 0)
|
if (overlapsCount != 0)
|
||||||
{
|
{
|
||||||
|
@ -409,11 +408,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
|
|
||||||
if (size != 0)
|
if (size != 0)
|
||||||
{
|
|
||||||
lock (_buffers)
|
|
||||||
{
|
{
|
||||||
buffer = _buffers.FindFirstOverlap(address, size);
|
buffer = _buffers.FindFirstOverlap(address, size);
|
||||||
}
|
|
||||||
|
|
||||||
buffer.SynchronizeMemory(address, size);
|
buffer.SynchronizeMemory(address, size);
|
||||||
|
|
||||||
|
@ -423,12 +419,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
lock (_buffers)
|
|
||||||
{
|
{
|
||||||
buffer = _buffers.FindFirstOverlap(address, 1);
|
buffer = _buffers.FindFirstOverlap(address, 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -442,12 +435,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
{
|
{
|
||||||
if (size != 0)
|
if (size != 0)
|
||||||
{
|
{
|
||||||
Buffer buffer;
|
Buffer buffer = _buffers.FindFirstOverlap(address, size);
|
||||||
|
|
||||||
lock (_buffers)
|
|
||||||
{
|
|
||||||
buffer = _buffers.FindFirstOverlap(address, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.SynchronizeMemory(address, size);
|
buffer.SynchronizeMemory(address, size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue