diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index 74dfd0236..21f8f0ee6 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -259,7 +259,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { case AttributeConsts.PositionX: return $"(gl_FragCoord.x / {DefaultNames.SupportBlockRenderScaleName}[0])"; case AttributeConsts.PositionY: return $"(gl_FragCoord.y / {DefaultNames.SupportBlockRenderScaleName}[0])"; - case AttributeConsts.PositionZ: return "gl_FragCoord.z"; + case AttributeConsts.PositionZ: + if (config.Options.TargetApi == TargetApi.Vulkan && config.GpuAccessor.QueryTransformDepthMinusOneToOne()) + { + return "((gl_FragCoord.z - (gl_FragCoord.w * 0.5)) * 2.0)"; + } + else + { + return "gl_FragCoord.z"; + } case AttributeConsts.PositionW: return "gl_FragCoord.w"; case AttributeConsts.FrontFacing: diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs index f52c90d04..17291a1f5 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs @@ -339,6 +339,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv value = FDiv(TypeFP32(), value, scale); } + else if (Config.Options.TargetApi == TargetApi.Vulkan && + attr == AttributeConsts.PositionZ && + Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) + { + var constTwo = Constant(TypeFP32(), 2.0f); + var constZeroPointFive = Constant(TypeFP32(), 0.5f); + + var elemPointerW = GetAttributeElemPointer(AttributeConsts.PositionW, isOutAttr, null, out var elemTypeW); + var valueW = Load(GetType(elemTypeW), elemPointerW); + + var halfW = FMul(TypeFP32(), valueW, constZeroPointFive); + + value = FMul(TypeFP32(), FSub(TypeFP32(), value, halfW), constTwo); + } else if (attr == AttributeConsts.FrontFacing && Config.GpuAccessor.QueryHostHasFrontFacingBug()) { // Workaround for what appears to be a bug on Intel compiler. diff --git a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs index 38c503e67..d023a4c2c 100644 --- a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs +++ b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs @@ -182,7 +182,7 @@ namespace Ryujinx.Graphics.Shader.Translation this.Copy(Attribute(AttributeConsts.PositionY), this.FPFusedMultiplyAdd(y, yScale, negativeOne)); } - if (Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) + if (Config.Options.TargetApi == TargetApi.Vulkan && Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) { Operand z = Attribute(AttributeConsts.PositionZ | AttributeConsts.LoadOutputMask); Operand w = Attribute(AttributeConsts.PositionW | AttributeConsts.LoadOutputMask); @@ -207,7 +207,7 @@ namespace Ryujinx.Graphics.Shader.Translation oldYLocal = null; } - if (Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) + if (Config.Options.TargetApi == TargetApi.Vulkan && Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) { oldZLocal = Local(); this.Copy(oldYLocal, Attribute(AttributeConsts.PositionZ | AttributeConsts.LoadOutputMask)); @@ -281,7 +281,14 @@ namespace Ryujinx.Graphics.Shader.Translation Operand src = Register(Config.GetDepthRegister(), RegisterType.Gpr); - this.Copy(dest, src); + if (Config.Options.TargetApi == TargetApi.Vulkan && Config.GpuAccessor.QueryTransformDepthMinusOneToOne()) + { + this.Copy(dest, this.FPFusedMultiplyAdd(src, ConstF(0.5f), ConstF(0.5f))); + } + else + { + this.Copy(dest, src); + } } AlphaTestOp alphaTestOp = Config.GpuAccessor.QueryAlphaTestCompare();