regl icon indicating copy to clipboard operation
regl copied to clipboard

Incorrect state management after VAO emulation

Open rreusser opened this issue 2 years ago • 2 comments

In this notebook: https://observablehq.com/@rreusser/strange-attractors-on-the-gpu-part-2

The particles use a VAO. It should look like this:

Screen Shot 2021-11-22 at 08 05 02

but when I disable the VAO extension, causing the particles to fall back to VAO emulation, the particles render correctly but the grid is incorrect:

Screen Shot 2021-11-22 at 08 05 29

~~I'll see if I can, but I don't yet have a more focused reproduction of the bug.~~ See below for reproduction.

Attribute 0 of particle rendering has divisor 0, all others have divisor 1. That could potentially be a cause.

rreusser avatar Nov 22 '21 16:11 rreusser

Confirmed, here is a notebook which reproduces the issue: https://observablehq.com/d/243a0f078d6865bd

To reproduce:

  1. draw geometry with divisors set in a vao
  2. draw geometry without instancing or vaos

If the OES_vertex_array_object is present, this will produce the expected result. If not, then emulation will render the second (unfancy) triangle incorrectly but throw no errors or warnings.

vaoissue

const regl = createREGL({
  extensions: ['ANGLE_instanced_arrays', 'OES_vertex_array_object']
});

const vao = regl.vao([
  { divisor: 0, buffer: regl.buffer([[-0.1, -0.1], [0.1, -0.1], [0, 0.1]]) },
  { divisor: 1, buffer: regl.buffer([[-0.2, 0.4], [0.2, .4]]) }
]);

const drawTrianglesWithVAO = regl({
  vert: `
    precision highp float;
    attribute vec2 xy, tri;
    void main () {
      gl_Position = vec4(xy + tri, 0, 1);
    }`,
  frag: `
    precision highp float;
    void main () {
      gl_FragColor = vec4(0,0,0,1);
    }`,
  attributes: { tri: 0, xy: 1 },
  vao,
  count: 3,
  instances: 2
});

const drawTriangle = regl({
  vert: `
    precision highp float;
    attribute vec2 xy;
    attribute vec3 color;
    varying vec3 vColor;
    void main () {
      vColor = color;
      gl_Position = vec4(xy, 0, 1);
    }`,
  frag: `
    precision highp float;
    varying vec3 vColor;
    void main () {
      gl_FragColor = vec4(pow(vColor, vec3(0.454)),1);
    }`,
  attributes: {
    xy: [[-0.1, -0.5], [0.1, -0.5], [0, -0.3]],
    color: [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
  },
  count: 3
});

regl.poll();
drawTrianglesWithVAO();
drawTriangle();

rreusser avatar Nov 23 '21 03:11 rreusser

Can still reproduce this issue.

Swoorup avatar Mar 19 '23 10:03 Swoorup