vc4: Add support for 8-bit unorm/snorm vertex inputs.
authorEric Anholt <eric@anholt.net>
Fri, 22 Aug 2014 22:02:52 +0000 (15:02 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 23 Sep 2014 20:40:10 +0000 (13:40 -0700)
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h
src/gallium/drivers/vc4/vc4_qpu_emit.c
src/gallium/drivers/vc4/vc4_register_allocate.c
src/gallium/drivers/vc4/vc4_screen.c

index 60d9ce92935f260cb8b15a8f9d45b5da2b98a2c0..b7b64c0de3aa8d3770fa815c9d461402c76eae69 100644 (file)
@@ -805,19 +805,41 @@ emit_vertex_input(struct vc4_compile *c, int attr)
 
         for (int i = 0; i < 4; i++) {
                 uint8_t swiz = desc->swizzle[i];
+                struct qreg result;
 
-                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;
+                if (swiz > UTIL_FORMAT_SWIZZLE_W)
+                        result = get_swizzled_channel(c, vpm_reads, swiz);
+                else if (desc->channel[swiz].size == 32 &&
+                         desc->channel[swiz].type == UTIL_FORMAT_TYPE_FLOAT) {
+                        result = get_swizzled_channel(c, vpm_reads, swiz);
+                } else if (desc->channel[swiz].size == 8 &&
+                           (desc->channel[swiz].type == UTIL_FORMAT_TYPE_UNSIGNED ||
+                            desc->channel[swiz].type == UTIL_FORMAT_TYPE_SIGNED) &&
+                           desc->channel[swiz].normalized) {
+                        struct qreg vpm = vpm_reads[0];
+                        if (desc->channel[swiz].type == UTIL_FORMAT_TYPE_SIGNED)
+                                vpm = qir_XOR(c, vpm, qir_uniform_ui(c, 0x80808080));
+                        result = qir_UNPACK_8(c, vpm, swiz);
+                } else {
+                        if (!format_warned) {
+                                fprintf(stderr,
+                                        "vtx element %d unsupported type: %s\n",
+                                        attr, util_format_name(format));
+                                format_warned = true;
+                        }
+                        result = qir_uniform_f(c, 0.0);
                 }
 
-                c->inputs[attr * 4 + i] =
-                        get_swizzled_channel(c, vpm_reads, swiz);
+                if (desc->channel[swiz].normalized &&
+                    desc->channel[swiz].type == UTIL_FORMAT_TYPE_SIGNED) {
+                        result = qir_FSUB(c,
+                                          qir_FMUL(c,
+                                                   result,
+                                                   qir_uniform_f(c, 2.0)),
+                                          qir_uniform_f(c, 1.0));
+                }
+
+                c->inputs[attr * 4 + i] = result;
         }
 }
 
index b4d6812311bef8419be76d71860e8c209a0fd05b..efba6d3c55e32c58b5d7bca3b0a7ded4a40d98a7 100644 (file)
@@ -97,6 +97,10 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_R4_UNPACK_B] = { "r4_unpack_b", 1, 1 },
         [QOP_R4_UNPACK_C] = { "r4_unpack_c", 1, 1 },
         [QOP_R4_UNPACK_D] = { "r4_unpack_d", 1, 1 },
+        [QOP_UNPACK_8A] = { "unpack_8a", 1, 1 },
+        [QOP_UNPACK_8B] = { "unpack_8b", 1, 1 },
+        [QOP_UNPACK_8C] = { "unpack_8c", 1, 1 },
+        [QOP_UNPACK_8D] = { "unpack_8d", 1, 1 },
 };
 
 static const char *
index f3e5332edfcec75b6d833cf7053cce5a4be1f387..d1bfc77621e8a29f21adaed76fdbccc2441242ea 100644 (file)
@@ -108,6 +108,11 @@ enum qop {
         QOP_FRAG_Z,
         QOP_FRAG_W,
 
+        QOP_UNPACK_8A,
+        QOP_UNPACK_8B,
+        QOP_UNPACK_8C,
+        QOP_UNPACK_8D,
+
         /** Texture x coordinate parameter write */
         QOP_TEX_S,
         /** Texture y coordinate parameter write */
@@ -386,4 +391,12 @@ qir_SEL_X_0_COND(struct vc4_compile *c, int i)
         return t;
 }
 
