[virglrenderer-devel] [PATCH 2/3] shader: refactor some source info out into a struct.

Dave Airlie airlied at gmail.com
Fri Jun 1 01:40:59 UTC 2018


From: Dave Airlie <airlied at redhat.com>

This just makes things a bit cleaner before adding fp64 support
---
 src/vrend_shader.c | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 8068576..192da9a 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -1215,9 +1215,9 @@ static int emit_clip_dist_movs(struct dump_ctx *ctx)
 
 #define emit_arit_op2(op) snprintf(buf, 255, "%s = %s(%s((%s %s %s))%s);\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), srcs[0], op, srcs[1], writemask)
 #define emit_op1(op) snprintf(buf, 255, "%s = %s(%s(%s(%s))%s);\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), op, srcs[0], writemask)
-#define emit_compare(op) snprintf(buf, 255, "%s = %s(%s((%s(%s(%s), %s(%s))))%s);\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), op, get_string(svec4), srcs[0], get_string(svec4), srcs[1], writemask)
+#define emit_compare(op) snprintf(buf, 255, "%s = %s(%s((%s(%s(%s), %s(%s))))%s);\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), op, get_string(sinfo.svec4), srcs[0], get_string(sinfo.svec4), srcs[1], writemask)
 
-#define emit_ucompare(op) snprintf(buf, 255, "%s = %s(uintBitsToFloat(%s(%s(%s(%s), %s(%s))%s) * %s(0xffffffff)));\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.udstconv), op, get_string(svec4), srcs[0], get_string(svec4), srcs[1], writemask, get_string(dinfo.udstconv))
+#define emit_ucompare(op) snprintf(buf, 255, "%s = %s(uintBitsToFloat(%s(%s(%s(%s), %s(%s))%s) * %s(0xffffffff)));\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.udstconv), op, get_string(sinfo.svec4), srcs[0], get_string(sinfo.svec4), srcs[1], writemask, get_string(dinfo.udstconv))
 
 static int emit_buf(struct dump_ctx *ctx, const char *buf)
 {
@@ -1876,12 +1876,18 @@ get_destination_info(struct dump_ctx *ctx,
    return 0;
 }
 
+struct source_info {
+   enum vrend_type_qualifier svec4;
+   int sreg_index;
+   bool tg4_has_component;
+   bool override_no_wm[3];
+};
+
 static int
 get_source_info(struct dump_ctx *ctx,
                 const struct tgsi_full_instruction *inst,
-                enum vrend_type_qualifier *svec4, int *sreg_index,
-                char srcs[3][255], char src_swizzle0[10],
-                bool *tg4_has_component, bool *override_no_wm)
+                struct source_info *sinfo,
+                char srcs[3][255], char src_swizzle0[10])
 {
    bool stprefix = false;
 
@@ -1894,12 +1900,12 @@ get_source_info(struct dump_ctx *ctx,
    switch (stype) {
    case TGSI_TYPE_UNSIGNED:
       stypeprefix = FLOAT_BITS_TO_UINT;
-      *svec4 = UVEC4;
+      sinfo->svec4 = UVEC4;
       stprefix = true;
       break;
    case TGSI_TYPE_SIGNED:
       stypeprefix = FLOAT_BITS_TO_INT;
-      *svec4 = IVEC4;
+      sinfo->svec4 = IVEC4;
       stprefix = true;
       break;
    default:
@@ -1914,7 +1920,7 @@ get_source_info(struct dump_ctx *ctx,
       int swz_idx = 0, pre_idx = 0;
       boolean isabsolute = src->Register.Absolute;
 
-      override_no_wm[i] = false;
+      sinfo->override_no_wm[i] = false;
       if (isabsolute)
          swizzle[swz_idx++] = ')';
 
@@ -1978,7 +1984,7 @@ get_source_info(struct dump_ctx *ctx,
                   snprintf(srcs[0], 255, "%s", ctx->inputs[j].glsl_name);
                   snprintf(src_swizzle0, 10, "%s", swizzle);
                }
-               override_no_wm[i] = ctx->inputs[j].override_no_wm;
+               sinfo->override_no_wm[i] = ctx->inputs[j].override_no_wm;
                break;
             }
       }
@@ -2050,7 +2056,7 @@ get_source_info(struct dump_ctx *ctx,
          } else {
             snprintf(srcs[i], 255, "%ssamp%d%s", cname, src->Register.Index, swizzle);
          }
-         *sreg_index = src->Register.Index;
+         sinfo->sreg_index = src->Register.Index;
       } else if (src->Register.File == TGSI_FILE_IMMEDIATE) {
          if (src->Register.Index >= ARRAY_SIZE(ctx->imm)) {
             fprintf(stderr, "Immediate exceeded, max is %lu\n", ARRAY_SIZE(ctx->imm));
@@ -2099,7 +2105,7 @@ get_source_info(struct dump_ctx *ctx,
 
             if (inst->Instruction.Opcode == TGSI_OPCODE_TG4 && i == 1 && j == 0) {
                if (imd->val[idx].ui > 0) {
-                  *tg4_has_component = true;
+                  sinfo->tg4_has_component = true;
                   ctx->shader_req_bits |= SHADER_REQ_GPU_SHADER5;
                }
             }
@@ -2146,7 +2152,7 @@ get_source_info(struct dump_ctx *ctx,
                            ctx->system_values[j].glsl_name, get_swiz_char(src->Register.SwizzleW));
                } else
                   snprintf(srcs[i], 255, "%s%s", prefix, ctx->system_values[j].glsl_name);
-               override_no_wm[i] = ctx->system_values[j].override_no_wm;
+               sinfo->override_no_wm[i] = ctx->system_values[j].override_no_wm;
                break;
             }
       }
@@ -2161,18 +2167,15 @@ iter_instruction(struct tgsi_iterate_context *iter,
 {
    struct dump_ctx *ctx = (struct dump_ctx *)iter;
    struct dest_info dinfo = { 0 };
+   struct source_info sinfo = { 0 };
    char srcs[4][255], dsts[3][255], buf[512];
    uint instno = ctx->instno++;
-   int sreg_index = 0;
    char writemask[6] = {0};
-   bool override_no_wm[3];
    char *sret;
    int ret;
    char src_swizzle0[10];
-   bool tg4_has_component = false;
 
-   enum vrend_type_qualifier svec4;
-   svec4 = VEC4;
+   sinfo.svec4 = VEC4;
 
    if (ctx->prog_type == -1)
       ctx->prog_type = iter->processor.Processor;
@@ -2194,7 +2197,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
    if (ret)
       return FALSE;
 
-   ret = get_source_info(ctx, inst, &svec4, &sreg_index, srcs, src_swizzle0, &tg4_has_component, override_no_wm);
+   ret = get_source_info(ctx, inst, &sinfo, srcs, src_swizzle0);
    if (ret)
       return FALSE;
 
@@ -2358,7 +2361,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
       EMIT_BUF_WITH_RET(ctx, buf);
       break;
    case TGSI_OPCODE_MOV:
-      snprintf(buf, 255, "%s = %s(%s(%s%s));\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), srcs[0], override_no_wm[0] ? "" : writemask);
+      snprintf(buf, 255, "%s = %s(%s(%s%s));\n", dsts[0], get_string(dinfo.dstconv), get_string(dinfo.dtypeprefix), srcs[0], sinfo.override_no_wm[0] ? "" : writemask);
       EMIT_BUF_WITH_RET(ctx, buf);
       break;
    case TGSI_OPCODE_ADD:
@@ -2442,7 +2445,7 @@ iter_instruction(struct tgsi_iterate_context *iter,
    case TGSI_OPCODE_TXP:
    case TGSI_OPCODE_TXQ:
    case TGSI_OPCODE_LODQ:
-      ret = translate_tex(ctx, inst, sreg_index, srcs, dsts, writemask, get_string(dinfo.dstconv), dinfo.dst_override_no_wm[0], tg4_has_component);
+      ret = translate_tex(ctx, inst, sinfo.sreg_index, srcs, dsts, writemask, get_string(dinfo.dstconv), dinfo.dst_override_no_wm[0], sinfo.tg4_has_component);
       if (ret)
          return FALSE;
       break;
-- 
2.14.3



More information about the virglrenderer-devel mailing list