[virglrenderer-devel] [PATCH] vrend_shader: emit shadow mask and offset with sampler ranges

Gurchetan Singh gurchetansingh at chromium.org
Wed Jun 27 03:51:23 UTC 2018


This patch refactors the sampler declaration so sampler ranges can work
with shadow textures.

Fixes a bunch of non-compute related dEQP-GLES31.functional.shaders.opaque_type_indexing.*
tests.

Example test cases:
   dEQP-GLES31.functional.shaders.opaque_type_indexing.sampler.uniform.vertex.sampler2dshadow
   dEQP-GLES31.functional.shaders.opaque_type_indexing.sampler.dynamically_uniform.tessellation_control.samplercubearrayshadow
   dEQP-GLES31.functional.shaders.opaque_type_indexing.sampler.dynamically_uniform.tessellation_evaluation.samplercubearrayshadow
   dEQP-GLES31.functional.shaders.opaque_type_indexing.sampler.uniform.geometry.sampler2dshadow
---
 src/vrend_shader.c | 81 ++++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 43 deletions(-)

diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index f1a20cf96f..3eb5b6b4b2 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -3406,6 +3406,39 @@ 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;
+
+   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;
@@ -3787,57 +3820,19 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
 
    if (ctx->info.indirect_files & (1 << TGSI_FILE_SAMPLER)) {
       for (i = 0; i < ctx->num_sampler_arrays; i++) {
-         int is_shad = 0;
-         const char *stc;
-         stc = vrend_shader_samplertypeconv(ctx->sampler_arrays[i].sview_type, &is_shad);
-         if (!stc)
-            continue;
-         snprintf(buf, 255, "uniform %csampler%s %ssamp%d[%d];\n",
-                  get_return_type_prefix(ctx->sampler_arrays[i].sview_rtype),
-                  stc, sname, ctx->sampler_arrays[i].idx,
-                  ctx->sampler_arrays[i].last - ctx->sampler_arrays[i].first);
-         STRCAT_WITH_RET(glsl_hdr, buf);
+         uint32_t range = ctx->sampler_arrays[i].last - ctx->sampler_arrays[i].first;
+         emit_sampler_declaration(ctx, glsl_hdr, i, range, ctx->sampler_arrays[i].sview_type,
+                                  ctx->sampler_arrays[i].sview_rtype);
       }
    } 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);
-         }
+         emit_sampler_declaration(ctx, glsl_hdr, i, 0, ctx->samplers[i].tgsi_sampler_type,
+                                  ctx->samplers[i].tgsi_sampler_return);
       }
    }
    if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT &&
-- 
2.18.0.rc2.346.g013aa6912e-goog



More information about the virglrenderer-devel mailing list