From 80a879cb447507822e19acb0e51e123b768acd61 Mon Sep 17 00:00:00 2001 From: Nicholas Rodine Date: Wed, 17 Aug 2022 18:49:43 -0500 Subject: 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 * Update Spv.Generator/Instruction.cs Co-authored-by: gdkchan * 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 --- Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Ryujinx.Graphics.Shader/CodeGen') diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs index bdd92553..eeae4576 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs @@ -234,7 +234,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv IrOperandType.Constant => GetConstant(type, operand), IrOperandType.ConstantBuffer => GetConstantBuffer(type, operand), IrOperandType.LocalVariable => GetLocal(type, operand), - IrOperandType.Undefined => Constant(GetType(type), 0), + IrOperandType.Undefined => GetUndefined(type), _ => throw new ArgumentException($"Invalid operand type \"{operand.Type}\".") }; } @@ -242,6 +242,17 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv throw new NotImplementedException(node.GetType().Name); } + private Instruction GetUndefined(AggregateType type) + { + return type switch + { + AggregateType.Bool => ConstantFalse(TypeBool()), + AggregateType.FP32 => Constant(TypeFP32(), 0f), + AggregateType.FP64 => Constant(TypeFP64(), 0d), + _ => Constant(GetType(type), 0) + }; + } + public Instruction GetAttributeElemPointer(int attr, bool isOutAttr, Instruction index, out AggregateType elemType) { var storageClass = isOutAttr ? StorageClass.Output : StorageClass.Input; -- cgit v1.2.3