Mesa (master): vc4: Extract the swizzle handling from vertex fetch.

Eric Anholt anholt at kemper.freedesktop.org
Mon Aug 18 22:28:04 UTC 2014


Module: Mesa
Branch: master
Commit: 37992a4e390bad9f7d83ce29bb7d01ad01bfc13c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=37992a4e390bad9f7d83ce29bb7d01ad01bfc13c

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 18 11:18:10 2014 -0700

vc4: Extract the swizzle handling from vertex fetch.

I want to reuse this elsewhere, and NONE debug output hasn't been useful
so I don't miss it being as detailed as it was before.

---

 src/gallium/drivers/vc4/vc4_program.c |   59 ++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 0210ebc..a072043 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -211,6 +211,27 @@ update_dst(struct tgsi_to_qir *trans, struct tgsi_full_instruction *tgsi_inst,
 };
 
 static struct qreg
+get_swizzled_channel(struct tgsi_to_qir *trans,
+                     struct qreg *srcs, int swiz)
+{
+        switch (swiz) {
+        default:
+        case UTIL_FORMAT_SWIZZLE_NONE:
+                fprintf(stderr, "warning: unknown swizzle\n");
+                /* FALLTHROUGH */
+        case UTIL_FORMAT_SWIZZLE_0:
+                return qir_uniform_f(trans, 0.0);
+        case UTIL_FORMAT_SWIZZLE_1:
+                return qir_uniform_f(trans, 1.0);
+        case UTIL_FORMAT_SWIZZLE_X:
+        case UTIL_FORMAT_SWIZZLE_Y:
+        case UTIL_FORMAT_SWIZZLE_Z:
+        case UTIL_FORMAT_SWIZZLE_W:
+                return srcs[swiz];
+        }
+}
+
+static struct qreg
 tgsi_to_qir_alu(struct tgsi_to_qir *trans,
                 struct tgsi_full_instruction *tgsi_inst,
                 enum qop op, struct qreg *src, int i)
@@ -557,34 +578,18 @@ emit_vertex_input(struct tgsi_to_qir *trans, int attr)
         for (int i = 0; i < 4; i++) {
                 uint8_t swiz = desc->swizzle[i];
 
-                switch (swiz) {
-                case UTIL_FORMAT_SWIZZLE_NONE:
-                        if (!format_warned) {
-                                fprintf(stderr,
-                                        "vtx element %d NONE swizzle: %s\n",
-                                        attr, util_format_name(format));
-                                format_warned = true;
-                        }
-                        /* FALLTHROUGH */
-                case UTIL_FORMAT_SWIZZLE_0:
-                        trans->inputs[attr * 4 + i] = qir_uniform_f(trans, 0.0);
-                        break;
-                case UTIL_FORMAT_SWIZZLE_1:
-                        trans->inputs[attr * 4 + i] = qir_uniform_f(trans, 1.0);
-                        break;
-                default:
-                        if (!format_warned &&
-                            (desc->channel[swiz].type != UTIL_FORMAT_TYPE_FLOAT ||
-                             desc->channel[swiz].size != 32)) {
-                                fprintf(stderr,
-                                        "vtx element %d unsupported type: %s\n",
-                                        attr, util_format_name(format));
-                                format_warned = true;
-                        }
-
-                        trans->inputs[attr * 4 + i] = vpm_reads[swiz];
-                        break;
+                if (swiz <= UTIL_FORMAT_SWIZZLE_W &&
+                    !format_warned &&
+                    (desc->channel[swiz].type != UTIL_FORMAT_TYPE_FLOAT ||
+                     desc->channel[swiz].size != 32)) {
+                        fprintf(stderr,
+                                "vtx element %d unsupported type: %s\n",
+                                attr, util_format_name(format));
+                        format_warned = true;
                 }
+
+                trans->inputs[attr * 4 + i] =
+                        get_swizzled_channel(trans, vpm_reads, swiz);
         }
 }
 




More information about the mesa-commit mailing list