[Piglit] [PATCH 6/7] arb_vertex_attrib_binding: Test instance-divisor

Fredrik Höglund fredrik at kde.org
Fri Nov 1 09:31:07 PDT 2013


On Wednesday 30 October 2013, Eric Anholt wrote:
> Fredrik Höglund <fredrik at kde.org> writes:
> > diff --git a/tests/spec/arb_vertex_attrib_binding/instance-divisor.c b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
> > new file mode 100644
> > index 0000000..88ae454
> > --- /dev/null
> > +++ b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
> 
> > +const char *vs_source =
> > +	"attribute vec4 pos;\n"
> > +	"attribute vec2 offset;\n"
> > +	"attribute vec4 color;\n"
> > +	"uniform vec2 global_offset;\n"
> > +	"varying vec4 col;\n"
> > +	"void main() {\n"
> > +	"    col = color;\n"
> > +	"    gl_Position = pos + vec4(global_offset + offset, vec2(0, 0));\n"
> > +	"}";
> 
> > +enum piglit_result
> > +piglit_display(void)
> > +{
> > +	const struct vec2 quad[] = {
> > +		{ -0.125,  0.125 }, { 0.125,  0.125 },
> > +		{ -0.125, -0.125 }, { 0.125, -0.125 }
> > +	};
> > +
> > +	const struct vec2 offsets[] = {
> > +		{ -.75, 0 }, { -.25, 0 }, { .25, 0 }, { .75, 0 }
> > +	};
> > +
> > +	const struct vec4 colors[] = {
> > +		{ 1.0, 0.0, 0.0, 1.0 },
> > +		{ 0.0, 1.0, 0.0, 1.0 },
> > +		{ 0.0, 0.0, 1.0, 1.0 },
> > +		{ 1.0, 1.0, 1.0, 1.0 }
> > +	};
> > +
> > +	GLuint vbo1, vbo2, vbo3, vao;
> > +	bool pass = true;
> > +
> > +	glGenVertexArrays(1, &vao);
> > +	glBindVertexArray(vao);
> > +
> > +	glGenBuffers(1, &vbo1);
> > +	glGenBuffers(1, &vbo2);
> > +	glGenBuffers(1, &vbo3);
> > +
> > +	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
> > +	glBufferData(GL_ARRAY_BUFFER, sizeof(quad), (const GLvoid *) quad, GL_STATIC_DRAW);
> > +
> > +	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
> > +	glBufferData(GL_ARRAY_BUFFER, sizeof(offsets), (const GLvoid *) offsets, GL_STATIC_DRAW);
> 
> I'm confused why there's both pos/quad (with two names) and offset.
> Could you just have a single pre-baked pos vec2?

quad is the quad we're drawing multiple instances of, and offset is how
much the quad is offset in each instance.  The positions can't be
pre-baked, since pos/quad advances per-vertex, and offset per-instance.

I could add some comments to make that more clear, and maybe
rename the quad array.  Another option is to remove the offsets array
and offset the positions by gl_InstanceID multiplied by some value
in the shader.  Or hardcode the quad array in the shader and index
into it using gl_VertexID.  But both those options have the drawback
that they add more dependencies.

> > +	pass = piglit_probe_pixel_rgba(piglit_width * .125, piglit_height * .75, (const float *) &colors[0]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .375, piglit_height * .75, (const float *) &colors[1]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .625, piglit_height * .75, (const float *) &colors[2]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .875, piglit_height * .75, (const float *) &colors[3]);
> > +
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .125, piglit_height * .25, (const float *) &colors[0]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .375, piglit_height * .25, (const float *) &colors[0]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .625, piglit_height * .25, (const float *) &colors[1]);
> > +	pass = piglit_probe_pixel_rgba(piglit_width * .875, piglit_height * .25, (const float *) &colors[1]);
> 
> Again, not required, but I like probe_rect (when the HW craps out and
> only draws some of the pixels, you get fewer false positives).
> 
> > +void
> > +piglit_init(int argc, char **argv)
> > +{
> > +	GLuint vs, fs;
> > +
> > +	piglit_require_extension("GL_ARB_vertex_attrib_binding");
> 
> Since I think we're enabling this extension on all Mesa drivers
> regardless of HW support for instancing, I think this should also depend
> on GL_ARB_instanced_arrays.  (It's not called out in the spec because
> they wrote it against 4.2).

The VertexBindingDivisor() implementation should also have a check
for ARB_instanced_arrays.  I'll add that.

> > +	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
> > +	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
> > +	program = piglit_link_simple_program(vs, fs);
> 
> piglit_build_simple_program().
> 
> > +	pos           = glGetAttribLocation(program, "pos");
> > +	offset        = glGetAttribLocation(program, "offset");
> > +	color         = glGetAttribLocation(program, "color");
> > +	global_offset = glGetUniformLocation(program, "global_offset");
> > +}
> 



More information about the Piglit mailing list