mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-25 01:57:11 +02:00
misc: chore: Use explicit types in Shader project
This commit is contained in:
parent
68bbb29be6
commit
f2aa6b3a5b
39 changed files with 726 additions and 725 deletions
|
@ -149,7 +149,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
if (context.Definitions.TransformFeedbackEnabled && context.Definitions.LastInVertexPipeline)
|
||||
{
|
||||
var tfOutput = context.Definitions.GetTransformFeedbackOutput(AttributeConsts.PositionX);
|
||||
TransformFeedbackOutput tfOutput = context.Definitions.GetTransformFeedbackOutput(AttributeConsts.PositionX);
|
||||
if (tfOutput.Valid)
|
||||
{
|
||||
context.AppendLine($"layout (xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}) out gl_PerVertex");
|
||||
|
@ -338,7 +338,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
private static void DeclareSamplers(CodeGenContext context, IEnumerable<TextureDefinition> definitions)
|
||||
{
|
||||
foreach (var definition in definitions)
|
||||
foreach (TextureDefinition definition in definitions)
|
||||
{
|
||||
string arrayDecl = string.Empty;
|
||||
|
||||
|
@ -366,7 +366,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
private static void DeclareImages(CodeGenContext context, IEnumerable<TextureDefinition> definitions)
|
||||
{
|
||||
foreach (var definition in definitions)
|
||||
foreach (TextureDefinition definition in definitions)
|
||||
{
|
||||
string arrayDecl = string.Empty;
|
||||
|
||||
|
@ -413,7 +413,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
}
|
||||
else
|
||||
{
|
||||
foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
foreach (IoDefinition ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
{
|
||||
DeclareInputAttribute(context, ioDefinition.Location, ioDefinition.Component);
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
private static void DeclareInputAttributesPerPatch(CodeGenContext context, IEnumerable<IoDefinition> inputs)
|
||||
{
|
||||
foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
foreach (IoDefinition ioDefinition in inputs.OrderBy(x => x.Location))
|
||||
{
|
||||
DeclareInputAttributePerPatch(context, ioDefinition.Location);
|
||||
}
|
||||
|
@ -521,7 +521,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var ioDefinition in outputs)
|
||||
foreach (IoDefinition ioDefinition in outputs)
|
||||
{
|
||||
DeclareOutputAttribute(context, ioDefinition.Location, ioDefinition.Component);
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
string xfb = string.Empty;
|
||||
|
||||
var tfOutput = context.Definitions.GetTransformFeedbackOutput(location, component);
|
||||
TransformFeedbackOutput tfOutput = context.Definitions.GetTransformFeedbackOutput(location, component);
|
||||
if (tfOutput.Valid)
|
||||
{
|
||||
xfb = $", xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}";
|
||||
|
@ -570,7 +570,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
string xfb = string.Empty;
|
||||
|
||||
var tfOutput = context.Definitions.GetTransformFeedbackOutput(location, 0);
|
||||
TransformFeedbackOutput tfOutput = context.Definitions.GetTransformFeedbackOutput(location, 0);
|
||||
if (tfOutput.Valid)
|
||||
{
|
||||
xfb = $", xfb_buffer = {tfOutput.Buffer}, xfb_offset = {tfOutput.Offset}, xfb_stride = {tfOutput.Stride}";
|
||||
|
@ -606,7 +606,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
private static void DeclareOutputAttributesPerPatch(CodeGenContext context, IEnumerable<IoDefinition> outputs)
|
||||
{
|
||||
foreach (var ioDefinition in outputs)
|
||||
foreach (IoDefinition ioDefinition in outputs)
|
||||
{
|
||||
DeclareOutputAttributePerPatch(context, ioDefinition.Location);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
Debug.Assert(funcId.Type == OperandType.Constant);
|
||||
|
||||
var function = context.GetFunction(funcId.Value);
|
||||
StructuredFunction function = context.GetFunction(funcId.Value);
|
||||
|
||||
string[] args = new string[operation.SourcesCount - 1];
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
|
||||
var texCallBuilder = new StringBuilder();
|
||||
StringBuilder texCallBuilder = new StringBuilder();
|
||||
|
||||
if (texOp.Inst == Instruction.ImageAtomic)
|
||||
{
|
||||
|
|
|
@ -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)})";
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private BlockState GetBlockStateLazy(AstBlock block)
|
||||
{
|
||||
if (!_labels.TryGetValue(block, out var blockState))
|
||||
if (!_labels.TryGetValue(block, out BlockState blockState))
|
||||
{
|
||||
blockState = new BlockState();
|
||||
|
||||
|
@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
public Instruction NewBlock()
|
||||
{
|
||||
var label = Label();
|
||||
Instruction label = Label();
|
||||
Branch(label);
|
||||
AddLabel(label);
|
||||
return label;
|
||||
|
@ -147,7 +147,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
public Instruction[] GetMainInterface()
|
||||
{
|
||||
var mainInterface = new List<Instruction>();
|
||||
List<Instruction> mainInterface = new List<Instruction>();
|
||||
|
||||
mainInterface.AddRange(Inputs.Values);
|
||||
mainInterface.AddRange(Outputs.Values);
|
||||
|
@ -196,7 +196,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
if (node is AstOperation operation)
|
||||
{
|
||||
var opResult = Instructions.Generate(this, operation);
|
||||
OperationResult opResult = Instructions.Generate(this, operation);
|
||||
return BitcastIfNeeded(type, opResult.Type, opResult.Value);
|
||||
}
|
||||
else if (node is AstOperand operand)
|
||||
|
@ -218,7 +218,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
if (node is AstOperation operation)
|
||||
{
|
||||
var opResult = Instructions.Generate(this, operation);
|
||||
OperationResult opResult = Instructions.Generate(this, operation);
|
||||
type = opResult.Type;
|
||||
return opResult.Value;
|
||||
}
|
||||
|
@ -273,13 +273,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
public Instruction GetLocal(AggregateType dstType, AstOperand local)
|
||||
{
|
||||
var srcType = local.VarType;
|
||||
AggregateType srcType = local.VarType;
|
||||
return BitcastIfNeeded(dstType, srcType, Load(GetType(srcType), GetLocalPointer(local)));
|
||||
}
|
||||
|
||||
public Instruction GetArgument(AggregateType dstType, AstOperand funcArg)
|
||||
{
|
||||
var srcType = funcArg.VarType;
|
||||
AggregateType srcType = funcArg.VarType;
|
||||
return BitcastIfNeeded(dstType, srcType, Load(GetType(srcType), GetArgumentPointer(funcArg)));
|
||||
}
|
||||
|
||||
|
@ -339,8 +339,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else if (srcType == AggregateType.Bool)
|
||||
{
|
||||
var intTrue = Constant(TypeS32(), IrConsts.True);
|
||||
var intFalse = Constant(TypeS32(), IrConsts.False);
|
||||
Instruction intTrue = Constant(TypeS32(), IrConsts.True);
|
||||
Instruction intFalse = Constant(TypeS32(), IrConsts.False);
|
||||
|
||||
return BitcastIfNeeded(dstType, AggregateType.S32, Select(TypeS32(), value, intTrue, intFalse));
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static void DeclareParameters(CodeGenContext context, IEnumerable<AggregateType> argTypes, int argIndex)
|
||||
{
|
||||
foreach (var argType in argTypes)
|
||||
foreach (AggregateType argType in argTypes)
|
||||
{
|
||||
var argPointerType = context.TypePointer(StorageClass.Function, context.GetType(argType));
|
||||
var spvArg = context.FunctionParameter(argPointerType);
|
||||
SpvInstruction argPointerType = context.TypePointer(StorageClass.Function, context.GetType(argType));
|
||||
SpvInstruction spvArg = context.FunctionParameter(argPointerType);
|
||||
|
||||
context.DeclareArgument(argIndex++, spvArg);
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
foreach (AstOperand local in function.Locals)
|
||||
{
|
||||
var localPointerType = context.TypePointer(StorageClass.Function, context.GetType(local.VarType));
|
||||
var spvLocal = context.Variable(localPointerType, StorageClass.Function);
|
||||
SpvInstruction localPointerType = context.TypePointer(StorageClass.Function, context.GetType(local.VarType));
|
||||
SpvInstruction spvLocal = context.Variable(localPointerType, StorageClass.Function);
|
||||
|
||||
context.AddLocalVariable(spvLocal);
|
||||
context.DeclareLocal(local, spvLocal);
|
||||
|
@ -60,8 +60,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
foreach ((int id, MemoryDefinition memory) in memories)
|
||||
{
|
||||
var pointerType = context.TypePointer(storage, context.GetType(memory.Type, memory.ArrayLength));
|
||||
var variable = context.Variable(pointerType, storage);
|
||||
SpvInstruction pointerType = context.TypePointer(storage, context.GetType(memory.Type, memory.ArrayLength));
|
||||
SpvInstruction variable = context.Variable(pointerType, storage);
|
||||
|
||||
context.AddGlobalVariable(variable);
|
||||
|
||||
|
@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
var structType = context.TypeStruct(false, structFieldTypes);
|
||||
SpvInstruction structType = context.TypeStruct(false, structFieldTypes);
|
||||
|
||||
if (decoratedTypes.Add(structType))
|
||||
{
|
||||
|
@ -135,8 +135,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
var pointerType = context.TypePointer(StorageClass.Uniform, structType);
|
||||
var variable = context.Variable(pointerType, StorageClass.Uniform);
|
||||
SpvInstruction pointerType = context.TypePointer(StorageClass.Uniform, structType);
|
||||
SpvInstruction variable = context.Variable(pointerType, StorageClass.Uniform);
|
||||
|
||||
context.Name(variable, buffer.Name);
|
||||
context.Decorate(variable, Decoration.DescriptorSet, (LiteralInteger)setIndex);
|
||||
|
@ -156,7 +156,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static void DeclareSamplers(CodeGenContext context, IEnumerable<TextureDefinition> samplers)
|
||||
{
|
||||
foreach (var sampler in samplers)
|
||||
foreach (TextureDefinition sampler in samplers)
|
||||
{
|
||||
int setIndex = context.TargetApi == TargetApi.Vulkan ? sampler.Set : 0;
|
||||
|
||||
|
@ -165,7 +165,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
if (sampler.Type != SamplerType.None)
|
||||
{
|
||||
var dim = (sampler.Type & SamplerType.Mask) switch
|
||||
Dim dim = (sampler.Type & SamplerType.Mask) switch
|
||||
{
|
||||
SamplerType.Texture1D => Dim.Dim1D,
|
||||
SamplerType.Texture2D => Dim.Dim2D,
|
||||
|
@ -191,22 +191,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
imageType = sampledImageType = context.TypeSampler();
|
||||
}
|
||||
|
||||
var sampledOrSeparateImageType = sampler.Separate ? imageType : sampledImageType;
|
||||
var sampledImagePointerType = context.TypePointer(StorageClass.UniformConstant, sampledOrSeparateImageType);
|
||||
var sampledImageArrayPointerType = sampledImagePointerType;
|
||||
SpvInstruction sampledOrSeparateImageType = sampler.Separate ? imageType : sampledImageType;
|
||||
SpvInstruction sampledImagePointerType = context.TypePointer(StorageClass.UniformConstant, sampledOrSeparateImageType);
|
||||
SpvInstruction sampledImageArrayPointerType = sampledImagePointerType;
|
||||
|
||||
if (sampler.ArrayLength == 0)
|
||||
{
|
||||
var sampledImageArrayType = context.TypeRuntimeArray(sampledOrSeparateImageType);
|
||||
SpvInstruction sampledImageArrayType = context.TypeRuntimeArray(sampledOrSeparateImageType);
|
||||
sampledImageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, sampledImageArrayType);
|
||||
}
|
||||
else if (sampler.ArrayLength != 1)
|
||||
{
|
||||
var sampledImageArrayType = context.TypeArray(sampledOrSeparateImageType, context.Constant(context.TypeU32(), sampler.ArrayLength));
|
||||
SpvInstruction sampledImageArrayType = context.TypeArray(sampledOrSeparateImageType, context.Constant(context.TypeU32(), sampler.ArrayLength));
|
||||
sampledImageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, sampledImageArrayType);
|
||||
}
|
||||
|
||||
var sampledImageVariable = context.Variable(sampledImageArrayPointerType, StorageClass.UniformConstant);
|
||||
SpvInstruction sampledImageVariable = context.Variable(sampledImageArrayPointerType, StorageClass.UniformConstant);
|
||||
|
||||
context.Samplers.Add(new(sampler.Set, sampler.Binding), new SamplerDeclaration(
|
||||
imageType,
|
||||
|
@ -225,13 +225,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static void DeclareImages(CodeGenContext context, IEnumerable<TextureDefinition> images)
|
||||
{
|
||||
foreach (var image in images)
|
||||
foreach (TextureDefinition image in images)
|
||||
{
|
||||
int setIndex = context.TargetApi == TargetApi.Vulkan ? image.Set : 0;
|
||||
|
||||
var dim = GetDim(image.Type);
|
||||
Dim dim = GetDim(image.Type);
|
||||
|
||||
var imageType = context.TypeImage(
|
||||
SpvInstruction imageType = context.TypeImage(
|
||||
context.GetType(image.Format.GetComponentType()),
|
||||
dim,
|
||||
image.Type.HasFlag(SamplerType.Shadow),
|
||||
|
@ -240,21 +240,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AccessQualifier.ReadWrite,
|
||||
GetImageFormat(image.Format));
|
||||
|
||||
var imagePointerType = context.TypePointer(StorageClass.UniformConstant, imageType);
|
||||
var imageArrayPointerType = imagePointerType;
|
||||
SpvInstruction imagePointerType = context.TypePointer(StorageClass.UniformConstant, imageType);
|
||||
SpvInstruction imageArrayPointerType = imagePointerType;
|
||||
|
||||
if (image.ArrayLength == 0)
|
||||
{
|
||||
var imageArrayType = context.TypeRuntimeArray(imageType);
|
||||
SpvInstruction imageArrayType = context.TypeRuntimeArray(imageType);
|
||||
imageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, imageArrayType);
|
||||
}
|
||||
else if (image.ArrayLength != 1)
|
||||
{
|
||||
var imageArrayType = context.TypeArray(imageType, context.Constant(context.TypeU32(), image.ArrayLength));
|
||||
SpvInstruction imageArrayType = context.TypeArray(imageType, context.Constant(context.TypeU32(), image.ArrayLength));
|
||||
imageArrayPointerType = context.TypePointer(StorageClass.UniformConstant, imageArrayType);
|
||||
}
|
||||
|
||||
var imageVariable = context.Variable(imageArrayPointerType, StorageClass.UniformConstant);
|
||||
SpvInstruction imageVariable = context.Variable(imageArrayPointerType, StorageClass.UniformConstant);
|
||||
|
||||
context.Images.Add(new(image.Set, image.Binding), new ImageDeclaration(imageType, imagePointerType, imageVariable, image.ArrayLength != 1));
|
||||
|
||||
|
@ -338,7 +338,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
if (context.Definitions.Stage == ShaderStage.Fragment && context.Definitions.DualSourceBlend)
|
||||
{
|
||||
foreach (var ioDefinition in info.IoDefinitions)
|
||||
foreach (IoDefinition ioDefinition in info.IoDefinitions)
|
||||
{
|
||||
if (ioDefinition.IoVariable == IoVariable.FragmentOutputColor && ioDefinition.Location < firstLocation)
|
||||
{
|
||||
|
@ -347,13 +347,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var ioDefinition in info.IoDefinitions)
|
||||
foreach (IoDefinition ioDefinition in info.IoDefinitions)
|
||||
{
|
||||
PixelImap iq = PixelImap.Unused;
|
||||
|
||||
if (context.Definitions.Stage == ShaderStage.Fragment)
|
||||
{
|
||||
var ioVariable = ioDefinition.IoVariable;
|
||||
IoVariable ioVariable = ioDefinition.IoVariable;
|
||||
if (ioVariable == IoVariable.UserDefined)
|
||||
{
|
||||
iq = context.Definitions.ImapTypes[ioDefinition.Location].GetFirstUsedType();
|
||||
|
@ -389,11 +389,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
if (context.Definitions.Stage != ShaderStage.Vertex)
|
||||
{
|
||||
var perVertexInputStructType = CreatePerVertexStructType(context);
|
||||
SpvInstruction perVertexInputStructType = CreatePerVertexStructType(context);
|
||||
int arraySize = context.Definitions.Stage == ShaderStage.Geometry ? context.Definitions.InputTopology.ToInputVertices() : 32;
|
||||
var perVertexInputArrayType = context.TypeArray(perVertexInputStructType, context.Constant(context.TypeU32(), arraySize));
|
||||
var perVertexInputPointerType = context.TypePointer(StorageClass.Input, perVertexInputArrayType);
|
||||
var perVertexInputVariable = context.Variable(perVertexInputPointerType, StorageClass.Input);
|
||||
SpvInstruction perVertexInputArrayType = context.TypeArray(perVertexInputStructType, context.Constant(context.TypeU32(), arraySize));
|
||||
SpvInstruction perVertexInputPointerType = context.TypePointer(StorageClass.Input, perVertexInputArrayType);
|
||||
SpvInstruction perVertexInputVariable = context.Variable(perVertexInputPointerType, StorageClass.Input);
|
||||
|
||||
context.Name(perVertexInputVariable, "gl_in");
|
||||
|
||||
|
@ -411,11 +411,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
var perVertexOutputStructType = CreatePerVertexStructType(context);
|
||||
SpvInstruction perVertexOutputStructType = CreatePerVertexStructType(context);
|
||||
|
||||
void DecorateTfo(IoVariable ioVariable, int fieldIndex)
|
||||
{
|
||||
if (context.Definitions.TryGetTransformFeedbackOutput(ioVariable, 0, 0, out var transformFeedbackOutput))
|
||||
if (context.Definitions.TryGetTransformFeedbackOutput(ioVariable, 0, 0, out TransformFeedbackOutput transformFeedbackOutput))
|
||||
{
|
||||
context.MemberDecorate(perVertexOutputStructType, fieldIndex, Decoration.XfbBuffer, (LiteralInteger)transformFeedbackOutput.Buffer);
|
||||
context.MemberDecorate(perVertexOutputStructType, fieldIndex, Decoration.XfbStride, (LiteralInteger)transformFeedbackOutput.Stride);
|
||||
|
@ -439,8 +439,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
perVertexOutputArrayType = perVertexOutputStructType;
|
||||
}
|
||||
|
||||
var perVertexOutputPointerType = context.TypePointer(StorageClass.Output, perVertexOutputArrayType);
|
||||
var perVertexOutputVariable = context.Variable(perVertexOutputPointerType, StorageClass.Output);
|
||||
SpvInstruction perVertexOutputPointerType = context.TypePointer(StorageClass.Output, perVertexOutputArrayType);
|
||||
SpvInstruction perVertexOutputVariable = context.Variable(perVertexOutputPointerType, StorageClass.Output);
|
||||
|
||||
context.AddGlobalVariable(perVertexOutputVariable);
|
||||
context.Outputs.Add(new IoDefinition(StorageKind.Output, IoVariable.Position), perVertexOutputVariable);
|
||||
|
@ -449,12 +449,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static SpvInstruction CreatePerVertexStructType(CodeGenContext context)
|
||||
{
|
||||
var vec4FloatType = context.TypeVector(context.TypeFP32(), 4);
|
||||
var floatType = context.TypeFP32();
|
||||
var array8FloatType = context.TypeArray(context.TypeFP32(), context.Constant(context.TypeU32(), 8));
|
||||
var array1FloatType = context.TypeArray(context.TypeFP32(), context.Constant(context.TypeU32(), 1));
|
||||
SpvInstruction vec4FloatType = context.TypeVector(context.TypeFP32(), 4);
|
||||
SpvInstruction floatType = context.TypeFP32();
|
||||
SpvInstruction array8FloatType = context.TypeArray(context.TypeFP32(), context.Constant(context.TypeU32(), 8));
|
||||
SpvInstruction array1FloatType = context.TypeArray(context.TypeFP32(), context.Constant(context.TypeU32(), 1));
|
||||
|
||||
var perVertexStructType = context.TypeStruct(true, vec4FloatType, floatType, array8FloatType, array1FloatType);
|
||||
SpvInstruction perVertexStructType = context.TypeStruct(true, vec4FloatType, floatType, array8FloatType, array1FloatType);
|
||||
|
||||
context.Name(perVertexStructType, "gl_PerVertex");
|
||||
|
||||
|
@ -487,7 +487,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
int firstLocation = 0)
|
||||
{
|
||||
IoVariable ioVariable = ioDefinition.IoVariable;
|
||||
var storageClass = isOutput ? StorageClass.Output : StorageClass.Input;
|
||||
StorageClass storageClass = isOutput ? StorageClass.Output : StorageClass.Input;
|
||||
|
||||
bool isBuiltIn;
|
||||
BuiltIn builtIn = default;
|
||||
|
@ -532,7 +532,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
};
|
||||
}
|
||||
|
||||
var spvType = context.GetType(varType, IoMap.GetSpirvBuiltInArrayLength(ioVariable));
|
||||
SpvInstruction spvType = context.GetType(varType, IoMap.GetSpirvBuiltInArrayLength(ioVariable));
|
||||
bool builtInPassthrough = false;
|
||||
|
||||
if (!isPerPatch && IoMap.IsPerVertex(ioVariable, context.Definitions.Stage, isOutput))
|
||||
|
@ -551,8 +551,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
spvType = context.TypeArray(spvType, context.Constant(context.TypeU32(), context.Definitions.ThreadsPerInputPrimitive));
|
||||
}
|
||||
|
||||
var spvPointerType = context.TypePointer(storageClass, spvType);
|
||||
var spvVar = context.Variable(spvPointerType, storageClass);
|
||||
SpvInstruction spvPointerType = context.TypePointer(storageClass, spvType);
|
||||
SpvInstruction spvVar = context.Variable(spvPointerType, storageClass);
|
||||
|
||||
if (builtInPassthrough)
|
||||
{
|
||||
|
@ -641,7 +641,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
ioVariable,
|
||||
ioDefinition.Location,
|
||||
ioDefinition.Component,
|
||||
out var transformFeedbackOutput))
|
||||
out TransformFeedbackOutput transformFeedbackOutput))
|
||||
{
|
||||
context.Decorate(spvVar, Decoration.XfbBuffer, (LiteralInteger)transformFeedbackOutput.Buffer);
|
||||
context.Decorate(spvVar, Decoration.XfbStride, (LiteralInteger)transformFeedbackOutput.Stride);
|
||||
|
@ -650,7 +650,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
context.AddGlobalVariable(spvVar);
|
||||
|
||||
var dict = isPerPatch
|
||||
Dictionary<IoDefinition, SpvInstruction> dict = isPerPatch
|
||||
? (isOutput ? context.OutputsPerPatch : context.InputsPerPatch)
|
||||
: (isOutput ? context.Outputs : context.Inputs);
|
||||
dict.Add(ioDefinition, spvVar);
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
public static OperationResult Generate(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var handler = _instTable[(int)(operation.Inst & Instruction.Mask)];
|
||||
Func<CodeGenContext, AstOperation, OperationResult> handler = _instTable[(int)(operation.Inst & Instruction.Mask)];
|
||||
if (handler != null)
|
||||
{
|
||||
return handler(context, operation);
|
||||
|
@ -226,13 +226,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateBallot(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
var uvec4Type = context.TypeVector(context.TypeU32(), 4);
|
||||
var execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
SpvInstruction uvec4Type = context.TypeVector(context.TypeU32(), 4);
|
||||
SpvInstruction execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
|
||||
var maskVector = context.GroupNonUniformBallot(uvec4Type, execution, context.Get(AggregateType.Bool, source));
|
||||
var mask = context.CompositeExtract(context.TypeU32(), maskVector, (SpvLiteralInteger)operation.Index);
|
||||
SpvInstruction maskVector = context.GroupNonUniformBallot(uvec4Type, execution, context.Get(AggregateType.Bool, source));
|
||||
SpvInstruction mask = context.CompositeExtract(context.TypeU32(), maskVector, (SpvLiteralInteger)operation.Index);
|
||||
|
||||
return new OperationResult(AggregateType.U32, mask);
|
||||
}
|
||||
|
@ -308,21 +308,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
Debug.Assert(funcId.Type == OperandType.Constant);
|
||||
|
||||
var (function, spvFunc) = context.GetFunction(funcId.Value);
|
||||
(StructuredFunction function, SpvInstruction spvFunc) = context.GetFunction(funcId.Value);
|
||||
|
||||
var args = new SpvInstruction[operation.SourcesCount - 1];
|
||||
SpvInstruction[] args = new SpvInstruction[operation.SourcesCount - 1];
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
var operand = operation.GetSource(i + 1);
|
||||
IAstNode operand = operation.GetSource(i + 1);
|
||||
|
||||
AstOperand local = (AstOperand)operand;
|
||||
Debug.Assert(local.Type == OperandType.LocalVariable);
|
||||
args[i] = context.GetLocalPointer(local);
|
||||
}
|
||||
|
||||
var retType = function.ReturnType;
|
||||
var result = context.FunctionCall(context.GetType(retType), spvFunc, args);
|
||||
AggregateType retType = function.ReturnType;
|
||||
SpvInstruction result = context.FunctionCall(context.GetType(retType), spvFunc, args);
|
||||
return new OperationResult(retType, result);
|
||||
}
|
||||
|
||||
|
@ -398,11 +398,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateConditionalSelect(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
var src3 = operation.GetSource(2);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
IAstNode src3 = operation.GetSource(2);
|
||||
|
||||
var cond = context.Get(AggregateType.Bool, src1);
|
||||
SpvInstruction cond = context.Get(AggregateType.Bool, src1);
|
||||
|
||||
if (operation.Inst.HasFlag(Instruction.FP64))
|
||||
{
|
||||
|
@ -420,70 +420,70 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateConvertFP32ToFP64(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP64, context.FConvert(context.TypeFP64(), context.GetFP32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertFP32ToS32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.S32, context.ConvertFToS(context.TypeS32(), context.GetFP32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertFP32ToU32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.U32, context.ConvertFToU(context.TypeU32(), context.GetFP32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertFP64ToFP32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, context.FConvert(context.TypeFP32(), context.GetFP64(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertFP64ToS32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.S32, context.ConvertFToS(context.TypeS32(), context.GetFP64(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertFP64ToU32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.U32, context.ConvertFToU(context.TypeU32(), context.GetFP64(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertS32ToFP32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, context.ConvertSToF(context.TypeFP32(), context.GetS32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertS32ToFP64(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP64, context.ConvertSToF(context.TypeFP64(), context.GetS32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertU32ToFP32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, context.ConvertUToF(context.TypeFP32(), context.GetU32(source)));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateConvertU32ToFP64(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
return new OperationResult(AggregateType.FP64, context.ConvertUToF(context.TypeFP64(), context.GetU32(source)));
|
||||
}
|
||||
|
@ -555,19 +555,19 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateFindLSB(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = context.GetU32(operation.GetSource(0));
|
||||
SpvInstruction source = context.GetU32(operation.GetSource(0));
|
||||
return new OperationResult(AggregateType.U32, context.GlslFindILsb(context.TypeU32(), source));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateFindMSBS32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = context.GetS32(operation.GetSource(0));
|
||||
SpvInstruction source = context.GetS32(operation.GetSource(0));
|
||||
return new OperationResult(AggregateType.U32, context.GlslFindSMsb(context.TypeU32(), source));
|
||||
}
|
||||
|
||||
private static OperationResult GenerateFindMSBU32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = context.GetU32(operation.GetSource(0));
|
||||
SpvInstruction source = context.GetU32(operation.GetSource(0));
|
||||
return new OperationResult(AggregateType.U32, context.GlslFindUMsb(context.TypeU32(), source));
|
||||
}
|
||||
|
||||
|
@ -591,7 +591,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
var componentType = texOp.Format.GetComponentType();
|
||||
AggregateType componentType = texOp.Format.GetComponentType();
|
||||
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
|
||||
|
@ -630,7 +630,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[i] = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
pCoords = context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -640,11 +640,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
SpvInstruction value = Src(componentType);
|
||||
|
||||
var pointer = context.ImageTexelPointer(imagePointerType, image, pCoords, context.Constant(context.TypeU32(), 0));
|
||||
var one = context.Constant(context.TypeU32(), 1);
|
||||
var zero = context.Constant(context.TypeU32(), 0);
|
||||
SpvInstruction pointer = context.ImageTexelPointer(imagePointerType, image, pCoords, context.Constant(context.TypeU32(), 0));
|
||||
SpvInstruction one = context.Constant(context.TypeU32(), 1);
|
||||
SpvInstruction zero = context.Constant(context.TypeU32(), 0);
|
||||
|
||||
var result = (texOp.Flags & TextureFlags.AtomicMask) switch
|
||||
SpvInstruction result = (texOp.Flags & TextureFlags.AtomicMask) switch
|
||||
{
|
||||
TextureFlags.Add => context.AtomicIAdd(resultType, pointer, one, zero, value),
|
||||
TextureFlags.Minimum => componentType == AggregateType.S32
|
||||
|
@ -670,7 +670,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
var componentType = texOp.Format.GetComponentType();
|
||||
AggregateType componentType = texOp.Format.GetComponentType();
|
||||
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
|
||||
|
@ -708,7 +708,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[i] = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
pCoords = context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -716,11 +716,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
pCoords = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var imageComponentType = context.GetType(componentType);
|
||||
var swizzledResultType = texOp.GetVectorType(componentType);
|
||||
SpvInstruction imageComponentType = context.GetType(componentType);
|
||||
AggregateType swizzledResultType = texOp.GetVectorType(componentType);
|
||||
|
||||
var texel = context.ImageRead(context.TypeVector(imageComponentType, 4), image, pCoords, ImageOperandsMask.MaskNone);
|
||||
var result = GetSwizzledResult(context, texel, swizzledResultType, texOp.Index);
|
||||
SpvInstruction texel = context.ImageRead(context.TypeVector(imageComponentType, 4), image, pCoords, ImageOperandsMask.MaskNone);
|
||||
SpvInstruction result = GetSwizzledResult(context, texel, swizzledResultType, texOp.Index);
|
||||
|
||||
return new OperationResult(componentType, result);
|
||||
}
|
||||
|
@ -765,7 +765,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[i] = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeS32(), pCount);
|
||||
pCoords = context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -773,7 +773,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
pCoords = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var componentType = texOp.Format.GetComponentType();
|
||||
AggregateType componentType = texOp.Format.GetComponentType();
|
||||
|
||||
const int ComponentsCount = 4;
|
||||
|
||||
|
@ -796,7 +796,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
var texel = context.CompositeConstruct(context.TypeVector(context.GetType(componentType), ComponentsCount), cElems);
|
||||
SpvInstruction texel = context.CompositeConstruct(context.TypeVector(context.GetType(componentType), ComponentsCount), cElems);
|
||||
|
||||
context.ImageWrite(image, pCoords, texel, ImageOperandsMask.MaskNone);
|
||||
|
||||
|
@ -805,7 +805,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateIsNan(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
SpvInstruction result;
|
||||
|
||||
|
@ -853,7 +853,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[i] = Src(AggregateType.FP32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeFP32(), pCount);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeFP32(), pCount);
|
||||
pCoords = context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -861,9 +861,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
pCoords = Src(AggregateType.FP32);
|
||||
}
|
||||
|
||||
var resultType = context.TypeVector(context.TypeFP32(), 2);
|
||||
var packed = context.ImageQueryLod(resultType, image, pCoords);
|
||||
var result = context.CompositeExtract(context.TypeFP32(), packed, (SpvLiteralInteger)texOp.Index);
|
||||
SpvInstruction resultType = context.TypeVector(context.TypeFP32(), 2);
|
||||
SpvInstruction packed = context.ImageQueryLod(resultType, image, pCoords);
|
||||
SpvInstruction result = context.CompositeExtract(context.TypeFP32(), packed, (SpvLiteralInteger)texOp.Index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
@ -959,11 +959,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateMultiplyHighS32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
var resultType = context.TypeStruct(false, context.TypeS32(), context.TypeS32());
|
||||
var result = context.SMulExtended(resultType, context.GetS32(src1), context.GetS32(src2));
|
||||
SpvInstruction resultType = context.TypeStruct(false, context.TypeS32(), context.TypeS32());
|
||||
SpvInstruction result = context.SMulExtended(resultType, context.GetS32(src1), context.GetS32(src2));
|
||||
result = context.CompositeExtract(context.TypeS32(), result, 1);
|
||||
|
||||
return new OperationResult(AggregateType.S32, result);
|
||||
|
@ -971,11 +971,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateMultiplyHighU32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
var resultType = context.TypeStruct(false, context.TypeU32(), context.TypeU32());
|
||||
var result = context.UMulExtended(resultType, context.GetU32(src1), context.GetU32(src2));
|
||||
SpvInstruction resultType = context.TypeStruct(false, context.TypeU32(), context.TypeU32());
|
||||
SpvInstruction result = context.UMulExtended(resultType, context.GetU32(src1), context.GetU32(src2));
|
||||
result = context.CompositeExtract(context.TypeU32(), result, 1);
|
||||
|
||||
return new OperationResult(AggregateType.U32, result);
|
||||
|
@ -988,20 +988,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GeneratePackDouble2x32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value0 = context.GetU32(operation.GetSource(0));
|
||||
var value1 = context.GetU32(operation.GetSource(1));
|
||||
var vector = context.CompositeConstruct(context.TypeVector(context.TypeU32(), 2), value0, value1);
|
||||
var result = context.GlslPackDouble2x32(context.TypeFP64(), vector);
|
||||
SpvInstruction value0 = context.GetU32(operation.GetSource(0));
|
||||
SpvInstruction value1 = context.GetU32(operation.GetSource(1));
|
||||
SpvInstruction vector = context.CompositeConstruct(context.TypeVector(context.TypeU32(), 2), value0, value1);
|
||||
SpvInstruction result = context.GlslPackDouble2x32(context.TypeFP64(), vector);
|
||||
|
||||
return new OperationResult(AggregateType.FP64, result);
|
||||
}
|
||||
|
||||
private static OperationResult GeneratePackHalf2x16(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value0 = context.GetFP32(operation.GetSource(0));
|
||||
var value1 = context.GetFP32(operation.GetSource(1));
|
||||
var vector = context.CompositeConstruct(context.TypeVector(context.TypeFP32(), 2), value0, value1);
|
||||
var result = context.GlslPackHalf2x16(context.TypeU32(), vector);
|
||||
SpvInstruction value0 = context.GetFP32(operation.GetSource(0));
|
||||
SpvInstruction value1 = context.GetFP32(operation.GetSource(1));
|
||||
SpvInstruction vector = context.CompositeConstruct(context.TypeVector(context.TypeFP32(), 2), value0, value1);
|
||||
SpvInstruction result = context.GlslPackHalf2x16(context.TypeU32(), vector);
|
||||
|
||||
return new OperationResult(AggregateType.U32, result);
|
||||
}
|
||||
|
@ -1049,40 +1049,40 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateShuffle(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetFP32(operation.GetSource(0));
|
||||
var index = context.GetU32(operation.GetSource(1));
|
||||
SpvInstruction value = context.GetFP32(operation.GetSource(0));
|
||||
SpvInstruction index = context.GetU32(operation.GetSource(1));
|
||||
|
||||
var result = context.GroupNonUniformShuffle(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
SpvInstruction result = context.GroupNonUniformShuffle(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateShuffleDown(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetFP32(operation.GetSource(0));
|
||||
var index = context.GetU32(operation.GetSource(1));
|
||||
SpvInstruction value = context.GetFP32(operation.GetSource(0));
|
||||
SpvInstruction index = context.GetU32(operation.GetSource(1));
|
||||
|
||||
var result = context.GroupNonUniformShuffleDown(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
SpvInstruction result = context.GroupNonUniformShuffleDown(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateShuffleUp(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetFP32(operation.GetSource(0));
|
||||
var index = context.GetU32(operation.GetSource(1));
|
||||
SpvInstruction value = context.GetFP32(operation.GetSource(0));
|
||||
SpvInstruction index = context.GetU32(operation.GetSource(1));
|
||||
|
||||
var result = context.GroupNonUniformShuffleUp(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
SpvInstruction result = context.GroupNonUniformShuffleUp(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateShuffleXor(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetFP32(operation.GetSource(0));
|
||||
var index = context.GetU32(operation.GetSource(1));
|
||||
SpvInstruction value = context.GetFP32(operation.GetSource(0));
|
||||
SpvInstruction index = context.GetU32(operation.GetSource(1));
|
||||
|
||||
var result = context.GroupNonUniformShuffleXor(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
SpvInstruction result = context.GroupNonUniformShuffleXor(context.TypeFP32(), context.Constant(context.TypeU32(), (int)Scope.Subgroup), value, index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
@ -1109,31 +1109,31 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateSwizzleAdd(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var x = context.Get(AggregateType.FP32, operation.GetSource(0));
|
||||
var y = context.Get(AggregateType.FP32, operation.GetSource(1));
|
||||
var mask = context.Get(AggregateType.U32, operation.GetSource(2));
|
||||
SpvInstruction x = context.Get(AggregateType.FP32, operation.GetSource(0));
|
||||
SpvInstruction y = context.Get(AggregateType.FP32, operation.GetSource(1));
|
||||
SpvInstruction mask = context.Get(AggregateType.U32, operation.GetSource(2));
|
||||
|
||||
var v4float = context.TypeVector(context.TypeFP32(), 4);
|
||||
var one = context.Constant(context.TypeFP32(), 1.0f);
|
||||
var minusOne = context.Constant(context.TypeFP32(), -1.0f);
|
||||
var zero = context.Constant(context.TypeFP32(), 0.0f);
|
||||
var xLut = context.ConstantComposite(v4float, one, minusOne, one, zero);
|
||||
var yLut = context.ConstantComposite(v4float, one, one, minusOne, one);
|
||||
SpvInstruction v4float = context.TypeVector(context.TypeFP32(), 4);
|
||||
SpvInstruction one = context.Constant(context.TypeFP32(), 1.0f);
|
||||
SpvInstruction minusOne = context.Constant(context.TypeFP32(), -1.0f);
|
||||
SpvInstruction zero = context.Constant(context.TypeFP32(), 0.0f);
|
||||
SpvInstruction xLut = context.ConstantComposite(v4float, one, minusOne, one, zero);
|
||||
SpvInstruction yLut = context.ConstantComposite(v4float, one, one, minusOne, one);
|
||||
|
||||
var three = context.Constant(context.TypeU32(), 3);
|
||||
SpvInstruction three = context.Constant(context.TypeU32(), 3);
|
||||
|
||||
var threadId = GetScalarInput(context, IoVariable.SubgroupLaneId);
|
||||
var shift = context.BitwiseAnd(context.TypeU32(), threadId, three);
|
||||
SpvInstruction threadId = GetScalarInput(context, IoVariable.SubgroupLaneId);
|
||||
SpvInstruction shift = context.BitwiseAnd(context.TypeU32(), threadId, three);
|
||||
shift = context.ShiftLeftLogical(context.TypeU32(), shift, context.Constant(context.TypeU32(), 1));
|
||||
var lutIdx = context.ShiftRightLogical(context.TypeU32(), mask, shift);
|
||||
SpvInstruction lutIdx = context.ShiftRightLogical(context.TypeU32(), mask, shift);
|
||||
lutIdx = context.BitwiseAnd(context.TypeU32(), lutIdx, three);
|
||||
|
||||
var xLutValue = context.VectorExtractDynamic(context.TypeFP32(), xLut, lutIdx);
|
||||
var yLutValue = context.VectorExtractDynamic(context.TypeFP32(), yLut, lutIdx);
|
||||
SpvInstruction xLutValue = context.VectorExtractDynamic(context.TypeFP32(), xLut, lutIdx);
|
||||
SpvInstruction yLutValue = context.VectorExtractDynamic(context.TypeFP32(), yLut, lutIdx);
|
||||
|
||||
var xResult = context.FMul(context.TypeFP32(), x, xLutValue);
|
||||
var yResult = context.FMul(context.TypeFP32(), y, yLutValue);
|
||||
var result = context.FAdd(context.TypeFP32(), xResult, yResult);
|
||||
SpvInstruction xResult = context.FMul(context.TypeFP32(), x, xLutValue);
|
||||
SpvInstruction yResult = context.FMul(context.TypeFP32(), y, yLutValue);
|
||||
SpvInstruction result = context.FAdd(context.TypeFP32(), xResult, yResult);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
@ -1200,7 +1200,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(intCoords ? context.TypeS32() : context.TypeFP32(), count);
|
||||
SpvInstruction vectorType = context.TypeVector(intCoords ? context.TypeS32() : context.TypeFP32(), count);
|
||||
return context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -1222,7 +1222,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[index] = Src(AggregateType.FP32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeFP32(), count);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeFP32(), count);
|
||||
return context.CompositeConstruct(vectorType, elems);
|
||||
}
|
||||
else
|
||||
|
@ -1272,7 +1272,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
elems[index] = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var vectorType = context.TypeVector(context.TypeS32(), count);
|
||||
SpvInstruction vectorType = context.TypeVector(context.TypeS32(), count);
|
||||
|
||||
return context.ConstantComposite(vectorType, elems);
|
||||
}
|
||||
|
@ -1327,8 +1327,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
compIdx = Src(AggregateType.S32);
|
||||
}
|
||||
|
||||
var operandsList = new List<SpvInstruction>();
|
||||
var operandsMask = ImageOperandsMask.MaskNone;
|
||||
List<SpvInstruction> operandsList = new List<SpvInstruction>();
|
||||
ImageOperandsMask operandsMask = ImageOperandsMask.MaskNone;
|
||||
|
||||
if (hasLodBias)
|
||||
{
|
||||
|
@ -1369,14 +1369,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
bool colorIsVector = isGather || !isShadow;
|
||||
|
||||
var resultType = colorIsVector ? context.TypeVector(context.TypeFP32(), 4) : context.TypeFP32();
|
||||
SpvInstruction resultType = colorIsVector ? context.TypeVector(context.TypeFP32(), 4) : context.TypeFP32();
|
||||
|
||||
if (intCoords)
|
||||
{
|
||||
image = context.Image(declaration.ImageType, image);
|
||||
}
|
||||
|
||||
var operands = operandsList.ToArray();
|
||||
SpvInstruction[] operands = operandsList.ToArray();
|
||||
|
||||
SpvInstruction result;
|
||||
|
||||
|
@ -1415,7 +1415,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
result = context.ImageSampleImplicitLod(resultType, image, pCoords, operandsMask, operands);
|
||||
}
|
||||
|
||||
var swizzledResultType = AggregateType.FP32;
|
||||
AggregateType swizzledResultType = AggregateType.FP32;
|
||||
|
||||
if (colorIsVector)
|
||||
{
|
||||
|
@ -1460,7 +1460,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else
|
||||
{
|
||||
var type = context.SamplersTypes[texOp.GetTextureSetAndBinding()];
|
||||
SamplerType type = context.SamplersTypes[texOp.GetTextureSetAndBinding()];
|
||||
bool hasLod = !type.HasFlag(SamplerType.Multisample) && type != SamplerType.TextureBuffer;
|
||||
|
||||
int dimensions = (type & SamplerType.Mask) == SamplerType.TextureCube ? 2 : type.GetDimensions();
|
||||
|
@ -1470,13 +1470,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
dimensions++;
|
||||
}
|
||||
|
||||
var resultType = dimensions == 1 ? context.TypeS32() : context.TypeVector(context.TypeS32(), dimensions);
|
||||
SpvInstruction resultType = dimensions == 1 ? context.TypeS32() : context.TypeVector(context.TypeS32(), dimensions);
|
||||
|
||||
SpvInstruction result;
|
||||
|
||||
if (hasLod)
|
||||
{
|
||||
var lod = context.GetS32(operation.GetSource(srcIndex));
|
||||
SpvInstruction lod = context.GetS32(operation.GetSource(srcIndex));
|
||||
result = context.ImageQuerySizeLod(resultType, image, lod);
|
||||
}
|
||||
else
|
||||
|
@ -1500,27 +1500,27 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateUnpackDouble2x32(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetFP64(operation.GetSource(0));
|
||||
var vector = context.GlslUnpackDouble2x32(context.TypeVector(context.TypeU32(), 2), value);
|
||||
var result = context.CompositeExtract(context.TypeU32(), vector, operation.Index);
|
||||
SpvInstruction value = context.GetFP64(operation.GetSource(0));
|
||||
SpvInstruction vector = context.GlslUnpackDouble2x32(context.TypeVector(context.TypeU32(), 2), value);
|
||||
SpvInstruction result = context.CompositeExtract(context.TypeU32(), vector, operation.Index);
|
||||
|
||||
return new OperationResult(AggregateType.U32, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateUnpackHalf2x16(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var value = context.GetU32(operation.GetSource(0));
|
||||
var vector = context.GlslUnpackHalf2x16(context.TypeVector(context.TypeFP32(), 2), value);
|
||||
var result = context.CompositeExtract(context.TypeFP32(), vector, operation.Index);
|
||||
SpvInstruction value = context.GetU32(operation.GetSource(0));
|
||||
SpvInstruction vector = context.GlslUnpackHalf2x16(context.TypeVector(context.TypeFP32(), 2), value);
|
||||
SpvInstruction result = context.CompositeExtract(context.TypeFP32(), vector, operation.Index);
|
||||
|
||||
return new OperationResult(AggregateType.FP32, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateVectorExtract(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var vector = context.GetWithType(operation.GetSource(0), out AggregateType vectorType);
|
||||
var scalarType = vectorType & ~AggregateType.ElementCountMask;
|
||||
var resultType = context.GetType(scalarType);
|
||||
SpvInstruction vector = context.GetWithType(operation.GetSource(0), out AggregateType vectorType);
|
||||
AggregateType scalarType = vectorType & ~AggregateType.ElementCountMask;
|
||||
SpvInstruction resultType = context.GetType(scalarType);
|
||||
SpvInstruction result;
|
||||
|
||||
if (operation.GetSource(1) is AstOperand indexOperand && indexOperand.Type == OperandType.Constant)
|
||||
|
@ -1529,7 +1529,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else
|
||||
{
|
||||
var index = context.Get(AggregateType.S32, operation.GetSource(1));
|
||||
SpvInstruction index = context.Get(AggregateType.S32, operation.GetSource(1));
|
||||
result = context.VectorExtractDynamic(resultType, vector, index);
|
||||
}
|
||||
|
||||
|
@ -1538,22 +1538,22 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static OperationResult GenerateVoteAll(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
var result = context.GroupNonUniformAll(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
SpvInstruction execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
SpvInstruction result = context.GroupNonUniformAll(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
return new OperationResult(AggregateType.Bool, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateVoteAllEqual(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
var result = context.GroupNonUniformAllEqual(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
SpvInstruction execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
SpvInstruction result = context.GroupNonUniformAllEqual(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
return new OperationResult(AggregateType.Bool, result);
|
||||
}
|
||||
|
||||
private static OperationResult GenerateVoteAny(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
var execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
var result = context.GroupNonUniformAny(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
SpvInstruction execution = context.Constant(context.TypeU32(), Scope.Subgroup);
|
||||
SpvInstruction result = context.GroupNonUniformAny(context.TypeBool(), execution, context.Get(AggregateType.Bool, operation.GetSource(0)));
|
||||
return new OperationResult(AggregateType.Bool, result);
|
||||
}
|
||||
|
||||
|
@ -1563,8 +1563,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitF,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitI)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
SpvInstruction result;
|
||||
|
||||
|
@ -1589,10 +1589,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitU)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
var result = emitU(context.TypeBool(), context.GetU32(src1), context.GetU32(src2));
|
||||
SpvInstruction result = emitU(context.TypeBool(), context.GetU32(src1), context.GetU32(src2));
|
||||
|
||||
return new OperationResult(AggregateType.Bool, result);
|
||||
}
|
||||
|
@ -1604,10 +1604,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
SpvInstruction elemPointer = GetStoragePointer(context, operation, out AggregateType varType);
|
||||
|
||||
var value = context.Get(varType, operation.GetSource(operation.SourcesCount - 1));
|
||||
SpvInstruction value = context.Get(varType, operation.GetSource(operation.SourcesCount - 1));
|
||||
|
||||
var one = context.Constant(context.TypeU32(), 1);
|
||||
var zero = context.Constant(context.TypeU32(), 0);
|
||||
SpvInstruction one = context.Constant(context.TypeU32(), 1);
|
||||
SpvInstruction zero = context.Constant(context.TypeU32(), 0);
|
||||
|
||||
return new OperationResult(varType, emitU(context.GetType(varType), elemPointer, one, zero, value));
|
||||
}
|
||||
|
@ -1616,11 +1616,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
SpvInstruction elemPointer = GetStoragePointer(context, operation, out AggregateType varType);
|
||||
|
||||
var value0 = context.Get(varType, operation.GetSource(operation.SourcesCount - 2));
|
||||
var value1 = context.Get(varType, operation.GetSource(operation.SourcesCount - 1));
|
||||
SpvInstruction value0 = context.Get(varType, operation.GetSource(operation.SourcesCount - 2));
|
||||
SpvInstruction value1 = context.Get(varType, operation.GetSource(operation.SourcesCount - 1));
|
||||
|
||||
var one = context.Constant(context.TypeU32(), 1);
|
||||
var zero = context.Constant(context.TypeU32(), 0);
|
||||
SpvInstruction one = context.Constant(context.TypeU32(), 1);
|
||||
SpvInstruction zero = context.Constant(context.TypeU32(), 0);
|
||||
|
||||
return new OperationResult(varType, context.AtomicCompareExchange(context.GetType(varType), elemPointer, one, zero, zero, value1, value0));
|
||||
}
|
||||
|
@ -1636,7 +1636,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else
|
||||
{
|
||||
var result = context.Load(context.GetType(varType), pointer);
|
||||
SpvInstruction result = context.Load(context.GetType(varType), pointer);
|
||||
return new OperationResult(varType, result);
|
||||
}
|
||||
}
|
||||
|
@ -1754,8 +1754,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
storageClass = isOutput ? StorageClass.Output : StorageClass.Input;
|
||||
|
||||
var ioDefinition = new IoDefinition(storageKind, ioVariable, location, component);
|
||||
var dict = isPerPatch
|
||||
IoDefinition ioDefinition = new IoDefinition(storageKind, ioVariable, location, component);
|
||||
Dictionary<IoDefinition, SpvInstruction> dict = isPerPatch
|
||||
? (isOutput ? context.OutputsPerPatch : context.InputsPerPatch)
|
||||
: (isOutput ? context.Outputs : context.Inputs);
|
||||
|
||||
|
@ -1773,7 +1773,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
int fieldIndex = IoMap.GetPerVertexStructFieldIndex(perVertexBuiltIn.Value);
|
||||
|
||||
var indexes = new SpvInstruction[inputsCount + 1];
|
||||
SpvInstruction[] indexes = new SpvInstruction[inputsCount + 1];
|
||||
int index = 0;
|
||||
|
||||
if (IoMap.IsPerVertexArrayBuiltIn(storageKind, context.Definitions.Stage))
|
||||
|
@ -1823,7 +1823,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
pointer = context.AccessChain(context.TypePointer(storageClass, context.GetType(varType)), baseObj, e0, e1, e2);
|
||||
break;
|
||||
default:
|
||||
var indexes = new SpvInstruction[inputsCount];
|
||||
SpvInstruction[] indexes = new SpvInstruction[inputsCount];
|
||||
int index = 0;
|
||||
|
||||
for (; index < inputsCount; srcIndex++, index++)
|
||||
|
@ -1840,10 +1840,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static SpvInstruction GetScalarInput(CodeGenContext context, IoVariable ioVariable)
|
||||
{
|
||||
var (_, varType) = IoMap.GetSpirvBuiltIn(ioVariable);
|
||||
(_, AggregateType varType) = IoMap.GetSpirvBuiltIn(ioVariable);
|
||||
varType &= AggregateType.ElementTypeMask;
|
||||
|
||||
var ioDefinition = new IoDefinition(StorageKind.Input, ioVariable);
|
||||
IoDefinition ioDefinition = new IoDefinition(StorageKind.Input, ioVariable);
|
||||
|
||||
return context.Load(context.GetType(varType), context.Inputs[ioDefinition]);
|
||||
}
|
||||
|
@ -1917,7 +1917,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
Func<SpvInstruction, SpvInstruction, SpvInstruction> emitF,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction> emitI)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
|
||||
if (operation.Inst.HasFlag(Instruction.FP64))
|
||||
{
|
||||
|
@ -1938,7 +1938,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction> emitB)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
return new OperationResult(AggregateType.Bool, emitB(context.TypeBool(), context.Get(AggregateType.Bool, source)));
|
||||
}
|
||||
|
||||
|
@ -1947,7 +1947,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction> emit)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
return new OperationResult(AggregateType.FP32, emit(context.TypeFP32(), context.GetFP32(source)));
|
||||
}
|
||||
|
||||
|
@ -1956,7 +1956,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction> emitS)
|
||||
{
|
||||
var source = operation.GetSource(0);
|
||||
IAstNode source = operation.GetSource(0);
|
||||
return new OperationResult(AggregateType.S32, emitS(context.TypeS32(), context.GetS32(source)));
|
||||
}
|
||||
|
||||
|
@ -1966,12 +1966,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitF,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitI)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
if (operation.Inst.HasFlag(Instruction.FP64))
|
||||
{
|
||||
var result = emitF(context.TypeFP64(), context.GetFP64(src1), context.GetFP64(src2));
|
||||
SpvInstruction result = emitF(context.TypeFP64(), context.GetFP64(src1), context.GetFP64(src2));
|
||||
|
||||
if (!context.HostCapabilities.ReducedPrecision || operation.ForcePrecise)
|
||||
{
|
||||
|
@ -1982,7 +1982,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else if (operation.Inst.HasFlag(Instruction.FP32))
|
||||
{
|
||||
var result = emitF(context.TypeFP32(), context.GetFP32(src1), context.GetFP32(src2));
|
||||
SpvInstruction result = emitF(context.TypeFP32(), context.GetFP32(src1), context.GetFP32(src2));
|
||||
|
||||
if (!context.HostCapabilities.ReducedPrecision || operation.ForcePrecise)
|
||||
{
|
||||
|
@ -2002,8 +2002,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitB)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
return new OperationResult(AggregateType.Bool, emitB(context.TypeBool(), context.Get(AggregateType.Bool, src1), context.Get(AggregateType.Bool, src2)));
|
||||
}
|
||||
|
@ -2013,8 +2013,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitS)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
return new OperationResult(AggregateType.S32, emitS(context.TypeS32(), context.GetS32(src1), context.GetS32(src2)));
|
||||
}
|
||||
|
@ -2024,8 +2024,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitU)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
|
||||
return new OperationResult(AggregateType.U32, emitU(context.TypeU32(), context.GetU32(src1), context.GetU32(src2)));
|
||||
}
|
||||
|
@ -2036,13 +2036,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitF,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitI)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
var src3 = operation.GetSource(2);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
IAstNode src3 = operation.GetSource(2);
|
||||
|
||||
if (operation.Inst.HasFlag(Instruction.FP64))
|
||||
{
|
||||
var result = emitF(context.TypeFP64(), context.GetFP64(src1), context.GetFP64(src2), context.GetFP64(src3));
|
||||
SpvInstruction result = emitF(context.TypeFP64(), context.GetFP64(src1), context.GetFP64(src2), context.GetFP64(src3));
|
||||
|
||||
if (!context.HostCapabilities.ReducedPrecision || operation.ForcePrecise)
|
||||
{
|
||||
|
@ -2053,7 +2053,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else if (operation.Inst.HasFlag(Instruction.FP32))
|
||||
{
|
||||
var result = emitF(context.TypeFP32(), context.GetFP32(src1), context.GetFP32(src2), context.GetFP32(src3));
|
||||
SpvInstruction result = emitF(context.TypeFP32(), context.GetFP32(src1), context.GetFP32(src2), context.GetFP32(src3));
|
||||
|
||||
if (!context.HostCapabilities.ReducedPrecision || operation.ForcePrecise)
|
||||
{
|
||||
|
@ -2073,9 +2073,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitU)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
var src3 = operation.GetSource(2);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
IAstNode src3 = operation.GetSource(2);
|
||||
|
||||
return new OperationResult(AggregateType.U32, emitU(
|
||||
context.TypeU32(),
|
||||
|
@ -2089,9 +2089,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitS)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
var src3 = operation.GetSource(2);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
IAstNode src3 = operation.GetSource(2);
|
||||
|
||||
return new OperationResult(AggregateType.S32, emitS(
|
||||
context.TypeS32(),
|
||||
|
@ -2105,10 +2105,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
AstOperation operation,
|
||||
Func<SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction, SpvInstruction> emitS)
|
||||
{
|
||||
var src1 = operation.GetSource(0);
|
||||
var src2 = operation.GetSource(1);
|
||||
var src3 = operation.GetSource(2);
|
||||
var src4 = operation.GetSource(3);
|
||||
IAstNode src1 = operation.GetSource(0);
|
||||
IAstNode src2 = operation.GetSource(1);
|
||||
IAstNode src3 = operation.GetSource(2);
|
||||
IAstNode src4 = operation.GetSource(3);
|
||||
|
||||
return new OperationResult(AggregateType.U32, emitS(
|
||||
context.TypeU32(),
|
||||
|
|
|
@ -124,20 +124,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
for (int funcIndex = 0; funcIndex < info.Functions.Count; funcIndex++)
|
||||
{
|
||||
var function = info.Functions[funcIndex];
|
||||
var retType = context.GetType(function.ReturnType);
|
||||
StructuredFunction function = info.Functions[funcIndex];
|
||||
SpvInstruction retType = context.GetType(function.ReturnType);
|
||||
|
||||
var funcArgs = new SpvInstruction[function.InArguments.Length + function.OutArguments.Length];
|
||||
SpvInstruction[] funcArgs = new SpvInstruction[function.InArguments.Length + function.OutArguments.Length];
|
||||
|
||||
for (int argIndex = 0; argIndex < funcArgs.Length; argIndex++)
|
||||
{
|
||||
var argType = context.GetType(function.GetArgumentType(argIndex));
|
||||
var argPointerType = context.TypePointer(StorageClass.Function, argType);
|
||||
SpvInstruction argType = context.GetType(function.GetArgumentType(argIndex));
|
||||
SpvInstruction argPointerType = context.TypePointer(StorageClass.Function, argType);
|
||||
funcArgs[argIndex] = argPointerType;
|
||||
}
|
||||
|
||||
var funcType = context.TypeFunction(retType, false, funcArgs);
|
||||
var spvFunc = context.Function(retType, FunctionControlMask.MaskNone, funcType);
|
||||
SpvInstruction funcType = context.TypeFunction(retType, false, funcArgs);
|
||||
SpvInstruction spvFunc = context.Function(retType, FunctionControlMask.MaskNone, funcType);
|
||||
|
||||
context.DeclareFunction(funcIndex, function, spvFunc);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
|
||||
private static void Generate(CodeGenContext context, StructuredProgramInfo info, int funcIndex)
|
||||
{
|
||||
var (function, spvFunc) = context.GetFunction(funcIndex);
|
||||
(StructuredFunction function, SpvInstruction spvFunc) = context.GetFunction(funcIndex);
|
||||
|
||||
context.CurrentFunction = function;
|
||||
context.AddFunction(spvFunc);
|
||||
|
@ -284,9 +284,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
}
|
||||
else if (context.Definitions.Stage == ShaderStage.Compute)
|
||||
{
|
||||
var localSizeX = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeX;
|
||||
var localSizeY = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeY;
|
||||
var localSizeZ = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeZ;
|
||||
SpvLiteralInteger localSizeX = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeX;
|
||||
SpvLiteralInteger localSizeY = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeY;
|
||||
SpvLiteralInteger localSizeZ = (SpvLiteralInteger)context.Definitions.ComputeLocalSizeZ;
|
||||
|
||||
context.AddExecutionMode(
|
||||
spvFunc,
|
||||
|
@ -307,7 +307,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
AstBlockVisitor visitor = new(block);
|
||||
|
||||
var loopTargets = new Dictionary<AstBlock, (SpvInstruction, SpvInstruction)>();
|
||||
Dictionary<AstBlock, (SpvInstruction, SpvInstruction)> loopTargets = new Dictionary<AstBlock, (SpvInstruction, SpvInstruction)>();
|
||||
|
||||
context.LoopTargets = loopTargets;
|
||||
|
||||
|
@ -329,14 +329,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
ifFalseBlock = mergeBlock;
|
||||
}
|
||||
|
||||
var condition = context.Get(AggregateType.Bool, e.Block.Condition);
|
||||
SpvInstruction condition = context.Get(AggregateType.Bool, e.Block.Condition);
|
||||
|
||||
context.SelectionMerge(context.GetNextLabel(mergeBlock), SelectionControlMask.MaskNone);
|
||||
context.BranchConditional(condition, context.GetNextLabel(ifTrueBlock), context.GetNextLabel(ifFalseBlock));
|
||||
}
|
||||
else if (e.Block.Type == AstBlockType.DoWhile)
|
||||
{
|
||||
var continueTarget = context.Label();
|
||||
SpvInstruction continueTarget = context.Label();
|
||||
|
||||
loopTargets.Add(e.Block, (context.NewBlock(), continueTarget));
|
||||
|
||||
|
@ -357,12 +357,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
// if the condition is true.
|
||||
AstBlock mergeBlock = e.Block.Parent;
|
||||
|
||||
var (loopTarget, continueTarget) = loopTargets[e.Block];
|
||||
(SpvInstruction loopTarget, SpvInstruction continueTarget) = loopTargets[e.Block];
|
||||
|
||||
context.Branch(continueTarget);
|
||||
context.AddLabel(continueTarget);
|
||||
|
||||
var condition = context.Get(AggregateType.Bool, e.Block.Condition);
|
||||
SpvInstruction condition = context.Get(AggregateType.Bool, e.Block.Condition);
|
||||
|
||||
context.BranchConditional(condition, loopTarget, context.GetNextLabel(mergeBlock));
|
||||
}
|
||||
|
@ -398,16 +398,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|||
{
|
||||
if (node is AstAssignment assignment)
|
||||
{
|
||||
var dest = (AstOperand)assignment.Destination;
|
||||
AstOperand dest = (AstOperand)assignment.Destination;
|
||||
|
||||
if (dest.Type == OperandType.LocalVariable)
|
||||
{
|
||||
var source = context.Get(dest.VarType, assignment.Source);
|
||||
SpvInstruction source = context.Get(dest.VarType, assignment.Source);
|
||||
context.Store(context.GetLocalPointer(dest), source);
|
||||
}
|
||||
else if (dest.Type == OperandType.Argument)
|
||||
{
|
||||
var source = context.Get(dest.VarType, assignment.Source);
|
||||
SpvInstruction source = context.Get(dest.VarType, assignment.Source);
|
||||
context.Store(context.GetArgumentPointer(dest), source);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue