2020-04-22 04:10:27 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Error?.Print(LogClass.SurfaceFlinger, "Android fence didn't signal in 3000 ms");
|
2020-04-22 04:10:27 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 18:39:52 +00:00
|
|
|
|
public void RegisterCallback(GpuContext gpuContext, Action callback)
|
|
|
|
|
{
|
|
|
|
|
ref NvFence fence = ref NvFences[FenceCount - 1];
|
|
|
|
|
|
|
|
|
|
gpuContext.Synchronization.RegisterCallbackOnSyncpoint(fence.Id, fence.Value, callback);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 04:10:27 +00:00
|
|
|
|
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>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|