1

我遇到了一个问题,对片段着色器的更改会暂时中断渲染。着色器编译;编译步骤、链接步骤或 glValidateProgram() 没有错误条件或日志输出。但随后对 glDrawArrays() 的调用返回 GL_INVALID_OPERATION,没有绘制任何内容,并且应用程序变得非常缓慢或无响应。

但是,当我从我的主要开发设备(iPad 2)切换到其他硬件(iPhone 5s 和 iPad Mini)时,相同的代码可以完美运行。奇怪的是,如果我随后重新连接到 iPad 2,问题就消失了,我可以继续在该设备上开发着色器。同样的循环现在已经重复了好几次:我修改并向着色器添加了一些新代码,问题又出现了。我切换到较新的设备,代码运行良好,切换回 iPad 2,问题神秘地消失了(有时),我可以继续工作。一旦它再次开始工作,它似乎会继续工作。但是,使用下面的代码,我现在似乎陷入了解决方法无济于事的地步。

我的预感(或希望)是我的代码中的某些内容正在通过编译器,但在某种程度上有些冒险,某些硬件接受它(A7 和 SGX 543)但有些不接受(SGX 535)。也许解决方法的间歇性只是一个红鲱鱼。如果没有这样的问题,我欢迎任何其他故障排除建议。

代码很长,所以我摘录了与这个问题的最新迭代相关的部分。以前的迭代只涉及添加几行看似无害的代码。

uniform highp vec3  vertexColors[3];

mediump vec3 hexagonLayer (highp float edge1, highp float edge2, int layer, mediump vec3 underColor, highp float opacity) {
    highp float opac = remap (length (faceP - vertexFacePositions[layer]), 0.0, edge1 * 3.0, 1.0, opacity);

    mediump vec3 shadowColor = pow (underColor, vec3 (2.0));
    highp float shadowOpacity = (1.0 - smoothstep (edge1, edge1 + SHADOW_WIDTH, 1.0 - trilinears[layer])) * SHADOW_OPACITY * opac;
    mediump vec3 color = mix (underColor, shadowColor, shadowOpacity);

    return mix (color, vertexColors[layer], (1.0 - smoothstep (edge1, edge2, 1.0 - trilinears[layer])) * opac);
}
4

1 回答 1

1

Answering my own question, at least partially. My first mistake was that my glValidateProgram() code was never being called. Turns out I had an error message after all, albeit unhelpful:

Validation Failed: Fragment program failed to compile with current context state.
Validation Failed: Vertex program failed to compile with current context state.

So lesson number one is that there can apparently be a compilation failure even when both GL_COMPILE_STATUS and GL_LINK_STATUS are good, and both logs are silent.

Thanks to a clue from this question I started looking at mismatched precision qualifiers, and sure enough changing all my mediump colors to highp solves the problem. Is that because I declared my uniform as highp, and then mix() between a highp and mediump vec3? (I shortened the code in my question to show the relevant sections.)

It makes some sense to me that this might accidentally work on the newer hardware, as I think I remember reading somewhere that GLES-3-capable hardware treats highp and mediump as the same bit depth. I would love some confirmation of that guess.

于 2014-05-14T22:35:31.173 回答