From 44d7fcff399888d311f61772a53146d924ee5b62 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Fri, 29 May 2020 05:51:10 -0300 Subject: Implement FIFO semaphore (#1286) * Implement FIFO semaphore * New enum for FIFO semaphore operation --- Ryujinx.Graphics.Gpu/Engine/MethodFifo.cs | 28 +++++++++++++++++++++++++++- Ryujinx.Graphics.Gpu/Engine/MethodReport.cs | 13 ++++++------- Ryujinx.Graphics.Gpu/Engine/Methods.cs | 3 ++- 3 files changed, 35 insertions(+), 9 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Engine') diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodFifo.cs b/Ryujinx.Graphics.Gpu/Engine/MethodFifo.cs index 1c0e72e5..c1f45941 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodFifo.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodFifo.cs @@ -1,11 +1,37 @@ using Ryujinx.Graphics.Gpu.State; -using System; using System.Threading; namespace Ryujinx.Graphics.Gpu.Engine { partial class Methods { + /// + /// Writes a GPU counter to guest memory. + /// + /// Current GPU state + /// Method call argument + public void Semaphore(GpuState state, int argument) + { + FifoSemaphoreOperation op = (FifoSemaphoreOperation)(argument & 3); + + var semaphore = state.Get(MethodOffset.Semaphore); + + int value = semaphore.Payload; + + if (op == FifoSemaphoreOperation.Counter) + { + // TODO: There's much more that should be done here. + // NVN only supports the "Accumulate" mode, so we + // can't currently guess which bits specify the + // reduction operation. + value += _context.MemoryAccessor.Read(semaphore.Address.Pack()); + } + + _context.MemoryAccessor.Write(semaphore.Address.Pack(), value); + + _context.AdvanceSequence(); + } + /// /// Waits for the GPU to be idle. /// diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs b/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs index e8efddea..224a4da1 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs @@ -21,14 +21,13 @@ namespace Ryujinx.Graphics.Gpu.Engine /// Method call argument private void Report(GpuState state, int argument) { - ReportMode mode = (ReportMode)(argument & 3); - + SemaphoreOperation op = (SemaphoreOperation)(argument & 3); ReportCounterType type = (ReportCounterType)((argument >> 23) & 0x1f); - switch (mode) + switch (op) { - case ReportMode.Release: ReleaseSemaphore(state); break; - case ReportMode.Counter: ReportCounter(state, type); break; + case SemaphoreOperation.Release: ReleaseSemaphore(state); break; + case SemaphoreOperation.Counter: ReportCounter(state, type); break; } } @@ -38,7 +37,7 @@ namespace Ryujinx.Graphics.Gpu.Engine /// Current GPU state private void ReleaseSemaphore(GpuState state) { - var rs = state.Get(MethodOffset.ReportState); + var rs = state.Get(MethodOffset.ReportState); _context.MemoryAccessor.Write(rs.Address.Pack(), rs.Payload); @@ -64,7 +63,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { CounterData counterData = new CounterData(); - var rs = state.Get(MethodOffset.ReportState); + var rs = state.Get(MethodOffset.ReportState); ulong gpuVa = rs.Address.Pack(); diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index d67ce2d1..5957bb62 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -104,6 +104,7 @@ namespace Ryujinx.Graphics.Gpu.Engine /// GPU state where the triggers will be registered public void RegisterCallbacksForFifo(GpuState state) { + state.RegisterCallback(MethodOffset.Semaphore, Semaphore); state.RegisterCallback(MethodOffset.FenceAction, FenceAction); state.RegisterCallback(MethodOffset.WaitForIdle, WaitForIdle); state.RegisterCallback(MethodOffset.SendMacroCodeData, SendMacroCodeData); @@ -430,7 +431,7 @@ namespace Ryujinx.Graphics.Gpu.Engine _context.Renderer.Pipeline.SetOrigin(origin); // The triangle rast flip flag only affects rasterization, the viewport is not flipped. - // Setting the origin mode to upper left on the host, however, not onlyy affects rasterization, + // Setting the origin mode to upper left on the host, however, not only affects rasterization, // but also flips the viewport. // We negate the effects of flipping the viewport by flipping it again using the viewport swizzle. if (origin == Origin.UpperLeft) -- cgit v1.2.3