vc4: Add support for texture swizzles.
authorEric Anholt <eric@anholt.net>
Tue, 9 Sep 2014 23:18:05 +0000 (16:18 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 10 Sep 2014 03:39:29 +0000 (20:39 -0700)
Fixes depth-tex-modes.

src/gallium/drivers/vc4/vc4_program.c

index 0252b995d743c71087ea38bef1ea5e4e4acff3df..b6284bb1a5579f3bb97ca65a0133c6236b7888a9 100644 (file)
@@ -42,6 +42,7 @@ struct vc4_key {
         struct pipe_shader_state *shader_state;
         struct {
                 enum pipe_format format;
+                uint8_t swizzle[4];
         } tex[VC4_MAX_TEXTURE_SAMPLERS];
 };
 
@@ -516,7 +517,9 @@ tgsi_to_qir_tex(struct vc4_compile *c,
                         unpacked[i] = qir_R4_UNPACK(c, r4, i);
         }
 
-        const uint8_t *swiz = vc4_get_format_swizzle(format);
+        const uint8_t *format_swiz = vc4_get_format_swizzle(format);
+        uint8_t swiz[4];
+        util_format_compose_swizzles(format_swiz, c->key->tex[unit].swizzle, swiz);
         for (int i = 0; i < 4; i++) {
                 if (!(tgsi_inst->Dst[0].Register.WriteMask & (1 << i)))
                         continue;
@@ -1434,6 +1437,10 @@ vc4_setup_shared_key(struct vc4_key *key, struct vc4_texture_stateobj *texstate)
                 if (sampler) {
                         struct pipe_resource *prsc = sampler->texture;
                         key->tex[i].format = prsc->format;
+                        key->tex[i].swizzle[0] = sampler->swizzle_r;
+                        key->tex[i].swizzle[1] = sampler->swizzle_g;
+                        key->tex[i].swizzle[2] = sampler->swizzle_b;
+                        key->tex[i].swizzle[3] = sampler->swizzle_a;
                 }
         }
 }