mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-02-21 16:43:35 +00:00
Improvements to -1 to 1 depth mode.
- Transformation is only applied on the last stage in the vertex pipeline. - Should fix some issues with geometry and tessellation (hopefully) - Reading back FragCoord Z on fragment will transform back to -1 to 1.
This commit is contained in:
parent
daaa7fda11
commit
8097480b02
3 changed files with 33 additions and 4 deletions
|
@ -259,7 +259,15 @@ 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: 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.PositionW: return "gl_FragCoord.w";
|
||||||
|
|
||||||
case AttributeConsts.FrontFacing:
|
case AttributeConsts.FrontFacing:
|
||||||
|
|
|
@ -339,6 +339,20 @@ 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.
|
||||||
|
|
|
@ -182,7 +182,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
this.Copy(Attribute(AttributeConsts.PositionY), this.FPFusedMultiplyAdd(y, yScale, negativeOne));
|
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 z = Attribute(AttributeConsts.PositionZ | AttributeConsts.LoadOutputMask);
|
||||||
Operand w = Attribute(AttributeConsts.PositionW | AttributeConsts.LoadOutputMask);
|
Operand w = Attribute(AttributeConsts.PositionW | AttributeConsts.LoadOutputMask);
|
||||||
|
@ -207,7 +207,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
oldYLocal = null;
|
oldYLocal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.GpuAccessor.QueryTransformDepthMinusOneToOne())
|
if (Config.Options.TargetApi == TargetApi.Vulkan && Config.GpuAccessor.QueryTransformDepthMinusOneToOne())
|
||||||
{
|
{
|
||||||
oldZLocal = Local();
|
oldZLocal = Local();
|
||||||
this.Copy(oldYLocal, Attribute(AttributeConsts.PositionZ | AttributeConsts.LoadOutputMask));
|
this.Copy(oldYLocal, Attribute(AttributeConsts.PositionZ | AttributeConsts.LoadOutputMask));
|
||||||
|
@ -281,7 +281,14 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
Operand src = Register(Config.GetDepthRegister(), RegisterType.Gpr);
|
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();
|
AlphaTestOp alphaTestOp = Config.GpuAccessor.QueryAlphaTestCompare();
|
||||||
|
|
Loading…
Reference in a new issue