[Piglit] [RFC PATCH 2/2] shader_runner: Add ARB_program_interface_query support to buffer variables

Samuel Iglesias Gonsalvez siglesias at igalia.com
Fri Sep 11 04:37:42 PDT 2015


Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
---
 tests/shaders/shader_runner.c | 136 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 7a647a1..81d694c 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -2046,6 +2046,140 @@ active_uniform(const char *line)
 	return;
 }
 
+/**
+ * Query a uniform using glGetActiveUniformsiv
+ *
+ * Format of the command:
+ *
+ *     active buffer_variable buffer_var_name GL_PNAME_ENUM integer
+ *
+ * or
+ *
+ *     active buffer_variable buffer_var_name GL_PNAME_ENUM GL_TYPE_ENUM
+ */
+void
+active_buffer_variable(const char *line)
+{
+	static const struct string_to_enum all_props[] = {
+		ENUM_STRING(GL_TYPE),
+		ENUM_STRING(GL_ARRAY_SIZE),
+		ENUM_STRING(GL_NAME_LENGTH),
+		ENUM_STRING(GL_BLOCK_INDEX),
+		ENUM_STRING(GL_OFFSET),
+		ENUM_STRING(GL_ARRAY_STRIDE),
+		ENUM_STRING(GL_MATRIX_STRIDE),
+		ENUM_STRING(GL_IS_ROW_MAJOR),
+		ENUM_STRING(GL_ATOMIC_COUNTER_BUFFER_INDEX),
+		ENUM_STRING(GL_BUFFER_BINDING),
+		ENUM_STRING(GL_BUFFER_DATA_SIZE),
+		ENUM_STRING(GL_NUM_ACTIVE_VARIABLES),
+		ENUM_STRING(GL_REFERENCED_BY_VERTEX_SHADER),
+		ENUM_STRING(GL_REFERENCED_BY_TESS_CONTROL_SHADER),
+		ENUM_STRING(GL_REFERENCED_BY_TESS_EVALUATION_SHADER),
+		ENUM_STRING(GL_REFERENCED_BY_GEOMETRY_SHADER),
+		ENUM_STRING(GL_REFERENCED_BY_FRAGMENT_SHADER),
+		ENUM_STRING(GL_REFERENCED_BY_COMPUTE_SHADER),
+		ENUM_STRING(GL_TOP_LEVEL_ARRAY_SIZE),
+		ENUM_STRING(GL_TOP_LEVEL_ARRAY_STRIDE),
+		ENUM_STRING(GL_LOCATION),
+		ENUM_STRING(GL_LOCATION_INDEX),
+		ENUM_STRING(GL_IS_PER_PATCH),
+		ENUM_STRING(GL_NUM_COMPATIBLE_SUBROUTINES),
+		ENUM_STRING(GL_COMPATIBLE_SUBROUTINES),
+		{ NULL, 0 }
+	};
+
+	char name[512];
+	char name_buf[512];
+	char prop_string[512];
+	GLenum prop;
+	GLint expected;
+	int i;
+	int num_active_buffers;
+
+	if (!piglit_is_extension_supported("GL_ARB_program_interface_query") &&
+	    piglit_get_gl_version() < 43) {
+		fprintf(stderr,
+			"GL_ARB_program_interface_query not supported or "
+			"OpenGL version < 4.3\n")
+		return;
+	}
+
+	line = strcpy_to_space(name, eat_whitespace(line));
+
+	strcpy_to_space(prop_string, eat_whitespace(line));
+	prop = lookup_enum_string(all_props, &line, "glGetProgramResourceiv pname");
+
+	line = eat_whitespace(line);
+	if (isdigit(line[0])) {
+		expected = strtol(line, NULL, 0);
+	} else {
+		expected = lookup_enum_string(all_types, &line, "type enum");
+	}
+
+	glGetProgramInterfaceiv(prog, GL_BUFFER_VARIABLE,
+				GL_ACTIVE_RESOURCES, &num_active_buffers);
+	for (i = 0; i < num_active_buffers; i++) {
+		GLint got;
+		GLint length;
+		GLsizei name_len;
+		bool pass = true;
+
+		glGetProgramResourceName(prog, GL_BUFFER_VARIABLE,
+					 i, 512, &name_len, name_buf);
+
+		if (!piglit_check_gl_error(GL_NO_ERROR)) {
+			fprintf(stderr, "glGetProgramResourceName error\n");
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		if (strcmp(name, name_buf) != 0)
+			continue;
+
+		if (prop == GL_NAME_LENGTH && name_len != expected) {
+			fprintf(stderr,
+				"glGetProgramResourceName(%s, %s): "
+				"expected %d (0x%04x), got %d (0x%04x)\n",
+				name, prop_string,
+				expected, expected, got, got);
+			pass = false;
+		}
+
+		/* Set 'got' to some value in case glGetActiveUniformsiv
+		 * doesn't write to it.  That should only be able to occur
+		 * when the function raises a GL error, but "should" is kind
+		 * of a funny word.
+		 */
+		got = ~expected;
+		glGetProgramResourceiv(prog, GL_BUFFER_VARIABLE,
+				       i, 1, &prop, 1,
+				       &length, &got);
+
+		if (!piglit_check_gl_error(GL_NO_ERROR)) {
+			fprintf(stderr, "glGetProgramResourceiv error\n");
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		if (got != expected) {
+			fprintf(stderr,
+				"glGetProgramResourceiv(%s, %s): "
+				"expected %d, got %d\n",
+				name, prop_string,
+				expected, got);
+			pass = false;
+		}
+
+		if (!pass)
+			piglit_report_result(PIGLIT_FAIL);
+
+		return;
+	}
+
+	fprintf(stderr, "No buffer variable named \"%s\"\n", name);
+	piglit_report_result(PIGLIT_FAIL);
+	return;
+}
+
 void
 set_parameter(const char *line)
 {
@@ -2889,6 +3023,8 @@ piglit_display(void)
 			get_ints(line + strlen("ubo array index "), &ubo_array_index, 1);
 		} else if (string_match("active uniform ", line)) {
 			active_uniform(line + strlen("active uniform "));
+		} else if (string_match("active buffer_variable ", line)) {
+			active_buffer_variable(line + strlen("active buffer_variable "));
 		} else if ((line[0] != '\n') && (line[0] != '\0')
 			   && (line[0] != '#')) {
 			printf("unknown command \"%s\"\n", line);
-- 
2.1.4



More information about the Piglit mailing list