Ryujinx/src/Ryujinx.Graphics.Nvdec/NvdecDevice.cs
TSRBerry 07fc3ded68
[Ryujinx.Graphics.Nvdec] Address dotnet-format issues (#5369)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Add previously silenced warnings back

I have no clue how these disappeared

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Address IDE0251 warnings

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass
2023-06-25 21:44:42 +02:00

83 lines
2.6 KiB
C#

using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Nvdec.Image;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
namespace Ryujinx.Graphics.Nvdec
{
public class NvdecDevice : IDeviceStateWithContext
{
private readonly ResourceManager _rm;
private readonly DeviceState<NvdecRegisters> _state;
private long _currentId;
private readonly ConcurrentDictionary<long, NvdecDecoderContext> _contexts;
private NvdecDecoderContext _currentContext;
public NvdecDevice(MemoryManager gmm)
{
_rm = new ResourceManager(gmm, new SurfaceCache(gmm));
_state = new DeviceState<NvdecRegisters>(new Dictionary<string, RwCallback>
{
{ nameof(NvdecRegisters.Execute), new RwCallback(Execute, null) }
});
_contexts = new ConcurrentDictionary<long, NvdecDecoderContext>();
}
public long CreateContext()
{
long id = Interlocked.Increment(ref _currentId);
_contexts.TryAdd(id, new NvdecDecoderContext());
return id;
}
public void DestroyContext(long id)
{
if (_contexts.TryRemove(id, out var context))
{
context.Dispose();
}
_rm.Cache.Trim();
}
public void BindContext(long id)
{
if (_contexts.TryGetValue(id, out var context))
{
_currentContext = context;
}
}
public int Read(int offset) => _state.Read(offset);
public void Write(int offset, int data) => _state.Write(offset, data);
private void Execute(int data)
{
Decode((ApplicationId)_state.State.SetApplicationId);
}
private void Decode(ApplicationId applicationId)
{
switch (applicationId)
{
case ApplicationId.H264:
H264Decoder.Decode(_currentContext, _rm, ref _state.State);
break;
case ApplicationId.Vp8:
Vp8Decoder.Decode(_currentContext, _rm, ref _state.State);
break;
case ApplicationId.Vp9:
Vp9Decoder.Decode(_rm, ref _state.State);
break;
default:
Logger.Error?.Print(LogClass.Nvdec, $"Unsupported codec \"{applicationId}\".");
break;
}
}
}
}