Fix gl_FragCoord.z transformation

FragCoord.z is always in 0-1, even when the real depth range is -1 to 1. Turns out the only bug was geo and tess stage outputs.

Fixes Pokemon Sword/Shield, possibly others.
This commit is contained in:
riperiperi 2022-05-21 17:23:35 +01:00
parent f636810c6c
commit 52050e4d48
3 changed files with 2 additions and 24 deletions

View file

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2; private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 6; private const uint CodeGenVersion = 7;
private const string SharedTocFileName = "shared.toc"; private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data"; private const string SharedDataFileName = "shared.data";

View file

@ -259,15 +259,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{ {
case AttributeConsts.PositionX: return $"(gl_FragCoord.x / {DefaultNames.SupportBlockRenderScaleName}[0])"; case AttributeConsts.PositionX: return $"(gl_FragCoord.x / {DefaultNames.SupportBlockRenderScaleName}[0])";
case AttributeConsts.PositionY: return $"(gl_FragCoord.y / {DefaultNames.SupportBlockRenderScaleName}[0])"; case AttributeConsts.PositionY: return $"(gl_FragCoord.y / {DefaultNames.SupportBlockRenderScaleName}[0])";
case AttributeConsts.PositionZ: case AttributeConsts.PositionZ: return "gl_FragCoord.z";
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.PositionW: return "gl_FragCoord.w";
case AttributeConsts.FrontFacing: case AttributeConsts.FrontFacing:

View file

@ -348,20 +348,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
value = FDiv(TypeFP32(), value, scale); 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()) else if (attr == AttributeConsts.FrontFacing && Config.GpuAccessor.QueryHostHasFrontFacingBug())
{ {
// Workaround for what appears to be a bug on Intel compiler. // Workaround for what appears to be a bug on Intel compiler.