2019-10-26 10:50:52 -07:00
|
|
|
|
using System;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.State
|
|
|
|
|
{
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GPU state.
|
|
|
|
|
/// </summary>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
class GpuState
|
|
|
|
|
{
|
|
|
|
|
private const int RegistersCount = 0xe00;
|
|
|
|
|
|
2019-11-21 18:46:14 -08:00
|
|
|
|
public delegate void MethodCallback(GpuState state, int argument);
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
private readonly int[] _memory;
|
|
|
|
|
private readonly int[] _shadow;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GPU register information.
|
|
|
|
|
/// </summary>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
private struct Register
|
|
|
|
|
{
|
|
|
|
|
public MethodCallback Callback;
|
|
|
|
|
|
2019-10-26 10:50:52 -07:00
|
|
|
|
public MethodOffset BaseOffset;
|
|
|
|
|
|
|
|
|
|
public int Stride;
|
|
|
|
|
public int Count;
|
|
|
|
|
|
|
|
|
|
public bool Modified;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
private readonly Register[] _registers;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of the GPU state.
|
|
|
|
|
/// </summary>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
public GpuState()
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
_memory = new int[RegistersCount];
|
|
|
|
|
_shadow = new int[RegistersCount];
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
|
|
|
|
_registers = new Register[RegistersCount];
|
|
|
|
|
|
2019-10-26 10:50:52 -07:00
|
|
|
|
for (int index = 0; index < _registers.Length; index++)
|
|
|
|
|
{
|
|
|
|
|
_registers[index].BaseOffset = (MethodOffset)index;
|
|
|
|
|
_registers[index].Stride = 1;
|
|
|
|
|
_registers[index].Count = 1;
|
|
|
|
|
_registers[index].Modified = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var item in GpuStateTable.Table)
|
|
|
|
|
{
|
|
|
|
|
int totalRegs = item.Size * item.Count;
|
|
|
|
|
|
|
|
|
|
for (int regOffset = 0; regOffset < totalRegs; regOffset++)
|
|
|
|
|
{
|
|
|
|
|
int index = (int)item.Offset + regOffset;
|
|
|
|
|
|
|
|
|
|
_registers[index].BaseOffset = item.Offset;
|
|
|
|
|
_registers[index].Stride = item.Size;
|
|
|
|
|
_registers[index].Count = item.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
InitializeDefaultState(_memory);
|
|
|
|
|
InitializeDefaultState(_shadow);
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls a GPU method, using this state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="meth">The GPU method to be called</param>
|
2020-04-25 06:56:56 -07:00
|
|
|
|
/// <param name="shadowCtrl">Shadow RAM control register value</param>
|
|
|
|
|
public void CallMethod(MethodParams meth, ShadowRamControl shadowCtrl)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
int value = meth.Argument;
|
|
|
|
|
|
2020-04-26 15:22:18 -07:00
|
|
|
|
// Methods < 0x80 shouldn't be affected by shadow RAM at all.
|
|
|
|
|
if (meth.Method >= 0x80)
|
2020-04-25 06:56:56 -07:00
|
|
|
|
{
|
2020-04-26 15:22:18 -07:00
|
|
|
|
// TODO: Figure out what TrackWithFilter does, compared to Track.
|
|
|
|
|
if (shadowCtrl == ShadowRamControl.Track ||
|
|
|
|
|
shadowCtrl == ShadowRamControl.TrackWithFilter)
|
|
|
|
|
{
|
|
|
|
|
_shadow[meth.Method] = value;
|
|
|
|
|
}
|
|
|
|
|
else if (shadowCtrl == ShadowRamControl.Replay)
|
|
|
|
|
{
|
|
|
|
|
value = _shadow[meth.Method];
|
|
|
|
|
}
|
2020-04-25 06:56:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
|
Register register = _registers[meth.Method];
|
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
if (_memory[meth.Method] != value)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-10-26 10:50:52 -07:00
|
|
|
|
_registers[(int)register.BaseOffset].Modified = true;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
_memory[meth.Method] = value;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2020-04-25 06:56:56 -07:00
|
|
|
|
register.Callback?.Invoke(this, value);
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads data from a GPU register at the given offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset to be read</param>
|
|
|
|
|
/// <returns>Data at the register</returns>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
public int Read(int offset)
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
return _memory[offset];
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 17:11:43 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes data to the GPU register at the given offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset to be written</param>
|
|
|
|
|
/// <param name="value">Value to be written</param>
|
|
|
|
|
public void Write(int offset, int value)
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
_memory[offset] = value;
|
2020-01-21 17:11:43 -08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
2020-01-01 15:14:18 -08:00
|
|
|
|
/// Writes an offset value at the uniform buffer offset register.
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">The offset to be written</param>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
public void SetUniformBufferOffset(int offset)
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
_memory[(int)MethodOffset.UniformBufferState + 3] = offset;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes registers with the default state.
|
|
|
|
|
/// </summary>
|
2020-04-25 07:17:22 -07:00
|
|
|
|
private void InitializeDefaultState(int[] memory)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2020-04-07 02:19:45 -07:00
|
|
|
|
// Enable Rasterizer
|
2020-04-25 06:56:56 -07:00
|
|
|
|
memory[(int)MethodOffset.RasterizeEnable] = 1;
|
2020-04-07 02:19:45 -07:00
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
|
// Depth ranges.
|
2020-04-15 20:21:58 -07:00
|
|
|
|
for (int index = 0; index < Constants.TotalViewports; index++)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
memory[(int)MethodOffset.ViewportExtents + index * 4 + 2] = 0;
|
|
|
|
|
memory[(int)MethodOffset.ViewportExtents + index * 4 + 3] = 0x3F800000;
|
2020-05-27 16:03:07 -07:00
|
|
|
|
|
|
|
|
|
// Set swizzle to +XYZW
|
|
|
|
|
memory[(int)MethodOffset.ViewportTransform + index * 8 + 6] = 0x6420;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-06 14:37:00 -08:00
|
|
|
|
// Viewport transform enable.
|
2020-04-25 06:56:56 -07:00
|
|
|
|
memory[(int)MethodOffset.ViewportTransformEnable] = 1;
|
2019-12-06 14:37:00 -08:00
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
|
// Default front stencil mask.
|
2020-04-25 06:56:56 -07:00
|
|
|
|
memory[0x4e7] = 0xff;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
|
2020-04-21 23:00:11 -07:00
|
|
|
|
// Conditional rendering condition.
|
2020-04-25 07:17:22 -07:00
|
|
|
|
memory[0x556] = (int)Condition.Always;
|
2020-04-21 23:00:11 -07:00
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
|
// Default color mask.
|
2019-12-06 14:37:00 -08:00
|
|
|
|
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
memory[(int)MethodOffset.RtColorMask + index] = 0x1111;
|
2019-12-06 14:37:00 -08:00
|
|
|
|
}
|
2020-04-25 06:00:43 -07:00
|
|
|
|
|
|
|
|
|
// Default blend states
|
|
|
|
|
Set(MethodOffset.BlendStateCommon, BlendStateCommon.Default);
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < Constants.TotalRenderTargets; index++)
|
|
|
|
|
{
|
|
|
|
|
Set(MethodOffset.BlendState, index, BlendState.Default);
|
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers a callback that is called every time a GPU method, or methods are called.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset of the method</param>
|
|
|
|
|
/// <param name="count">Word count of the methods region</param>
|
|
|
|
|
/// <param name="callback">Calllback to be called</param>
|
2019-10-26 10:50:52 -07:00
|
|
|
|
public void RegisterCallback(MethodOffset offset, int count, MethodCallback callback)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-10-26 10:50:52 -07:00
|
|
|
|
for (int index = 0; index < count; index++)
|
|
|
|
|
{
|
|
|
|
|
_registers[(int)offset + index].Callback = callback;
|
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Registers a callback that is called every time a GPU method is called.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset of the method</param>
|
|
|
|
|
/// <param name="callback">Calllback to be called</param>
|
2019-10-26 10:50:52 -07:00
|
|
|
|
public void RegisterCallback(MethodOffset offset, MethodCallback callback)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-10-26 10:50:52 -07:00
|
|
|
|
_registers[(int)offset].Callback = callback;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if a given register has been modified since the last call to this method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Register offset</param>
|
|
|
|
|
/// <returns>True if modified, false otherwise</returns>
|
2019-11-22 21:17:22 -08:00
|
|
|
|
public bool QueryModified(MethodOffset offset)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-11-22 21:17:22 -08:00
|
|
|
|
bool modified = _registers[(int)offset].Modified;
|
2019-10-26 10:50:52 -07:00
|
|
|
|
|
2019-11-22 21:17:22 -08:00
|
|
|
|
_registers[(int)offset].Modified = false;
|
2019-10-26 10:50:52 -07:00
|
|
|
|
|
|
|
|
|
return modified;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if two registers have been modified since the last call to this method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m1">First register offset</param>
|
|
|
|
|
/// <param name="m2">Second register offset</param>
|
|
|
|
|
/// <returns>True if any register was modified, false otherwise</returns>
|
2019-11-22 21:17:22 -08:00
|
|
|
|
public bool QueryModified(MethodOffset m1, MethodOffset m2)
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-11-22 21:17:22 -08:00
|
|
|
|
bool modified = _registers[(int)m1].Modified ||
|
|
|
|
|
_registers[(int)m2].Modified;
|
2019-10-26 10:50:52 -07:00
|
|
|
|
|
2019-11-22 21:17:22 -08:00
|
|
|
|
_registers[(int)m1].Modified = false;
|
|
|
|
|
_registers[(int)m2].Modified = false;
|
|
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
2020-04-25 06:00:43 -07:00
|
|
|
|
/// Checks if three registers have been modified since the last call to this method.
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m1">First register offset</param>
|
|
|
|
|
/// <param name="m2">Second register offset</param>
|
2020-01-01 07:39:09 -08:00
|
|
|
|
/// <param name="m3">Third register offset</param>
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <returns>True if any register was modified, false otherwise</returns>
|
2019-11-22 21:17:22 -08:00
|
|
|
|
public bool QueryModified(MethodOffset m1, MethodOffset m2, MethodOffset m3)
|
|
|
|
|
{
|
|
|
|
|
bool modified = _registers[(int)m1].Modified ||
|
|
|
|
|
_registers[(int)m2].Modified ||
|
|
|
|
|
_registers[(int)m3].Modified;
|
|
|
|
|
|
|
|
|
|
_registers[(int)m1].Modified = false;
|
|
|
|
|
_registers[(int)m2].Modified = false;
|
|
|
|
|
_registers[(int)m3].Modified = false;
|
|
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
2020-04-25 06:00:43 -07:00
|
|
|
|
/// Checks if four registers have been modified since the last call to this method.
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m1">First register offset</param>
|
|
|
|
|
/// <param name="m2">Second register offset</param>
|
2020-01-01 07:39:09 -08:00
|
|
|
|
/// <param name="m3">Third register offset</param>
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <param name="m4">Fourth register offset</param>
|
|
|
|
|
/// <returns>True if any register was modified, false otherwise</returns>
|
2019-11-22 21:17:22 -08:00
|
|
|
|
public bool QueryModified(MethodOffset m1, MethodOffset m2, MethodOffset m3, MethodOffset m4)
|
|
|
|
|
{
|
|
|
|
|
bool modified = _registers[(int)m1].Modified ||
|
|
|
|
|
_registers[(int)m2].Modified ||
|
|
|
|
|
_registers[(int)m3].Modified ||
|
|
|
|
|
_registers[(int)m4].Modified;
|
|
|
|
|
|
|
|
|
|
_registers[(int)m1].Modified = false;
|
|
|
|
|
_registers[(int)m2].Modified = false;
|
|
|
|
|
_registers[(int)m3].Modified = false;
|
|
|
|
|
_registers[(int)m4].Modified = false;
|
2019-10-26 10:50:52 -07:00
|
|
|
|
|
|
|
|
|
return modified;
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
2020-04-25 06:00:43 -07:00
|
|
|
|
/// Checks if five registers have been modified since the last call to this method.
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m1">First register offset</param>
|
|
|
|
|
/// <param name="m2">Second register offset</param>
|
2020-01-01 07:39:09 -08:00
|
|
|
|
/// <param name="m3">Third register offset</param>
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <param name="m4">Fourth register offset</param>
|
|
|
|
|
/// <param name="m5">Fifth register offset</param>
|
|
|
|
|
/// <returns>True if any register was modified, false otherwise</returns>
|
2019-12-05 12:34:47 -08:00
|
|
|
|
public bool QueryModified(
|
|
|
|
|
MethodOffset m1,
|
|
|
|
|
MethodOffset m2,
|
|
|
|
|
MethodOffset m3,
|
|
|
|
|
MethodOffset m4,
|
|
|
|
|
MethodOffset m5)
|
|
|
|
|
{
|
|
|
|
|
bool modified = _registers[(int)m1].Modified ||
|
|
|
|
|
_registers[(int)m2].Modified ||
|
|
|
|
|
_registers[(int)m3].Modified ||
|
|
|
|
|
_registers[(int)m4].Modified ||
|
|
|
|
|
_registers[(int)m5].Modified;
|
|
|
|
|
|
|
|
|
|
_registers[(int)m1].Modified = false;
|
|
|
|
|
_registers[(int)m2].Modified = false;
|
|
|
|
|
_registers[(int)m3].Modified = false;
|
|
|
|
|
_registers[(int)m4].Modified = false;
|
|
|
|
|
_registers[(int)m5].Modified = false;
|
|
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 06:00:43 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if six registers have been modified since the last call to this method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m1">First register offset</param>
|
|
|
|
|
/// <param name="m2">Second register offset</param>
|
|
|
|
|
/// <param name="m3">Third register offset</param>
|
|
|
|
|
/// <param name="m4">Fourth register offset</param>
|
|
|
|
|
/// <param name="m5">Fifth register offset</param>
|
|
|
|
|
/// <param name="m6">Sixth register offset</param>
|
|
|
|
|
/// <returns>True if any register was modified, false otherwise</returns>
|
|
|
|
|
public bool QueryModified(
|
|
|
|
|
MethodOffset m1,
|
|
|
|
|
MethodOffset m2,
|
|
|
|
|
MethodOffset m3,
|
|
|
|
|
MethodOffset m4,
|
|
|
|
|
MethodOffset m5,
|
|
|
|
|
MethodOffset m6)
|
|
|
|
|
{
|
|
|
|
|
bool modified = _registers[(int)m1].Modified ||
|
|
|
|
|
_registers[(int)m2].Modified ||
|
|
|
|
|
_registers[(int)m3].Modified ||
|
|
|
|
|
_registers[(int)m4].Modified ||
|
|
|
|
|
_registers[(int)m5].Modified ||
|
|
|
|
|
_registers[(int)m6].Modified;
|
|
|
|
|
|
|
|
|
|
_registers[(int)m1].Modified = false;
|
|
|
|
|
_registers[(int)m2].Modified = false;
|
|
|
|
|
_registers[(int)m3].Modified = false;
|
|
|
|
|
_registers[(int)m4].Modified = false;
|
|
|
|
|
_registers[(int)m5].Modified = false;
|
|
|
|
|
_registers[(int)m6].Modified = false;
|
|
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets indexed data from a given register offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type of the data</typeparam>
|
|
|
|
|
/// <param name="offset">Register offset</param>
|
|
|
|
|
/// <param name="index">Index for indexed data</param>
|
|
|
|
|
/// <returns>The data at the specified location</returns>
|
2019-10-26 10:50:52 -07:00
|
|
|
|
public T Get<T>(MethodOffset offset, int index) where T : struct
|
2019-10-12 23:02:07 -07:00
|
|
|
|
{
|
2019-10-26 10:50:52 -07:00
|
|
|
|
Register register = _registers[(int)offset];
|
|
|
|
|
|
|
|
|
|
if ((uint)index >= register.Count)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Get<T>(offset + index * register.Stride);
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-31 08:32:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets data from a given register offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type of the data</typeparam>
|
|
|
|
|
/// <param name="offset">Register offset</param>
|
|
|
|
|
/// <returns>The data at the specified location</returns>
|
2019-10-12 23:02:07 -07:00
|
|
|
|
public T Get<T>(MethodOffset offset) where T : struct
|
|
|
|
|
{
|
2020-04-25 06:56:56 -07:00
|
|
|
|
return MemoryMarshal.Cast<int, T>(_memory.AsSpan().Slice((int)offset))[0];
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
2020-04-25 06:00:43 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets indexed data to a given register offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type of the data</typeparam>
|
|
|
|
|
/// <param name="offset">Register offset</param>
|
|
|
|
|
/// <param name="index">Index for indexed data</param>
|
|
|
|
|
/// <param name="data">The data to set</param>
|
|
|
|
|
public void Set<T>(MethodOffset offset, int index, T data) where T : struct
|
|
|
|
|
{
|
|
|
|
|
Register register = _registers[(int)offset];
|
|
|
|
|
|
|
|
|
|
if ((uint)index >= register.Count)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set(offset + index * register.Stride, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets data to a given register offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type of the data</typeparam>
|
|
|
|
|
/// <param name="offset">Register offset</param>
|
|
|
|
|
/// <param name="data">The data to set</param>
|
|
|
|
|
public void Set<T>(MethodOffset offset, T data) where T : struct
|
|
|
|
|
{
|
|
|
|
|
ReadOnlySpan<int> intSpan = MemoryMarshal.Cast<T, int>(MemoryMarshal.CreateReadOnlySpan(ref data, 1));
|
2020-04-25 07:17:22 -07:00
|
|
|
|
intSpan.CopyTo(_memory.AsSpan().Slice((int)offset, intSpan.Length));
|
2020-04-25 06:00:43 -07:00
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
|
}
|
|
|
|
|
}
|