From 45b104e0a228595142ed4bc62bbc8948100b9325 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 23 Sep 2014 15:27:55 -0700 Subject: [PATCH] vc4: Add support for flat shading. 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 | 5 +++++ src/gallium/drivers/vc4/vc4_emit.c | 6 ++++++ src/gallium/drivers/vc4/vc4_program.c | 16 ++++++++++++++-- src/gallium/drivers/vc4/vc4_qir.h | 1 + src/gallium/drivers/vc4/vc4_state.c | 7 +++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/vc4/vc4_context.h b/src/gallium/drivers/vc4/vc4_context.h index 1dc0f97a775..7839a5a8868 100644 --- a/src/gallium/drivers/vc4/vc4_context.h +++ b/src/gallium/drivers/vc4/vc4_context.h @@ -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; }; diff --git a/src/gallium/drivers/vc4/vc4_emit.c b/src/gallium/drivers/vc4/vc4_emit.c index 476ea9c6fd4..2a25ca08b9d 100644 --- a/src/gallium/drivers/vc4/vc4_emit.c +++ b/src/gallium/drivers/vc4/vc4_emit.c @@ -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); + } } diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index 587831f231d..38e80dd5ba9 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -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; } diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h index d1bfc77621e..04a81c95459 100644 --- a/src/gallium/drivers/vc4/vc4_qir.h +++ b/src/gallium/drivers/vc4/vc4_qir.h @@ -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); diff --git a/src/gallium/drivers/vc4/vc4_state.c b/src/gallium/drivers/vc4/vc4_state.c index c7757709ee6..2e14573deb0 100644 --- a/src/gallium/drivers/vc4/vc4_state.c +++ b/src/gallium/drivers/vc4/vc4_state.c @@ -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; } -- 2.30.2