[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Re: Unused but enabled VertexAttribs



On Tue, May 11, 2010 at 10:20 AM, Gregg Tavares <gman@google.com> wrote:
>
>
> On Mon, May 10, 2010 at 10:53 AM, Gregg Tavares <gman@google.com> wrote:
>>
>> So it turns out that if you just enable a vertex attrib, even though your
>> shader doesn't use it, you can crash some OpenGL drivers.
>>
>> Example: this is just the modified triangle sample from here.
>>
>> https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/tests/fast/triangle.html
>>
>> Just before draw, add the following line
>>
>>             gl = initWebGL("example", "vshader", "fshader", [
>> "vPosition"], [ 0, 0, 0, 1 ], 1);
>>             gl.viewport(0, 0, 50, 50);
>>
>>             var vertexObject = gl.createBuffer();
>>             gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
>>             gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray([ 0,0.5,0,
>> -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
>>             gl.enableVertexAttribArray(0);
>>             gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
>>
>>             gl.enableVertexAttribArray(3);  // added line
>>
>>             gl.drawArrays(gl.TRIANGLES, 0, 3);   // CRASH! (depending on
>> GL driver)
>>
>> Catching this issue in WebGL 2 paths come to mind.
>>
>> #1) Generate INVALID_OPERATION on drawArrays because the enabled vertex
>> attrib is not used by the current shader program
>>
>> #2) Generate INVALID_OPERATION on drawArrays because the enabled vertex
>> attrib does not have a buffer bound that has enough elements to satisfy the
>> drawArray call (as though it was used by the current shader program)
>>
>> #2 seems like the better option as many programs probably enable 4 to 8
>> attribs and never disable them and after that just manipulate what they
>> point to through vertexAttribPointer()
>>
>> Thoughts?
>>
>>
>
> So Ken Russell suggested that WebGL should do something under the hood to
> hide this issue from WebGL programs instead of reporting an error.  There
> are various solutions. For example, disable the unused arrays, draw,
> re-enable. How doesn't matter. What matters is that we decide what the
> correct behavior is for the WebGL spec.

As mentioned, I'm in favor of making this silently work since the
program doesn't actually reference the vertex attribute. We're going
to try to fix this in WebKit by binding all vertex attributes to a
zero-length buffer at context initialization time. See
https://bugs.webkit.org/show_bug.cgi?id=38962 . I think, but am not
sure, that that will work. In particular, our experience has been that
as long as the vertex attribute is bound to a buffer object (rather
than using a client-side vertex array), then if the program doesn't
reference the vertex attribute, the GPU doesn't actually try to
dereference it -- or, if it does, that fact isn't visible to the
programmer.

-Ken

-----------------------------------------------------------
You are currently subscribe to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: