Skip to content

Commit 158df5f

Browse files
paigealesys_zuul
authored andcommitted
This change is needed for it is risky to mess with precision in vertex shaders by contracting fmul+(add/sub) into a mad going into a trig function like sin,
otherwise the position values can become off their expected values. Change-Id: I5e45ae6fc2bd6110a87113501e3248181de32d23
1 parent fab7eaf commit 158df5f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,21 @@ namespace IGC
19891989
{
19901990
return false;
19911991
}
1992+
1993+
using namespace llvm::PatternMatch;
1994+
Value* LHS = NULL, * RHS = NULL, * Op1 = NULL, * Op0 = NULL;
1995+
if (m_ctx->type == ShaderType::VERTEX_SHADER &&
1996+
m_ctx->m_DriverInfo.PreventZFighting() &&
1997+
(match(&I,m_BinOp(m_FMul(m_Value(LHS), m_Value(RHS)), m_Value(Op1))) ||
1998+
match(&I,m_BinOp(m_Value(Op0), m_FMul(m_Value(LHS), m_Value(RHS))))) &&
1999+
I.hasOneUse() && isa<IntrinsicInst>(I.user_back()))
2000+
{
2001+
auto fmul_val = Op0 != NULL ? I.getOperand(1) : I.getOperand(0);
2002+
auto fmul = cast<BinaryOperator>(fmul_val);
2003+
if (cast<IntrinsicInst>(I.user_back())->getIntrinsicID() == llvm::Intrinsic::sin &&
2004+
m_PosDep->PositionDependsOnInst(fmul) && NeedInstruction(*fmul))
2005+
return false;
2006+
}
19922007
if (IGC_IS_FLAG_ENABLED(DisableMatchMad))
19932008
{
19942009
return false;

0 commit comments

Comments
 (0)