Aeva / m.grl

Midnight Graphics & Recreation Library
http://mgrl.midnightsisters.org
GNU Lesser General Public License v3.0
44 stars 3 forks source link

remove uniform boilerplate where possible from compiled draw calls #238

Closed Aeva closed 7 years ago

Aeva commented 7 years ago

This is an offshoot from issue #232, building off of the work that is already in the heap_experiment branch. (the heap thing wasn't actually useful, so its been stripped out, so the branch name is kind of a misnomer now)

Basic gist, is, to generate js ir tokens for making the gl calls directly for updating a uniform, rather than all of the boilerplate we use. Should speed things up a lot, even if the heap thing doesn't work.

Aeva commented 7 years ago

I got it as far as getting the compiled output to look like this now:

this.prog.attrs['position'].enabled = true;
this.prog.attrs['tcoords'].enabled = true;
gl.bindBuffer(gl.ARRAY_BUFFER, please.gl.__buffers.all[4].id);
gl.vertexAttribPointer(this.prog.attrs['position'].loc, 3, 5126, false, 32, 0);
gl.vertexAttribPointer(this.prog.attrs['tcoords'].loc, 2, 5126, false, 32, 24);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, please.gl.__buffers.all[5].id);
gl.uniform1f(gl.getUniformLocation(this.prog.id, 'mgrl_orthographic_scale'), null);
gl.uniformMatrix4fv(gl.getUniformLocation(this.prog.id, 'world_matrix'), false, new Float32Array(this.heap.__blocks[0], 0, 16));
gl.uniform1f(gl.getUniformLocation(this.prog.id, 'billboard_mode'), 0);
this.prog.samplers['diffuse_texture'] = "flip_tile_test_grid.png";
gl.uniform1f(gl.getUniformLocation(this.prog.id, 'alpha'), 1);
gl.uniform1i(gl.getUniformLocation(this.prog.id, 'is_sprite'), false);
gl.uniform1i(gl.getUniformLocation(this.prog.id, 'is_transparent'), false);
gl.drawElements(4, 60, 5123, 0);

gl.uniformMatrix4fv(gl.getUniformLocation(this.prog.id, 'world_matrix'), false, new Float32Array(this.heap.__blocks[0], 64, 16));
gl.drawElements(4, 60, 5123, 0);

The heap access points even seem to be returning the correct values!

Runs like garbage (single digit frame rates), and nothing shows up :| The entire generated function is 30683 lines long, lol - way longer than M.GRL. So, its probably not surprising that the new debugger in firefox developer edition kind of struggles with it =P

I'm really happy with some of this. I think the answer here is probably to get rid of the heap stuff, and just replace the vector gl calls with non-vector ones, and hardcode the values w/o array syntax.

Aeva commented 7 years ago

The dynamic_glsl demo has a regression where the swappable function isn't getting setup correctly, and so the surfaces of the objects are painted black. The other demos don't seem to have any new regressions that aren't already in fast_graph.