[virglrenderer-devel] [PATCH 1/2] vrend_shader: split out sampler declaration emission logic

Dave Airlie airlied at gmail.com
Tue Jul 3 03:49:30 UTC 2018


On 29 June 2018 at 13:31, Gurchetan Singh <gurchetansingh at chromium.org> wrote:
> Sampler arrays don't work with shadow textures. Let's have a
> separate emission function that we can use with sampler arrays and
> normal samplers.

I've just sent out a patch to refactor the first step like I'd want to
see it, it just moves
the code without changing it.

Dave.
>
> v2: Split out in separate function, initialize shadow variable to
>     zero
> ---
>  src/vrend_shader.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/src/vrend_shader.c b/src/vrend_shader.c
> index f7bf853c46..f0dc49cbbf 100644
> --- a/src/vrend_shader.c
> +++ b/src/vrend_shader.c
> @@ -3409,6 +3409,40 @@ static char get_return_type_prefix(enum tgsi_return_type type)
>     return ' ';
>  }
>
> +/* i represents the i-th sampler array or i-th sampler. */
> +static void emit_sampler_declaration(struct dump_ctx *ctx, char *glsl_hdr, uint32_t i,
> +                                     uint32_t range, uint32_t texture_type, uint32_t return_type)
> +{
> +   int shadow;
> +   char buf[255], ret_type;
> +   const char *sname, *precision, *tex_type;
> +
> +   shadow = 0;
> +   sname = tgsi_proc_to_prefix(ctx->prog_type);
> +   precision = (ctx->cfg->use_gles) ? "highp " : " ";
> +
> +   tex_type = vrend_shader_samplertypeconv(texture_type, &shadow);
> +   ret_type = vrend_shader_samplerreturnconv(return_type);
> +
> +   /* GLES does not support 1D textures -- we use a 2D texture and set the parameter set to 0.5 */
> +   if (ctx->cfg->use_gles && texture_type == TGSI_TEXTURE_1D)
> +      snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ret_type, sname, i);
> +   else if (range)
> +      snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d[%d];\n", precision, ret_type, tex_type, sname, i, range);
> +   else
> +      snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ret_type, tex_type, sname, i);
> +
> +   strcat_realloc(glsl_hdr, buf);
> +
> +   if (shadow) {
> +      snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision, sname, i);
> +      strcat_realloc(glsl_hdr, buf);
> +      snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision, sname, i);
> +      strcat_realloc(glsl_hdr, buf);
> +      ctx->shadow_samp_mask |= (1 << i);
> +   }
> +}
> +
>  static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
>  {
>     uint32_t i;
> --
> 2.18.0.rc2.346.g013aa6912e-goog
>
> _______________________________________________
> 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