Exemple #1
0
void
piglit_require_GLSL_version(int version)
{
	bool es;
	int major, minor;

	piglit_require_GLSL();

	piglit_get_glsl_version(&es, &major, &minor);

	if (es || 100 * major + minor < version) {
		printf("GLSL %d.%d not supported.\n",
		       version / 100, version % 100);
		piglit_report_result(PIGLIT_SKIP);
		exit(1);
	}
}
Exemple #2
0
GLuint
dsa_create_program(GLenum target)
{
	char *fs_source;
	char *vs_source;
	GLuint prog;
	bool es;
	int major;
	int minor;
	const char * ver;
	GLint loc;
	GLfloat xform[9];

	piglit_get_glsl_version(&es, &major, &minor);
	ver = ((major * 100 + minor) >= 140) ? "140" : "110";

	(void)!asprintf(&vs_source, vs_template, ver);
	switch (target) {
	case GL_TEXTURE_1D:
		(void)!asprintf(&fs_source, fs_1d_template, ver);
		break;
	case GL_TEXTURE_2D:
		(void)!asprintf(&fs_source, fs_2d_template, ver);
		break;
	case GL_TEXTURE_3D:
		(void)!asprintf(&fs_source, fs_3d_template, ver);
		break;
	case GL_TEXTURE_RECTANGLE_ARB:
		(void)!asprintf(&fs_source, fs_rect_template, ver);
		break;
	default:
		fprintf(stderr, "Invalid texture target in %s\n", __func__);
		piglit_report_result(PIGLIT_FAIL);
	}

	prog = piglit_build_simple_program(vs_source, fs_source);
	free(vs_source);
	free(fs_source);

	/* Note: the default value for all uniforms after linking is zero, so
	 * there is no need to explicitly set it here.  However, the xform
	 * matrix needs to be set to the identity matrix.
	 */
	loc = glGetUniformLocation(prog, "xform");

	xform[0] = 1.0;
	xform[1] = 0.0;
	xform[2] = 0.0;

	xform[3] = 0.0;
	xform[4] = 1.0;
	xform[5] = 0.0;

	xform[6] = 0.0;
	xform[7] = 0.0;
	xform[8] = 1.0;

	glProgramUniformMatrix3fv(prog, loc, 1, GL_FALSE, xform);

	return prog;
}
void
piglit_init(int argc, char **argv)
{
	bool pass = true;
	GLuint pipe;
	GLuint vs_prog;
	GLuint active_prog;
	GLuint unlinked_prog;
	GLuint shader;
	unsigned glsl_version;
	bool es;
	int glsl_major;
	int glsl_minor;
	char *source;

	piglit_require_extension("GL_ARB_separate_shader_objects");

	piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);
	glsl_version = ((glsl_major * 100) + glsl_minor) >= 140
		? 140 : ((glsl_major * 100) + glsl_minor);

	glGenProgramPipelines(1, &pipe);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	glBindProgramPipeline(pipe);

	asprintf(&source, vs_code_template, glsl_version);
	vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
					 (const GLchar *const *) &source);
	piglit_link_check_status(vs_prog);

	/* First, make a valid program active.
	 */
	glActiveShaderProgram(pipe, vs_prog);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* Next, try to make an invalid program active and verify that the
	 * correct error is generated.  Also make sure the old program is
	 * still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_VALUE error is generated if program is not zero and
	 *     is not the name of either a program or shader object."
	 */
	glActiveShaderProgram(pipe, ~vs_prog);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with an invalid program name "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}

	/* Try the same thing with a valid shader object (that is not part of
	 * a linked program).  Verify that the correct error is generated, and
	 * make sure the old program is still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if program is the name
	 *     of a shader object."
	 */
	shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
	glActiveShaderProgram(pipe, shader);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with a shader object "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}

	/* Finally, try the same thing with a valid program that is not
	 * linked.  Verify that the correct error is generated, and make sure
	 * the old program is still active.
	 *
	 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
	 * the OpenGL 4.4 spec says:
	 *
	 *     "An INVALID_OPERATION error is generated if program is not zero
	 *     and has not been linked, or was last linked unsuccessfully."
	 */
	unlinked_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
					       (const GLchar *const *) &invalid_code);

	glActiveShaderProgram(pipe, unlinked_prog);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog);
	if (active_prog != vs_prog) {
		printf("glActiveShaderProgram with an unlinked program "
		       "changed the active program state.\n");
		pass = false;
	} else {
		glActiveShaderProgram(pipe, vs_prog);
	}


	free(source);
	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Exemple #4
