[Piglit] [PATCH 4/4] Add GL_EXT_texture_swizzle support to texelFetch.
Brian Paul
brianp at vmware.com
Tue Dec 6 15:33:31 PST 2011
On 12/06/2011 02:23 PM, Kenneth Graunke wrote:
> texelFetch now takes an optional command line parameter representing the
> EXT_texture_swizzle mode. Examples include: "rgba", "b1gr", "r0rr".
>
> Making the test support arbitrary swizzling was easy enough, and seemed
> like it could be useful. However, we probably don't want to test all
> combinations of this by default, as there are far too many. So, I only
> added [iu ]sampler2DArray tests with "b0r1" swizzling to all.tests.
>
> Signed-off-by: Kenneth Graunke<kenneth at whitecape.org>
> ---
> tests/all.tests | 3 +
> tests/texturing/shaders/common.c | 77 ++++++++++++++++++++++++++++++++++
> tests/texturing/shaders/common.h | 9 ++++-
> tests/texturing/shaders/texelFetch.c | 10 ++++
> 4 files changed, 98 insertions(+), 1 deletions(-)
>
> diff --git a/tests/all.tests b/tests/all.tests
> index eb6725b..3c87550 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -890,6 +890,9 @@ for stage in ['vs', 'fs']:
> # texelFetch():
> for sampler in ['sampler1D', 'sampler2D', 'sampler3D', 'sampler1DArray', 'sampler2DArray', 'isampler1D', 'isampler2D', 'isampler3D', 'isampler1DArray', 'isampler2DArray', 'usampler1D', 'usampler2D', 'usampler3D', 'usampler1DArray', 'usampler2DArray']:
> spec['glsl-1.30']['execution']['texelFetch'][stage + '-texelFetch-' + sampler] = PlainExecTest(['texelFetch', stage, sampler, '-auto', '-fbo'])
> + # texelFetch() with EXT_texture_swizzle mode "b0r1":
> + for type in ['i', 'u', '']:
> + spec['glsl-1.30']['execution']['texelFetch'][stage + '-texelFetch-' + type + 'sampler2DArray-swizzle'] = PlainExecTest(['texelFetch', stage, type + 'sampler2DArray', 'b0r1', '-auto', '-fbo'])
>
> add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetch-2D')
> add_plain_test(spec['glsl-1.30']['execution'], 'fs-texelFetchOffset-2D')
> diff --git a/tests/texturing/shaders/common.c b/tests/texturing/shaders/common.c
> index d5cc45d..cedca89 100644
> --- a/tests/texturing/shaders/common.c
> +++ b/tests/texturing/shaders/common.c
> @@ -286,3 +286,80 @@ require_GL_features(enum shader_target test_stage)
> if (test_stage == VS&& tex_units<= 0)
> piglit_report_result(PIGLIT_SKIP);
> }
> +
> +/**
> + * Performs an in-place swizzle of a vec4 based on the EXT_texture_swizzle mode.
> + */
> +void
> +swizzle(float vec[])
> +{
> + int i;
> + float temp[4];
> +
> + memcpy(temp, vec, 4*sizeof(float));
> +
> + for (i = 0; i< 4; i++) {
> + switch (sampler.swizzle[i]) {
> + case GL_RED:
> + vec[i] = temp[0];
> + break;
> + case GL_GREEN:
> + vec[i] = temp[1];
> + break;
> + case GL_BLUE:
> + vec[i] = temp[2];
> + break;
> + case GL_ALPHA:
> + vec[i] = temp[3];
> + break;
> + case GL_ZERO:
> + vec[i] = 0.0;
> + break;
> + case GL_ONE:
> + vec[i] = 1.0;
> + break;
> + default:
> + assert(!"Should not get here.");
> + }
> + }
> +}
> +
> +/**
> + * Parse the command line argument for the EXT_texture_swizzle mode.
> + * It should be a string of length 4 consisting of r, g, b, a, 0, or 1.
> + * For example, "bgr1".
> + */
> +bool
> +parse_swizzle(const char *swiz)
> +{
> + int i;
> + if (strlen(swiz) != 4 || strspn(swiz, "rgba01") != 4)
> + return false;
> +
> + for (i = 0; i< 4; i++) {
> + switch (swiz[i]) {
> + case 'r':
> + sampler.swizzle[i] = GL_RED;
> + break;
> + case 'g':
> + sampler.swizzle[i] = GL_GREEN;
> + break;
> + case 'b':
> + sampler.swizzle[i] = GL_BLUE;
> + break;
> + case 'a':
> + sampler.swizzle[i] = GL_ALPHA;
> + break;
> + case '0':
> + sampler.swizzle[i] = GL_ZERO;
> + break;
> + case '1':
> + sampler.swizzle[i] = GL_ONE;
> + break;
> + default:
> + assert(!"Should not get here.");
> + }
> + }
> +
> + return true;
> +}
> diff --git a/tests/texturing/shaders/common.h b/tests/texturing/shaders/common.h
> index c25bf2c..456152a 100644
> --- a/tests/texturing/shaders/common.h
> +++ b/tests/texturing/shaders/common.h
> @@ -74,8 +74,13 @@ struct sampler_info
> * GL_DEPTH_COMPONENT.
> */
> GLenum internal_format;
> +
> + /** GL_EXT_texture_swizzle setting: GL_RED/GREEN/BLUE/ALPHA/ZERO/ONE */
> + int swizzle[4];
Maybe s/int/GLenum/ since you're using GLenum for the other fields.
> } sampler;
>
> +static const int default_swizzle[4] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
GLenum here too
> +
> /**
> * Which shader stage to test
> */
> @@ -94,8 +99,10 @@ bool has_slices();
> bool is_array_sampler();
> bool is_shadow_sampler();
>
> +void swizzle(float vec4[]);
> +
> void upload_miplevel_data(GLenum target, int level, void *level_image);
> void compute_miplevel_info();
> void require_GL_features(enum shader_target test_stage);
> bool select_sampler(const char *name);
> -
> +bool parse_swizzle(const char *swiz);
> diff --git a/tests/texturing/shaders/texelFetch.c b/tests/texturing/shaders/texelFetch.c
> index 34b09da..8ce4b2d 100644
> --- a/tests/texturing/shaders/texelFetch.c
> +++ b/tests/texturing/shaders/texelFetch.c
> @@ -131,6 +131,7 @@ piglit_display()
> float divisors[4];
>
> compute_divisors(l, divisors);
> + swizzle(divisors);
> glUniform4fv(divisor_loc, 1, divisors);
>
> glDrawArrays(GL_POINTS, i, points);
> @@ -249,6 +250,7 @@ generate_texture()
> glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> + glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, sampler.swizzle);
Shouldn't this call be qualified by "if (texture swizzle is supported)"?
>
> expected_colors = calloc(miplevels, sizeof(float **));
>
> @@ -295,6 +297,7 @@ generate_texture()
> expected_ptr[1] = f_ptr[1]/divisors[1];
> expected_ptr[2] = f_ptr[2]/divisors[2];
> expected_ptr[3] = 1.0;
> + swizzle(expected_ptr);
>
> f_ptr += 4;
> i_ptr += 4;
> @@ -468,6 +471,7 @@ piglit_init(int argc, char **argv)
> int i;
> enum shader_target test_stage = UNKNOWN;
> bool sampler_found = false;
> + bool swizzle_found = false;
>
> for (i = 1; i< argc; i++) {
> if (test_stage == UNKNOWN) {
> @@ -485,12 +489,18 @@ piglit_init(int argc, char **argv)
> if (!sampler_found&& (sampler_found = select_sampler(argv[i])))
> continue;
>
> + if (!swizzle_found&& (swizzle_found = parse_swizzle(argv[i])))
> + continue;
> +
> fail_and_show_usage();
> }
>
> if (test_stage == UNKNOWN || !sampler_found)
> fail_and_show_usage();
>
> + if (!swizzle_found)
> + memcpy(sampler.swizzle, default_swizzle, 4 * sizeof(int));
> +
> if (!supported_sampler()) {
> printf("%s unsupported\n", sampler.name);
> piglit_report_result(PIGLIT_FAIL);
I don't see a check if GL_EXT_texture_swizzle is supported.
-Brian
More information about the Piglit
mailing list