GLSL 循环赋值 -> "invalid operation"

GLSL looped assignment -> "invalid operation"

我试图让一个多项式方程求解器在 GLSL 中工作,但是当我包含这一小段代码时它失败了:

//bs_a: start of monotonic section
//bs_b: end
//factor: 1.0 if bs_a < bs_b and -1.0 else
for (int iter = 0; iter < bisectionIterations; iter++) {
    bs_m = mix(bs_a, bs_b, 0.5);
    if (poly_calculatevalue(in_p, bs_m) * factor < 0.0)
        bs_a = mix(bs_a, bs_b, 0.5);
    else bs_b = bs_m;
}

我也试过这样重写:

for (int iter = 0; iter < bisectionIterations; iter++) {
    bs_m = mix(bs_a, bs_b, 0.5);
    tmp = step(0.0, poly_calculatevalue(in_p, bs_m) * factor);
    bs_a = (1-tmp) * bs_m + tmp * bs_a;
    bs_b = tmp * bs_m + (1-tmp) * bs_b;
}

此代码在 Nvidia Gtx580 上的 GLSL 430 计算着色器中执行。我只在调用 glUseProgram 和使用此程序的所有后续函数(SetUniform、DispatchCompute 等)时出现运行时错误 (GL_INVALID_OPERATION)

编辑:该代码实际上适用于我配备 AMD E-300 APU 的笔记本电脑。 nvidia 卡有什么问题?

这段代码实际上工作得很好,错误是从其他地方传播的。在另一个循环中有一些微妙的数组越界错误,但 AMD 驱动程序似乎忽略了这些边缘情况。