aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2021-07-11 17:20:40 -0300
committerGitHub <noreply@github.com>2021-07-11 17:20:40 -0300
commit40b21cc3c4d2622bbd4f88d43073341854d9a671 (patch)
tree6e9dc6a42e7c0bae5b03db468481771d5a6937ef /Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs
parentb5190f16810eb77388c861d1d1773e19644808db (diff)
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
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs95
1 files changed, 95 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs b/Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs
new file mode 100644
index 00000000..3a06bc2a
--- /dev/null
+++ b/Ryujinx.Graphics.Gpu/Engine/DeviceStateWithShadow.cs
@@ -0,0 +1,95 @@
+using Ryujinx.Graphics.Device;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+namespace Ryujinx.Graphics.Gpu.Engine
+{
+ /// <summary>
+ /// State interface with a shadow memory control register.
+ /// </summary>
+ interface IShadowState
+ {
+ /// <summary>
+ /// MME shadow ram control mode.
+ /// </summary>
+ SetMmeShadowRamControlMode SetMmeShadowRamControlMode { get; }
+ }
+
+ /// <summary>
+ /// Represents a device's state, with a additional shadow state.
+ /// </summary>
+ /// <typeparam name="TState">Type of the state</typeparam>
+ class DeviceStateWithShadow<TState> : IDeviceState where TState : unmanaged, IShadowState
+ {
+ private readonly DeviceState<TState> _state;
+ private readonly DeviceState<TState> _shadowState;
+
+ /// <summary>
+ /// Current device state.
+ /// </summary>
+ public ref TState State => ref _state.State;
+
+ /// <summary>
+ /// Creates a new instance of the device state, with shadow state.
+ /// </summary>
+ /// <param name="callbacks">Optional that will be called if a register specified by name is read or written</param>
+ /// <param name="debugLogCallback">Optional callback to be used for debug log messages</param>
+ public DeviceStateWithShadow(IReadOnlyDictionary<string, RwCallback> callbacks = null, Action<string> debugLogCallback = null)
+ {
+ _state = new DeviceState<TState>(callbacks, debugLogCallback);
+ _shadowState = new DeviceState<TState>();
+ }
+
+ /// <summary>
+ /// Reads a value from a register.
+ /// </summary>
+ /// <param name="offset">Register offset in bytes</param>
+ /// <returns>Value stored on the register</returns>
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public int Read(int offset)
+ {
+ return _state.Read(offset);
+ }
+
+ /// <summary>
+ /// Writes a value to a register.
+ /// </summary>
+ /// <param name="offset">Register offset in bytes</param>
+ /// <param name="value">Value to be written</param>
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void Write(int offset, int value)
+ {
+ WriteWithRedundancyCheck(offset, value, out _);
+ }
+
+ /// <summary>
+ /// Writes a value to a register, returning a value indicating if <paramref name="value"/>
+ /// is different from the current value on the register.
+ /// </summary>
+ /// <param name="offset">Register offset in bytes</param>
+ /// <param name="value">Value to be written</param>
+ /// <param name="changed">True if the value was changed, false otherwise</param>
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void WriteWithRedundancyCheck(int offset, int value, out bool changed)
+ {
+ var shadowRamControl = _state.State.SetMmeShadowRamControlMode;
+ if (shadowRamControl == SetMmeShadowRamControlMode.MethodPassthrough || offset < 0x200)
+ {
+ _state.WriteWithRedundancyCheck(offset, value, out changed);
+ }
+ else if (shadowRamControl == SetMmeShadowRamControlMode.MethodTrack ||
+ shadowRamControl == SetMmeShadowRamControlMode.MethodTrackWithFilter)
+ {
+ _shadowState.Write(offset, value);
+ _state.WriteWithRedundancyCheck(offset, value, out changed);
+ }
+ else /* if (shadowRamControl == SetMmeShadowRamControlMode.MethodReplay) */
+ {
+ Debug.Assert(shadowRamControl == SetMmeShadowRamControlMode.MethodReplay);
+ _state.WriteWithRedundancyCheck(offset, _shadowState.Read(offset), out changed);
+ }
+ }
+ }
+}