From b7a1544e8b4e538272c491a746bdd19ec188a0c3 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 8 Nov 2021 11:39:30 -0300 Subject: [PATCH] Fix InvocationInfo on geometry shader and bindless default integer const (#2822) * Fix InvocationInfo on geometry shader and bindless default integer const * Shader cache version bump * Consistency for the default value --- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 2 +- .../Glsl/Instructions/InstGenMemory.cs | 14 +++++++---- .../Instructions/InstEmitMove.cs | 23 +++++++++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index be5e7ab90d..67a397b3c4 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Version of the codegen (to be changed when codegen or guest format change). /// - private const ulong ShaderCodeGenVersion = 2768; + private const ulong ShaderCodeGenVersion = 2822; // Progress reporting helpers private volatile int _shaderCount; diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index f976ec5ecf..abca03aa56 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -18,12 +18,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions // TODO: Bindless texture support. For now we just return 0/do nothing. if (isBindless) { - return texOp.Inst switch + switch (texOp.Inst) { - Instruction.ImageStore => "// imageStore(bindless)", - Instruction.ImageLoad => NumberFormatter.FormatFloat(0), - _ => NumberFormatter.FormatInt(0) - }; + case Instruction.ImageStore: + return "// imageStore(bindless)"; + case Instruction.ImageLoad: + NumberFormatter.TryFormat(0, texOp.Format.GetComponentType(), out string imageConst); + return imageConst; + default: + return NumberFormatter.FormatInt(0); + } } bool isArray = (texOp.Type & SamplerType.Array) != 0; diff --git a/Ryujinx.Graphics.Shader/Instructions/InstEmitMove.cs b/Ryujinx.Graphics.Shader/Instructions/InstEmitMove.cs index 240fd6b156..51b706011c 100644 --- a/Ryujinx.Graphics.Shader/Instructions/InstEmitMove.cs +++ b/Ryujinx.Graphics.Shader/Instructions/InstEmitMove.cs @@ -95,9 +95,28 @@ namespace Ryujinx.Graphics.Shader.Instructions if (context.Config.Stage != ShaderStage.Compute && context.Config.Stage != ShaderStage.Fragment) { Operand primitiveId = Attribute(AttributeConsts.PrimitiveId); - Operand patchVerticesIn = Attribute(AttributeConsts.PatchVerticesIn); + Operand patchVerticesIn; - patchVerticesIn = context.ShiftLeft(patchVerticesIn, Const(16)); + if (context.Config.Stage == ShaderStage.TessellationEvaluation) + { + patchVerticesIn = context.ShiftLeft(Attribute(AttributeConsts.PatchVerticesIn), Const(16)); + } + else + { + InputTopology inputTopology = context.Config.GpuAccessor.QueryPrimitiveTopology(); + + int inputVertices = inputTopology switch + { + InputTopology.Points => 1, + InputTopology.Lines or + InputTopology.LinesAdjacency => 2, + InputTopology.Triangles or + InputTopology.TrianglesAdjacency => 3, + _ => 1 + }; + + patchVerticesIn = Const(inputVertices << 16); + } src = context.BitwiseOr(primitiveId, patchVerticesIn); }