+static inline struct qreg
+qir_UNPACK_8(struct vc4_compile *c, struct qreg src, int i)
+{
+        struct qreg t = qir_get_temp(c);
+        qir_emit(c, qir_inst(QOP_UNPACK_8A + i, t, src, c->undef));
+        return t;
+}
+
 #endif /* VC4_QIR_H */
index 3f30f2cd3c586159df90eb7f1e6aaa494381883f..81b3b8bd78452329a1b251e799c72a2e5d6f448a 100644 (file)
@@ -490,6 +490,31 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
 
                         break;
 
+                case QOP_UNPACK_8A:
+                case QOP_UNPACK_8B:
+                case QOP_UNPACK_8C:
+                case QOP_UNPACK_8D: {
+                        assert(src[0].mux == QPU_MUX_A);
+
+                        /* And, since we're setting the pack bits, if the
+                         * destination is in A it would get re-packed.
+                         */
+                        struct qpu_reg orig_dst = dst;
+                        if (orig_dst.mux == QPU_MUX_A)
+                                dst = qpu_rn(3);
+
+                        queue(c, qpu_a_FMAX(dst, src[0], src[0]));
+                        *last_inst(c) |= QPU_SET_FIELD(QPU_UNPACK_8A +
+                                                       (qinst->op -
+                                                        QOP_UNPACK_8A),
+                                                       QPU_UNPACK);
+
+                        if (orig_dst.mux == QPU_MUX_A) {
+                                queue(c, qpu_a_MOV(orig_dst, dst));
+                        }
+                }
+                        break;
+
                 default:
                         assert(qinst->op < ARRAY_SIZE(translate));
                         assert(translate[qinst->op].op != 0); /* NOPs */
index 204c080467e194fa3c8573a1c12839cf2d3963ce..639037e60f7b7526fa2ecb9ae5cd6303a33a8b71 100644 (file)
@@ -212,6 +212,14 @@ vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c)
                         ra_set_node_class(g, inst->dst.index, vc4->reg_class_a);
                         break;
 
+                case QOP_UNPACK_8A:
+                case QOP_UNPACK_8B:
+                case QOP_UNPACK_8C:
+                case QOP_UNPACK_8D:
+                        /* The unpack flags require an A-file src register. */
+                        ra_set_node_class(g, inst->src[0].index, vc4->reg_class_a);
+                        break;
+
                 default:
                         break;
                 }
index 58d5f711376fba3576021f49669fb7cddcdf9fc0..4a5ce4feee7f51047e3a76ce7b27699ec2b5fe07 100644 (file)
@@ -327,12 +327,25 @@ vc4_screen_is_format_supported(struct pipe_screen *pscreen,
                 return FALSE;
         }
 
-        if (usage & PIPE_BIND_VERTEX_BUFFER &&
-            (format == PIPE_FORMAT_R32G32B32A32_FLOAT ||
-             format == PIPE_FORMAT_R32G32B32_FLOAT ||
-             format == PIPE_FORMAT_R32G32_FLOAT ||
-             format == PIPE_FORMAT_R32_FLOAT)) {
-                retval |= PIPE_BIND_VERTEX_BUFFER;
+        if (usage & PIPE_BIND_VERTEX_BUFFER) {
+                switch (format) {
+                case PIPE_FORMAT_R32G32B32A32_FLOAT:
+                case PIPE_FORMAT_R32G32B32_FLOAT:
+                case PIPE_FORMAT_R32G32_FLOAT:
+                case PIPE_FORMAT_R32_FLOAT:
+                case PIPE_FORMAT_R8G8B8A8_UNORM:
+                case PIPE_FORMAT_R8G8B8_UNORM:
+                case PIPE_FORMAT_R8G8_UNORM:
+                case PIPE_FORMAT_R8_UNORM:
+                case PIPE_FORMAT_R8G8B8A8_SNORM:
+                case PIPE_FORMAT_R8G8B8_SNORM:
+                case PIPE_FORMAT_R8G8_SNORM:
+                case PIPE_FORMAT_R8_SNORM:
+                        retval |= PIPE_BIND_VERTEX_BUFFER;
+                        break;
+                default:
+                        break;
+                }
         }
 
         if ((usage & PIPE_BIND_RENDER_TARGET) &&