misc: chore: Use explicit types in GPU, Device, and Host1x projects

This commit is contained in:
Evan Husted 2025-01-25 14:05:44 -06:00
parent 5099548856
commit 1ae349efb1
55 changed files with 350 additions and 339 deletions

View file

@ -2,6 +2,7 @@ using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Engine.InlineToMemory;
using Ryujinx.Graphics.Gpu.Engine.Threed;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Graphics.Shader;
using System;
@ -90,7 +91,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
/// <param name="argument">Method call argument</param>
private void SendSignalingPcasB(int argument)
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
// Since we're going to change the state, make sure any pending instanced draws are done.
_3dEngine.PerformDeferredDraws();
@ -100,7 +101,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
uint qmdAddress = _state.State.SendPcasA;
var qmd = _channel.MemoryManager.Read<ComputeQmd>((ulong)qmdAddress << 8);
ComputeQmd qmd = _channel.MemoryManager.Read<ComputeQmd>((ulong)qmdAddress << 8);
ulong shaderGpuVa = ((ulong)_state.State.SetProgramRegionAAddressUpper << 32) | _state.State.SetProgramRegionB;

View file

@ -80,7 +80,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteWithRedundancyCheck(int offset, int value, out bool changed)
{
var shadowRamControl = _state.State.SetMmeShadowRamControlMode;
SetMmeShadowRamControlMode shadowRamControl = _state.State.SetMmeShadowRamControlMode;
if (shadowRamControl == SetMmeShadowRamControlMode.MethodPassthrough || offset < 0x200)
{
_state.WriteWithRedundancyCheck(offset, value, out changed);

View file

@ -190,7 +190,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
/// <param name="argument">The LaunchDma call argument</param>
private void DmaCopy(int argument)
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
CopyFlags copyFlags = (CopyFlags)argument;
@ -225,8 +225,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
int srcBpp = remap ? srcComponents * componentSize : 1;
int dstBpp = remap ? dstComponents * componentSize : 1;
var dst = Unsafe.As<uint, DmaTexture>(ref _state.State.SetDstBlockSize);
var src = Unsafe.As<uint, DmaTexture>(ref _state.State.SetSrcBlockSize);
DmaTexture dst = Unsafe.As<uint, DmaTexture>(ref _state.State.SetDstBlockSize);
DmaTexture src = Unsafe.As<uint, DmaTexture>(ref _state.State.SetSrcBlockSize);
int srcRegionX = 0, srcRegionY = 0, dstRegionX = 0, dstRegionY = 0;
@ -245,7 +245,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
int srcStride = (int)_state.State.PitchIn;
int dstStride = (int)_state.State.PitchOut;
var srcCalculator = new OffsetCalculator(
OffsetCalculator srcCalculator = new OffsetCalculator(
src.Width,
src.Height,
srcStride,
@ -254,7 +254,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
src.MemoryLayout.UnpackGobBlocksInZ(),
srcBpp);
var dstCalculator = new OffsetCalculator(
OffsetCalculator dstCalculator = new OffsetCalculator(
dst.Width,
dst.Height,
dstStride,
@ -293,7 +293,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
if (completeSource && completeDest && !srcLinear && isIdentityRemap)
{
var source = memoryManager.Physical.TextureCache.FindTexture(
Image.Texture source = memoryManager.Physical.TextureCache.FindTexture(
memoryManager,
srcGpuVa,
srcBpp,
@ -309,7 +309,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
{
source.SynchronizeMemory();
var target = memoryManager.Physical.TextureCache.FindOrCreateTexture(
Image.Texture target = memoryManager.Physical.TextureCache.FindOrCreateTexture(
memoryManager,
source.Info.FormatInfo,
dstGpuVa,
@ -339,7 +339,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
if (completeSource && completeDest && !(dstLinear && !srcLinear) && isIdentityRemap)
{
var target = memoryManager.Physical.TextureCache.FindTexture(
Image.Texture target = memoryManager.Physical.TextureCache.FindTexture(
memoryManager,
dstGpuVa,
dstBpp,

View file

@ -159,7 +159,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
int availableCount = commandBuffer.Length - offset;
int consumeCount = Math.Min(_state.MethodCount, availableCount);
var data = commandBuffer.Slice(offset, consumeCount);
ReadOnlySpan<int> data = commandBuffer.Slice(offset, consumeCount);
if (_state.SubChannel == 0)
{

View file

@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Texture;
using System;
using System.Collections.Generic;
@ -168,9 +169,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
/// </summary>
private void FinishTransfer()
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
var data = MemoryMarshal.Cast<int, byte>(_buffer)[.._size];
Span<byte> data = MemoryMarshal.Cast<int, byte>(_buffer)[.._size];
if (_isLinear && _lineCount == 1)
{
@ -184,7 +185,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
// Right now the copy code at the bottom assumes that it is used on both which might be incorrect.
if (!_isLinear)
{
var target = memoryManager.Physical.TextureCache.FindTexture(
Image.Texture target = memoryManager.Physical.TextureCache.FindTexture(
memoryManager,
_dstGpuVa,
1,
@ -199,7 +200,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
if (target != null)
{
target.SynchronizeMemory();
var dataCopy = MemoryOwner<byte>.RentCopy(data);
MemoryOwner<byte> dataCopy = MemoryOwner<byte>.RentCopy(data);
target.SetData(dataCopy, 0, 0, new GAL.Rectangle<int>(_dstX, _dstY, _lineLengthIn / target.Info.FormatInfo.BytesPerPixel, _lineCount));
target.SignalModified();
@ -207,7 +208,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
}
}
var dstCalculator = new OffsetCalculator(
OffsetCalculator dstCalculator = new OffsetCalculator(
_dstWidth,
_dstHeight,
_dstStride,

View file

@ -285,12 +285,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="arg0">First argument of the call</param>
private void DrawArraysInstanced(IDeviceState state, int arg0)
{
var topology = (PrimitiveTopology)arg0;
PrimitiveTopology topology = (PrimitiveTopology)arg0;
var count = FetchParam();
var instanceCount = FetchParam();
var firstVertex = FetchParam();
var firstInstance = FetchParam();
FifoWord count = FetchParam();
FifoWord instanceCount = FetchParam();
FifoWord firstVertex = FetchParam();
FifoWord firstInstance = FetchParam();
if (ShouldSkipDraw(state, instanceCount.Word))
{
@ -314,13 +314,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="arg0">First argument of the call</param>
private void DrawElements(IDeviceState state, int arg0)
{
var topology = (PrimitiveTopology)arg0;
PrimitiveTopology topology = (PrimitiveTopology)arg0;
var indexAddressHigh = FetchParam();
var indexAddressLow = FetchParam();
var indexType = FetchParam();
var firstIndex = 0;
var indexCount = FetchParam();
FifoWord indexAddressHigh = FetchParam();
FifoWord indexAddressLow = FetchParam();
FifoWord indexType = FetchParam();
int firstIndex = 0;
FifoWord indexCount = FetchParam();
_processor.ThreedClass.UpdateIndexBuffer(
(uint)indexAddressHigh.Word,
@ -344,13 +344,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="arg0">First argument of the call</param>
private void DrawElementsInstanced(IDeviceState state, int arg0)
{
var topology = (PrimitiveTopology)arg0;
PrimitiveTopology topology = (PrimitiveTopology)arg0;
var count = FetchParam();
var instanceCount = FetchParam();
var firstIndex = FetchParam();
var firstVertex = FetchParam();
var firstInstance = FetchParam();
FifoWord count = FetchParam();
FifoWord instanceCount = FetchParam();
FifoWord firstIndex = FetchParam();
FifoWord firstVertex = FetchParam();
FifoWord firstInstance = FetchParam();
if (ShouldSkipDraw(state, instanceCount.Word))
{
@ -374,17 +374,17 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="arg0">First argument of the call</param>
private void DrawElementsIndirect(IDeviceState state, int arg0)
{
var topology = (PrimitiveTopology)arg0;
PrimitiveTopology topology = (PrimitiveTopology)arg0;
var count = FetchParam();
var instanceCount = FetchParam();
var firstIndex = FetchParam();
var firstVertex = FetchParam();
var firstInstance = FetchParam();
FifoWord count = FetchParam();
FifoWord instanceCount = FetchParam();
FifoWord firstIndex = FetchParam();
FifoWord firstVertex = FetchParam();
FifoWord firstInstance = FetchParam();
ulong indirectBufferGpuVa = count.GpuVa;
var bufferCache = _processor.MemoryManager.Physical.BufferCache;
BufferCache bufferCache = _processor.MemoryManager.Physical.BufferCache;
bool useBuffer = bufferCache.CheckModified(_processor.MemoryManager, indirectBufferGpuVa, IndirectIndexedDataEntrySize, out ulong indirectBufferAddress);
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
int startDraw = arg0;
int endDraw = arg1;
var topology = (PrimitiveTopology)arg2;
PrimitiveTopology topology = (PrimitiveTopology)arg2;
int paddingWords = arg3;
int stride = paddingWords * 4 + 0x14;
@ -468,12 +468,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
for (int i = 0; i < maxDrawCount; i++)
{
var count = FetchParam();
FifoWord count = FetchParam();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
var instanceCount = FetchParam();
var firstIndex = FetchParam();
var firstVertex = FetchParam();
var firstInstance = FetchParam();
FifoWord instanceCount = FetchParam();
FifoWord firstIndex = FetchParam();
FifoWord firstVertex = FetchParam();
FifoWord firstInstance = FetchParam();
#pragma warning restore IDE0059
if (i == 0)
@ -492,7 +492,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
}
}
var bufferCache = _processor.MemoryManager.Physical.BufferCache;
BufferCache bufferCache = _processor.MemoryManager.Physical.BufferCache;
ulong indirectBufferSize = (ulong)maxDrawCount * (ulong)stride;
@ -526,7 +526,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <returns>The call argument, or a 0 value with null address if the FIFO is empty</returns>
private FifoWord FetchParam()
{
if (!Fifo.TryDequeue(out var value))
if (!Fifo.TryDequeue(out FifoWord value))
{
Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");

View file

@ -90,13 +90,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <returns>True if there is a implementation available and supported, false otherwise</returns>
public static bool TryGetMacroHLEFunction(ReadOnlySpan<int> code, Capabilities caps, out MacroHLEFunctionName name)
{
var mc = MemoryMarshal.Cast<int, byte>(code);
ReadOnlySpan<byte> mc = MemoryMarshal.Cast<int, byte>(code);
for (int i = 0; i < _table.Length; i++)
{
ref var entry = ref _table[i];
ref TableEntry entry = ref _table[i];
var hash = Hash128.ComputeHash(mc[..entry.Length]);
Hash128 hash = Hash128.ComputeHash(mc[..entry.Length]);
if (hash == entry.Hash)
{
if (IsMacroHLESupported(caps, entry.Name))

View file

@ -369,7 +369,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <returns>The call argument, or 0 if the FIFO is empty</returns>
private int FetchParam()
{
if (!Fifo.TryDequeue(out var value))
if (!Fifo.TryDequeue(out FifoWord value))
{
Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");

View file

@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <returns>The call argument, or 0 if the FIFO is empty</returns>
public int FetchParam()
{
if (!Fifo.TryDequeue(out var value))
if (!Fifo.TryDequeue(out FifoWord value))
{
Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");

View file

@ -221,7 +221,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
sb.AppendLine($"private static Dictionary<Hash128, AdvancedBlendEntry> _entries = new()");
sb.AppendLine("{");
foreach (var entry in Table)
foreach (AdvancedBlendUcode entry in Table)
{
Hash128 hash = Hash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(entry.Code));

View file

@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
descriptor = default;
if (!AdvancedBlendPreGenTable.Entries.TryGetValue(hash, out var entry))
if (!AdvancedBlendPreGenTable.Entries.TryGetValue(hash, out AdvancedBlendEntry entry))
{
return false;
}

View file

@ -65,7 +65,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
{
if (disposing)
{
foreach (var texture in _cache.Values)
foreach (ITexture texture in _cache.Values)
{
texture.Release();
}
@ -603,7 +603,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
DestroyIfNotNull(ref _geometryIndexDataBuffer.Handle);
DestroyIfNotNull(ref _sequentialIndexBuffer);
foreach (var indexBuffer in _topologyRemapBuffers.Values)
foreach (IndexBuffer indexBuffer in _topologyRemapBuffers.Values)
{
_context.Renderer.DeleteBuffer(indexBuffer.Handle);
}

View file

@ -127,7 +127,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
for (int index = 0; index < Constants.TotalVertexAttribs; index++)
{
var vertexAttrib = _state.State.VertexAttribState[index];
VertexAttribState vertexAttrib = _state.State.VertexAttribState[index];
if (!FormatTable.TryGetSingleComponentAttribFormat(vertexAttrib.UnpackFormat(), out Format format, out int componentsCount))
{
@ -153,7 +153,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
int bufferIndex = vertexAttrib.UnpackBufferIndex();
GpuVa endAddress = _state.State.VertexBufferEndAddress[bufferIndex];
var vertexBuffer = _state.State.VertexBufferState[bufferIndex];
VertexBufferState vertexBuffer = _state.State.VertexBufferState[bufferIndex];
bool instanced = _state.State.VertexBufferInstanced[bufferIndex];
ulong address = vertexBuffer.Address.Pack();
@ -351,7 +351,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
/// <param name="size">Size of the buffer in bytes</param>
private readonly void SetBufferTexture(ResourceReservations reservations, int index, Format format, ulong address, ulong size)
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
BufferRange range = memoryManager.Physical.BufferCache.GetBufferRange(memoryManager.GetPhysicalRegions(address, size), BufferStage.VertexBuffer);
@ -392,7 +392,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw
indexOffset <<= shift;
size <<= shift;
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
ulong misalign = address & ((ulong)_context.Capabilities.TextureBufferOffsetAlignment - 1);
BufferRange range = memoryManager.Physical.BufferCache.GetBufferRange(

View file

@ -1,3 +1,4 @@
using Ryujinx.Graphics.Gpu.Memory;
using System;
using System.Runtime.InteropServices;
@ -92,7 +93,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (enable)
{
var uniformBuffer = _state.State.UniformBufferState;
UniformBufferState uniformBuffer = _state.State.UniformBufferState;
ulong address = uniformBuffer.Address.Pack();
@ -111,7 +112,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
if (_ubFollowUpAddress != 0)
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
Span<byte> data = MemoryMarshal.Cast<int, byte>(_ubData.AsSpan(0, (int)(_ubByteCount / 4)));
@ -131,7 +132,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="argument">New uniform buffer data word</param>
public void Update(int argument)
{
var uniformBuffer = _state.State.UniformBufferState;
UniformBufferState uniformBuffer = _state.State.UniformBufferState;
ulong address = uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset;
@ -157,7 +158,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="data">Data to be written to the uniform buffer</param>
public void Update(ReadOnlySpan<int> data)
{
var uniformBuffer = _state.State.UniformBufferState;
UniformBufferState uniformBuffer = _state.State.UniformBufferState;
ulong address = uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset;

View file

@ -471,7 +471,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
int textureId = _state.State.DrawTextureTextureId;
int samplerId = _state.State.DrawTextureSamplerId;
(var texture, var sampler) = _channel.TextureManager.GetGraphicsTextureAndSampler(textureId, samplerId);
(Image.Texture texture, Sampler sampler) = _channel.TextureManager.GetGraphicsTextureAndSampler(textureId, samplerId);
srcX0 *= texture.ScaleFactor;
srcY0 *= texture.ScaleFactor;
@ -684,8 +684,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (hasCount)
{
var indirectBuffer = memory.BufferCache.GetBufferRange(indirectBufferRange, BufferStage.Indirect);
var parameterBuffer = memory.BufferCache.GetBufferRange(parameterBufferRange, BufferStage.Indirect);
BufferRange indirectBuffer = memory.BufferCache.GetBufferRange(indirectBufferRange, BufferStage.Indirect);
BufferRange parameterBuffer = memory.BufferCache.GetBufferRange(parameterBufferRange, BufferStage.Indirect);
if (indexed)
{
@ -698,7 +698,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
}
else
{
var indirectBuffer = memory.BufferCache.GetBufferRange(indirectBufferRange, BufferStage.Indirect);
BufferRange indirectBuffer = memory.BufferCache.GetBufferRange(indirectBufferRange, BufferStage.Indirect);
if (indexed)
{
@ -820,7 +820,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
// If there is a mismatch on the host clip region and the one explicitly defined by the guest
// on the screen scissor state, then we need to force only one texture to be bound to avoid
// host clipping.
var screenScissorState = _state.State.ScreenScissorState;
ScreenScissorState screenScissorState = _state.State.ScreenScissorState;
bool clearAffectedByStencilMask = (_state.State.ClearFlags & 1) != 0;
bool clearAffectedByScissor = (_state.State.ClearFlags & 0x100) != 0;
@ -833,7 +833,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (fullClear && clearAffectedByScissor && _state.State.ScissorState[0].Enable)
{
ref var scissorState = ref _state.State.ScissorState[0];
ref ScissorState scissorState = ref _state.State.ScissorState[0];
fullClear = scissorState.X1 == screenScissorState.X &&
scissorState.Y1 == screenScissorState.Y &&
@ -894,7 +894,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (clearAffectedByScissor && _state.State.ScissorState[0].Enable)
{
ref var scissorState = ref _state.State.ScissorState[0];
ref ScissorState scissorState = ref _state.State.ScissorState[0];
scissorX = Math.Max(scissorX, scissorState.X1);
scissorY = Math.Max(scissorY, scissorState.Y1);
@ -923,7 +923,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (componentMask != 0)
{
var clearColor = _state.State.ClearColors;
ClearColors clearColor = _state.State.ClearColors;
ColorF color = new(clearColor.Red, clearColor.Green, clearColor.Blue, clearColor.Alpha);

View file

@ -288,7 +288,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
int rtIndex = rtControl.UnpackPermutationIndex(index);
var colorState = state[rtIndex];
RtColorState colorState = state[rtIndex];
if (index < count && StateUpdater.IsRtEnabled(colorState))
{

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -58,13 +59,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
_registerToGroupMapping = new byte[BlockSize];
_callbacks = new Action[entries.Length];
var fieldToDelegate = new Dictionary<string, int>();
Dictionary<string, int> fieldToDelegate = new Dictionary<string, int>();
for (int entryIndex = 0; entryIndex < entries.Length; entryIndex++)
{
var entry = entries[entryIndex];
StateUpdateCallbackEntry entry = entries[entryIndex];
foreach (var fieldName in entry.FieldNames)
foreach (string fieldName in entry.FieldNames)
{
fieldToDelegate.Add(fieldName, entryIndex);
}
@ -72,15 +73,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
_callbacks[entryIndex] = entry.Callback;
}
var fields = typeof(TState).GetFields();
FieldInfo[] fields = typeof(TState).GetFields();
int offset = 0;
for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++)
{
var field = fields[fieldIndex];
FieldInfo field = fields[fieldIndex];
var currentFieldOffset = (int)Marshal.OffsetOf<TState>(field.Name);
var nextFieldOffset = fieldIndex + 1 == fields.Length ? Unsafe.SizeOf<TState>() : (int)Marshal.OffsetOf<TState>(fields[fieldIndex + 1].Name);
int currentFieldOffset = (int)Marshal.OffsetOf<TState>(field.Name);
int nextFieldOffset = fieldIndex + 1 == fields.Length ? Unsafe.SizeOf<TState>() : (int)Marshal.OffsetOf<TState>(fields[fieldIndex + 1].Name);
int sizeOfField = nextFieldOffset - currentFieldOffset;

View file

@ -3,6 +3,7 @@ using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Threed.Blender;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Graphics.Shader;
using Ryujinx.Graphics.Texture;
@ -463,8 +464,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="singleUse">If this is not -1, it indicates that only the given indexed target will be used.</param>
public void UpdateRenderTargetState(RenderTargetUpdateFlags updateFlags, int singleUse = -1)
{
var memoryManager = _channel.MemoryManager;
var rtControl = _state.State.RtControl;
MemoryManager memoryManager = _channel.MemoryManager;
RtControl rtControl = _state.State.RtControl;
bool useControl = updateFlags.HasFlag(RenderTargetUpdateFlags.UseControl);
bool layered = updateFlags.HasFlag(RenderTargetUpdateFlags.Layered);
@ -473,12 +474,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
int count = useControl ? rtControl.UnpackCount() : Constants.TotalRenderTargets;
var msaaMode = _state.State.RtMsaaMode;
TextureMsaaMode msaaMode = _state.State.RtMsaaMode;
int samplesInX = msaaMode.SamplesInX();
int samplesInY = msaaMode.SamplesInY();
var scissor = _state.State.ScreenScissorState;
ScreenScissorState scissor = _state.State.ScreenScissorState;
Size sizeHint = new((scissor.X + scissor.Width) * samplesInX, (scissor.Y + scissor.Height) * samplesInY, 1);
int clipRegionWidth = int.MaxValue;
@ -491,7 +492,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
int rtIndex = useControl ? rtControl.UnpackPermutationIndex(index) : index;
var colorState = _state.State.RtColorState[rtIndex];
RtColorState colorState = _state.State.RtColorState[rtIndex];
if (index >= count || !IsRtEnabled(colorState) || (singleColor && index != singleUse))
{
@ -541,8 +542,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (dsEnable && updateFlags.HasFlag(RenderTargetUpdateFlags.UpdateDepthStencil))
{
var dsState = _state.State.RtDepthStencilState;
var dsSize = _state.State.RtDepthStencilSize;
RtDepthStencilState dsState = _state.State.RtDepthStencilState;
Size3D dsSize = _state.State.RtDepthStencilSize;
depthStencil = memoryManager.Physical.TextureCache.FindOrCreateTexture(
memoryManager,
@ -643,7 +644,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (_state.State.YControl.HasFlag(YControl.NegateY))
{
ref var screenScissor = ref _state.State.ScreenScissorState;
ref ScreenScissorState screenScissor = ref _state.State.ScreenScissorState;
y = screenScissor.Height - height - y;
if (y < 0)
@ -721,8 +722,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateViewportTransform()
{
var yControl = _state.State.YControl;
var face = _state.State.FaceState;
YControl yControl = _state.State.YControl;
FaceState face = _state.State.FaceState;
bool disableTransform = _state.State.ViewportTransformEnable == 0;
bool yNegate = yControl.HasFlag(YControl.NegateY);
@ -736,17 +737,17 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
if (disableTransform)
{
ref var scissor = ref _state.State.ScreenScissorState;
ref ScreenScissorState scissor = ref _state.State.ScreenScissorState;
float rScale = _channel.TextureManager.RenderTargetScale;
var scissorRect = new Rectangle<float>(0, 0, (scissor.X + scissor.Width) * rScale, (scissor.Y + scissor.Height) * rScale);
Rectangle<float> scissorRect = new Rectangle<float>(0, 0, (scissor.X + scissor.Width) * rScale, (scissor.Y + scissor.Height) * rScale);
viewports[index] = new Viewport(scissorRect, ViewportSwizzle.PositiveX, ViewportSwizzle.PositiveY, ViewportSwizzle.PositiveZ, ViewportSwizzle.PositiveW, 0, 1);
continue;
}
ref var transform = ref _state.State.ViewportTransform[index];
ref var extents = ref _state.State.ViewportExtents[index];
ref ViewportTransform transform = ref _state.State.ViewportTransform[index];
ref ViewportExtents extents = ref _state.State.ViewportExtents[index];
float scaleX = MathF.Abs(transform.ScaleX);
float scaleY = transform.ScaleY;
@ -841,7 +842,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateDepthBiasState()
{
var depthBias = _state.State.DepthBiasState;
DepthBiasState depthBias = _state.State.DepthBiasState;
float factor = _state.State.DepthBiasFactor;
float units = _state.State.DepthBiasUnits;
@ -862,9 +863,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateStencilTestState()
{
var backMasks = _state.State.StencilBackMasks;
var test = _state.State.StencilTestState;
var backTest = _state.State.StencilBackTestState;
StencilBackMasks backMasks = _state.State.StencilBackMasks;
StencilTestState test = _state.State.StencilTestState;
StencilBackTestState backTest = _state.State.StencilBackTestState;
CompareOp backFunc;
StencilOp backSFail;
@ -934,10 +935,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateSamplerPoolState()
{
var texturePool = _state.State.TexturePoolState;
var samplerPool = _state.State.SamplerPoolState;
PoolState texturePool = _state.State.TexturePoolState;
PoolState samplerPool = _state.State.SamplerPoolState;
var samplerIndex = _state.State.SamplerIndex;
SamplerIndex samplerIndex = _state.State.SamplerIndex;
int maximumId = samplerIndex == SamplerIndex.ViaHeaderIndex
? texturePool.MaximumId
@ -951,7 +952,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateTexturePoolState()
{
var texturePool = _state.State.TexturePoolState;
PoolState texturePool = _state.State.TexturePoolState;
_channel.TextureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_channel.TextureManager.SetGraphicsTextureBufferIndex((int)_state.State.TextureBufferIndex);
@ -971,7 +972,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int index = 0; index < Constants.TotalVertexAttribs; index++)
{
var vertexAttrib = _state.State.VertexAttribState[index];
VertexAttribState vertexAttrib = _state.State.VertexAttribState[index];
int bufferIndex = vertexAttrib.UnpackBufferIndex();
@ -1065,7 +1066,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateIndexBufferState()
{
var indexBuffer = _state.State.IndexBufferState;
IndexBufferState indexBuffer = _state.State.IndexBufferState;
if (_drawState.IndexCount == 0)
{
@ -1109,7 +1110,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int index = 0; index < Constants.TotalVertexBuffers; index++)
{
var vertexBuffer = _state.State.VertexBufferState[index];
VertexBufferState vertexBuffer = _state.State.VertexBufferState[index];
if (!vertexBuffer.UnpackEnable())
{
@ -1193,8 +1194,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateFaceState()
{
var yControl = _state.State.YControl;
var face = _state.State.FaceState;
YControl yControl = _state.State.YControl;
FaceState face = _state.State.FaceState;
_pipeline.CullEnable = face.CullEnable;
_pipeline.CullMode = face.CullFace;
@ -1233,7 +1234,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int index = 0; index < Constants.TotalRenderTargets; index++)
{
var colorMask = _state.State.RtColorMask[rtColorMaskShared ? 0 : index];
RtColorMask colorMask = _state.State.RtColorMask[rtColorMaskShared ? 0 : index];
uint componentMask;
@ -1256,7 +1257,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
if (_state.State.BlendUcodeEnable != BlendUcodeEnable.Disabled)
{
if (_context.Capabilities.SupportsBlendEquationAdvanced && _blendManager.TryGetAdvancedBlend(out var blendDescriptor))
if (_context.Capabilities.SupportsBlendEquationAdvanced && _blendManager.TryGetAdvancedBlend(out AdvancedBlendDescriptor blendDescriptor))
{
// Try to HLE it using advanced blend on the host if we can.
_context.Renderer.Pipeline.SetBlendState(blendDescriptor);
@ -1278,9 +1279,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int index = 0; index < Constants.TotalRenderTargets; index++)
{
bool enable = _state.State.BlendEnable[index];
var blend = _state.State.BlendState[index];
BlendState blend = _state.State.BlendState[index];
var descriptor = new BlendDescriptor(
BlendDescriptor descriptor = new BlendDescriptor(
enable,
blendConstant,
blend.ColorOp,
@ -1306,9 +1307,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
else
{
bool enable = _state.State.BlendEnable[0];
var blend = _state.State.BlendStateCommon;
BlendStateCommon blend = _state.State.BlendStateCommon;
var descriptor = new BlendDescriptor(
BlendDescriptor descriptor = new BlendDescriptor(
enable,
blendConstant,
blend.ColorOp,
@ -1409,7 +1410,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateShaderState()
{
var shaderCache = _channel.MemoryManager.Physical.ShaderCache;
ShaderCache shaderCache = _channel.MemoryManager.Physical.ShaderCache;
_vtgWritesRtLayer = false;
@ -1420,7 +1421,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int index = 0; index < 6; index++)
{
var shader = _state.State.ShaderState[index];
ShaderState shader = _state.State.ShaderState[index];
if (!shader.UnpackEnable() && index != 1)
{
continue;
@ -1525,7 +1526,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
private void UpdateSupportBufferViewportSize()
{
ref var transform = ref _state.State.ViewportTransform[0];
ref ViewportTransform transform = ref _state.State.ViewportTransform[0];
float scaleX = MathF.Abs(transform.ScaleX);
float scaleY = transform.ScaleY;
@ -1564,8 +1565,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <returns>Current depth mode</returns>
private DepthMode GetDepthMode()
{
ref var transform = ref _state.State.ViewportTransform[0];
ref var extents = ref _state.State.ViewportExtents[0];
ref ViewportTransform transform = ref _state.State.ViewportTransform[0];
ref ViewportExtents extents = ref _state.State.ViewportExtents[0];
DepthMode depthMode;

View file

@ -82,8 +82,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
_i2mClass = new InlineToMemoryClass(context, channel, initializeState: false);
var spec = new SpecializationStateUpdater(context);
var drawState = new DrawState();
SpecializationStateUpdater spec = new SpecializationStateUpdater(context);
DrawState drawState = new DrawState();
_drawManager = new DrawManager(context, channel, _state, drawState, spec);
_blendManager = new AdvancedBlendManager(_state);
@ -253,8 +253,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
}
else
{
ref var lhsVec = ref Unsafe.As<T, Vector128<uint>>(ref lhs);
ref var rhsVec = ref Unsafe.As<T, Vector128<uint>>(ref rhs);
ref Vector128<uint> lhsVec = ref Unsafe.As<T, Vector128<uint>>(ref lhs);
ref Vector128<uint> rhsVec = ref Unsafe.As<T, Vector128<uint>>(ref rhs);
return Vector128.EqualsAll(lhsVec, rhsVec) &&
Vector128.EqualsAll(Unsafe.Add(ref lhsVec, 1), Unsafe.Add(ref rhsVec, 1));
@ -267,8 +267,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="masks">Blend enable</param>
public void UpdateBlendEnable(ref Array8<Boolean32> enable)
{
var shadow = ShadowMode;
ref var state = ref _state.State.BlendEnable;
SetMmeShadowRamControlMode shadow = ShadowMode;
ref Array8<Boolean32> state = ref _state.State.BlendEnable;
if (shadow.IsReplay())
{
@ -294,8 +294,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="masks">Color masks</param>
public void UpdateColorMasks(ref Array8<RtColorMask> masks)
{
var shadow = ShadowMode;
ref var state = ref _state.State.RtColorMask;
SetMmeShadowRamControlMode shadow = ShadowMode;
ref Array8<RtColorMask> state = ref _state.State.RtColorMask;
if (shadow.IsReplay())
{
@ -323,12 +323,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="type">Type of the binding</param>
public void UpdateIndexBuffer(uint addrHigh, uint addrLow, IndexType type)
{
var shadow = ShadowMode;
ref var state = ref _state.State.IndexBufferState;
SetMmeShadowRamControlMode shadow = ShadowMode;
ref IndexBufferState state = ref _state.State.IndexBufferState;
if (shadow.IsReplay())
{
ref var shadowState = ref _state.ShadowState.IndexBufferState;
ref IndexBufferState shadowState = ref _state.ShadowState.IndexBufferState;
addrHigh = shadowState.Address.High;
addrLow = shadowState.Address.Low;
type = shadowState.Type;
@ -345,7 +345,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (shadow.IsTrack())
{
ref var shadowState = ref _state.ShadowState.IndexBufferState;
ref IndexBufferState shadowState = ref _state.ShadowState.IndexBufferState;
shadowState.Address.High = addrHigh;
shadowState.Address.Low = addrLow;
shadowState.Type = type;
@ -360,12 +360,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="addrLow">Low part of the address</param>
public void UpdateUniformBufferState(int size, uint addrHigh, uint addrLow)
{
var shadow = ShadowMode;
ref var state = ref _state.State.UniformBufferState;
SetMmeShadowRamControlMode shadow = ShadowMode;
ref UniformBufferState state = ref _state.State.UniformBufferState;
if (shadow.IsReplay())
{
ref var shadowState = ref _state.ShadowState.UniformBufferState;
ref UniformBufferState shadowState = ref _state.ShadowState.UniformBufferState;
size = shadowState.Size;
addrHigh = shadowState.Address.High;
addrLow = shadowState.Address.Low;
@ -377,7 +377,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (shadow.IsTrack())
{
ref var shadowState = ref _state.ShadowState.UniformBufferState;
ref UniformBufferState shadowState = ref _state.ShadowState.UniformBufferState;
shadowState.Size = size;
shadowState.Address.High = addrHigh;
shadowState.Address.Low = addrLow;
@ -391,8 +391,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="offset">Offset to update with</param>
public void SetShaderOffset(int index, uint offset)
{
var shadow = ShadowMode;
ref var shaderState = ref _state.State.ShaderState[index];
SetMmeShadowRamControlMode shadow = ShadowMode;
ref ShaderState shaderState = ref _state.State.ShaderState[index];
if (shadow.IsReplay())
{
@ -418,8 +418,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// <param name="ubState">Uniform buffer state</param>
public void UpdateUniformBufferState(UniformBufferState ubState)
{
var shadow = ShadowMode;
ref var state = ref _state.State.UniformBufferState;
SetMmeShadowRamControlMode shadow = ShadowMode;
ref UniformBufferState state = ref _state.State.UniformBufferState;
if (shadow.IsReplay())
{

View file

@ -3,6 +3,7 @@ using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Texture;
using Ryujinx.Memory;
using System;
@ -123,7 +124,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
/// <param name="bpp">Bytes per pixel</param>
private void UnscaledFullCopy(TwodTexture src, TwodTexture dst, int w, int h, int bpp)
{
var srcCalculator = new OffsetCalculator(
OffsetCalculator srcCalculator = new OffsetCalculator(
w,
h,
src.Stride,
@ -134,7 +135,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
(int _, int srcSize) = srcCalculator.GetRectangleRange(0, 0, w, h);
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
ulong srcGpuVa = src.Address.Pack();
ulong dstGpuVa = dst.Address.Pack();
@ -228,10 +229,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
/// <param name="argument">Method call argument</param>
private void PixelsFromMemorySrcY0Int(int argument)
{
var memoryManager = _channel.MemoryManager;
MemoryManager memoryManager = _channel.MemoryManager;
var dstCopyTexture = Unsafe.As<uint, TwodTexture>(ref _state.State.SetDstFormat);
var srcCopyTexture = Unsafe.As<uint, TwodTexture>(ref _state.State.SetSrcFormat);
TwodTexture dstCopyTexture = Unsafe.As<uint, TwodTexture>(ref _state.State.SetDstFormat);
TwodTexture srcCopyTexture = Unsafe.As<uint, TwodTexture>(ref _state.State.SetSrcFormat);
long srcX = ((long)_state.State.SetPixelsFromMemorySrcX0Int << 32) | (long)(ulong)_state.State.SetPixelsFromMemorySrcX0Frac;
long srcY = ((long)_state.State.PixelsFromMemorySrcY0Int << 32) | (long)(ulong)_state.State.SetPixelsFromMemorySrcY0Frac;
@ -268,10 +269,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
// The source and destination textures should at least be as big as the region being requested.
// The hints will only resize within alignment constraints, so out of bound copies won't resize in most cases.
var srcHint = new Size(srcX2, srcY2, 1);
var dstHint = new Size(dstX2, dstY2, 1);
Size srcHint = new Size(srcX2, srcY2, 1);
Size dstHint = new Size(dstX2, dstY2, 1);
var srcCopyTextureFormat = srcCopyTexture.Format.Convert();
FormatInfo srcCopyTextureFormat = srcCopyTexture.Format.Convert();
int srcWidthAligned = srcCopyTexture.Stride / srcCopyTextureFormat.BytesPerPixel;
@ -304,7 +305,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
// are the same, as we can't blit between different depth formats.
bool srcDepthAlias = srcCopyTexture.Format == dstCopyTexture.Format;
var srcTexture = memoryManager.Physical.TextureCache.FindOrCreateTexture(
Image.Texture srcTexture = memoryManager.Physical.TextureCache.FindOrCreateTexture(
memoryManager,
srcCopyTexture,
offset,
@ -341,7 +342,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
dstCopyTextureFormat = dstCopyTexture.Format.Convert();
}
var dstTexture = memoryManager.Physical.TextureCache.FindOrCreateTexture(
Image.Texture dstTexture = memoryManager.Physical.TextureCache.FindOrCreateTexture(
memoryManager,
dstCopyTexture,
0,