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.
This commit is contained in:
Eric Anholt 2014-09-23 15:27:55 -07:00
parent 0e7bc3088b
commit 45b104e0a2
5 changed files with 33 additions and 2 deletions

View 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;
};

View 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);
}
}

View 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;
}

View 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);

View 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;
}