[Piglit] [PATCH 1/3] ARB_ubo/referenced-by-shader: Add support for ARB_geometry_shader4.

Fabian Bieler fabianbieler at fastmail.fm
Mon Jun 17 14:35:12 PDT 2013


On 2013-06-17 22:34, Eric Anholt wrote:
> Like before, we enumerate all the combinations of stages that could
> use a uniform block.  But since we may not have GS support, we only
> check for support in that stage if we actually found the extension and
> linked the GS.
> ---
>  .../referenced-by-shader.c                         | 117 +++++++++++++++------
>  1 file changed, 84 insertions(+), 33 deletions(-)
> 
> diff --git a/tests/spec/arb_uniform_buffer_object/referenced-by-shader.c b/tests/spec/arb_uniform_buffer_object/referenced-by-shader.c
> index dad8c77..0608ac6 100644
> --- a/tests/spec/arb_uniform_buffer_object/referenced-by-shader.c
> +++ b/tests/spec/arb_uniform_buffer_object/referenced-by-shader.c
> @@ -51,65 +51,116 @@ piglit_init(int argc, char **argv)
>  {
>  	bool pass = true;
>  	unsigned int i;
> -	GLuint vs, fs, prog;
> +	GLuint vs, fs, gs, prog;
>  	const char *vs_source =
> -		"#extension GL_ARB_uniform_buffer_object : enable\n"
> -		"uniform vs { float a; };\n"
> -		"uniform vsfs { float c; };\n"
> +		"%s"
> +		"uniform vs { float v; };\n"
> +		"uniform vsgs { float vg; };\n"
> +		"uniform vsfs { float vf; };\n"
> +		"uniform vsgsfs { float vgf; };\n"
>  		"uniform float dddd;\n"
I know this was not introduced in this patch, but just out of curiosity, does the dddd uniform serve any purpose (it appears in the fs, too)?
>  		"void main() {\n"
> -		"	gl_Position = gl_Vertex + vec4(a + c);\n"
> +		"	gl_Position = vec4(v + vg + vf + vgf);\n"
> +		"}\n";
> +	const char *gs_source =
> +		"%s"
> +		"\n"
> +		"uniform gs { float g; };\n"
> +		"uniform vsgs { float vg; };\n"
> +		"uniform gsfs { float gf; };\n"
> +		"uniform vsgsfs { float vgf; };\n"
> +		"\n"
> +		"void main() {\n"
> +		"	gl_Position = gl_PositionIn[0] + vec4(g + vg + gf + vgf);\n"
> +		"	EmitVertex();\n"
>  		"}\n";
>  	const char *fs_source =
> -		"#extension GL_ARB_uniform_buffer_object : enable\n"
> -		"uniform fs { float b; };\n"
> -		"uniform vsfs { float c; };\n"
> +		"%s"
> +		"uniform fs { float f; };\n"
> +		"uniform vsfs { float vf; };\n"
> +		"uniform gsfs { float gf; };\n"
> +		"uniform vsgsfs { float vgf; };\n"
>  		"uniform float dddd;\n"
>  		"void main() {\n"
> -		"	gl_FragColor = vec4(b + c);\n"
> +		"	gl_FragColor = vec4(f + vf + gf + vgf);\n"
>  		"}\n";
> +	char *gen_source;
>  	char name[10];
> +	bool use_gs = piglit_is_extension_supported("GL_ARB_geometry_shader4");
> +	const char *header;
> +
> +	if (use_gs) {
> +		header =
> +			"#version 110\n"
> +			"#extension GL_ARB_uniform_buffer_object : enable\n"
> +			"#extension GL_ARB_geometry_shader4 : enable\n";
> +	} else {
> +		header =
> +			"#version 110\n"
> +			"#extension GL_ARB_uniform_buffer_object : enable\n";
> +	}
>  
>  	piglit_require_extension("GL_ARB_uniform_buffer_object");
>  
> -	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
> -	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
> -	prog = piglit_link_simple_program(vs, fs);
> -	if (!prog) {
> +	prog = glCreateProgram();
> +
> +	asprintf(&gen_source, vs_source, header);
> +	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, gen_source);
> +	free(gen_source);
> +
> +	glAttachShader(prog, vs);
> +	if (use_gs) {
> +		asprintf(&gen_source, gs_source, header);
> +		gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gen_source);
> +		free(gen_source);
> +		glAttachShader(prog, gs);
> +
> +		glProgramParameteri(prog,
> +				    GL_GEOMETRY_INPUT_TYPE_ARB, GL_POINTS);
> +		glProgramParameteri(prog,
> +				    GL_GEOMETRY_OUTPUT_TYPE_ARB, GL_POINTS);
> +		glProgramParameteri(prog,
> +				    GL_GEOMETRY_VERTICES_OUT_ARB, 1);
> +	}
> +	asprintf(&gen_source, fs_source, header);
> +	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, gen_source);
> +	free(gen_source);
> +	glAttachShader(prog, fs);
> +
> +	glLinkProgram(prog);
> +	if (!piglit_link_check_status(prog)) {
>  		fprintf(stderr, "Failed to link shaders.\n");
>  		piglit_report_result(PIGLIT_FAIL);
>  	}
>  
> -	for (i = 0; i < 3; i++) {
> -		GLint ref_vs, ref_fs;
> +	for (i = 0; i < 5; i++) {
> +		GLint ref_vs, ref_fs, ref_gs = 0;
> +		bool block_fail;
block_fail is used uninitialized. With that fixed,

Reviewed-by: Fabian Bieler <fabianbieler at fastmail.fm>
>  
>  		glGetActiveUniformBlockName(prog, i, sizeof(name), NULL, name);
>  
>  		glGetActiveUniformBlockiv(prog, i,
>  					  GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
>  					  &ref_vs);
> +		if (use_gs) {
> +			glGetActiveUniformBlockiv(prog, i,
> +						  GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER,
> +						  &ref_gs);
> +		}
>  		glGetActiveUniformBlockiv(prog, i,
>  					  GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,
>  					  &ref_fs);
>  
> -		printf("%10s: %d %d", name, ref_vs, ref_fs);
> -
> -		if (strcmp(name, "vs") == 0) {
> -			if (!ref_vs || ref_fs) {
> -				printf(" FAIL");
> -				pass = false;
> -			}
> -		} else if (strcmp(name, "fs") == 0) {
> -			if (ref_vs || !ref_fs) {
> -				printf(" FAIL");
> -				pass = false;
> -			}
> -		} else if (strcmp(name, "vsfs") == 0) {
> -			if (!ref_vs || !ref_fs) {
> -				printf(" FAIL");
> -				pass = false;
> -			}
> -		} else {
> +		printf("%10s: %d %d %d", name, ref_vs, ref_gs, ref_fs);
> +
> +		block_fail = block_fail || ((strstr(name, "vs") != 0) != ref_vs);
> +		if (use_gs) {
> +			block_fail = block_fail || ((strstr(name, "gs") != 0) !=
> +						    ref_gs);
> +		}
> +		block_fail = block_fail || ((strstr(name, "fs") != 0) != ref_fs);
> +
> +		if (block_fail) {
>  			printf(" FAIL");
>  			pass = false;
>  		}
> 



More information about the Piglit mailing list