[virglrenderer-devel] [PATCH] shader: refactor sampler emission.

Elie Tournier tournier.elie at gmail.com
Tue Jul 3 09:35:05 UTC 2018


On Tue, Jul 03, 2018 at 01:48:39PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This just moves the code to a function, it doesn't change any
> of the expected code. It should make it easier to spot fixes.
With the small nit:
Reviewed-by: Elie Tournier <elie.tournier at collabora.com>
> ---
>  src/vrend_shader.c | 76 ++++++++++++++++++++++++++--------------------
>  1 file changed, 43 insertions(+), 33 deletions(-)
> 
> diff --git a/src/vrend_shader.c b/src/vrend_shader.c
> index f7bf853..f22eae7 100644
> --- a/src/vrend_shader.c
> +++ b/src/vrend_shader.c
> @@ -3409,6 +3409,46 @@ static char get_return_type_prefix(enum tgsi_return_type type)
>     return ' ';
>  }
>  
> +static void *emit_sampler_decleration(struct dump_ctx *ctx, char *glsl_hdr,
s/decleration/declaration/
English is not my mother tongue so I'm maybe wrong. ;)
> +                                      uint32_t i)
> +{
> +   char buf[255];
> +   int is_shad = 0;
> +   const char *stc;
> +   char ptc;
> +   const char *sname;
> +   const char *precision;
> +
> +   ptc = vrend_shader_samplerreturnconv(ctx->samplers[i].tgsi_sampler_return);
> +   stc = vrend_shader_samplertypeconv(ctx->samplers[i].tgsi_sampler_type, &is_shad);
> +
> +   sname = tgsi_proc_to_prefix(ctx->prog_type);
> +
> +   if (ctx->cfg->use_gles) {
> +      precision = "highp ";
> +   } else {
> +      precision = " ";
> +   }
> +
> +   /* OpenGL ES do not support 1D texture
> +    * so we use a 2D texture with a parameter set to 0.5
> +    */
> +   if (ctx->cfg->use_gles && !strcmp(stc, "1D"))
> +      snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
> +   else
> +      snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision,  ptc, stc, sname, i);
> +
> +   STRCAT_WITH_RET(glsl_hdr, buf);
> +   if (is_shad) {
> +      snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision,  sname, i);
> +      STRCAT_WITH_RET(glsl_hdr, buf);
> +      snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision,  sname, i);
> +      STRCAT_WITH_RET(glsl_hdr, buf);
> +      ctx->shadow_samp_mask |= (1 << i);
> +   }
> +   return glsl_hdr;
> +}
> +
>  static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
>  {
>     uint32_t i;
> @@ -3804,43 +3844,13 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
>     } else {
>        nsamp = util_last_bit(ctx->samplers_used);
>        for (i = 0; i < nsamp; i++) {
> -         int is_shad = 0;
> -         const char *stc;
> -         char ptc;
>  
>           if ((ctx->samplers_used & (1 << i)) == 0)
>              continue;
>  
> -         const char *sname;
> -         const char *precision;
> -
> -         ptc = vrend_shader_samplerreturnconv(ctx->samplers[i].tgsi_sampler_return);
> -         stc = vrend_shader_samplertypeconv(ctx->samplers[i].tgsi_sampler_type, &is_shad);
> -
> -         sname = tgsi_proc_to_prefix(ctx->prog_type);
> -
> -         if (ctx->cfg->use_gles) {
> -            precision = "highp ";
> -         } else {
> -            precision = " ";
> -         }
> -
> -         /* OpenGL ES do not support 1D texture
> -          * so we use a 2D texture with a parameter set to 0.5
> -          */
> -         if (ctx->cfg->use_gles && !strcmp(stc, "1D"))
> -            snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
> -         else
> -            snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision,  ptc, stc, sname, i);
> -
> -         STRCAT_WITH_RET(glsl_hdr, buf);
> -         if (is_shad) {
> -            snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision,  sname, i);
> -            STRCAT_WITH_RET(glsl_hdr, buf);
> -            snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision,  sname, i);
> -            STRCAT_WITH_RET(glsl_hdr, buf);
> -            ctx->shadow_samp_mask |= (1 << i);
> -         }
> +         glsl_hdr = emit_sampler_decleration(ctx, glsl_hdr, i);
ditto
> +         if (!glsl_hdr)
> +            return NULL;
>        }
>     }
>     if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT &&
> -- 
> 2.17.1
> 
> _______________________________________________
> virglrenderer-devel mailing list
> virglrenderer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel


More information about the virglrenderer-devel mailing list