diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index d902a91a77..2b0e17e103 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -4355,7 +4355,10 @@ builtin_builder::_normalize(builtin_available_predicate avail, const glsl_type * if (type->vector_elements == 1) { body.emit(ret(sign(x))); } else { - body.emit(ret(mul(x, rsq(dot(x, x))))); + ir_variable *sq_length = body.make_temp(type->get_base_type(), "sq_length"); + body.emit(assign(sq_length, dot(x, x))); + ir_constant *zero = ir_constant::zero(mem_ctx, type->get_base_type()); + body.emit(ret(mul(x, csel(nequal(sq_length, zero), rsq(sq_length), zero)))); } return sig;