From c8e36bd128a29654b2ec145038da9e132330581b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 14 Mar 2019 16:21:03 -0400 Subject: Hotfix/bool fix (#907) * * Handle ! for bool vector in glsl * Handle operators that have a boolean return value * || or && take bool * * Add comment in bool-op.slang test about doing || or && on vector types not supported for GLSL targets --- source/slang/emit.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 0c1896c0c..d2de479b4 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3621,6 +3621,33 @@ struct EmitVisitor } } + void emitNot(EmitContext* ctx, IRInst* inst, IREmitMode mode, EOpInfo& ioOuterPrec, bool* outNeedClose) + { + IRInst* operand = inst->getOperand(0); + + if (getTarget(ctx) == CodeGenTarget::GLSL) + { + if (auto vectorType = as(operand->getDataType())) + { + // Handle as a function call + auto prec = kEOp_Postfix; + *outNeedClose = maybeEmitParens(ioOuterPrec, prec); + + emit("not("); + emitIROperand(ctx, operand, mode, kEOp_General); + emit(")"); + return; + } + } + + auto prec = kEOp_Prefix; + *outNeedClose = maybeEmitParens(ioOuterPrec, prec); + + emit("!"); + emitIROperand(ctx, operand, mode, rightSide(prec, ioOuterPrec)); + } + + void emitComparison(EmitContext* ctx, IRInst* inst, IREmitMode mode, EOpInfo& ioOuterPrec, const EOpInfo& opPrec, bool* needCloseOut) { if (getTarget(ctx) == CodeGenTarget::GLSL) @@ -3839,11 +3866,7 @@ struct EmitVisitor case kIROp_Not: { - auto prec = kEOp_Prefix; - needClose = maybeEmitParens(outerPrec, prec); - - emit("!"); - emitIROperand(ctx, inst->getOperand(0), mode, rightSide(prec, outerPrec)); + emitNot(ctx, inst, mode, outerPrec, &needClose); } break; -- cgit v1.2.3