0
void piglit_init(int argc, char **argv)
{
	unsigned glsl_version;
	GLuint vs_prog;
	GLuint fs_prog_same_declaration_order;
	GLuint fs_prog_same_location_order;
	bool es;
	int glsl_major;
	int glsl_minor;
	char *source;

	piglit_require_vertex_shader();
	piglit_require_fragment_shader();
	piglit_require_extension("GL_ARB_separate_shader_objects");
	piglit_require_extension("GL_ARB_explicit_attrib_location");

	/* Some NVIDIA drivers have issues with layout qualifiers, 'in'
	 * keywords, and 'out' keywords in "lower" GLSL versions.  If the
	 * driver supports GLSL >= 1.40, use 1.40.  Otherwise, pick the
	 * highest version that the driver supports.
	 */
	piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);
	glsl_version = ((glsl_major * 100) + glsl_minor) >= 140
		? 140 : ((glsl_major * 100) + glsl_minor);

	asprintf(&source, vs_code_template, glsl_version);
	vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
					 (const GLchar *const *) &source);
	piglit_link_check_status(vs_prog);
	free(source);

	asprintf(&source, fs_code_same_declaration_order_template, glsl_version);
	fs_prog_same_declaration_order =
		glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
				       (const GLchar *const *) &source);
	piglit_link_check_status(fs_prog_same_declaration_order);
	free(source);

	asprintf(&source, fs_code_same_location_order_template, glsl_version);
	fs_prog_same_location_order =
		glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
				       (const GLchar *const *) &source);
	piglit_link_check_status(fs_prog_same_location_order);
	free(source);

	glGenProgramPipelines(1, &pipeline_same_declaration_order);
	glUseProgramStages(pipeline_same_declaration_order,
			   GL_VERTEX_SHADER_BIT,
			   vs_prog);
	glUseProgramStages(pipeline_same_declaration_order,
			   GL_FRAGMENT_SHADER_BIT,
			   fs_prog_same_declaration_order);
	piglit_program_pipeline_check_status(pipeline_same_declaration_order);

	glGenProgramPipelines(1, &pipeline_same_location_order);
	glUseProgramStages(pipeline_same_location_order,
			   GL_VERTEX_SHADER_BIT,
			   vs_prog);
	glUseProgramStages(pipeline_same_location_order,
			   GL_FRAGMENT_SHADER_BIT,
			   fs_prog_same_location_order);
	piglit_program_pipeline_check_status(pipeline_same_location_order);

	if (!piglit_check_gl_error(0))
		piglit_report_result(PIGLIT_FAIL);
}
void piglit_init(int argc, char **argv)
{
	bool pass = true;
	int gl_version;
	int glsl_major;
	int glsl_minor;
	int glsl_version;
	const char *version_for_float_shader = NULL;
	const char *version_for_double_shader = NULL;
	const char *version_for_int_shader = NULL;
	GLint context_flags = 0;

	piglit_require_vertex_shader();
	piglit_require_extension("GL_ARB_separate_shader_objects");

	gl_version = piglit_get_gl_version();
	if (gl_version >= 30)
		glGetIntegerv(GL_CONTEXT_FLAGS, &context_flags);

	piglit_get_glsl_version(NULL, &glsl_major, &glsl_minor);
	glsl_version = (glsl_major * 100) + glsl_minor;

	/* Select a shading language version string based on the GL version
	 * and whether or not we're running in a core profile.
	 */
	switch (gl_version / 10) {
	case 1:
	case 2:
		/* Selecting 1.20 will enable the non-square matrix tests.
		 */
		version_for_float_shader = (glsl_version >= 120)
			? "#version 120\n" : "#version 110\n";

		if (glsl_version >= 130)
			version_for_int_shader = "#version 130\n";
		break;
	case 3:
		/* OpenGL 3.0 deprecated GLSL 1.10 and 1.20.  OpenGL 3.1
		 * removed almost all deprecated features.
		 * Forworad-compatible contexts remove all deprecated
		 * features.
		 */
		if (gl_version == 30) {
			version_for_float_shader =
				(context_flags
				 & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
				? "#version 130\n" : "#version 120\n";

			version_for_int_shader = "#version 130\n";
		} else {
			/* Section 1.6.1 (OpenGL Shading Language) of the
			 * OpenGL 3.1 spec says:
			 *
			 *     "OpenGL 3.1 implementations are guaranteed to
			 *     support at least version 1.30 of the shading
			 *     language."
			 *
			 * This is likely a copy-and-paste error from version
			 * 3.0.  This should be 1.40.
			 *
			 * Section 1.6.1 (OpenGL Shading Language) of the
			 * OpenGL 3.2 spec says:
			 *
			 *     "OpenGL 3.2 implementations are guaranteed to
			 *     support versions 1.40 and 1.50 of the OpenGL
			 *     Shading Language."
			 *
			 * Section 1.7.1 (OpenGL Shading Language) of the
			 * OpenGL 3.3 spec says:
			 *
			 *     "OpenGL 3.3 implementations are guaranteed to
			 *     support version 3.30 of the OpenGL Shading
			 *     Language."
			 *
			 * Based on all of this, pick version 1.40 for OpenGL
			 * versions before 3.3, and version 3.30 for version
			 * 3.3.
			 */
			if (gl_version < 33) {
				version_for_float_shader = "#version 140\n";
				version_for_int_shader = "#version 140\n";
			} else {
				version_for_float_shader =
					"#version 330 core\n";
				version_for_int_shader = "#version 330 core\n";
			}

			if (piglit_is_extension_supported("GL_ARB_gpu_shader_fp64")) {
				/* The GL_ARB_gpu_shader_fp64 extensions spec
				 * says:
				 *
				 *     "OpenGL 3.2 and GLSL 1.50 are required."
				 */
				version_for_double_shader =
					"#version 150 core\n"
					"#extension GL_ARB_gpu_shader_fp64: require\n"
					;
			}
		}
		break;
	case 4:
		/* Section 1.7.1 (OpenGL Shading Language) of the
		 * OpenGL 4.0 spec says:
		 *
		 *     "OpenGL 4.0 implementations are guaranteed to support
		 *     version 4.00 of the OpenGL Shading Language."
		 *
		 * Section 1.7.1 (OpenGL Shading Language) of the
		 * OpenGL 4.1 spec says:
		 *
		 *     "OpenGL 4.1 implementations are guaranteed to support
		 *     version 4.10 of the OpenGL Shading Language."
		 *
		 * Section 1.7.1 (OpenGL Shading Language) of the
		 * OpenGL 4.2 spec says:
		 *
		 *     "OpenGL 4.2 implementations are guaranteed to support
		 *     version 4.20 of the OpenGL Shading Language....The core
		 *     profile of OpenGL 4.2 is also guaranteed to support all
		 *     previous versions of the OpenGL Shading Language back
		 *     to version 1.40."
		 *
		 * Section 1.3.1 (OpenGL Shading Language) of the
		 * OpenGL 4.3 spec says:
		 *
		 *     "OpenGL 4.3 implementations are guaranteed to support
		 *     version 4.30 of the OpenGL Shading Language....The core
		 *     profile of OpenGL 4.3 is also guaranteed to support all
		 *     previous versions of the OpenGL Shading Language back
		 *     to version 1.40."
		 *
		 * Section 1.3.1 (OpenGL Shading Language) of the
		 * OpenGL 4.4 spec says:
		 *
		 *     "OpenGL 4.4 implementations are guaranteed to support
		 *     version 4.40 of the OpenGL Shading Language....The core
		 *     profile of OpenGL 4.4 is also guaranteed to support all
		 *     previous versions of the OpenGL Shading Language back
		 *     to version 1.40."
		 *
		 * Even though 4.1 doesn't say anything about GLSL 4.00, the
		 * inference is that the addition starting in 4.2 was a
		 * clarification.
		 */
		version_for_float_shader = "#version 400 core\n";
		version_for_double_shader = "#version 400 core\n";
		version_for_int_shader = "#version 400 core\n";
		break;
	
	default:
		fprintf(stderr, "Unknown GL version!\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	pass = test_float(version_for_float_shader) && pass;
	pass = test_square_mat(version_for_float_shader) && pass;

	pass = test_nonsquare_mat(version_for_float_shader) && pass;

	pass = test_int(version_for_int_shader) && pass;
	pass = test_uint(version_for_int_shader) && pass;

	pass = test_double(version_for_double_shader) && pass;
	pass = test_dmat(version_for_double_shader) && pass;

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}