diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2020-07-12 00:07:01 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-12 05:07:01 +0200 |
| commit | 4d02a2d2c0451b4de1f6de3bbce54c457cacebe2 (patch) | |
| tree | 120fe4fb8cfa1ac1c6ef4c97d92be47e955e8c0f /Ryujinx.Graphics.Host1x/Host1xDevice.cs | |
| parent | 38b26cf4242999fa7d8c550993ac0940cd03d55f (diff) | |
New NVDEC and VIC implementation (#1384)
* Initial NVDEC and VIC implementation
* Update FFmpeg.AutoGen to 4.3.0
* Add nvdec dependencies for Windows
* Unify some VP9 structures
* Rename VP9 structure fields
* Improvements to Video API
* XML docs for Common.Memory
* Remove now unused or redundant overloads from MemoryAccessor
* NVDEC UV surface read/write scalar paths
* Add FIXME comments about hacky things/stuff that will need to be fixed in the future
* Cleaned up VP9 memory allocation
* Remove some debug logs
* Rename some VP9 structs
* Remove unused struct
* No need to compile Ryujinx.Graphics.Host1x with unsafe anymore
* Name AsyncWorkQueue threads to make debugging easier
* Make Vp9PictureInfo a ref struct
* LayoutConverter no longer needs the depth argument (broken by rebase)
* Pooling of VP9 buffers, plus fix a memory leak on VP9
* Really wish VS could rename projects properly...
* Address feedback
* Remove using
* Catch OperationCanceledException
* Add licensing informations
* Add THIRDPARTY.md to release too
Co-authored-by: Thog <me@thog.eu>
Diffstat (limited to 'Ryujinx.Graphics.Host1x/Host1xDevice.cs')
| -rw-r--r-- | Ryujinx.Graphics.Host1x/Host1xDevice.cs | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Host1x/Host1xDevice.cs b/Ryujinx.Graphics.Host1x/Host1xDevice.cs new file mode 100644 index 00000000..6406378f --- /dev/null +++ b/Ryujinx.Graphics.Host1x/Host1xDevice.cs @@ -0,0 +1,123 @@ +using Ryujinx.Common; +using Ryujinx.Common.Logging; +using Ryujinx.Graphics.Device; +using Ryujinx.Graphics.Gpu.Synchronization; +using System; +using System.Numerics; + +namespace Ryujinx.Graphics.Host1x +{ + public sealed class Host1xDevice : IDisposable + { + private readonly SyncptIncrManager _syncptIncrMgr; + private readonly AsyncWorkQueue<int[]> _commandQueue; + + private readonly Devices _devices = new Devices(); + + public Host1xClass Class { get; } + + private IDeviceState _device; + + private int _count; + private int _offset; + private int _mask; + private bool _incrementing; + + public Host1xDevice(SynchronizationManager syncMgr) + { + _syncptIncrMgr = new SyncptIncrManager(syncMgr); + _commandQueue = new AsyncWorkQueue<int[]>(Process, "Ryujinx.Host1xProcessor"); + + Class = new Host1xClass(syncMgr); + + _devices.RegisterDevice(ClassId.Host1x, Class); + } + + public void RegisterDevice(ClassId classId, IDeviceState device) + { + var thi = new ThiDevice(classId, device ?? throw new ArgumentNullException(nameof(device)), _syncptIncrMgr); + _devices.RegisterDevice(classId, thi); + } + + public void Submit(ReadOnlySpan<int> commandBuffer) + { + _commandQueue.Add(commandBuffer.ToArray()); + } + + private void Process(int[] commandBuffer) + { + for (int index = 0; index < commandBuffer.Length; index++) + { + Step(commandBuffer[index]); + } + } + + private void Step(int value) + { + if (_mask != 0) + { + int lbs = BitOperations.TrailingZeroCount(_mask); + + _mask &= ~(1 << lbs); + + DeviceWrite(_offset + lbs, value); + + return; + } + else if (_count != 0) + { + _count--; + + DeviceWrite(_offset, value); + + if (_incrementing) + { + _offset++; + } + + return; + } + + OpCode opCode = (OpCode)((value >> 28) & 0xf); + + switch (opCode) + { + case OpCode.SetClass: + _mask = value & 0x3f; + ClassId classId = (ClassId)((value >> 6) & 0x3ff); + _offset = (value >> 16) & 0xfff; + _device = _devices.GetDevice(classId); + break; + case OpCode.Incr: + case OpCode.NonIncr: + _count = value & 0xffff; + _offset = (value >> 16) & 0xfff; + _incrementing = opCode == OpCode.Incr; + break; + case OpCode.Mask: + _mask = value & 0xffff; + _offset = (value >> 16) & 0xfff; + break; + case OpCode.Imm: + int data = value & 0xfff; + _offset = (value >> 16) & 0xfff; + DeviceWrite(_offset, data); + break; + default: + Logger.PrintError(LogClass.Host1x, $"Unsupported opcode \"{opCode}\"."); + break; + } + } + + private void DeviceWrite(int offset, int data) + { + _device?.Write(offset * 4, data); + } + + public void Dispose() + { + _commandQueue.Dispose(); + _devices.Dispose(); + } + } +} |
