[Mesa-dev] [PATCH] meta: Use a #define for the vector type to avoid %svec4 everywhere.

Ian Romanick idr at freedesktop.org
Mon Feb 24 09:29:33 PST 2014


On 02/21/2014 07:15 PM, Kenneth Graunke wrote:
> By adding "#define gvec4 %svec4" to the top of our fragment shader, we
> can write generic code without needing to specialize it to vec4, ivec4,
> or uvec4 via asprintf.
>
> This also makes the INT and UNSIGNED_INT merge function code identical,
> so I combined those two cases.
>
> It's not a big savings, but a little bit tidier.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>   src/mesa/drivers/common/meta_blit.c | 17 +++++++----------
>   1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
> index 69c2590..f9c8814 100644
> --- a/src/mesa/drivers/common/meta_blit.c
> +++ b/src/mesa/drivers/common/meta_blit.c
> @@ -228,12 +228,9 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
>            sample_resolve = ralloc_asprintf(mem_ctx, "   out_color = texelFetch(texSampler, ivec2(texCoords), gl_SampleID);");
>            merge_function = "";
>         } else {
> -         if (src_datatype == GL_INT) {
> +         if (src_datatype == GL_INT || src_datatype == GL_UNSIGNED_INT) {
>               merge_function =
> -               "ivec4 merge(ivec4 a, ivec4 b) { return (a >> ivec4(1)) + (b >> ivec4(1)) + (a & b & ivec4(1)); }\n";
> -         } else if (src_datatype == GL_UNSIGNED_INT) {
> -            merge_function =
> -               "uvec4 merge(uvec4 a, uvec4 b) { return (a >> uvec4(1)) + (b >> uvec4(1)) + (a & b & uvec4(1)); }\n";
> +               "gvec4 merge(gvec4 a, gvec4 b) { return (a >> gvec4(1)) + (b >> gvec4(1)) + (a & b & gvec4(1)); }\n";
>            } else {
>               /* The divide will happen at the end for floats. */
>               merge_function =
> @@ -254,8 +251,8 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
>            sample_resolve = rzalloc_size(mem_ctx, 1);
>            for (int i = 0; i < samples; i++) {
>               ralloc_asprintf_append(&sample_resolve,
> -                                   "   %svec4 sample_1_%d = texelFetch(texSampler, ivec2(texCoords), %d);\n",
> -                                   vec4_prefix, i, i);
> +                                   "   gvec4 sample_1_%d = texelFetch(texSampler, ivec2(texCoords), %d);\n",
> +                                   i, i);
>            }
>            /* Now, merge each pair of samples, then merge each pair of those,
>             * etc.
> @@ -263,8 +260,7 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
>            for (int step = 2; step <= samples; step *= 2) {
>               for (int i = 0; i < samples; i += step) {
>                  ralloc_asprintf_append(&sample_resolve,
> -                                      "   %svec4 sample_%d_%d = merge(sample_%d_%d, sample_%d_%d);\n",
> -                                      vec4_prefix,
> +                                      "   gvec4 sample_%d_%d = merge(sample_%d_%d, sample_%d_%d);\n",
>                                         step, i,
>                                         step / 2, i,
>                                         step / 2, i + step / 2);
> @@ -297,9 +293,10 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
>                                     "#version 130\n"
>                                     "#extension GL_ARB_texture_multisample : enable\n"
>                                     "%s\n"
> +                                  "#define gvec4 %svec4\n"
>                                     "uniform %ssampler2DMS texSampler;\n"
>                                     "in vec2 texCoords;\n"
> -                                  "out %svec4 out_color;\n"
> +                                  "out gvec4 out_color;\n"
>                                     "\n"
>                                     "%s" /* merge_function */
>                                     "void main()\n"
>



More information about the mesa-dev mailing list