Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fd01259d2b | ||
|
7ffe7f8442 | ||
|
2b2ce68f07 |
@@ -12,8 +12,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
private readonly AVCodec_decode _decodeFrame;
|
private readonly AVCodec_decode _decodeFrame;
|
||||||
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
|
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
|
||||||
private readonly AVCodec* _codec;
|
private readonly AVCodec* _codec;
|
||||||
private AVPacket* _packet;
|
private readonly AVPacket* _packet;
|
||||||
private AVCodecContext* _context;
|
private readonly AVCodecContext* _context;
|
||||||
|
|
||||||
public FFmpegContext(AVCodecID codecId)
|
public FFmpegContext(AVCodecID codecId)
|
||||||
{
|
{
|
||||||
@@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
FFmpegApi.av_packet_free(ppPacket);
|
FFmpegApi.av_packet_free(ppPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
FFmpegApi.avcodec_close(_context);
|
_ = FFmpegApi.avcodec_close(_context);
|
||||||
|
|
||||||
fixed (AVCodecContext** ppContext = &_context)
|
fixed (AVCodecContext** ppContext = &_context)
|
||||||
{
|
{
|
||||||
|
@@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
|
|
||||||
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
|
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
|
||||||
|
|
||||||
private FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
|
private FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_H264);
|
||||||
|
|
||||||
private int _oldOutputWidth;
|
private int _oldOutputWidth;
|
||||||
private int _oldOutputHeight;
|
private int _oldOutputHeight;
|
||||||
@@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
byte[] output = new byte[data.Length + prep.Length];
|
byte[] output = new byte[data.Length + prep.Length];
|
||||||
|
|
||||||
prep.CopyTo(output);
|
prep.CopyTo(output);
|
||||||
data.CopyTo(new Span<byte>(output).Slice(prep.Length));
|
data.CopyTo(new Span<byte>(output)[prep.Length..]);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span<byte> AsSpan()
|
public readonly Span<byte> AsSpan()
|
||||||
{
|
{
|
||||||
return new Span<byte>(_workBuffer).Slice(0, _offset);
|
return new Span<byte>(_workBuffer)[.._offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
|
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
|
||||||
|
@@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
|
|||||||
{
|
{
|
||||||
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
|
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
|
||||||
{
|
{
|
||||||
H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer);
|
H264BitStreamWriter writer = new(workBuffer);
|
||||||
|
|
||||||
// Sequence Parameter Set.
|
// Sequence Parameter Set.
|
||||||
writer.WriteU(1, 24);
|
writer.WriteU(1, 24);
|
||||||
|
@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodec
|
struct AVCodec
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe byte* Name;
|
public unsafe byte* Name;
|
||||||
public unsafe byte* LongName;
|
public unsafe byte* LongName;
|
||||||
public int Type;
|
public int Type;
|
||||||
|
@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodec501
|
struct AVCodec501
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe byte* Name;
|
public unsafe byte* Name;
|
||||||
public unsafe byte* LongName;
|
public unsafe byte* LongName;
|
||||||
public int Type;
|
public int Type;
|
||||||
|
@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVCodecContext
|
struct AVCodecContext
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe IntPtr AvClass;
|
public unsafe IntPtr AvClass;
|
||||||
public int LogLevelOffset;
|
public int LogLevelOffset;
|
||||||
public int CodecType;
|
public int CodecType;
|
||||||
|
@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct AVFrame
|
struct AVFrame
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public Array8<IntPtr> Data;
|
public Array8<IntPtr> Data;
|
||||||
public Array8<int> LineSize;
|
public Array8<int> LineSize;
|
||||||
public IntPtr ExtendedData;
|
public IntPtr ExtendedData;
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
using System;
|
using AVBufferRef = System.IntPtr;
|
||||||
|
|
||||||
using AVBufferRef = System.IntPtr;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
||||||
{
|
{
|
||||||
struct AVPacket
|
struct AVPacket
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public unsafe AVBufferRef* Buf;
|
public unsafe AVBufferRef* Buf;
|
||||||
public long Pts;
|
public long Pts;
|
||||||
public long Dts;
|
public long Dts;
|
||||||
@@ -14,11 +12,11 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
public int Size;
|
public int Size;
|
||||||
public int StreamIndex;
|
public int StreamIndex;
|
||||||
public int Flags;
|
public int Flags;
|
||||||
public IntPtr SizeData;
|
public AVBufferRef SizeData;
|
||||||
public int SizeDataElems;
|
public int SizeDataElems;
|
||||||
public long Duration;
|
public long Duration;
|
||||||
public long Position;
|
public long Position;
|
||||||
public IntPtr Opaque;
|
public AVBufferRef Opaque;
|
||||||
public unsafe AVBufferRef* OpaqueRef;
|
public unsafe AVBufferRef* OpaqueRef;
|
||||||
public AVRational TimeBase;
|
public AVRational TimeBase;
|
||||||
#pragma warning restore CS0649
|
#pragma warning restore CS0649
|
||||||
|
@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct FFCodec<T> where T : struct
|
struct FFCodec<T> where T : struct
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public T Base;
|
public T Base;
|
||||||
public int CapsInternalOrCbType;
|
public int CapsInternalOrCbType;
|
||||||
public int PrivDataSize;
|
public int PrivDataSize;
|
||||||
|
@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
struct FFCodecLegacy<T> where T : struct
|
struct FFCodecLegacy<T> where T : struct
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649 // Field is never assigned to
|
||||||
public T Base;
|
public T Base;
|
||||||
public uint CapsInternalOrCbType;
|
public uint CapsInternalOrCbType;
|
||||||
public int PrivDataSize;
|
public int PrivDataSize;
|
||||||
|
@@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
public const string AvCodecLibraryName = "avcodec";
|
public const string AvCodecLibraryName = "avcodec";
|
||||||
public const string AvUtilLibraryName = "avutil";
|
public const string AvUtilLibraryName = "avutil";
|
||||||
|
|
||||||
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new Dictionary<string, (int, int)>
|
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new()
|
||||||
{
|
{
|
||||||
{ AvCodecLibraryName, (58, 59) },
|
{ AvCodecLibraryName, (58, 59) },
|
||||||
{ AvUtilLibraryName, (56, 57) }
|
{ AvUtilLibraryName, (56, 57) }
|
||||||
@@ -61,9 +61,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
|
|||||||
{
|
{
|
||||||
NativeLibrary.SetDllImportResolver(typeof(FFmpegApi).Assembly, (name, assembly, path) =>
|
NativeLibrary.SetDllImportResolver(typeof(FFmpegApi).Assembly, (name, assembly, path) =>
|
||||||
{
|
{
|
||||||
IntPtr handle;
|
|
||||||
|
|
||||||
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out handle))
|
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out nint handle))
|
||||||
{
|
{
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
|
|||||||
public int RequestedWidth { get; }
|
public int RequestedWidth { get; }
|
||||||
public int RequestedHeight { get; }
|
public int RequestedHeight { get; }
|
||||||
|
|
||||||
public Plane YPlane => new Plane((IntPtr)Frame->Data[0], Stride * Height);
|
public Plane YPlane => new((IntPtr)Frame->Data[0], Stride * Height);
|
||||||
public Plane UPlane => new Plane((IntPtr)Frame->Data[1], UvStride * UvHeight);
|
public Plane UPlane => new((IntPtr)Frame->Data[1], UvStride * UvHeight);
|
||||||
public Plane VPlane => new Plane((IntPtr)Frame->Data[2], UvStride * UvHeight);
|
public Plane VPlane => new((IntPtr)Frame->Data[2], UvStride * UvHeight);
|
||||||
|
|
||||||
public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive;
|
public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive;
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
|
|||||||
{
|
{
|
||||||
public bool IsHardwareAccelerated => false;
|
public bool IsHardwareAccelerated => false;
|
||||||
|
|
||||||
private readonly FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_VP8);
|
private readonly FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_VP8);
|
||||||
|
|
||||||
public ISurface CreateSurface(int width, int height)
|
public ISurface CreateSurface(int width, int height)
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
|
|||||||
frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
|
frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
bitstream.CopyTo(new Span<byte>(frame).Slice(uncompHeaderSize));
|
bitstream.CopyTo(new Span<byte>(frame)[uncompHeaderSize..]);
|
||||||
|
|
||||||
return _context.DecodeFrame(outSurf, frame) == 0;
|
return _context.DecodeFrame(outSurf, frame) == 0;
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ namespace Ryujinx.ShaderTools
|
|||||||
|
|
||||||
public ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize)
|
public ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize)
|
||||||
{
|
{
|
||||||
return MemoryMarshal.Cast<byte, ulong>(new ReadOnlySpan<byte>(_data).Slice((int)address));
|
return MemoryMarshal.Cast<byte, ulong>(new ReadOnlySpan<byte>(_data)[(int)address..]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ namespace Ryujinx.ShaderTools
|
|||||||
|
|
||||||
byte[] data = File.ReadAllBytes(options.InputPath);
|
byte[] data = File.ReadAllBytes(options.InputPath);
|
||||||
|
|
||||||
TranslationOptions translationOptions = new TranslationOptions(options.TargetLanguage, options.TargetApi, flags);
|
TranslationOptions translationOptions = new(options.TargetLanguage, options.TargetApi, flags);
|
||||||
|
|
||||||
ShaderProgram program = Translator.CreateContext(0, new GpuAccessor(data), translationOptions).Translate();
|
ShaderProgram program = Translator.CreateContext(0, new GpuAccessor(data), translationOptions).Translate();
|
||||||
|
|
||||||
|
@@ -9,8 +9,6 @@ namespace Ryujinx.Tests.Memory
|
|||||||
{
|
{
|
||||||
public class MultiRegionTrackingTests
|
public class MultiRegionTrackingTests
|
||||||
{
|
{
|
||||||
private const int RndCnt = 3;
|
|
||||||
|
|
||||||
private const ulong MemorySize = 0x8000;
|
private const ulong MemorySize = 0x8000;
|
||||||
private const int PageSize = 4096;
|
private const int PageSize = 4096;
|
||||||
|
|
||||||
@@ -39,7 +37,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
(IMultiRegionHandle)_tracking.BeginGranularTracking(address, size, null, granularity, 0);
|
(IMultiRegionHandle)_tracking.BeginGranularTracking(address, size, null, granularity, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RandomOrder(Random random, List<int> indices, Action<int> action)
|
private static void RandomOrder(Random random, List<int> indices, Action<int> action)
|
||||||
{
|
{
|
||||||
List<int> choices = indices.ToList();
|
List<int> choices = indices.ToList();
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate)
|
private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate)
|
||||||
{
|
{
|
||||||
int regionCount = 0;
|
int regionCount = 0;
|
||||||
ulong lastAddress = startAddress;
|
ulong lastAddress = startAddress;
|
||||||
@@ -67,7 +65,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
return regionCount;
|
return regionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate, int sequenceNumber)
|
private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate, int sequenceNumber)
|
||||||
{
|
{
|
||||||
int regionCount = 0;
|
int regionCount = 0;
|
||||||
ulong lastAddress = startAddress;
|
ulong lastAddress = startAddress;
|
||||||
@@ -83,9 +81,9 @@ namespace Ryujinx.Tests.Memory
|
|||||||
return regionCount;
|
return regionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0)
|
private static void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new();
|
||||||
|
|
||||||
// Make sure the list has minimum granularity (smart region changes granularity based on requested ranges)
|
// Make sure the list has minimum granularity (smart region changes granularity based on requested ranges)
|
||||||
RandomOrder(random, Enumerable.Range(0, pageCount).ToList(), (i) =>
|
RandomOrder(random, Enumerable.Range(0, pageCount).ToList(), (i) =>
|
||||||
@@ -105,7 +103,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
const int pageCount = 32;
|
const int pageCount = 32;
|
||||||
IMultiRegionHandle handle = GetGranular(smart, 0, PageSize * pageCount, PageSize);
|
IMultiRegionHandle handle = GetGranular(smart, 0, PageSize * pageCount, PageSize);
|
||||||
|
|
||||||
Random random = new Random();
|
Random random = new();
|
||||||
|
|
||||||
PreparePages(handle, pageCount);
|
PreparePages(handle, pageCount);
|
||||||
|
|
||||||
@@ -149,7 +147,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
|
|
||||||
PreparePages(handle, pageCount);
|
PreparePages(handle, pageCount);
|
||||||
|
|
||||||
Random random = new Random();
|
Random random = new();
|
||||||
|
|
||||||
IEnumerable<int> halfRange = Enumerable.Range(0, pageCount / 2);
|
IEnumerable<int> halfRange = Enumerable.Range(0, pageCount / 2);
|
||||||
List<int> odd = halfRange.Select(x => x * 2 + 1).ToList();
|
List<int> odd = halfRange.Select(x => x * 2 + 1).ToList();
|
||||||
@@ -240,7 +238,8 @@ namespace Ryujinx.Tests.Memory
|
|||||||
ulong expectedAddress = 0;
|
ulong expectedAddress = 0;
|
||||||
|
|
||||||
// Expect each region to trigger in its entirety, in address ascending order.
|
// Expect each region to trigger in its entirety, in address ascending order.
|
||||||
handle.QueryModified((address, size) => {
|
handle.QueryModified((address, size) =>
|
||||||
|
{
|
||||||
int region = regionSizes[regionInd++];
|
int region = regionSizes[regionInd++];
|
||||||
|
|
||||||
Assert.AreEqual(address, expectedAddress);
|
Assert.AreEqual(address, expectedAddress);
|
||||||
|
@@ -7,14 +7,14 @@ namespace Ryujinx.Tests.Memory
|
|||||||
{
|
{
|
||||||
public class Tests
|
public class Tests
|
||||||
{
|
{
|
||||||
private static readonly ulong MemorySize = MemoryBlock.GetPageSize() * 8;
|
private static readonly ulong _memorySize = MemoryBlock.GetPageSize() * 8;
|
||||||
|
|
||||||
private MemoryBlock _memoryBlock;
|
private MemoryBlock _memoryBlock;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
_memoryBlock = new MemoryBlock(MemorySize);
|
_memoryBlock = new MemoryBlock(_memorySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
@@ -47,8 +47,8 @@ namespace Ryujinx.Tests.Memory
|
|||||||
ulong pageSize = MemoryBlock.GetPageSize();
|
ulong pageSize = MemoryBlock.GetPageSize();
|
||||||
ulong blockSize = MemoryBlock.GetPageSize() * 16;
|
ulong blockSize = MemoryBlock.GetPageSize() * 16;
|
||||||
|
|
||||||
using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable);
|
using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable);
|
||||||
using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
||||||
|
|
||||||
toAlias.MapView(backing, pageSize, 0, pageSize * 4);
|
toAlias.MapView(backing, pageSize, 0, pageSize * 4);
|
||||||
toAlias.UnmapView(backing, pageSize * 3, pageSize);
|
toAlias.UnmapView(backing, pageSize * 3, pageSize);
|
||||||
@@ -66,10 +66,10 @@ namespace Ryujinx.Tests.Memory
|
|||||||
int pageBits = (int)ulong.Log2(pageSize);
|
int pageBits = (int)ulong.Log2(pageSize);
|
||||||
ulong blockSize = MemoryBlock.GetPageSize() * 128;
|
ulong blockSize = MemoryBlock.GetPageSize() * 128;
|
||||||
|
|
||||||
using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable);
|
using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable);
|
||||||
using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
||||||
|
|
||||||
Random rng = new Random(123);
|
Random rng = new(123);
|
||||||
|
|
||||||
for (int i = 0; i < 20000; i++)
|
for (int i = 0; i < 20000; i++)
|
||||||
{
|
{
|
||||||
@@ -101,8 +101,8 @@ namespace Ryujinx.Tests.Memory
|
|||||||
ulong pageSize = MemoryBlock.GetPageSize();
|
ulong pageSize = MemoryBlock.GetPageSize();
|
||||||
ulong size = 100000 * pageSize; // The mappings limit on Linux is usually around 65K, so let's make sure we are above that.
|
ulong size = 100000 * pageSize; // The mappings limit on Linux is usually around 65K, so let's make sure we are above that.
|
||||||
|
|
||||||
using MemoryBlock backing = new MemoryBlock(pageSize, MemoryAllocationFlags.Mirrorable);
|
using MemoryBlock backing = new(pageSize, MemoryAllocationFlags.Mirrorable);
|
||||||
using MemoryBlock toAlias = new MemoryBlock(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
using MemoryBlock toAlias = new(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
|
||||||
|
|
||||||
for (ulong offset = 0; offset < size; offset += pageSize)
|
for (ulong offset = 0; offset < size; offset += pageSize)
|
||||||
{
|
{
|
||||||
|
@@ -102,15 +102,17 @@ namespace Ryujinx.Tests.Memory
|
|||||||
allHandle.Reprotect();
|
allHandle.Reprotect();
|
||||||
|
|
||||||
(ulong address, ulong size)? readTrackingTriggeredAll = null;
|
(ulong address, ulong size)? readTrackingTriggeredAll = null;
|
||||||
Action registerReadAction = () =>
|
|
||||||
|
void RegisterReadAction()
|
||||||
{
|
{
|
||||||
readTrackingTriggeredAll = null;
|
readTrackingTriggeredAll = null;
|
||||||
allHandle.RegisterAction((address, size) =>
|
allHandle.RegisterAction((address, size) =>
|
||||||
{
|
{
|
||||||
readTrackingTriggeredAll = (address, size);
|
readTrackingTriggeredAll = (address, size);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
registerReadAction();
|
|
||||||
|
RegisterReadAction();
|
||||||
|
|
||||||
// Create 16 page sized handles contained within the allHandle.
|
// Create 16 page sized handles contained within the allHandle.
|
||||||
RegionHandle[] containedHandles = new RegionHandle[16];
|
RegionHandle[] containedHandles = new RegionHandle[16];
|
||||||
@@ -149,7 +151,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear flags and reset read action.
|
// Clear flags and reset read action.
|
||||||
registerReadAction();
|
RegisterReadAction();
|
||||||
allHandle.Reprotect();
|
allHandle.Reprotect();
|
||||||
containedHandles[i].Reprotect();
|
containedHandles[i].Reprotect();
|
||||||
}
|
}
|
||||||
@@ -204,7 +206,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
long finishedTime = 0;
|
long finishedTime = 0;
|
||||||
|
|
||||||
RegionHandle[] handles = new RegionHandle[threadCount * handlesPerThread];
|
RegionHandle[] handles = new RegionHandle[threadCount * handlesPerThread];
|
||||||
Random globalRand = new Random();
|
Random globalRand = new();
|
||||||
|
|
||||||
for (int i = 0; i < handles.Length; i++)
|
for (int i = 0; i < handles.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -212,7 +214,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
handles[i].Reprotect();
|
handles[i].Reprotect();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Thread> testThreads = new List<Thread>();
|
List<Thread> testThreads = new();
|
||||||
|
|
||||||
// Dirty flag consumer threads
|
// Dirty flag consumer threads
|
||||||
int dirtyFlagReprotects = 0;
|
int dirtyFlagReprotects = 0;
|
||||||
@@ -224,7 +226,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
int handleBase = randSeed * handlesPerThread;
|
int handleBase = randSeed * handlesPerThread;
|
||||||
while (Stopwatch.GetTimestamp() < finishedTime)
|
while (Stopwatch.GetTimestamp() < finishedTime)
|
||||||
{
|
{
|
||||||
Random random = new Random(randSeed);
|
Random random = new(randSeed);
|
||||||
RegionHandle handle = handles[handleBase + random.Next(handlesPerThread)];
|
RegionHandle handle = handles[handleBase + random.Next(handlesPerThread)];
|
||||||
|
|
||||||
if (handle.Dirty)
|
if (handle.Dirty)
|
||||||
@@ -243,7 +245,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
int randSeed = i;
|
int randSeed = i;
|
||||||
testThreads.Add(new Thread(() =>
|
testThreads.Add(new Thread(() =>
|
||||||
{
|
{
|
||||||
Random random = new Random(randSeed);
|
Random random = new(randSeed);
|
||||||
ulong handleBase = (ulong)(randSeed * handlesPerThread * PageSize);
|
ulong handleBase = (ulong)(randSeed * handlesPerThread * PageSize);
|
||||||
while (Stopwatch.GetTimestamp() < finishedTime)
|
while (Stopwatch.GetTimestamp() < finishedTime)
|
||||||
{
|
{
|
||||||
@@ -261,7 +263,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
testThreads.Add(new Thread(() =>
|
testThreads.Add(new Thread(() =>
|
||||||
{
|
{
|
||||||
int maxAddress = threadCount * handlesPerThread * PageSize;
|
int maxAddress = threadCount * handlesPerThread * PageSize;
|
||||||
Random random = new Random(randSeed + 512);
|
Random random = new(randSeed + 512);
|
||||||
while (Stopwatch.GetTimestamp() < finishedTime)
|
while (Stopwatch.GetTimestamp() < finishedTime)
|
||||||
{
|
{
|
||||||
RegionHandle handle = _tracking.BeginTracking((ulong)random.Next(maxAddress), (ulong)random.Next(65536), 0);
|
RegionHandle handle = _tracking.BeginTracking((ulong)random.Next(maxAddress), (ulong)random.Next(65536), 0);
|
||||||
@@ -303,7 +305,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
int signalThreadsDone = 0;
|
int signalThreadsDone = 0;
|
||||||
bool isRegistered = false;
|
bool isRegistered = false;
|
||||||
|
|
||||||
Action registerReadAction = () =>
|
void RegisterReadAction()
|
||||||
{
|
{
|
||||||
registeredCount++;
|
registeredCount++;
|
||||||
handle.RegisterAction((address, size) =>
|
handle.RegisterAction((address, size) =>
|
||||||
@@ -311,7 +313,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
isRegistered = false;
|
isRegistered = false;
|
||||||
Interlocked.Increment(ref triggeredCount);
|
Interlocked.Increment(ref triggeredCount);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
const int threadCount = 16;
|
const int threadCount = 16;
|
||||||
const int iterationCount = 10000;
|
const int iterationCount = 10000;
|
||||||
@@ -322,7 +324,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
int randSeed = i;
|
int randSeed = i;
|
||||||
signalThreads[i] = new Thread(() =>
|
signalThreads[i] = new Thread(() =>
|
||||||
{
|
{
|
||||||
Random random = new Random(randSeed);
|
Random random = new(randSeed);
|
||||||
for (int j = 0; j < iterationCount; j++)
|
for (int j = 0; j < iterationCount; j++)
|
||||||
{
|
{
|
||||||
_tracking.VirtualMemoryEvent((ulong)random.Next(PageSize), 4, false);
|
_tracking.VirtualMemoryEvent((ulong)random.Next(PageSize), 4, false);
|
||||||
@@ -346,7 +348,7 @@ namespace Ryujinx.Tests.Memory
|
|||||||
if (!isRegistered)
|
if (!isRegistered)
|
||||||
{
|
{
|
||||||
isRegistered = true;
|
isRegistered = true;
|
||||||
registerReadAction();
|
RegisterReadAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user