misc: chore: Use explicit types in Shader project

This commit is contained in:
Evan Husted 2025-01-25 14:07:59 -06:00
parent 68bbb29be6
commit f2aa6b3a5b
39 changed files with 726 additions and 725 deletions

View file

@ -1,5 +1,6 @@
using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
@ -256,8 +257,8 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int tfbIndex = 0; tfbIndex < ResourceReservations.TfeBuffersCount; tfbIndex++)
{
var locations = TranslatorContext.GpuAccessor.QueryTransformFeedbackVaryingLocations(tfbIndex);
var stride = TranslatorContext.GpuAccessor.QueryTransformFeedbackStride(tfbIndex);
ReadOnlySpan<byte> locations = TranslatorContext.GpuAccessor.QueryTransformFeedbackVaryingLocations(tfbIndex);
int stride = TranslatorContext.GpuAccessor.QueryTransformFeedbackStride(tfbIndex);
Operand baseOffset = this.Load(StorageKind.ConstantBuffer, SupportBuffer.Binding, Const((int)SupportBufferField.TfeOffset), Const(tfbIndex));
Operand baseVertex = this.Load(StorageKind.Input, IoVariable.BaseVertex);

View file

@ -490,8 +490,8 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int index = 0; index < pTreeNode.Uses.Count; index++)
{
var pUse = pTreeNode.Uses[index];
var cUse = cTreeNode.Uses[index];
PatternTreeNodeUse pUse = pTreeNode.Uses[index];
TreeNodeUse cUse = cTreeNode.Uses[index];
if (pUse.Index <= -2)
{
@ -524,8 +524,8 @@ namespace Ryujinx.Graphics.Shader.Translation
{
public static IPatternTreeNode[] GetFsiGetAddress()
{
var affinityValue = S2r(SReg.Affinity).Use(PT).Out;
var orderingTicketValue = S2r(SReg.OrderingTicket).Use(PT).Out;
PatternTreeNodeUse affinityValue = S2r(SReg.Affinity).Use(PT).Out;
PatternTreeNodeUse orderingTicketValue = S2r(SReg.OrderingTicket).Use(PT).Out;
return new IPatternTreeNode[]
{
@ -554,8 +554,8 @@ namespace Ryujinx.Graphics.Shader.Translation
public static IPatternTreeNode[] GetFsiGetAddressV2()
{
var affinityValue = S2r(SReg.Affinity).Use(PT).Out;
var orderingTicketValue = S2r(SReg.OrderingTicket).Use(PT).Out;
PatternTreeNodeUse affinityValue = S2r(SReg.Affinity).Use(PT).Out;
PatternTreeNodeUse orderingTicketValue = S2r(SReg.OrderingTicket).Use(PT).Out;
return new IPatternTreeNode[]
{
@ -582,8 +582,8 @@ namespace Ryujinx.Graphics.Shader.Translation
public static IPatternTreeNode[] GetFsiIsLastWarpThread()
{
var threadKillValue = S2r(SReg.ThreadKill).Use(PT).Out;
var laneIdValue = S2r(SReg.LaneId).Use(PT).Out;
PatternTreeNodeUse threadKillValue = S2r(SReg.ThreadKill).Use(PT).Out;
PatternTreeNodeUse laneIdValue = S2r(SReg.LaneId).Use(PT).Out;
return new IPatternTreeNode[]
{
@ -609,11 +609,11 @@ namespace Ryujinx.Graphics.Shader.Translation
public static IPatternTreeNode[] GetFsiBeginPattern()
{
var addressLowValue = CallArg(1);
PatternTreeNodeUse addressLowValue = CallArg(1);
static PatternTreeNodeUse HighU16Equals(PatternTreeNodeUse x)
{
var expectedValue = CallArg(3);
PatternTreeNodeUse expectedValue = CallArg(3);
return IsetpU32(IComp.Eq)
.Use(PT)
@ -644,13 +644,13 @@ namespace Ryujinx.Graphics.Shader.Translation
public static IPatternTreeNode[] GetFsiEndPattern()
{
var voteResult = Vote(VoteMode.All).Use(PT).Use(PT).OutAt(1);
var popcResult = Popc().Use(PT).Use(voteResult).Out;
var threadKillValue = S2r(SReg.ThreadKill).Use(PT).Out;
var laneIdValue = S2r(SReg.LaneId).Use(PT).Out;
PatternTreeNodeUse voteResult = Vote(VoteMode.All).Use(PT).Use(PT).OutAt(1);
PatternTreeNodeUse popcResult = Popc().Use(PT).Use(voteResult).Out;
PatternTreeNodeUse threadKillValue = S2r(SReg.ThreadKill).Use(PT).Out;
PatternTreeNodeUse laneIdValue = S2r(SReg.LaneId).Use(PT).Out;
var addressLowValue = CallArg(1);
var incrementValue = CallArg(2);
PatternTreeNodeUse addressLowValue = CallArg(1);
PatternTreeNodeUse incrementValue = CallArg(2);
return new IPatternTreeNode[]
{

View file

@ -267,7 +267,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
{
Operand value = operation.GetSource(operation.SourcesCount - 1);
var result = FindUniqueBaseAddressCb(gtsContext, block, value, needsOffset: false);
SearchResult result = FindUniqueBaseAddressCb(gtsContext, block, value, needsOffset: false);
if (result.Found)
{
uint targetCb = PackCbSlotAndOffset(result.SbCbSlot, result.SbCbOffset);
@ -1018,7 +1018,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
offset = src1;
}
var result = GetBaseAddressCbWithOffset(baseAddr, offset, 0);
SearchResult result = GetBaseAddressCbWithOffset(baseAddr, offset, 0);
if (result.Found)
{
return result;

View file

@ -302,7 +302,7 @@ namespace Ryujinx.Graphics.Shader.Translation
Debug.Assert(funcId.Type == OperandType.Constant);
var fru = frus[funcId.Value];
FunctionRegisterUsage fru = frus[funcId.Value];
Operand[] inRegs = new Operand[fru.InArguments.Length];

View file

@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.Shader.Translation
size = DefaultLocalMemorySize;
}
var lmem = new MemoryDefinition("local_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
MemoryDefinition lmem = new MemoryDefinition("local_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
LocalMemoryId = Properties.AddLocalMemory(lmem);
}
@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Shader.Translation
size = DefaultSharedMemorySize;
}
var smem = new MemoryDefinition("shared_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
MemoryDefinition smem = new MemoryDefinition("shared_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
SharedMemoryId = Properties.AddSharedMemory(smem);
}
@ -283,16 +283,16 @@ namespace Ryujinx.Graphics.Shader.Translation
bool coherent,
bool separate)
{
var dimensions = type == SamplerType.None ? 0 : type.GetDimensions();
var dict = isImage ? _usedImages : _usedTextures;
int dimensions = type == SamplerType.None ? 0 : type.GetDimensions();
Dictionary<TextureInfo, TextureMeta> dict = isImage ? _usedImages : _usedTextures;
var usageFlags = TextureUsageFlags.None;
TextureUsageFlags usageFlags = TextureUsageFlags.None;
if (intCoords)
{
usageFlags |= TextureUsageFlags.NeedsScaleValue;
var canScale = _stage.SupportsRenderScale() && arrayLength == 1 && !write && dimensions == 2;
bool canScale = _stage.SupportsRenderScale() && arrayLength == 1 && !write && dimensions == 2;
if (!canScale)
{
@ -314,9 +314,9 @@ namespace Ryujinx.Graphics.Shader.Translation
// For array textures, we also want to use type as key,
// since we may have texture handles stores in the same buffer, but for textures with different types.
var keyType = arrayLength > 1 ? type : SamplerType.None;
var info = new TextureInfo(cbufSlot, handle, arrayLength, separate, keyType, format);
var meta = new TextureMeta()
SamplerType keyType = arrayLength > 1 ? type : SamplerType.None;
TextureInfo info = new TextureInfo(cbufSlot, handle, arrayLength, separate, keyType, format);
TextureMeta meta = new TextureMeta()
{
AccurateType = accurateType,
Type = type,
@ -326,7 +326,7 @@ namespace Ryujinx.Graphics.Shader.Translation
int setIndex;
int binding;
if (dict.TryGetValue(info, out var existingMeta))
if (dict.TryGetValue(info, out TextureMeta existingMeta))
{
dict[info] = MergeTextureMeta(meta, existingMeta);
setIndex = existingMeta.Set;
@ -383,7 +383,7 @@ namespace Ryujinx.Graphics.Shader.Translation
nameSuffix = cbufSlot < 0 ? $"{prefix}_tcb_{handle:X}" : $"{prefix}_cb{cbufSlot}_{handle:X}";
}
var definition = new TextureDefinition(
TextureDefinition definition = new TextureDefinition(
setIndex,
binding,
arrayLength,
@ -443,8 +443,8 @@ namespace Ryujinx.Graphics.Shader.Translation
{
selectedMeta.UsageFlags |= TextureUsageFlags.NeedsScaleValue;
var dimensions = type.GetDimensions();
var canScale = _stage.SupportsRenderScale() && selectedInfo.ArrayLength == 1 && dimensions == 2;
int dimensions = type.GetDimensions();
bool canScale = _stage.SupportsRenderScale() && selectedInfo.ArrayLength == 1 && dimensions == 2;
if (!canScale)
{
@ -464,7 +464,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public BufferDescriptor[] GetConstantBufferDescriptors()
{
var descriptors = new BufferDescriptor[_usedConstantBufferBindings.Count];
BufferDescriptor[] descriptors = new BufferDescriptor[_usedConstantBufferBindings.Count];
int descriptorIndex = 0;
@ -488,7 +488,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public BufferDescriptor[] GetStorageBufferDescriptors()
{
var descriptors = new BufferDescriptor[_sbSlots.Count];
BufferDescriptor[] descriptors = new BufferDescriptor[_sbSlots.Count];
int descriptorIndex = 0;
@ -575,7 +575,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public ShaderProgramInfo GetVertexAsComputeInfo(bool isVertex = false)
{
var cbDescriptors = new BufferDescriptor[_vacConstantBuffers.Count];
BufferDescriptor[] cbDescriptors = new BufferDescriptor[_vacConstantBuffers.Count];
int cbDescriptorIndex = 0;
foreach (BufferDefinition definition in _vacConstantBuffers)
@ -583,7 +583,7 @@ namespace Ryujinx.Graphics.Shader.Translation
cbDescriptors[cbDescriptorIndex++] = new BufferDescriptor(definition.Set, definition.Binding, 0, 0, 0, BufferUsageFlags.None);
}
var sbDescriptors = new BufferDescriptor[_vacStorageBuffers.Count];
BufferDescriptor[] sbDescriptors = new BufferDescriptor[_vacStorageBuffers.Count];
int sbDescriptorIndex = 0;
foreach (BufferDefinition definition in _vacStorageBuffers)
@ -591,7 +591,7 @@ namespace Ryujinx.Graphics.Shader.Translation
sbDescriptors[sbDescriptorIndex++] = new BufferDescriptor(definition.Set, definition.Binding, 0, 0, 0, BufferUsageFlags.Write);
}
var tDescriptors = new TextureDescriptor[_vacTextures.Count];
TextureDescriptor[] tDescriptors = new TextureDescriptor[_vacTextures.Count];
int tDescriptorIndex = 0;
foreach (TextureDefinition definition in _vacTextures)
@ -608,7 +608,7 @@ namespace Ryujinx.Graphics.Shader.Translation
definition.Flags);
}
var iDescriptors = new TextureDescriptor[_vacImages.Count];
TextureDescriptor[] iDescriptors = new TextureDescriptor[_vacImages.Count];
int iDescriptorIndex = 0;
foreach (TextureDefinition definition in _vacImages)

View file

@ -192,7 +192,7 @@ namespace Ryujinx.Graphics.Shader.Translation
component = subIndex;
}
var transformFeedbackVariable = new TransformFeedbackVariable(ioVariable, location, component);
TransformFeedbackVariable transformFeedbackVariable = new TransformFeedbackVariable(ioVariable, location, component);
_transformFeedbackDefinitions.TryAdd(transformFeedbackVariable, transformFeedbackOutputs[wordOffset]);
}
}
@ -219,7 +219,7 @@ namespace Ryujinx.Graphics.Shader.Translation
return false;
}
var transformFeedbackVariable = new TransformFeedbackVariable(ioVariable, location, component);
TransformFeedbackVariable transformFeedbackVariable = new TransformFeedbackVariable(ioVariable, location, component);
return _transformFeedbackDefinitions.TryGetValue(transformFeedbackVariable, out transformFeedbackOutput);
}
@ -271,8 +271,8 @@ namespace Ryujinx.Graphics.Shader.Translation
for (; count < 4; count++)
{
ref var prev = ref _transformFeedbackOutputs[baseIndex + count - 1];
ref var curr = ref _transformFeedbackOutputs[baseIndex + count];
ref TransformFeedbackOutput prev = ref _transformFeedbackOutputs[baseIndex + count - 1];
ref TransformFeedbackOutput curr = ref _transformFeedbackOutputs[baseIndex + count];
int prevOffset = prev.Offset;
int currOffset = curr.Offset;

View file

@ -110,8 +110,8 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int tfbIndex = 0; tfbIndex < 4; tfbIndex++)
{
var locations = gpuAccessor.QueryTransformFeedbackVaryingLocations(tfbIndex);
var stride = gpuAccessor.QueryTransformFeedbackStride(tfbIndex);
ReadOnlySpan<byte> locations = gpuAccessor.QueryTransformFeedbackVaryingLocations(tfbIndex);
int stride = gpuAccessor.QueryTransformFeedbackStride(tfbIndex);
for (int i = 0; i < locations.Length; i++)
{

View file

@ -243,8 +243,8 @@ namespace Ryujinx.Graphics.Shader.Translation
usedFeatures |= FeatureFlags.VtgAsCompute;
}
var cfgs = new ControlFlowGraph[functions.Length];
var frus = new RegisterUsage.FunctionRegisterUsage[functions.Length];
ControlFlowGraph[] cfgs = new ControlFlowGraph[functions.Length];
RegisterUsage.FunctionRegisterUsage[] frus = new RegisterUsage.FunctionRegisterUsage[functions.Length];
for (int i = 0; i < functions.Length; i++)
{
@ -267,14 +267,14 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int i = 0; i < functions.Length; i++)
{
var cfg = cfgs[i];
ControlFlowGraph cfg = cfgs[i];
int inArgumentsCount = 0;
int outArgumentsCount = 0;
if (i != 0)
{
var fru = frus[i];
RegisterUsage.FunctionRegisterUsage fru = frus[i];
inArgumentsCount = fru.InArguments.Length;
outArgumentsCount = fru.OutArguments.Length;
@ -326,7 +326,7 @@ namespace Ryujinx.Graphics.Shader.Translation
FeatureFlags usedFeatures,
byte clipDistancesWritten)
{
var sInfo = StructuredProgram.MakeStructuredProgram(
StructuredProgramInfo sInfo = StructuredProgram.MakeStructuredProgram(
funcs,
attributeUsage,
definitions,
@ -342,7 +342,7 @@ namespace Ryujinx.Graphics.Shader.Translation
_ => 1
};
var info = new ShaderProgramInfo(
ShaderProgramInfo info = new ShaderProgramInfo(
resourceManager.GetConstantBufferDescriptors(),
resourceManager.GetStorageBufferDescriptors(),
resourceManager.GetTextureDescriptors(),
@ -358,7 +358,7 @@ namespace Ryujinx.Graphics.Shader.Translation
clipDistancesWritten,
originalDefinitions.OmapTargets);
var hostCapabilities = new HostCapabilities(
HostCapabilities hostCapabilities = new HostCapabilities(
GpuAccessor.QueryHostReducedPrecision(),
GpuAccessor.QueryHostSupportsFragmentShaderInterlock(),
GpuAccessor.QueryHostSupportsFragmentShaderOrderingIntel(),
@ -369,7 +369,7 @@ namespace Ryujinx.Graphics.Shader.Translation
GpuAccessor.QueryHostSupportsTextureShadowLod(),
GpuAccessor.QueryHostSupportsViewportMask());
var parameters = new CodeGenParameters(attributeUsage, definitions, resourceManager.Properties, hostCapabilities, GpuAccessor, Options.TargetApi);
CodeGenParameters parameters = new CodeGenParameters(attributeUsage, definitions, resourceManager.Properties, hostCapabilities, GpuAccessor, Options.TargetApi);
return Options.TargetLanguage switch
{
@ -494,10 +494,10 @@ namespace Ryujinx.Graphics.Shader.Translation
public (ShaderProgram, ShaderProgramInfo) GenerateVertexPassthroughForCompute()
{
var attributeUsage = new AttributeUsage(GpuAccessor);
var resourceManager = new ResourceManager(ShaderStage.Vertex, GpuAccessor);
AttributeUsage attributeUsage = new AttributeUsage(GpuAccessor);
ResourceManager resourceManager = new ResourceManager(ShaderStage.Vertex, GpuAccessor);
var reservations = GetResourceReservations();
ResourceReservations reservations = GetResourceReservations();
int vertexInfoCbBinding = reservations.VertexInfoConstantBufferBinding;
@ -516,7 +516,7 @@ namespace Ryujinx.Graphics.Shader.Translation
BufferDefinition vertexOutputBuffer = new(BufferLayout.Std430, 1, vertexDataSbBinding, "vb_input", vertexInputStruct);
resourceManager.AddVertexAsComputeStorageBuffer(vertexOutputBuffer);
var context = new EmitterContext();
EmitterContext context = new EmitterContext();
Operand vertexIndex = Options.TargetApi == TargetApi.OpenGL
? context.Load(StorageKind.Input, IoVariable.VertexId)
@ -561,13 +561,13 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
var operations = context.GetOperations();
var cfg = ControlFlowGraph.Create(operations);
var function = new Function(cfg.Blocks, "main", false, 0, 0);
Operation[] operations = context.GetOperations();
ControlFlowGraph cfg = ControlFlowGraph.Create(operations);
Function function = new Function(cfg.Blocks, "main", false, 0, 0);
var transformFeedbackOutputs = GetTransformFeedbackOutputs(GpuAccessor, out ulong transformFeedbackVecMap);
TransformFeedbackOutput[] transformFeedbackOutputs = GetTransformFeedbackOutputs(GpuAccessor, out ulong transformFeedbackVecMap);
var definitions = new ShaderDefinitions(ShaderStage.Vertex, transformFeedbackVecMap, transformFeedbackOutputs)
ShaderDefinitions definitions = new ShaderDefinitions(ShaderStage.Vertex, transformFeedbackVecMap, transformFeedbackOutputs)
{
LastInVertexPipeline = true
};
@ -612,10 +612,10 @@ namespace Ryujinx.Graphics.Shader.Translation
break;
}
var attributeUsage = new AttributeUsage(GpuAccessor);
var resourceManager = new ResourceManager(ShaderStage.Geometry, GpuAccessor);
AttributeUsage attributeUsage = new AttributeUsage(GpuAccessor);
ResourceManager resourceManager = new ResourceManager(ShaderStage.Geometry, GpuAccessor);
var context = new EmitterContext();
EmitterContext context = new EmitterContext();
for (int v = 0; v < maxOutputVertices; v++)
{
@ -656,11 +656,11 @@ namespace Ryujinx.Graphics.Shader.Translation
context.EndPrimitive();
var operations = context.GetOperations();
var cfg = ControlFlowGraph.Create(operations);
var function = new Function(cfg.Blocks, "main", false, 0, 0);
Operation[] operations = context.GetOperations();
ControlFlowGraph cfg = ControlFlowGraph.Create(operations);
Function function = new Function(cfg.Blocks, "main", false, 0, 0);
var definitions = new ShaderDefinitions(
ShaderDefinitions definitions = new ShaderDefinitions(
ShaderStage.Geometry,
GpuAccessor.QueryGraphicsState(),
false,