vc4: Add support for flat shading.
authorEric Anholt <eric@anholt.net>
Tue, 23 Sep 2014 22:27:55 +0000 (15:27 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 24 Sep 2014 00:23:29 +0000 (17:23 -0700)
This is just the GL 1.1 flat shading of colors -- we don't need to support
TGSI constant interpolation bits, because we don't do GLSL 1.30.

Fixes 7 piglit tests.

src/gallium/drivers/vc4/vc4_context.h
src/gallium/drivers/vc4/vc4_emit.c
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.h
src/gallium/drivers/vc4/vc4_state.c

index 1dc0f97a775b6f57f45c798d2b34ad902ca25efb..7839a5a8868fc57850c8571f898b8cecf7e98d66 100644 (file)
@@ -56,6 +56,7 @@
 #define VC4_DIRTY_VTXBUF        (1 << 15)
 #define VC4_DIRTY_INDEXBUF      (1 << 16)
 #define VC4_DIRTY_SCISSOR       (1 << 17)
+#define VC4_DIRTY_FLAT_SHADE_FLAGS (1 << 18)
 
 #define VC4_SHADER_DIRTY_VP     (1 << 0)
 #define VC4_SHADER_DIRTY_FP     (1 << 1)
@@ -81,6 +82,10 @@ struct vc4_compiled_shader {
         struct vc4_shader_uniform_info uniforms[2];
 
         uint32_t coord_shader_offset;
+
+        /** bitmask of which inputs are color inputs, for flat shade handling. */
+        uint32_t color_inputs;
+
         uint8_t num_inputs;
 };
 
index 476ea9c6fd4e4773765fa9afd6449fda2fd9d3b9..2a25ca08b9dc9448e9c2ca335ce13bf383e3a175 100644 (file)
@@ -62,4 +62,10 @@ vc4_emit_state(struct pipe_context *pctx)
                 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[0]);
                 cl_u16(&vc4->bcl, 16 * vc4->viewport.translate[1]);
         }
+
+        if (vc4->dirty & VC4_DIRTY_FLAT_SHADE_FLAGS) {
+                cl_u8(&vc4->bcl, VC4_PACKET_FLAT_SHADE_FLAGS);
+                cl_u32(&vc4->bcl, vc4->rasterizer->base.flatshade ?
+                       vc4->prog.fs->color_inputs : 0);
+        }
 }
index 587831f231db93aa0fb0514e65e0634b699c3e17..38e80dd5ba99bdb6dbd73aed2b8c2115ea2b3f12 100644 (file)
@@ -877,12 +877,17 @@ emit_fragment_varying(struct vc4_compile *c, int index)
 }
 
 static void
-emit_fragment_input(struct vc4_compile *c, int attr)
+emit_fragment_input(struct vc4_compile *c, int attr,
+                    struct tgsi_full_declaration *decl)
 {
         for (int i = 0; i < 4; i++) {
                 c->inputs[attr * 4 + i] =
                         emit_fragment_varying(c, attr * 4 + i);
                 c->num_inputs++;
+
+                if (decl->Semantic.Name == TGSI_SEMANTIC_COLOR ||
+                    decl->Semantic.Name == TGSI_SEMANTIC_BCOLOR)
+                        c->color_inputs |= 1 << i;
         }
 }
 
@@ -908,7 +913,7 @@ emit_tgsi_declaration(struct vc4_compile *c,
                                     TGSI_SEMANTIC_POSITION) {
                                         emit_fragcoord_input(c, i);
                                 } else {
-                                        emit_fragment_input(c, i);
+                                        emit_fragment_input(c, i, decl);
                                 }
                         } else {
                                 emit_vertex_input(c, i);
@@ -1527,6 +1532,7 @@ vc4_fs_compile(struct vc4_context *vc4, struct vc4_compiled_shader *shader,
                                                        QSTAGE_FRAG,
                                                        &key->base);
         shader->num_inputs = c->num_inputs;
+        shader->color_inputs = c->color_inputs;
         copy_uniform_state_to_shader(shader, 0, c);
         shader->bo = vc4_bo_alloc_mem(vc4->screen, c->qpu_insts,
                                       c->qpu_inst_count * sizeof(uint64_t),
@@ -1620,6 +1626,12 @@ vc4_update_compiled_fs(struct vc4_context *vc4, uint8_t prim_mode)
         vc4_fs_compile(vc4, shader, key);
         util_hash_table_set(vc4->fs_cache, key, shader);
 
+        if (vc4->rasterizer->base.flatshade &&
+            vc4->prog.fs &&
+            vc4->prog.fs->color_inputs != shader->color_inputs) {
+                vc4->dirty |= VC4_DIRTY_FLAT_SHADE_FLAGS;
+        }
+
         vc4->prog.fs = shader;
 }
 
index d1bfc77621e8a29f21adaed76fdbccc2441242ea..04a81c95459ef6c5fea26f6b7ff31d46b2c9663b 100644 (file)
@@ -248,6 +248,7 @@ struct vc4_compile {
         uint32_t qpu_inst_count;
         uint32_t qpu_inst_size;
         uint32_t num_inputs;
+        uint32_t color_inputs;
 };
 
 struct vc4_compile *qir_compile_init(void);
index c7757709ee605852fd3d832b070b1697735ce19b..2e14573deb0e985930fa45ecf55e32a4d87acd42 100644 (file)
@@ -290,6 +290,13 @@ static void
 vc4_rasterizer_state_bind(struct pipe_context *pctx, void *hwcso)
 {
         struct vc4_context *vc4 = vc4_context(pctx);
+        struct vc4_rasterizer_state *rast = hwcso;
+
+        if (vc4->rasterizer && rast &&
+            vc4->rasterizer->base.flatshade != rast->base.flatshade) {
+                vc4->dirty |= VC4_DIRTY_FLAT_SHADE_FLAGS;
+        }
+
         vc4->rasterizer = hwcso;
         vc4->dirty |= VC4_DIRTY_RASTERIZER;
 }