@@ -1469,6 +1469,7 @@ struct EmitVisitor
1469
1469
EOpInfo leftSide (EOpInfo const & outerPrec, EOpInfo const & prec)
1470
1470
{
1471
1471
EOpInfo result;
1472
+ result.op = nullptr ;
1472
1473
result.leftPrecedence = outerPrec.leftPrecedence ;
1473
1474
result.rightPrecedence = prec.leftPrecedence ;
1474
1475
return result;
@@ -1477,6 +1478,7 @@ struct EmitVisitor
1477
1478
EOpInfo rightSide (EOpInfo const & prec, EOpInfo const & outerPrec)
1478
1479
{
1479
1480
EOpInfo result;
1481
+ result.op = nullptr ;
1480
1482
result.leftPrecedence = prec.rightPrecedence ;
1481
1483
result.rightPrecedence = outerPrec.rightPrecedence ;
1482
1484
return result;
@@ -3599,34 +3601,69 @@ struct EmitVisitor
3599
3601
}
3600
3602
}
3601
3603
3602
- void emitComparison (EmitContext* ctx, IRInst* inst, IREmitMode mode, EOpInfo& inOutOuterPrec, const EOpInfo& opPrec, bool * needCloseOut )
3604
+ void _maybeEmitGLSLCast (EmitContext* ctx, IRType* castType, IRInst* inst, IREmitMode mode)
3603
3605
{
3604
- *needCloseOut = maybeEmitParens (inOutOuterPrec, opPrec);
3605
-
3606
- if (getTarget (ctx) == CodeGenTarget::GLSL
3607
- && as<IRVectorType>(inst->getOperand (0 )->getDataType ())
3608
- && as<IRVectorType>(inst->getOperand (1 )->getDataType ()))
3606
+ // Wrap in cast if a cast type is specified
3607
+ if (castType)
3609
3608
{
3610
- const char * funcName = getGLSLVectorCompareFunctionName (inst->op );
3611
- SLANG_ASSERT (funcName);
3612
-
3613
- emit (funcName);
3609
+ emitIRType (ctx, castType);
3614
3610
emit (" (" );
3615
- emitIROperand (ctx, inst->getOperand (0 ), mode, leftSide (inOutOuterPrec, opPrec));
3616
- emit (" ," );
3617
- emitIROperand (ctx, inst->getOperand (1 ), mode, rightSide (inOutOuterPrec, opPrec));
3611
+
3612
+ // Emit the operand
3613
+ emitIROperand (ctx, inst, mode, kEOp_General );
3614
+
3618
3615
emit (" )" );
3619
3616
}
3620
3617
else
3621
3618
{
3622
- emitIROperand (ctx, inst->getOperand (0 ), mode, leftSide (inOutOuterPrec, opPrec));
3623
- emit (" " );
3624
- emit (opPrec.op );
3625
- emit (" " );
3626
- emitIROperand (ctx, inst->getOperand (1 ), mode, rightSide (inOutOuterPrec, opPrec));
3619
+ // Emit the operand
3620
+ emitIROperand (ctx, inst, mode, kEOp_General );
3627
3621
}
3628
3622
}
3629
3623
3624
+ void emitComparison (EmitContext* ctx, IRInst* inst, IREmitMode mode, EOpInfo& ioOuterPrec, const EOpInfo& opPrec, bool * needCloseOut)
3625
+ {
3626
+ if (getTarget (ctx) == CodeGenTarget::GLSL)
3627
+ {
3628
+ IRInst* left = inst->getOperand (0 );
3629
+ IRInst* right = inst->getOperand (1 );
3630
+
3631
+ auto leftVectorType = as<IRVectorType>(left->getDataType ());
3632
+ auto rightVectorType = as<IRVectorType>(right->getDataType ());
3633
+
3634
+ // If either side is a vector handle as a vector
3635
+ if (leftVectorType || rightVectorType)
3636
+ {
3637
+ const char * funcName = getGLSLVectorCompareFunctionName (inst->op );
3638
+ SLANG_ASSERT (funcName);
3639
+
3640
+ // Determine the vector type
3641
+ const auto vecType = leftVectorType ? leftVectorType : rightVectorType;
3642
+
3643
+ // Handle as a function call
3644
+ auto prec = kEOp_Postfix ;
3645
+ *needCloseOut = maybeEmitParens (ioOuterPrec, prec);
3646
+
3647
+ emit (funcName);
3648
+ emit (" (" );
3649
+ _maybeEmitGLSLCast (ctx, (leftVectorType ? nullptr : vecType), left, mode);
3650
+ emit (" ," );
3651
+ _maybeEmitGLSLCast (ctx, (rightVectorType ? nullptr : vecType), right, mode);
3652
+ emit (" )" );
3653
+
3654
+ return ;
3655
+ }
3656
+ }
3657
+
3658
+ *needCloseOut = maybeEmitParens (ioOuterPrec, opPrec);
3659
+
3660
+ emitIROperand (ctx, inst->getOperand (0 ), mode, leftSide (ioOuterPrec, opPrec));
3661
+ emit (" " );
3662
+ emit (opPrec.op );
3663
+ emit (" " );
3664
+ emitIROperand (ctx, inst->getOperand (1 ), mode, rightSide (ioOuterPrec, opPrec));
3665
+ }
3666
+
3630
3667
void emitIRInstExpr (
3631
3668
EmitContext* ctx,
3632
3669
IRInst* inst,
0 commit comments