glsl/loops: Simplify loop unrolling logic by breaking into functions.