[Piglit] [PATCH 2/7] arb_vertex_attrib_binding: Test new states
Fredrik Höglund
fredrik at kde.org
Fri Nov 1 08:57:21 PDT 2013
On Wednesday 30 October 2013, Eric Anholt wrote:
> Fredrik Höglund <fredrik at kde.org> writes:
>
> > Test setting and quering all new states. This also tests interactions
> > with glVertexAttribPointer().
>
> Same MIN2 and uncreached comments as the previous test.
>
> > +#include "piglit-util-gl-common.h"
> > +
> > +#define MIN(a, b) (a < b ? a : b)
> > +
> > +PIGLIT_GL_TEST_CONFIG_BEGIN
> > +
> > + config.supports_gl_compat_version = 10;
>
> This should just be "30", and then you can drop the
> requires_gl_version() below.
>
> Also, don't these tests support core profile implementations? It would
> be nice, but not required, to see them tested on that and a
> config.supports_gl_core_version = 31 added.
All the tests should work with core profile contexts.
> > + /* Check limits */
> > + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribs);
> > + if (maxAttribs < 16) {
> > + fprintf(stderr, "GL_MAX_VERTEX_ATTRIBS must be at least 16");
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &maxBindings);
> > + if (maxBindings < 16) {
> > + fprintf(stderr, "GL_MAX_VERTEX_ATTRIB_BINDINGS must be at least 16");
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetIntegerv(GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET, &value);
> > + if (value < 2047) {
> > + fprintf(stderr, "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET must be at least 2047");
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
>
> Previously I've done these kinds of tests in a separate minmax.c test,
> but since you're getting these values to use them anyway, this seems
> totally reasonable. Same comment about early exiting, though.
> > + /* Create a buffer object */
> > + glGenBuffers(1, &buf);
> > + glBindBuffer(GL_ARRAY_BUFFER, buf);
> > +
> > + /* Bind the buffer object to binding point 0, offset=1024, stride=32 */
> > + glBindVertexBuffer(0, buf, 1024, 32);
>
> > + /* Test glVertexAttribFormat */
> > + {
> > + struct {
> > + GLuint size;
> > + GLenum type;
> > + GLboolean normalized;
> > + } formats[] = {
> > + { 1, GL_BYTE, GL_TRUE },
> > + { 2, GL_UNSIGNED_BYTE, GL_TRUE },
> > + { 3, GL_SHORT, GL_TRUE },
> > + { 4, GL_UNSIGNED_SHORT, GL_TRUE },
> > + { 1, GL_INT, GL_FALSE },
> > + { 2, GL_UNSIGNED_INT, GL_FALSE },
> > + { 3, GL_FIXED, GL_FALSE },
> > + { 4, GL_FLOAT, GL_FALSE },
> > + { 1, GL_HALF_FLOAT, GL_FALSE },
> > + { 2, GL_DOUBLE, GL_FALSE },
> > + { 4, GL_INT_2_10_10_10_REV, GL_TRUE },
> > + { 4, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE },
> > + { GL_BGRA, GL_UNSIGNED_BYTE, GL_TRUE },
> > + { GL_BGRA, GL_INT_2_10_10_10_REV, GL_TRUE },
> > + { GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE }
> > + };
> > +
> > + for (i = 0; i < maxAttribs; i++)
> > + glVertexAttribFormat(i, formats[i % 15].size,
> > formats[i % 15].type, formats[i % 15].normalized, i);
>
> 15 is the size of that array I guess? ARRAY_SIZE() is the macro to get
> that so we don't have magic numbers.
>
> > + for (i = 0; i < maxAttribs; i++) {
> > + const GLuint size = formats[i % 15].size == GL_BGRA ? 4 : formats[i % 15].size;
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_RELATIVE_OFFSET, &value);
> > + if (value != i) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_RELATIVE_OFFSET[%d] was %d, expected %d\n", i, value, i);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
>
> piglit tests are generally wrapped at 80 columns when it doesn't
> make the code super ugly, and these printfs look like they'd wrap
> reasonably.
>
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &value);
> > + if (value != size) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_SIZE[%d] was %d, expected %d\n", i, value, size);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &value);
> > + if (value != formats[i % 15].type) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_TYPE[%d] was %s, expected %s\n", i,
> > + piglit_get_gl_enum_name(value),
> > + piglit_get_gl_enum_name(formats[i % 15].type));
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &value);
> > + if (value != formats[i % 15].normalized) {
> > + if (value == GL_TRUE)
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_NORMALIZED[%d] was GL_TRUE, expected GL_FALSE\n", i);
> > + else
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_NORMALIZED[%d] was GL_FALSE, expected GL_TRUE\n", i);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_INTEGER, &value);
> > + if (value != GL_FALSE) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_INTEGER[%d] was GL_TRUE, expected GL_FALSE\n", i);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribPointerv(i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr);
> > + if (ptr != NULL) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_POINTER[%d] was %p, expected NULL\n", i, ptr);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > + }
> > + }
> > +
> > +
> > + /* Test glVertexAttribIFormat */
> > + {
> > + struct {
> > + GLuint size;
> > + GLenum type;
> > + } formats[] = {
> > + { 1, GL_BYTE },
> > + { 2, GL_UNSIGNED_BYTE },
> > + { 3, GL_SHORT },
> > + { 4, GL_UNSIGNED_SHORT },
> > + { 1, GL_INT },
> > + { 2, GL_UNSIGNED_INT }
> > + };
> > +
> > + for (i = 0; i < maxAttribs; i++)
> > + glVertexAttribIFormat(i, formats[i % 6].size, formats[i % 6].type, maxAttribs - i);
> > +
> > + for (i = 0; i < maxAttribs; i++) {
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_RELATIVE_OFFSET, &value);
> > + if (value != maxAttribs - i) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_RELATIVE_OFFSET[%d] was %d, expected %d\n", i, value,
> > + maxAttribs - i);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &value);
> > + if (value != formats[i % 6].size) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_SIZE[%d] was %d, expected %d\n", i, value,
> > + formats[i % 6].size);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &value);
> > + if (value != formats[i % 6].type) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_TYPE[%d] was %s, expected %s\n", i,
> > + piglit_get_gl_enum_name(value),
> > + piglit_get_gl_enum_name(formats[i % 6].type));
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_INTEGER, &value);
> > + if (value != GL_TRUE) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_INTEGER[%d] was GL_FALSE, expected GL_TRUE\n", i);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > +
> > + glGetVertexAttribPointerv(i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr);
> > + if (ptr != NULL) {
> > + fprintf(stderr, "GL_VERTEX_ATTRIB_ARRAY_POINTER[%d] was %p, expected NULL\n", i, ptr);
> > + piglit_report_result(PIGLIT_FAIL);
> > + }
> > + }
> > + }
>
> I'm pretty sure these repeated loops full of checking of getters could
> be in a helper function taking an array of struct format and a count.
> Trying to stay attentive when reading it 3 times is hard.
Seems reasonable. I'll add that.
Fredrik
More information about the Piglit
mailing list