aboutsummaryrefslogtreecommitdiff
path: root/Spv.Generator/InstructionOperands.cs
diff options
context:
space:
mode:
authorNicholas Rodine <halfofastaple@gmail.com>2022-08-17 18:49:43 -0500
committerGitHub <noreply@github.com>2022-08-18 01:49:43 +0200
commit80a879cb447507822e19acb0e51e123b768acd61 (patch)
tree9af35446532b44cdaa794ad2de3b70f20e5471c1 /Spv.Generator/InstructionOperands.cs
parent2197f41506e1ed7c4c657a1899491298bd66f7f9 (diff)
Fix SpirV parse failure (#3597)
* Added .ToString overrides, to help diagnose and debug SpirV generated code. * Added Spirv to team shared dictionary, so the word will not show up as a warning. * Fixed bug where we were creating invalid constants (bool 0i and float 0i) * Update Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Update Spv.Generator/Instruction.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Adjusted spacing to match style of the rest of the code. * Added handler for FP64(double) as well, for undefined aggregate types. * Made the operand labels a static dictionary, to avoid re-allocation on each call. Replaced Contains/Get with a TryGetValue, to reduce the number of dictionary lookups. * Added newline between AllOperands and ToString(). Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Diffstat (limited to 'Spv.Generator/InstructionOperands.cs')
-rw-r--r--Spv.Generator/InstructionOperands.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/Spv.Generator/InstructionOperands.cs b/Spv.Generator/InstructionOperands.cs
index a349827a..c48b004f 100644
--- a/Spv.Generator/InstructionOperands.cs
+++ b/Spv.Generator/InstructionOperands.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Runtime.InteropServices;
namespace Spv.Generator
@@ -49,5 +51,22 @@ namespace Spv.Generator
Overflow[Count++] = operand;
}
}
+
+ private IEnumerable<Operand> AllOperands => new[] { Operand1, Operand2, Operand3, Operand4, Operand5 }
+ .Concat(Overflow ?? Array.Empty<Operand>())
+ .Take(Count);
+
+ public override string ToString()
+ {
+ return $"({string.Join(", ", AllOperands)})";
+ }
+
+ public string ToString(string[] labels)
+ {
+ var labeledParams = AllOperands.Zip(labels, (op, label) => $"{label}: {op}");
+ var unlabeledParams = AllOperands.Skip(labels.Length).Select(op => op.ToString());
+ var paramsToPrint = labeledParams.Concat(unlabeledParams);
+ return $"({string.Join(", ", paramsToPrint)})";
+ }
}
}