hxsl
hxsl copied to clipboard
If / Float / Bool problem
Hi,
I noticed a Float/Bool conversion problem while trying to test an expression such as: if ( xxx > 0.5) doSomething; xxx being a Float
Compiler gives: "Float should be Bool" for the expression "xxx > 0.5"
The problem is that comparison operations between Float return a Float which value is 0 or 1 but if test requires a Bool and there is no conversion.
It seems to occurs in Compiler.hx when on line 206 is called "unify(cond.t, TBool, e.p);" unify calls tryUnify which throws that error.
I also noticed that expressions such as if (aConstant == null) or if (aConstant!=null) do compile as they seem to return a Bool.
I presume that that exception is linked with the lines 801-817 of Compiler.hx, in the makeOp method. That block starts with the comment: // if we have a null check, infer a VParam
On line 76, I tried to replace: case CMin, CMax, CLt, CGte, CEq, CNeq, CLte, CGt: floats; By: case CMin, CMax: floats; case CLt, CGte, CEq, CNeq, CLte, CGt: [ { p1 : TFloat4, p2 : TFloat4, r : TFloat4}, { p1 : TFloat3, p2 : TFloat3, r : TFloat3}, { p1 : TFloat2, p2 : TFloat2, r : TFloat2} , { p1 : TFloat, p2 : TFloat, r : TBool } ]; My shader compiled but failed at runtime.
I also tried to put in tryUnify, after the line 740: case TFloat: return (t2 == TFloat || t2 == TBool); but I had the same result. It compiled but failed at runtime.
Thank you for your work, Olivier.
yes, such compile-time comparisons are not yet supported because we currently only track changes in Bools as a bit-flag