[Piglit] [PATCH] Add geometry shader support to texelFetch and textureSize tests.

Fabian Bieler fabianbieler at fastmail.fm
Mon Jun 24 15:45:12 PDT 2013


Reviewed-by: Fabian Bieler <fabianbieler at fastmail.fm>

On 2013-06-24 18:12, Paul Berry wrote:
> v2: Address both texelFetch and textureSize in a single patch, since
> they're commingled in all.tests.
> ---
>  tests/all.tests                       | 10 ++---
>  tests/texturing/shaders/common.c      |  3 ++
>  tests/texturing/shaders/texelFetch.c  | 69 ++++++++++++++++++++++++++++++++--
>  tests/texturing/shaders/textureSize.c | 71 ++++++++++++++++++++++++++++++++---
>  4 files changed, 140 insertions(+), 13 deletions(-)
> 
> diff --git a/tests/all.tests b/tests/all.tests
> index 9c928a0..6a1e242 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -835,7 +835,7 @@ import_glsl_parser_tests(spec['glsl-1.30'],
>  spec['glsl-1.30']['execution'] = Group()
>  
>  textureSize_samplers_130 = ['sampler1D', 'sampler2D', 'sampler3D', 'samplerCube', 'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow', 'sampler1DArray', 'sampler2DArray', 'sampler1DArrayShadow', 'sampler2DArrayShadow', 'isampler1D', 'isampler2D', 'isampler3D', 'isamplerCube', 'isampler1DArray', 'isampler2DArray', 'usampler1D', 'usampler2D', 'usampler3D', 'usamplerCube', 'usampler1DArray', 'usampler2DArray']
> -for stage in ['vs', 'fs']:
> +for stage in ['vs', 'gs', 'fs']:
>  	# textureSize():
>  	for sampler in textureSize_samplers_130:
>  		spec['glsl-1.30/execution/textureSize/' + stage + '-textureSize-' + sampler] = concurrent_test('textureSize ' + stage + ' ' + sampler)
> @@ -882,7 +882,7 @@ add_shader_test_dir(spec['glsl-1.40'],
>  spec['glsl-1.40']['execution']['tf-no-position'] = concurrent_test('glsl-1.40-tf-no-position')
>  
>  textureSize_samplers_140 = textureSize_samplers_130 + ['sampler2DRect', 'isampler2DRect', 'sampler2DRectShadow', 'samplerBuffer', 'isamplerBuffer', 'usamplerBuffer']
> -for stage in ['vs', 'fs']:
> +for stage in ['vs', 'gs', 'fs']:
>  	# textureSize():
>  	for sampler in textureSize_samplers_140:
>  		spec['glsl-1.40/execution/textureSize/' + stage + '-textureSize-' + sampler] = concurrent_test('textureSize 140 ' + stage + ' ' + sampler)
> @@ -935,7 +935,7 @@ for sample_count in MSAA_SAMPLE_COUNTS:
>      spec['ARB_texture_multisample/fb-completeness/%d' % (sample_count,)] = \
>          concurrent_test('arb_texture_multisample-fb-completeness %d' % (sample_count,))
>      # texel-fetch execution
> -    for stage in ['vs','fs']:
> +    for stage in ['vs', 'gs', 'fs']:
>          for sampler in samplers_atm:
>                  spec['ARB_texture_multisample/texelFetch/%d-%s-%s' % (
>                      sample_count, stage, sampler)] = \
> @@ -950,7 +950,7 @@ add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mas
>  add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution')
>  add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution -tex')
>  add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-negative-max-samples')
> -for stage in ['vs', 'fs']:
> +for stage in ['vs', 'gs', 'fs']:
>  	# textureSize():
>  	for sampler in samplers_atm:
>  		spec['ARB_texture_multisample/textureSize/' + stage + '-textureSize-' + sampler] = concurrent_test('textureSize ' + stage + ' ' + sampler)
> @@ -1794,7 +1794,7 @@ textureSize_samplers_atcma = ['samplerCubeArray', 'isamplerCubeArray', 'usampler
>  import_glsl_parser_tests(arb_texture_cube_map_array,
>  			 os.path.join(testsDir, 'spec', 'arb_texture_cube_map_array'),
>  			 ['compiler'])
> -for stage in ['vs', 'fs']:
> +for stage in ['vs', 'gs', 'fs']:
>  	# textureSize():
>  	for sampler in textureSize_samplers_atcma:
>  		spec['ARB_texture_cube_map_array/textureSize/' + stage + '-textureSize-' + sampler] = concurrent_test('textureSize ' + stage + ' ' + sampler)
> diff --git a/tests/texturing/shaders/common.c b/tests/texturing/shaders/common.c
> index 0b13d47..dba578a 100644
> --- a/tests/texturing/shaders/common.c
> +++ b/tests/texturing/shaders/common.c
> @@ -333,6 +333,9 @@ require_GL_features(enum shader_target test_stage)
>  
>  	piglit_require_GLSL_version(shader_version);
>  
> +	if (test_stage == GS)
> +		piglit_require_extension("GL_ARB_geometry_shader4");
> +
>  	if (swizzling)
>  		piglit_require_extension("GL_EXT_texture_swizzle");
>  
> diff --git a/tests/texturing/shaders/texelFetch.c b/tests/texturing/shaders/texelFetch.c
> index ebfdfe0..71f2b5e 100644
> --- a/tests/texturing/shaders/texelFetch.c
> +++ b/tests/texturing/shaders/texelFetch.c
> @@ -33,7 +33,7 @@
>   * ./bin/texelFetch usampler3D vs
>   *
>   * The test covers:
> - * - All pipeline stages (VS, FS)
> + * - All pipeline stages (VS, GS, FS)
>   * - Integer and floating point texture formats
>   * - Sampler dimensionality (1D, 2D, 3D, 1DArray, 2DArray)
>   * - Mipmapping
> @@ -556,9 +556,10 @@ coordinate_size()
>  int
>  generate_GLSL(enum shader_target test_stage)
>  {
> -	int vs, fs, prog;
> +	int vs, gs, fs, prog;
>  
>  	static char *vs_code;
> +	static char *gs_code = NULL;
>  	static char *fs_code;
>  	const char *offset_func, *offset_arg;
>  
> @@ -621,6 +622,52 @@ generate_GLSL(enum shader_target test_stage)
>  			 shader_version,
>  			 sampler.return_type);
>  		break;
> +	case GS:
> +		asprintf(&vs_code,
> +			 "#version %d\n"
> +			 "in vec4 pos;\n"
> +			 "in ivec4 texcoord;\n"
> +			 "flat out ivec4 texcoord_to_gs;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    texcoord_to_gs = texcoord;\n"
> +			 "    gl_Position = pos;\n"
> +			 "}\n",
> +			 shader_version);
> +		asprintf(&gs_code,
> +			 "#version %d\n"
> +			 "#extension GL_ARB_geometry_shader4: require\n"
> +			 "%s\n"
> +			 "#define ivec1 int\n"
> +			 "flat out %s color;\n"
> +			 "flat in ivec4 texcoord_to_gs[1];\n"
> +			 "uniform %s tex;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    ivec4 texcoord = texcoord_to_gs[0];\n"
> +			 "    color = texelFetch%s(tex, ivec%d(texcoord)%s%s);\n"
> +			 "    gl_Position = gl_PositionIn[0];\n"
> +			 "    EmitVertex();\n"
> +			 "}\n",
> +			 shader_version,
> +			 has_samples() ? "#extension GL_ARB_texture_multisample: require" : "",
> +			 sampler.return_type, sampler.name,
> +			 offset_func,
> +			 coordinate_size(),
> +			 ((sampler.target == GL_TEXTURE_RECTANGLE) ?
> +			  "" : ", texcoord.w"),
> +			 offset_arg);
> +		asprintf(&fs_code,
> +			 "#version %d\n"
> +			 "flat in %s color;\n"
> +			 "uniform vec4 divisor;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    gl_FragColor = vec4(color)/divisor;\n"
> +			 "}\n",
> +			 shader_version,
> +			 sampler.return_type);
> +		break;
>  	case FS:
>  		asprintf(&vs_code,
>  			 "#version %d\n"
> @@ -665,6 +712,13 @@ generate_GLSL(enum shader_target test_stage)
>  		printf("VS code:\n%s", vs_code);
>  		piglit_report_result(PIGLIT_FAIL);
>  	}
> +	if (gs_code) {
> +		gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_code);
> +		if (!gs) {
> +			printf("GS code:\n%s", gs_code);
> +			piglit_report_result(PIGLIT_FAIL);
> +		}
> +	}
>  	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
>  	if (!fs) {
>  		printf("FS code:\n%s", fs_code);
> @@ -672,6 +726,12 @@ generate_GLSL(enum shader_target test_stage)
>  	}
>  	prog = glCreateProgram();
>  	glAttachShader(prog, vs);
> +	if (gs_code) {
> +		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);
> +	}
>  	glAttachShader(prog, fs);
>  
>  	glBindAttribLocation(prog, pos_loc, "pos");
> @@ -718,7 +778,7 @@ supported_sampler()
>  void
>  fail_and_show_usage()
>  {
> -	printf("Usage: texelFetch [140] [offset] <vs|fs> <sampler type> "
> +	printf("Usage: texelFetch [140] [offset] <vs|gs|fs> <sampler type> "
>  	       "[sample_count] [swizzle] [piglit args...]\n");
>  	piglit_report_result(PIGLIT_FAIL);
>  }
> @@ -738,6 +798,9 @@ piglit_init(int argc, char **argv)
>  			if (strcmp(argv[i], "vs") == 0) {
>  				test_stage = VS;
>  				continue;
> +			} else if (strcmp(argv[i], "gs") == 0) {
> +				test_stage = GS;
> +				continue;
>  			} else if (strcmp(argv[i], "fs") == 0) {
>  				test_stage = FS;
>  				continue;
> diff --git a/tests/texturing/shaders/textureSize.c b/tests/texturing/shaders/textureSize.c
> index 999f794..05187a3 100644
> --- a/tests/texturing/shaders/textureSize.c
> +++ b/tests/texturing/shaders/textureSize.c
> @@ -27,7 +27,7 @@
>   * Tests the GLSL 1.30+ textureSize() built-in function.
>   *
>   * The test covers:
> - * - All pipeline stages (VS, FS)
> + * - All pipeline stages (VS, GS, FS)
>   * - Sampler data types (floating point, signed integer, unsigned integer)
>   * - Sampler dimensionality (1D, 2D, 3D, Cube, 1DArray, 2DArray)
>   * - Color and shadow samplers
> @@ -235,9 +235,11 @@ has_lod(void)
>  int
>  generate_GLSL(enum shader_target test_stage)
>  {
> -	int vs, fs;
> +	int vs, gs, fs;
> +	int prog;
>  
>  	static char *vs_code;
> +	static char *gs_code = NULL;
>  	static char *fs_code;
>  	char *lod_arg;
>  	static const char *zeroes[3] = { "", "0, ", "0, 0, " };
> @@ -276,6 +278,44 @@ generate_GLSL(enum shader_target test_stage)
>  			 "}\n",
>  			 shader_version, size, zeroes[3 - size]);
>  		break;
> +	case GS:
> +		asprintf(&vs_code,
> +			 "#version %d\n"
> +			 "in vec4 vertex;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    gl_Position = vertex;\n"
> +			 "}\n",
> +			 shader_version);
> +		asprintf(&gs_code,
> +			 "#version %d\n"
> +			 "#extension GL_ARB_geometry_shader4: require\n"
> +			 "%s\n"
> +			 "#define ivec1 int\n"
> +			 "uniform int lod;\n"
> +			 "uniform %s tex;\n"
> +			 "flat out ivec%d size;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    for (int i = 0; i < 3; i++) {\n"
> +			 "        size = textureSize(tex%s);\n"
> +			 "        gl_Position = gl_PositionIn[i];\n"
> +			 "        EmitVertex();\n"
> +			 "    }\n"
> +			 "}\n",
> +			 shader_version, extension, sampler.name, size,
> +			 lod_arg);
> +		asprintf(&fs_code,
> +			 "#version %d\n"
> +			 "#define ivec1 int\n"
> +			 "#define vec1 float\n"
> +			 "flat in ivec%d size;\n"
> +			 "void main()\n"
> +			 "{\n"
> +			 "    gl_FragColor = vec4(0.01 * size,%s 1);\n"
> +			 "}\n",
> +			 shader_version, size, zeroes[3 - size]);
> +		break;
>  	case FS:
>  		asprintf(&vs_code,
>  			 "#version %d\n"
> @@ -304,18 +344,36 @@ generate_GLSL(enum shader_target test_stage)
>  	}
>  
>  	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
> +	if (gs_code) {
> +		gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_code);
> +	}
>  	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
>  
> -	if (!vs || !fs)
> +	if (!vs || (gs_code && !gs) || !fs)
>  		return 0;
>  
> -	return piglit_link_simple_program(vs, fs);
> +	prog = glCreateProgram();
> +	glAttachShader(prog, vs);
> +	if (gs_code) {
> +		glAttachShader(prog, gs);
> +		glProgramParameteri(prog, GL_GEOMETRY_INPUT_TYPE_ARB,
> +				    GL_TRIANGLES);
> +		glProgramParameteri(prog, GL_GEOMETRY_OUTPUT_TYPE_ARB,
> +				    GL_TRIANGLE_STRIP);
> +		glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB, 3);
> +	}
> +	glAttachShader(prog, fs);
> +	glLinkProgram(prog);
> +	if (!piglit_link_check_status(prog))
> +		piglit_report_result(PIGLIT_FAIL);
> +
> +	return prog;
>  }
>  
>  void
>  fail_and_show_usage()
>  {
> -	printf("Usage: textureSize [140] <vs|fs> <sampler type> [piglit args...]\n");
> +	printf("Usage: textureSize [140] <vs|gs|fs> <sampler type> [piglit args...]\n");
>  	piglit_report_result(PIGLIT_SKIP);
>  }
>  
> @@ -334,6 +392,9 @@ piglit_init(int argc, char **argv)
>  			if (strcmp(argv[i], "vs") == 0) {
>  				test_stage = VS;
>  				continue;
> +			} else if (strcmp(argv[i], "gs") == 0) {
> +				test_stage = GS;
> +				continue;
>  			} else if (strcmp(argv[i], "fs") == 0) {
>  				test_stage = FS;
>  				continue;
> 



More information about the Piglit mailing list