aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Vic/VicDevice.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-12 00:07:01 -0300
committerGitHub <noreply@github.com>2020-07-12 05:07:01 +0200
commit4d02a2d2c0451b4de1f6de3bbce54c457cacebe2 (patch)
tree120fe4fb8cfa1ac1c6ef4c97d92be47e955e8c0f /Ryujinx.Graphics.Vic/VicDevice.cs
parent38b26cf4242999fa7d8c550993ac0940cd03d55f (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.Vic/VicDevice.cs')
-rw-r--r--Ryujinx.Graphics.Vic/VicDevice.cs97
1 files changed, 97 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Vic/VicDevice.cs b/Ryujinx.Graphics.Vic/VicDevice.cs
new file mode 100644
index 00000000..db4fe513
--- /dev/null
+++ b/Ryujinx.Graphics.Vic/VicDevice.cs
@@ -0,0 +1,97 @@
+using Ryujinx.Common.Logging;
+using Ryujinx.Graphics.Device;
+using Ryujinx.Graphics.Gpu.Memory;
+using Ryujinx.Graphics.Vic.Image;
+using Ryujinx.Graphics.Vic.Types;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.Graphics.Vic
+{
+ public class VicDevice : IDeviceState
+ {
+ private readonly MemoryManager _gmm;
+ private readonly ResourceManager _rm;
+ private readonly DeviceState<VicRegisters> _state;
+
+ private PlaneOffsets _overrideOffsets;
+ private bool _hasOverride;
+
+ public VicDevice(MemoryManager gmm)
+ {
+ _gmm = gmm;
+ _rm = new ResourceManager(gmm, new BufferPool<Pixel>(), new BufferPool<byte>());
+ _state = new DeviceState<VicRegisters>(new Dictionary<string, RwCallback>
+ {
+ { nameof(VicRegisters.Execute), new RwCallback(Execute, null) }
+ });
+ }
+
+ /// <summary>
+ /// Overrides all input surfaces with a custom surface.
+ /// </summary>
+ /// <param name="lumaOffset">Offset of the luma plane or packed data for this surface</param>
+ /// <param name="chromaUOffset">Offset of the U chroma plane (for planar formats) or both chroma planes (for semiplanar formats)</param>
+ /// <param name="chromaVOffset">Offset of the V chroma plane for planar formats</param>
+ public void SetSurfaceOverride(uint lumaOffset, uint chromaUOffset, uint chromaVOffset)
+ {
+ _overrideOffsets.LumaOffset = lumaOffset;
+ _overrideOffsets.ChromaUOffset = chromaUOffset;
+ _overrideOffsets.ChromaVOffset = chromaVOffset;
+ _hasOverride = true;
+ }
+
+ /// <summary>
+ /// Disables overriding input surfaces.
+ /// </summary>
+ /// <remarks>
+ /// Surface overrides are disabled by default.
+ /// Call this if you previously called <see cref="SetSurfaceOverride(uint, uint, uint)"/> and which to disable it.
+ /// </remarks>
+ public void DisableSurfaceOverride()
+ {
+ _hasOverride = false;
+ }
+
+ public int Read(int offset) => _state.Read(offset);
+ public void Write(int offset, int data) => _state.Write(offset, data);
+
+ private void Execute(int data)
+ {
+ ConfigStruct config = ReadIndirect<ConfigStruct>(_state.State.SetConfigStructOffset);
+
+ using Surface output = new Surface(
+ _rm.SurfacePool,
+ config.OutputSurfaceConfig.OutSurfaceWidth + 1,
+ config.OutputSurfaceConfig.OutSurfaceHeight + 1);
+
+ for (int i = 0; i < config.SlotStruct.Length; i++)
+ {
+ ref SlotStruct slot = ref config.SlotStruct[i];
+
+ if (!slot.SlotConfig.SlotEnable)
+ {
+ continue;
+ }
+
+ var offsets = _state.State.SetSurfacexSlotx[i][0];
+
+ if (_hasOverride)
+ {
+ offsets = _overrideOffsets;
+ }
+
+ using Surface src = SurfaceReader.Read(_rm, ref slot.SlotSurfaceConfig, ref offsets);
+
+ Blender.BlendOne(output, src, ref slot);
+ }
+
+ SurfaceWriter.Write(_rm, output, ref config.OutputSurfaceConfig, ref _state.State.SetOutputSurface);
+ }
+
+ private T ReadIndirect<T>(uint offset) where T : unmanaged
+ {
+ return _gmm.Read<T>((ulong)offset << 8);
+ }
+ }
+}