mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-10-20 20:01:41 +00:00
10aa11ce13
* Interrupt GPU command processing when a frame's fence is reached. * Accumulate times rather than %s * Accurate timer for vsync Spin wait for the last .667ms of a frame. Avoids issues caused by signalling 16ms vsync. (periodic stutters in smo) * Use event wait for better timing. * Fix lazy wait Windows doesn't seem to want to do 1ms consistently, so force a spin if we're less than 2ms. * A bit more efficiency on frame waits. Should now wait the remainder 0.6667 instead of 1.6667 sometimes (odd waits above 1ms are reliable, unlike 1ms waits) * Better swap interval 0 solution 737 fps without breaking a sweat. Downside: Vsync can no longer be disabled on games that use the event heavily (link's awakening - which is ok since it breaks anyways) * Fix comment. * Address Comments.
96 lines
No EOL
2.5 KiB
C#
96 lines
No EOL
2.5 KiB
C#
using Ryujinx.Common.Logging;
|
|
using Ryujinx.Graphics.Gpu;
|
|
using Ryujinx.HLE.HOS.Services.Nv.Types;
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|
{
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x24)]
|
|
struct AndroidFence : IFlattenable
|
|
{
|
|
public int FenceCount;
|
|
|
|
private byte _fenceStorageStart;
|
|
|
|
private Span<byte> _storage => MemoryMarshal.CreateSpan(ref _fenceStorageStart, Unsafe.SizeOf<NvFence>() * 4);
|
|
|
|
public Span<NvFence> NvFences => MemoryMarshal.Cast<byte, NvFence>(_storage);
|
|
|
|
public static AndroidFence NoFence
|
|
{
|
|
get
|
|
{
|
|
AndroidFence fence = new AndroidFence
|
|
{
|
|
FenceCount = 0
|
|
};
|
|
|
|
fence.NvFences[0].Id = NvFence.InvalidSyncPointId;
|
|
|
|
return fence;
|
|
}
|
|
}
|
|
|
|
public void AddFence(NvFence fence)
|
|
{
|
|
NvFences[FenceCount++] = fence;
|
|
}
|
|
|
|
public void WaitForever(GpuContext gpuContext)
|
|
{
|
|
bool hasTimeout = Wait(gpuContext, TimeSpan.FromMilliseconds(3000));
|
|
|
|
if (hasTimeout)
|
|
{
|
|
Logger.Error?.Print(LogClass.SurfaceFlinger, "Android fence didn't signal in 3000 ms");
|
|
Wait(gpuContext, Timeout.InfiniteTimeSpan);
|
|
}
|
|
|
|
}
|
|
|
|
public bool Wait(GpuContext gpuContext, TimeSpan timeout)
|
|
{
|
|
for (int i = 0; i < FenceCount; i++)
|
|
{
|
|
bool hasTimeout = NvFences[i].Wait(gpuContext, timeout);
|
|
|
|
if (hasTimeout)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void RegisterCallback(GpuContext gpuContext, Action callback)
|
|
{
|
|
ref NvFence fence = ref NvFences[FenceCount - 1];
|
|
|
|
gpuContext.Synchronization.RegisterCallbackOnSyncpoint(fence.Id, fence.Value, callback);
|
|
}
|
|
|
|
public uint GetFlattenedSize()
|
|
{
|
|
return (uint)Unsafe.SizeOf<AndroidFence>();
|
|
}
|
|
|
|
public uint GetFdCount()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public void Flatten(Parcel parcel)
|
|
{
|
|
parcel.WriteUnmanagedType(ref this);
|
|
}
|
|
|
|
public void Unflatten(Parcel parcel)
|
|
{
|
|
this = parcel.ReadUnmanagedType<AndroidFence>();
|
|
}
|
|
}
|
|
} |