mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-08-12 05:05:26 +02:00
misc: chore: Use explicit types in Shader project
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
context.AppendLine("using namespace metal;");
|
||||
context.AppendLine();
|
||||
|
||||
var fsi = (info.HelperFunctionsMask & HelperFunctionsMask.FSI) != 0;
|
||||
bool fsi = (info.HelperFunctionsMask & HelperFunctionsMask.FSI) != 0;
|
||||
|
||||
DeclareInputAttributes(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.Input)));
|
||||
context.AppendLine();
|
||||
@@ -79,25 +79,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
DeclareBufferStructures(context, context.Properties.StorageBuffers.Values.OrderBy(x => x.Binding).ToArray(), false, fsi);
|
||||
|
||||
// We need to declare each set as a new struct
|
||||
var textureDefinitions = context.Properties.Textures.Values
|
||||
Dictionary<int, TextureDefinition[]> textureDefinitions = context.Properties.Textures.Values
|
||||
.GroupBy(x => x.Set)
|
||||
.ToDictionary(x => x.Key, x => x.OrderBy(y => y.Binding).ToArray());
|
||||
|
||||
var imageDefinitions = context.Properties.Images.Values
|
||||
Dictionary<int, TextureDefinition[]> imageDefinitions = context.Properties.Images.Values
|
||||
.GroupBy(x => x.Set)
|
||||
.ToDictionary(x => x.Key, x => x.OrderBy(y => y.Binding).ToArray());
|
||||
|
||||
var textureSets = textureDefinitions.Keys.ToArray();
|
||||
var imageSets = imageDefinitions.Keys.ToArray();
|
||||
int[] textureSets = textureDefinitions.Keys.ToArray();
|
||||
int[] imageSets = imageDefinitions.Keys.ToArray();
|
||||
|
||||
var sets = textureSets.Union(imageSets).ToArray();
|
||||
int[] sets = textureSets.Union(imageSets).ToArray();
|
||||
|
||||
foreach (var set in textureDefinitions)
|
||||
foreach (KeyValuePair<int, TextureDefinition[]> set in textureDefinitions)
|
||||
{
|
||||
DeclareTextures(context, set.Value, set.Key);
|
||||
}
|
||||
|
||||
foreach (var set in imageDefinitions)
|
||||
foreach (KeyValuePair<int, TextureDefinition[]> set in imageDefinitions)
|
||||
{
|
||||
DeclareImages(context, set.Value, set.Key, fsi);
|
||||
}
|
||||
@@ -186,8 +186,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
public static string GetVarTypeName(AggregateType type, bool atomic = false)
|
||||
{
|
||||
var s32 = atomic ? "atomic_int" : "int";
|
||||
var u32 = atomic ? "atomic_uint" : "uint";
|
||||
string s32 = atomic ? "atomic_int" : "int";
|
||||
string u32 = atomic ? "atomic_uint" : "uint";
|
||||
|
||||
return type switch
|
||||
{
|
||||
@@ -216,22 +216,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
string prefix = isShared ? "threadgroup " : string.Empty;
|
||||
|
||||
foreach (var memory in memories)
|
||||
foreach (MemoryDefinition memory in memories)
|
||||
{
|
||||
string arraySize = "";
|
||||
if ((memory.Type & AggregateType.Array) != 0)
|
||||
{
|
||||
arraySize = $"[{memory.ArrayLength}]";
|
||||
}
|
||||
var typeName = GetVarTypeName(memory.Type & ~AggregateType.Array);
|
||||
string typeName = GetVarTypeName(memory.Type & ~AggregateType.Array);
|
||||
context.AppendLine($"{prefix}{typeName} {memory.Name}{arraySize};");
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeclareBufferStructures(CodeGenContext context, BufferDefinition[] buffers, bool constant, bool fsi)
|
||||
{
|
||||
var name = constant ? "ConstantBuffers" : "StorageBuffers";
|
||||
var addressSpace = constant ? "constant" : "device";
|
||||
string name = constant ? "ConstantBuffers" : "StorageBuffers";
|
||||
string addressSpace = constant ? "constant" : "device";
|
||||
|
||||
string[] bufferDec = new string[buffers.Length];
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
BufferDefinition buffer = buffers[i];
|
||||
|
||||
var needsPadding = buffer.Layout == BufferLayout.Std140;
|
||||
bool needsPadding = buffer.Layout == BufferLayout.Std140;
|
||||
string fsiSuffix = !constant && fsi ? " [[raster_order_group(0)]]" : "";
|
||||
|
||||
bufferDec[i] = $"{addressSpace} {Defaults.StructPrefix}_{buffer.Name}* {buffer.Name}{fsiSuffix};";
|
||||
@@ -249,7 +249,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
foreach (StructureField field in buffer.Type.Fields)
|
||||
{
|
||||
var type = field.Type;
|
||||
AggregateType type = field.Type;
|
||||
type |= (needsPadding && (field.Type & AggregateType.Array) != 0)
|
||||
? AggregateType.Vector4
|
||||
: AggregateType.Invalid;
|
||||
@@ -282,7 +282,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
context.AppendLine($"struct {name}");
|
||||
context.EnterScope();
|
||||
|
||||
foreach (var declaration in bufferDec)
|
||||
foreach (string declaration in bufferDec)
|
||||
{
|
||||
context.AppendLine(declaration);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
private static void DeclareTextures(CodeGenContext context, TextureDefinition[] textures, int set)
|
||||
{
|
||||
var setName = GetNameForSet(set);
|
||||
string setName = GetNameForSet(set);
|
||||
context.AppendLine($"struct {setName}");
|
||||
context.EnterScope();
|
||||
|
||||
@@ -303,7 +303,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
if (texture.Type != SamplerType.None)
|
||||
{
|
||||
var textureTypeName = texture.Type.ToMslTextureType(texture.Format.GetComponentType());
|
||||
string textureTypeName = texture.Type.ToMslTextureType(texture.Format.GetComponentType());
|
||||
|
||||
if (texture.ArrayLength > 1)
|
||||
{
|
||||
@@ -315,7 +315,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
if (!texture.Separate && texture.Type != SamplerType.TextureBuffer)
|
||||
{
|
||||
var samplerType = "sampler";
|
||||
string samplerType = "sampler";
|
||||
|
||||
if (texture.ArrayLength > 1)
|
||||
{
|
||||
@@ -326,7 +326,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var declaration in textureDec)
|
||||
foreach (string declaration in textureDec)
|
||||
{
|
||||
context.AppendLine(declaration);
|
||||
}
|
||||
@@ -337,7 +337,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
private static void DeclareImages(CodeGenContext context, TextureDefinition[] images, int set, bool fsi)
|
||||
{
|
||||
var setName = GetNameForSet(set);
|
||||
string setName = GetNameForSet(set);
|
||||
context.AppendLine($"struct {setName}");
|
||||
context.EnterScope();
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
TextureDefinition image = images[i];
|
||||
|
||||
var imageTypeName = image.Type.ToMslTextureType(image.Format.GetComponentType(), true);
|
||||
string imageTypeName = image.Type.ToMslTextureType(image.Format.GetComponentType(), true);
|
||||
if (image.ArrayLength > 1)
|
||||
{
|
||||
imageTypeName = $"array<{imageTypeName}, {image.ArrayLength}>";
|
||||
@@ -358,7 +358,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
imageDec[i] = $"{imageTypeName} {image.Name}{fsiSuffix};";
|
||||
}
|
||||
|
||||
foreach (var declaration in imageDec)
|
||||
foreach (string declaration in imageDec)
|
||||
{
|
||||
context.AppendLine(declaration);
|
||||
}
|
||||
@@ -401,14 +401,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
// We need to use the SPIRV-Cross workaround
|
||||
for (int i = 0; i < Constants.MaxAttributes; i++)
|
||||
{
|
||||
var suffix = context.Definitions.Stage == ShaderStage.Fragment ? $"[[user(loc{i})]]" : $"[[attribute({i})]]";
|
||||
string suffix = context.Definitions.Stage == ShaderStage.Fragment ? $"[[user(loc{i})]]" : $"[[attribute({i})]]";
|
||||
context.AppendLine($"float4 {Defaults.IAttributePrefix}{i} {suffix};");
|
||||
}
|
||||
}
|
||||
|
||||
if (inputs.Any())
|
||||
{
|
||||
foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
foreach (IoDefinition ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
{
|
||||
if (context.Definitions.IaIndexing && ioDefinition.IoVariable == IoVariable.UserDefined)
|
||||
{
|
||||
@@ -500,11 +500,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
IoDefinition firstOutput = outputs.ElementAtOrDefault(0);
|
||||
IoDefinition secondOutput = outputs.ElementAtOrDefault(1);
|
||||
|
||||
var type1 = GetVarTypeName(context.Definitions.GetFragmentOutputColorType(firstOutput.Location));
|
||||
var type2 = GetVarTypeName(context.Definitions.GetFragmentOutputColorType(secondOutput.Location));
|
||||
string type1 = GetVarTypeName(context.Definitions.GetFragmentOutputColorType(firstOutput.Location));
|
||||
string type2 = GetVarTypeName(context.Definitions.GetFragmentOutputColorType(secondOutput.Location));
|
||||
|
||||
var name1 = $"color{firstOutput.Location}";
|
||||
var name2 = $"color{firstOutput.Location + 1}";
|
||||
string name1 = $"color{firstOutput.Location}";
|
||||
string name2 = $"color{firstOutput.Location + 1}";
|
||||
|
||||
context.AppendLine($"{type1} {name1} [[color({firstOutput.Location}), index(0)]];");
|
||||
context.AppendLine($"{type2} {name2} [[color({firstOutput.Location}), index(1)]];");
|
||||
@@ -512,7 +512,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
outputs = outputs.Skip(2);
|
||||
}
|
||||
|
||||
foreach (var ioDefinition in outputs)
|
||||
foreach (IoDefinition ioDefinition in outputs)
|
||||
{
|
||||
if (context.Definitions.OaIndexing && ioDefinition.IoVariable == IoVariable.UserDefined)
|
||||
{
|
||||
|
@@ -49,7 +49,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
? AggregateType.S32
|
||||
: AggregateType.U32;
|
||||
|
||||
var shared = operation.StorageKind == StorageKind.SharedMemory;
|
||||
bool shared = operation.StorageKind == StorageKind.SharedMemory;
|
||||
|
||||
builder.Append($"({(shared ? "threadgroup" : "device")} {Declarations.GetVarTypeName(dstType, true)}*)&{GenerateLoadOrStore(context, operation, isStore: false)}");
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
case 2:
|
||||
if (operation.ForcePrecise)
|
||||
{
|
||||
var func = (inst & Instruction.Mask) switch
|
||||
string func = (inst & Instruction.Mask) switch
|
||||
{
|
||||
Instruction.Add => "PreciseFAdd",
|
||||
Instruction.Subtract => "PreciseFSub",
|
||||
|
@@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
{
|
||||
public static string Barrier(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var device = (operation.Inst & Instruction.Mask) == Instruction.MemoryBarrier;
|
||||
bool device = (operation.Inst & Instruction.Mask) == Instruction.MemoryBarrier;
|
||||
|
||||
return $"threadgroup_barrier(mem_flags::mem_{(device ? "device" : "threadgroup")})";
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
{
|
||||
AstOperand funcId = (AstOperand)operation.GetSource(0);
|
||||
|
||||
var function = context.GetFunction(funcId.Value);
|
||||
StructuredFunction function = context.GetFunction(funcId.Value);
|
||||
|
||||
int argCount = operation.SourcesCount - 1;
|
||||
int additionalArgCount = CodeGenContext.AdditionalArgCount + (context.Definitions.Stage != ShaderStage.Compute ? 1 : 0);
|
||||
|
@@ -157,7 +157,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
|
||||
var texCallBuilder = new StringBuilder();
|
||||
StringBuilder texCallBuilder = new StringBuilder();
|
||||
|
||||
int srcIndex = 0;
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
|
||||
texCallBuilder.Append('(');
|
||||
|
||||
var coordsBuilder = new StringBuilder();
|
||||
StringBuilder coordsBuilder = new StringBuilder();
|
||||
|
||||
int coordsCount = texOp.Type.GetDimensions();
|
||||
|
||||
@@ -326,8 +326,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
coordsExpr = GetSourceExpr(context, texOp.GetSource(coordsIndex), AggregateType.FP32);
|
||||
}
|
||||
|
||||
var clamped = $"{textureName}.calculate_clamped_lod({samplerName}, {coordsExpr})";
|
||||
var unclamped = $"{textureName}.calculate_unclamped_lod({samplerName}, {coordsExpr})";
|
||||
string clamped = $"{textureName}.calculate_clamped_lod({samplerName}, {coordsExpr})";
|
||||
string unclamped = $"{textureName}.calculate_unclamped_lod({samplerName}, {coordsExpr})";
|
||||
|
||||
return $"float2({clamped}, {unclamped}){GetMask(texOp.Index)}";
|
||||
}
|
||||
@@ -352,7 +352,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
bool isShadow = (texOp.Type & SamplerType.Shadow) != 0;
|
||||
|
||||
var texCallBuilder = new StringBuilder();
|
||||
StringBuilder texCallBuilder = new StringBuilder();
|
||||
|
||||
bool colorIsVector = isGather || !isShadow;
|
||||
|
||||
@@ -525,8 +525,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
|
||||
private static string GetSamplerName(CodeGenContext context, AstTextureOperation texOp, ref int srcIndex)
|
||||
{
|
||||
var index = texOp.IsSeparate ? texOp.GetSamplerSetAndBinding() : texOp.GetTextureSetAndBinding();
|
||||
var sourceIndex = texOp.IsSeparate ? srcIndex++ : srcIndex + 1;
|
||||
SetBindingPair index = texOp.IsSeparate ? texOp.GetSamplerSetAndBinding() : texOp.GetTextureSetAndBinding();
|
||||
int sourceIndex = texOp.IsSeparate ? srcIndex++ : srcIndex + 1;
|
||||
|
||||
TextureDefinition samplerDefinition = context.Properties.Textures[index];
|
||||
string name = samplerDefinition.Name;
|
||||
@@ -589,7 +589,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
var texCallBuilder = new StringBuilder();
|
||||
StringBuilder texCallBuilder = new StringBuilder();
|
||||
|
||||
int srcIndex = 0;
|
||||
|
||||
|
@@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
bool isOutput,
|
||||
bool isPerPatch)
|
||||
{
|
||||
var returnValue = ioVariable switch
|
||||
(string, AggregateType) returnValue = ioVariable switch
|
||||
{
|
||||
IoVariable.BaseInstance => ("base_instance", AggregateType.U32),
|
||||
IoVariable.BaseVertex => ("base_vertex", AggregateType.U32),
|
||||
|
@@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
|
||||
CodeGenContext context = new(info, parameters);
|
||||
|
||||
var sets = Declarations.Declare(context, info);
|
||||
int[] sets = Declarations.Declare(context, info);
|
||||
|
||||
if (info.Functions.Count != 0)
|
||||
{
|
||||
@@ -168,15 +168,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
args = args.Append($"constant ConstantBuffers &constant_buffers [[buffer({Defaults.ConstantBuffersIndex})]]").ToArray();
|
||||
args = args.Append($"device StorageBuffers &storage_buffers [[buffer({Defaults.StorageBuffersIndex})]]").ToArray();
|
||||
|
||||
foreach (var set in sets)
|
||||
foreach (int set in sets)
|
||||
{
|
||||
var bindingIndex = set + Defaults.BaseSetIndex;
|
||||
long bindingIndex = set + Defaults.BaseSetIndex;
|
||||
args = args.Append($"constant {Declarations.GetNameForSet(set)} &{Declarations.GetNameForSet(set, true)} [[buffer({bindingIndex})]]").ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
var funcPrefix = $"{funcKeyword} {returnType} {funcName ?? function.Name}(";
|
||||
var indent = new string(' ', funcPrefix.Length);
|
||||
string funcPrefix = $"{funcKeyword} {returnType} {funcName ?? function.Name}(";
|
||||
string indent = new string(' ', funcPrefix.Length);
|
||||
|
||||
return $"{funcPrefix}{string.Join($", \n{indent}", args)})";
|
||||
}
|
||||
|
Reference in New Issue
Block a user