NVDEC implementation using FFmpeg (#443)
* Initial nvdec implementation using FFmpeg * Fix swapped channels on the video decoder and the G8R8 texture format * Fix texture samplers not being set properly (regression) * Rebased * Remove unused code introduced on the rebase * Add support for RGBA8 output format on the video image composer * Correct spacing * Some fixes for rebase and other tweaks * Allow size mismatch on frame copy * Get rid of GetHostAddress calls on VDec
This commit is contained in:
parent
ad00fd0244
commit
c86aacde76
65 changed files with 2795 additions and 76 deletions
|
@ -3,6 +3,7 @@ using Ryujinx.Common.Logging;
|
|||
using Ryujinx.Graphics.Memory;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Services.Nv.NvGpuAS;
|
||||
using Ryujinx.HLE.HOS.Services.Nv.NvMap;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
|
@ -10,37 +11,25 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvHostChannel
|
|||
{
|
||||
class NvHostChannelIoctl
|
||||
{
|
||||
private class ChannelsPerProcess
|
||||
{
|
||||
public ConcurrentDictionary<NvChannelName, NvChannel> Channels { get; private set; }
|
||||
|
||||
public ChannelsPerProcess()
|
||||
{
|
||||
Channels = new ConcurrentDictionary<NvChannelName, NvChannel>();
|
||||
|
||||
Channels.TryAdd(NvChannelName.Gpu, new NvChannel());
|
||||
}
|
||||
}
|
||||
|
||||
private static ConcurrentDictionary<KProcess, ChannelsPerProcess> Channels;
|
||||
private static ConcurrentDictionary<KProcess, NvChannel> Channels;
|
||||
|
||||
static NvHostChannelIoctl()
|
||||
{
|
||||
Channels = new ConcurrentDictionary<KProcess, ChannelsPerProcess>();
|
||||
Channels = new ConcurrentDictionary<KProcess, NvChannel>();
|
||||
}
|
||||
|
||||
public static int ProcessIoctlGpu(ServiceCtx Context, int Cmd)
|
||||
{
|
||||
return ProcessIoctl(Context, NvChannelName.Gpu, Cmd);
|
||||
}
|
||||
|
||||
public static int ProcessIoctl(ServiceCtx Context, NvChannelName Channel, int Cmd)
|
||||
public static int ProcessIoctl(ServiceCtx Context, int Cmd)
|
||||
{
|
||||
switch (Cmd & 0xffff)
|
||||
{
|
||||
case 0x0001: return Submit (Context);
|
||||
case 0x0002: return GetSyncpoint (Context);
|
||||
case 0x0003: return GetWaitBase (Context);
|
||||
case 0x0009: return MapBuffer (Context);
|
||||
case 0x000a: return UnmapBuffer (Context);
|
||||
case 0x4714: return SetUserData (Context);
|
||||
case 0x4801: return SetNvMap (Context);
|
||||
case 0x4803: return SetTimeout (Context, Channel);
|
||||
case 0x4803: return SetTimeout (Context);
|
||||
case 0x4808: return SubmitGpfifo (Context);
|
||||
case 0x4809: return AllocObjCtx (Context);
|
||||
case 0x480b: return ZcullBind (Context);
|
||||
|
@ -53,6 +42,138 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvHostChannel
|
|||
throw new NotImplementedException(Cmd.ToString("x8"));
|
||||
}
|
||||
|
||||
private static int Submit(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
long OutputPosition = Context.Request.GetBufferType0x22().Position;
|
||||
|
||||
NvHostChannelSubmit Args = MemoryHelper.Read<NvHostChannelSubmit>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;
|
||||
|
||||
for (int Index = 0; Index < Args.CmdBufsCount; Index++)
|
||||
{
|
||||
long CmdBufOffset = InputPosition + 0x10 + Index * 0xc;
|
||||
|
||||
NvHostChannelCmdBuf CmdBuf = MemoryHelper.Read<NvHostChannelCmdBuf>(Context.Memory, CmdBufOffset);
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMap(Context, CmdBuf.MemoryId);
|
||||
|
||||
int[] CmdBufData = new int[CmdBuf.WordsCount];
|
||||
|
||||
for (int Offset = 0; Offset < CmdBufData.Length; Offset++)
|
||||
{
|
||||
CmdBufData[Offset] = Context.Memory.ReadInt32(Map.Address + CmdBuf.Offset + Offset * 4);
|
||||
}
|
||||
|
||||
Context.Device.Gpu.PushCommandBuffer(Vmm, CmdBufData);
|
||||
}
|
||||
|
||||
//TODO: Relocation, waitchecks, etc.
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int GetSyncpoint(ServiceCtx Context)
|
||||
{
|
||||
//TODO
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
long OutputPosition = Context.Request.GetBufferType0x22().Position;
|
||||
|
||||
NvHostChannelGetParamArg Args = MemoryHelper.Read<NvHostChannelGetParamArg>(Context.Memory, InputPosition);
|
||||
|
||||
Args.Value = 0;
|
||||
|
||||
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int GetWaitBase(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
long OutputPosition = Context.Request.GetBufferType0x22().Position;
|
||||
|
||||
NvHostChannelGetParamArg Args = MemoryHelper.Read<NvHostChannelGetParamArg>(Context.Memory, InputPosition);
|
||||
|
||||
Args.Value = 0;
|
||||
|
||||
MemoryHelper.Write(Context.Memory, OutputPosition, Args);
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int MapBuffer(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
long OutputPosition = Context.Request.GetBufferType0x22().Position;
|
||||
|
||||
NvHostChannelMapBuffer Args = MemoryHelper.Read<NvHostChannelMapBuffer>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;
|
||||
|
||||
for (int Index = 0; Index < Args.NumEntries; Index++)
|
||||
{
|
||||
int Handle = Context.Memory.ReadInt32(InputPosition + 0xc + Index * 8);
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMap(Context, Handle);
|
||||
|
||||
if (Map == null)
|
||||
{
|
||||
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Handle:x8}!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
lock (Map)
|
||||
{
|
||||
if (Map.DmaMapAddress == 0)
|
||||
{
|
||||
Map.DmaMapAddress = Vmm.MapLow(Map.Address, Map.Size);
|
||||
}
|
||||
|
||||
Context.Memory.WriteInt32(OutputPosition + 0xc + 4 + Index * 8, (int)Map.DmaMapAddress);
|
||||
}
|
||||
}
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int UnmapBuffer(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
|
||||
NvHostChannelMapBuffer Args = MemoryHelper.Read<NvHostChannelMapBuffer>(Context.Memory, InputPosition);
|
||||
|
||||
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;
|
||||
|
||||
for (int Index = 0; Index < Args.NumEntries; Index++)
|
||||
{
|
||||
int Handle = Context.Memory.ReadInt32(InputPosition + 0xc + Index * 8);
|
||||
|
||||
NvMapHandle Map = NvMapIoctl.GetNvMap(Context, Handle);
|
||||
|
||||
if (Map == null)
|
||||
{
|
||||
Logger.PrintWarning(LogClass.ServiceNv, $"Invalid handle 0x{Handle:x8}!");
|
||||
|
||||
return NvResult.InvalidInput;
|
||||
}
|
||||
|
||||
lock (Map)
|
||||
{
|
||||
if (Map.DmaMapAddress != 0)
|
||||
{
|
||||
Vmm.Free(Map.DmaMapAddress, Map.Size);
|
||||
|
||||
Map.DmaMapAddress = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int SetUserData(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
|
@ -73,11 +194,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvHostChannel
|
|||
return NvResult.Success;
|
||||
}
|
||||
|
||||
private static int SetTimeout(ServiceCtx Context, NvChannelName Channel)
|
||||
private static int SetTimeout(ServiceCtx Context)
|
||||
{
|
||||
long InputPosition = Context.Request.GetBufferType0x21().Position;
|
||||
|
||||
GetChannel(Context, Channel).Timeout = Context.Memory.ReadInt32(InputPosition);
|
||||
GetChannel(Context).Timeout = Context.Memory.ReadInt32(InputPosition);
|
||||
|
||||
return NvResult.Success;
|
||||
}
|
||||
|
@ -185,14 +306,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvHostChannel
|
|||
Context.Device.Gpu.Pusher.Push(Vmm, Gpfifo);
|
||||
}
|
||||
|
||||
public static NvChannel GetChannel(ServiceCtx Context, NvChannelName Channel)
|
||||
public static NvChannel GetChannel(ServiceCtx Context)
|
||||
{
|
||||
ChannelsPerProcess Cpp = Channels.GetOrAdd(Context.Process, (Key) =>
|
||||
{
|
||||
return new ChannelsPerProcess();
|
||||
});
|
||||
|
||||
return Cpp.Channels[Channel];
|
||||
return Channels.GetOrAdd(Context.Process, (Key) => new NvChannel());
|
||||
}
|
||||
|
||||
public static void UnloadProcess(KProcess Process)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue