From 40b21cc3c4d2622bbd4f88d43073341854d9a671 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 11 Jul 2021 17:20:40 -0300 Subject: Separate GPU engines (part 2/2) (#2440) * 3D engine now uses DeviceState too, plus new state modification tracking * Remove old methods code * Remove GpuState and friends * Optimize DeviceState, force inline some functions * This change was not supposed to go in * Proper channel initialization * Optimize state read/write methods even more * Fix debug build * Do not dirty state if the write is redundant * The YControl register should dirty either the viewport or front face state too, to update the host origin * Avoid redundant vertex buffer updates * Move state and get rid of the Ryujinx.Graphics.Gpu.State namespace * Comments and nits * Fix rebase * PR feedback * Move changed = false to improve codegen * PR feedback * Carry RyuJIT a bit more --- Ryujinx.Graphics.Gpu/Engine/MethodReport.cs | 131 ---------------------------- 1 file changed, 131 deletions(-) delete mode 100644 Ryujinx.Graphics.Gpu/Engine/MethodReport.cs (limited to 'Ryujinx.Graphics.Gpu/Engine/MethodReport.cs') diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs b/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs deleted file mode 100644 index 2dd0bbfa..00000000 --- a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs +++ /dev/null @@ -1,131 +0,0 @@ -using Ryujinx.Common; -using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.Gpu.Memory; -using Ryujinx.Graphics.Gpu.State; -using System; -using System.Runtime.InteropServices; - -namespace Ryujinx.Graphics.Gpu.Engine -{ - partial class Methods - { - private const int NsToTicksFractionNumerator = 384; - private const int NsToTicksFractionDenominator = 625; - - /// - /// Writes a GPU counter to guest memory. - /// - /// Current GPU state - /// Method call argument - private void Report(GpuState state, int argument) - { - SemaphoreOperation op = (SemaphoreOperation)(argument & 3); - ReportCounterType type = (ReportCounterType)((argument >> 23) & 0x1f); - - switch (op) - { - case SemaphoreOperation.Release: ReleaseSemaphore(state); break; - case SemaphoreOperation.Counter: ReportCounter(state, type); break; - } - } - - /// - /// Writes (or Releases) a GPU semaphore value to guest memory. - /// - /// Current GPU state - private void ReleaseSemaphore(GpuState state) - { - var rs = state.Get(MethodOffset.ReportState); - - state.Channel.MemoryManager.Write(rs.Address.Pack(), rs.Payload); - - _context.AdvanceSequence(); - } - - /// - /// Packed GPU counter data (including GPU timestamp) in memory. - /// - private struct CounterData - { - public ulong Counter; - public ulong Timestamp; - } - - /// - /// Writes a GPU counter to guest memory. - /// This also writes the current timestamp value. - /// - /// Current GPU state - /// Counter to be written to memory - private void ReportCounter(GpuState state, ReportCounterType type) - { - var rs = state.Get(MethodOffset.ReportState); - - ulong gpuVa = rs.Address.Pack(); - - ulong ticks = ConvertNanosecondsToTicks((ulong)PerformanceCounter.ElapsedNanoseconds); - - if (GraphicsConfig.FastGpuTime) - { - // Divide by some amount to report time as if operations were performed faster than they really are. - // This can prevent some games from switching to a lower resolution because rendering is too slow. - ticks /= 256; - } - - ICounterEvent counter = null; - - EventHandler resultHandler = (object evt, ulong result) => - { - CounterData counterData = new CounterData(); - - counterData.Counter = result; - counterData.Timestamp = ticks; - - if (counter?.Invalid != true) - { - state.Channel.MemoryManager.Write(gpuVa, counterData); - } - }; - - switch (type) - { - case ReportCounterType.Zero: - resultHandler(null, 0); - break; - case ReportCounterType.SamplesPassed: - counter = _context.Renderer.ReportCounter(CounterType.SamplesPassed, resultHandler); - break; - case ReportCounterType.PrimitivesGenerated: - counter = _context.Renderer.ReportCounter(CounterType.PrimitivesGenerated, resultHandler); - break; - case ReportCounterType.TransformFeedbackPrimitivesWritten: - counter = _context.Renderer.ReportCounter(CounterType.TransformFeedbackPrimitivesWritten, resultHandler); - break; - } - - state.Channel.MemoryManager.CounterCache.AddOrUpdate(gpuVa, counter); - } - - /// - /// Converts a nanoseconds timestamp value to Maxwell time ticks. - /// - /// - /// The frequency is 614400000 Hz. - /// - /// Timestamp in nanoseconds - /// Maxwell ticks - private static ulong ConvertNanosecondsToTicks(ulong nanoseconds) - { - // We need to divide first to avoid overflows. - // We fix up the result later by calculating the difference and adding - // that to the result. - ulong divided = nanoseconds / NsToTicksFractionDenominator; - - ulong rounded = divided * NsToTicksFractionDenominator; - - ulong errorBias = (nanoseconds - rounded) * NsToTicksFractionNumerator / NsToTicksFractionDenominator; - - return divided * NsToTicksFractionNumerator + errorBias; - } - } -} \ No newline at end of file -- cgit v1.2.3