vc4: Add support for 8-bit unnormalized vertex attrs.
authorEric Anholt <eric@anholt.net>
Mon, 15 Dec 2014 19:19:58 +0000 (11:19 -0800)
committerEric Anholt <eric@anholt.net>
Mon, 15 Dec 2014 22:33:00 +0000 (14:33 -0800)
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 fd9cd5e34719939efbbb889a88c51732b53e250c..1efdf37097f5399fe7de63f76a46fa20d167316e 100644 (file)
@@ -1003,20 +1003,28 @@ get_channel_from_vpm(struct vc4_compile *c,
                 return get_swizzled_channel(c, vpm_reads, swiz);
         } else if (chan->size == 8 &&
                    (chan->type == UTIL_FORMAT_TYPE_UNSIGNED ||
-                    chan->type == UTIL_FORMAT_TYPE_SIGNED) &&
-                   chan->normalized) {
+                    chan->type == UTIL_FORMAT_TYPE_SIGNED)) {
                 struct qreg vpm = vpm_reads[0];
-                if (chan->type == UTIL_FORMAT_TYPE_SIGNED)
-                        vpm = qir_XOR(c, vpm, qir_uniform_ui(c, 0x80808080));
-                temp = qir_UNPACK_8_F(c, vpm, swiz);
-
                 if (chan->type == UTIL_FORMAT_TYPE_SIGNED) {
-                        return qir_FSUB(c, qir_FMUL(c,
-                                                    temp,
-                                                    qir_uniform_f(c, 2.0)),
-                                        qir_uniform_f(c, 1.0));
+                        temp = qir_XOR(c, vpm, qir_uniform_ui(c, 0x80808080));
+                        if (chan->normalized) {
+                                return qir_FSUB(c, qir_FMUL(c,
+                                                            qir_UNPACK_8_F(c, temp, swiz),
+                                                            qir_uniform_f(c, 2.0)),
+                                                qir_uniform_f(c, 1.0));
+                        } else {
+                                return qir_FADD(c,
+                                                qir_ITOF(c,
+                                                         qir_UNPACK_8_I(c, temp,
+                                                                        swiz)),
+                                                qir_uniform_f(c, -128.0));
+                        }
                 } else {
-                        return temp;
+                        if (chan->normalized) {
+                                return qir_UNPACK_8_F(c, vpm, swiz);
+                        } else {
+                                return qir_ITOF(c, qir_UNPACK_8_I(c, vpm, swiz));
+                        }
                 }
         } else {
                 return c->undef;
index e83c03654b01fc60c8daf38f96acb1c0b6b33579..8cd571d5b77dc8c99c40a8a58a3a28ee71842d31 100644 (file)
@@ -103,6 +103,10 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_UNPACK_8B_F] = { "unpack_8b_f", 1, 1 },
         [QOP_UNPACK_8C_F] = { "unpack_8c_f", 1, 1 },
         [QOP_UNPACK_8D_F] = { "unpack_8d_f", 1, 1 },
+        [QOP_UNPACK_8A_I] = { "unpack_8a_i", 1, 1 },
+        [QOP_UNPACK_8B_I] = { "unpack_8b_i", 1, 1 },
+        [QOP_UNPACK_8C_I] = { "unpack_8c_i", 1, 1 },
+        [QOP_UNPACK_8D_I] = { "unpack_8d_i", 1, 1 },
 };
 
 static const char *
index c612b283b9075a614d056b0cd43cce483d0b2cd6..9da120ab91253d01ccb41569e16acd49cfb3dec8 100644 (file)
@@ -114,6 +114,11 @@ enum qop {
         QOP_UNPACK_8C_F,
         QOP_UNPACK_8D_F,
 
+        QOP_UNPACK_8A_I,
+        QOP_UNPACK_8B_I,
+        QOP_UNPACK_8C_I,
+        QOP_UNPACK_8D_I,
+
         /** Texture x coordinate parameter write */
         QOP_TEX_S,
         /** Texture y coordinate parameter write */
@@ -496,6 +501,14 @@ qir_UNPACK_8_F(struct vc4_compile *c, struct qreg src, int i)
         return t;
 }
 
+static inline struct qreg
+qir_UNPACK_8_I(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 + i, t, src, c->undef));
+        return t;
+}
+
 static inline struct qreg
 qir_POW(struct vc4_compile *c, struct qreg x, struct qreg y)
 {
index 8b3a0010d334d1912a2d6d4d6c86033f7656c35e..f88072766601687fd17b809f77abe1a55823ba69 100644 (file)
@@ -490,6 +490,27 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
                         }
                         break;
 
+                case QOP_UNPACK_8A_I:
+                case QOP_UNPACK_8B_I:
+                case QOP_UNPACK_8C_I:
+                case QOP_UNPACK_8D_I:
+                        assert(src[0].mux == QPU_MUX_A);
+
+                        /* Since we're setting the pack bits, if the
+                         * destination is in A it would get re-packed.
+                         */
+                        queue(c, qpu_a_MOV((dst.mux == QPU_MUX_A ?
+                                            qpu_rb(31) : dst), src[0]));
+                        *last_inst(c) |= QPU_SET_FIELD(QPU_UNPACK_8A +
+                                                       (qinst->op -
+                                                        QOP_UNPACK_8A_I),
+                                                       QPU_UNPACK);
+
+                        if (dst.mux == QPU_MUX_A) {
+                                queue(c, qpu_a_MOV(dst, qpu_rb(31)));
+                        }
+                        break;
+
                 default:
                         assert(qinst->op < ARRAY_SIZE(translate));
                         assert(translate[qinst->op].op != 0); /* NOPs */
index f48ce1804d3d1c9b6f5eeed9eac0ff03f42e6379..8f8c1899071711de5f9c7a2ca7ab958e6fe41eea 100644 (file)
@@ -258,6 +258,10 @@ vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c)
                 case QOP_UNPACK_8B_F:
                 case QOP_UNPACK_8C_F:
                 case QOP_UNPACK_8D_F:
+                case QOP_UNPACK_8A_I:
+                case QOP_UNPACK_8B_I:
+                case QOP_UNPACK_8C_I:
+                case QOP_UNPACK_8D_I:
                         /* The unpack flags require an A-file src register. */
                         ra_set_node_class(g, temp_to_node[inst->src[0].index],
                                           vc4->reg_class_a);
index aa5cbfa2348c6088be0b94b7338b2411e7bab5ab..6bb158b59900dda616b1ba5099ce3bb444c74bf3 100644 (file)
@@ -354,6 +354,14 @@ vc4_screen_is_format_supported(struct pipe_screen *pscreen,
                 case PIPE_FORMAT_R8G8B8_SNORM:
                 case PIPE_FORMAT_R8G8_SNORM:
                 case PIPE_FORMAT_R8_SNORM:
+                case PIPE_FORMAT_R8G8B8A8_USCALED:
+                case PIPE_FORMAT_R8G8B8_USCALED:
+                case PIPE_FORMAT_R8G8_USCALED:
+                case PIPE_FORMAT_R8_USCALED:
+                case PIPE_FORMAT_R8G8B8A8_SSCALED:
+                case PIPE_FORMAT_R8G8B8_SSCALED:
+                case PIPE_FORMAT_R8G8_SSCALED:
+                case PIPE_FORMAT_R8_SSCALED:
                         retval |= PIPE_BIND_VERTEX_BUFFER;
                         break;
                 default: