SPIR-V: Workaround for Intel FrontFacing bug

This commit is contained in:
gdk 2022-04-08 22:24:06 -03:00 committed by riperiperi
parent ad081de56b
commit f16b47114c

View file

@ -326,7 +326,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
var elemPointer = GetAttributeElemPointer(attr, isOutAttr, index, out var elemType); var elemPointer = GetAttributeElemPointer(attr, isOutAttr, index, out var elemType);
var value = Load(GetType(elemType), elemPointer); var value = Load(GetType(elemType), elemPointer);
if (Config.Stage == ShaderStage.Fragment && (attr == AttributeConsts.PositionX || attr == AttributeConsts.PositionY)) if (Config.Stage == ShaderStage.Fragment)
{
if (attr == AttributeConsts.PositionX || attr == AttributeConsts.PositionY)
{ {
var pointerType = TypePointer(StorageClass.Uniform, TypeFP32()); var pointerType = TypePointer(StorageClass.Uniform, TypeFP32());
var fieldIndex = Constant(TypeU32(), 3); var fieldIndex = Constant(TypeU32(), 3);
@ -337,6 +339,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
value = FDiv(TypeFP32(), value, scale); value = FDiv(TypeFP32(), value, scale);
} }
else if (attr == AttributeConsts.FrontFacing && Config.GpuAccessor.QueryHostHasFrontFacingBug())
{
// Workaround for what appears to be a bug on Intel compiler.
var valueFloat = Select(TypeFP32(), value, Constant(TypeFP32(), 1f), Constant(TypeFP32(), 0f));
var valueAsInt = Bitcast(TypeS32(), valueFloat);
var valueNegated = SNegate(TypeS32(), valueAsInt);
value = SLessThan(TypeBool(), valueNegated, Constant(TypeS32(), 0));
}
}
return BitcastIfNeeded(type, elemType, value); return BitcastIfNeeded(type, elemType, value);
} }