Commit 42136858 authored by Alejandro Piñeiro's avatar Alejandro Piñeiro Committed by Arcady Goldmints-Orlov

shader_runner: add xfb query object support

This commit adds query objects for GL_PRIMITIVES_GENERATED and
GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, and only for xfb
drawing. Those query objects are created implicitly during xfb
drawing.

We don't add general query object support for two reasons:
  * Right now only xfb tests would be using it.

  * Adding general support would make the test section more
    complicated, as we would need to add beginquery/endquery like
    commands, making [test] section too much of a GL pseudocode.

If in the future we need general query object support, we can just
expand this.

It also add them always for any xfb drawing, instead of
conditionally. Again, to make things easier.

So it introduces just one [test] command, that can be used as:

  * "verify query_object GL_PRIMITIVES_GENERATED <integer value>"

  * "verify query_object GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN <integer_value>"

v2: Create a helper function to deal with the array of query object names.
Signed-off-by: Arcady Goldmints-Orlov's avatarArcady Goldmints-Orlov <agoldmints@igalia.com>
Reviewed-by: Caio Marcelo de Oliveira Filho's avatarCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
parent 728dde0e
......@@ -137,6 +137,9 @@ static char **shader_include_path;
#define MAX_XFB_BUFFERS 4 /* Same value used at nir_xfb_info */
static GLuint xfb[MAX_XFB_BUFFERS];
#define MAX_QUERIES 2
static GLuint queries[MAX_QUERIES];
#define SHADER_TYPES 6
static GLuint *subuniform_locations[SHADER_TYPES];
static int num_subuniform_locations[SHADER_TYPES];
......@@ -3170,6 +3173,81 @@ active_program_interface(const char *line)
return;
}
static unsigned
query_index(GLenum query)
{
switch (query) {
case GL_PRIMITIVES_GENERATED:
return 0;
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
return 1;
default:
return 0;
}
}
/**
* Checks if the GL_QUERY_RESULT of a given query object has the
* expected value.
*
* Note that right now it only supports the following two queries:
* * GL_PRIMITIVES_GENERATED
* * GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
*
* As right now we are only creating those query objects with xfb
* rendering.
*
* Format of the command:
*
* verify query_object GL_PRIMITIVES_GENERATED integer
*
* or
*
* verify query_object GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN integer
*/
static void
verify_query_object_result(const char *line)
{
static const struct string_to_enum all_targets[] = {
ENUM_STRING(GL_PRIMITIVES_GENERATED),
ENUM_STRING(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN),
{ NULL, 0 }
};
unsigned target;
unsigned expected;
unsigned value = 0;
unsigned index = 0;
REQUIRE(parse_enum_tab(all_targets, line,
&target, &line),
"Bad query object target at: %s\n", line);
REQUIRE(parse_uint(line, &expected, &line),
"Bad expected value at: %s\n", line);
/* Previous require already checks if the target is one of the
* supported ones.
*/
index = query_index(target);
if (queries[index]) {
glGetQueryObjectuiv(queries[index], GL_QUERY_RESULT, &value);
} else {
fprintf(stderr, "query object for target %s is not initialized. "
"Did you forget to call \"xfb draw arrays\"?\n",
piglit_get_gl_enum_name(target));
piglit_report_result(PIGLIT_FAIL);
}
if (expected != value) {
fprintf(stderr, "glGetQueryObjectuiv(GL_QUERY_RESULT) for a %s "
"query object: expected %d, got %d\n",
piglit_get_gl_enum_name(target), expected, value);
piglit_report_result(PIGLIT_FAIL);
}
}
static void
set_parameter(const char *line)
{
......@@ -3574,6 +3652,9 @@ static void
teardown_xfb(void)
{
glDeleteBuffers(MAX_XFB_BUFFERS, xfb);
glDeleteQueries(1, &queries[query_index(GL_PRIMITIVES_GENERATED)]);
glDeleteQueries(1, &queries[query_index(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)]);
}
static enum piglit_result
......@@ -3763,11 +3844,23 @@ GLenum piglit_xfb_primitive_mode(GLenum draw_arrays_mode)
piglit_report_result(PIGLIT_FAIL);
}
static void
begin_query(GLenum query_type)
{
unsigned idx = query_index(query_type);
if (queries[idx] == 0)
glGenQueries(1, &queries[idx]);
glBeginQuery(query_type, queries[idx]);
}
static void
piglit_xfb_draw_arrays(GLenum mode, int first, size_t count)
{
GLenum primitive_mode = piglit_xfb_primitive_mode(mode);
begin_query(GL_PRIMITIVES_GENERATED);
begin_query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glEnable(GL_RASTERIZER_DISCARD);
/* We don't need to call glBindBufferBase here, it is done on
......@@ -3781,6 +3874,9 @@ piglit_xfb_draw_arrays(GLenum mode, int first, size_t count)
glDisable(GL_RASTERIZER_DISCARD);
glFlush();
glEndQuery(GL_PRIMITIVES_GENERATED);
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
}
static bool
......@@ -4796,6 +4892,8 @@ piglit_display(void)
verify_program_query(rest);
} else if (parse_str(line, "verify program_interface_query ", &rest)) {
active_program_interface(rest);
} else if (parse_str(line, "verify query_object", &rest)) {
verify_query_object_result(rest);
} else if (parse_str(line, "vertex attrib ", &rest)) {
set_vertex_attrib(rest);
} else if (parse_str(line, "newlist ", &rest)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment