[virglrenderer-devel] [PATCH 12/21] tessellation: add clip distance support.

Dave Airlie airlied at gmail.com
Mon Jun 11 05:11:03 UTC 2018


From: Dave Airlie <airlied at redhat.com>

This changes the swizzled clip distance emit to allow for reading
from outputs, which will be used in a later patch
---
 src/vrend_shader.c | 63 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 8710a85..c5948c4 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -628,7 +628,9 @@ iter_declaration(struct tgsi_iterate_context *iter,
          }
          /* fallthrough */
       case TGSI_SEMANTIC_CLIPDIST:
-         if (iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY) {
+         if (iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY ||
+             iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL ||
+             iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL) {
             name_prefix = "gl_ClipDistance";
             ctx->inputs[i].glsl_predefined_no_emit = true;
             ctx->inputs[i].glsl_no_index = true;
@@ -763,8 +765,10 @@ iter_declaration(struct tgsi_iterate_context *iter,
          ctx->outputs[i].glsl_no_index = true;
          ctx->num_clip_dist += 4;
          if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX &&
-             ctx->key->gs_present)
+             (ctx->key->gs_present || ctx->key->tcs_present))
             require_glsl_ver(ctx, 150);
+         if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL)
+            ctx->outputs[i].glsl_gl_block = true;
          break;
       case TGSI_SEMANTIC_CLIPVERTEX:
          name_prefix = "gl_ClipVertex";
@@ -1306,9 +1310,13 @@ static int emit_clip_dist_movs(struct dump_ctx *ctx)
    char *sret;
    bool has_prop = (ctx->num_clip_dist_prop + ctx->num_cull_dist_prop) > 0;
    int ndists;
+   const char *prefix="";
+
+   if (ctx->prog_type == PIPE_SHADER_TESS_CTRL)
+      prefix = "gl_out[gl_InvocationID].";
    if (ctx->num_clip_dist == 0 && ctx->key->clip_plane_enable) {
       for (i = 0; i < 8; i++) {
-         snprintf(buf, 255, "gl_ClipDistance[%d] = dot(%s, clipp[%d]);\n", i, ctx->has_clipvertex ? "clipv_tmp" : "gl_Position", i);
+         snprintf(buf, 255, "%sgl_ClipDistance[%d] = dot(%s, clipp[%d]);\n", prefix, i, ctx->has_clipvertex ? "clipv_tmp" : "gl_Position", i);
          sret = add_str_to_glsl_main(ctx, buf);
          if (!sret)
             return ENOMEM;
@@ -1336,7 +1344,7 @@ static int emit_clip_dist_movs(struct dump_ctx *ctx)
             is_cull = true;
       }
       const char *clip_cull = is_cull ? "Cull" : "Clip";
-      snprintf(buf, 255, "gl_%sDistance[%d] = clip_dist_temp[%d].%c;\n", clip_cull,
+      snprintf(buf, 255, "%sgl_%sDistance[%d] = clip_dist_temp[%d].%c;\n", prefix, clip_cull,
                is_cull ? i - ctx->num_clip_dist_prop : i, clipidx, wm);
       sret = add_str_to_glsl_main(ctx, buf);
       if (!sret)
@@ -1896,8 +1904,8 @@ static void
 create_swizzled_clipdist(struct dump_ctx *ctx,
                          char *result,
                          const struct tgsi_full_src_register *src,
-                         int input_idx,
-                         bool gl_in,
+                         int sid,
+                         int direction,
                          const char *stypeprefix,
                          const char *prefix,
                          const char *arrayname)
@@ -1908,8 +1916,8 @@ create_swizzled_clipdist(struct dump_ctx *ctx,
    int num_culls = has_prev_vals ? ctx->key->prev_stage_num_cull_out : 0;
    int num_clips = has_prev_vals ? ctx->key->prev_stage_num_clip_out : ctx->num_in_clip_dist;
    for (unsigned cc = 0; cc < 4; cc++) {
-      const char *cc_name = ctx->inputs[input_idx].glsl_name;
-      idx = ctx->inputs[input_idx].sid * 4;
+      const char *cc_name = "gl_ClipDistance";
+      idx = sid * 4;
       if (cc == 0)
          idx += src->Register.SwizzleX;
       else if (cc == 1)
@@ -1932,8 +1940,10 @@ create_swizzled_clipdist(struct dump_ctx *ctx,
             if (idx >= ctx->key->prev_stage_num_clip_out)
                idx = 0;
       }
-      if (gl_in)
+      if (direction == -1)
          snprintf(clipdistvec[cc], 64, "%sgl_in%s.%s[%d]", prefix, arrayname, cc_name, idx);
+      else if (direction == 1)
+         snprintf(clipdistvec[cc], 64, "%sgl_out%s.%s[%d]", prefix, arrayname, cc_name, idx);
       else
          snprintf(clipdistvec[cc], 64, "%s%s%s[%d]", prefix, arrayname, cc_name, idx);
    }
@@ -2176,7 +2186,7 @@ get_source_info(struct dump_ctx *ctx,
                else if (ctx->inputs[j].glsl_gl_block) {
                   /* GS input clipdist requires a conversion */
                   if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) {
-                     create_swizzled_clipdist(ctx, srcs[i], src, j, true, get_string(stypeprefix), prefix, arrayname);
+                     create_swizzled_clipdist(ctx, srcs[i], src, ctx->inputs[j].sid, -1, get_string(stypeprefix), prefix, arrayname);
                   } else {
                      snprintf(srcs[i], 255, "%s(vec4(%sgl_in%s.%s)%s)", get_string(stypeprefix), prefix, arrayname, ctx->inputs[j].glsl_name, swizzle);
                   }
@@ -2186,7 +2196,7 @@ get_source_info(struct dump_ctx *ctx,
                else if (ctx->inputs[j].name == TGSI_SEMANTIC_FACE)
                   snprintf(srcs[i], 255, "%s(%s ? 1.0 : -1.0)", get_string(stypeprefix), ctx->inputs[j].glsl_name);
                else if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) {
-                  create_swizzled_clipdist(ctx, srcs[i], src, j, false, get_string(stypeprefix), prefix, arrayname);
+                  create_swizzled_clipdist(ctx, srcs[i], src, j, 0, get_string(stypeprefix), prefix, arrayname);
                } else {
                   enum vrend_type_qualifier srcstypeprefix = stypeprefix;
                   if (stype == TGSI_TYPE_UNSIGNED &&
@@ -2826,6 +2836,13 @@ iter_instruction(struct tgsi_iterate_context *iter,
          if (handle_vertex_proc_exit(ctx) == FALSE)
             return FALSE;
       } else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL) {
+         ret = emit_clip_dist_movs(ctx);
+         if (ret)
+            return FALSE;
+      } else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL) {
+         ret = emit_clip_dist_movs(ctx);
+         if (ret)
+            return FALSE;
          if (!ctx->key->gs_present) {
             ret = emit_prescale(ctx);
             if (ret)
@@ -3356,6 +3373,30 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
       }
    }
 
+   if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) {
+      if (ctx->num_in_clip_dist || ctx->key->prev_stage_pervertex_out) {
+         int clip_dist, cull_dist;
+         char clip_var[64] = {}, cull_var[64] = {};
+
+         clip_dist = ctx->key->prev_stage_num_clip_out ? ctx->key->prev_stage_num_clip_out : ctx->num_in_clip_dist;
+         cull_dist = ctx->key->prev_stage_num_cull_out;
+
+         if (clip_dist)
+            snprintf(clip_var, 64, "float gl_ClipDistance[%d];\n", clip_dist);
+         if (cull_dist)
+            snprintf(cull_var, 64, "float gl_CullDistance[%d];\n", cull_dist);
+
+         snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s} gl_in[];\n", clip_var, cull_var);
+         STRCAT_WITH_RET(glsl_hdr, buf);
+      }
+      if (ctx->num_clip_dist) {
+         snprintf(buf, 255, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n float gl_ClipDistance[%d];\n} gl_out[];\n", ctx->num_clip_dist ? ctx->num_clip_dist : 8);
+         STRCAT_WITH_RET(glsl_hdr, buf);
+         snprintf(buf, 255, "vec4 clip_dist_temp[2];\n");
+         STRCAT_WITH_RET(glsl_hdr, buf);
+      }
+   }
+
    if (ctx->so) {
       char outtype[6] = {0};
       for (i = 0; i < ctx->so->num_outputs; i++) {
-- 
2.14.3



More information about the virglrenderer-devel mailing list