From 3c2fea206fa279f40ecca6a1dba00251857e1029 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 4 Jun 2013 18:37:23 +0800 Subject: ilo: construct 3DSTATE_CLIP in create_rasterizer_state() Add ilo_rasterizer_clip and initialize it in create_rasterizer_state(). --- src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c | 2 +- src/gallium/drivers/ilo/ilo_gpe.h | 22 +++++ src/gallium/drivers/ilo/ilo_gpe_gen6.c | 108 ++++++++++++++----------- src/gallium/drivers/ilo/ilo_gpe_gen6.h | 2 +- src/gallium/drivers/ilo/ilo_state.c | 2 + 5 files changed, 86 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c index c53e5b87e74..04e88bd0093 100644 --- a/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c +++ b/src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c @@ -615,7 +615,7 @@ gen6_pipeline_clip(struct ilo_3d_pipeline *p, } p->gen6_3DSTATE_CLIP(p->dev, - &ilo->rasterizer->state, + ilo->rasterizer, (ilo->fs && ilo->fs->shader->in.has_linear_interp), enable_guardband, 1, p->cp); } diff --git a/src/gallium/drivers/ilo/ilo_gpe.h b/src/gallium/drivers/ilo/ilo_gpe.h index b31dbf2ee7a..2b8152aa351 100644 --- a/src/gallium/drivers/ilo/ilo_gpe.h +++ b/src/gallium/drivers/ilo/ilo_gpe.h @@ -111,8 +111,17 @@ struct ilo_scissor_state { uint32_t payload[ILO_MAX_VIEWPORTS * 2]; }; +struct ilo_rasterizer_clip { + /* 3DSTATE_CLIP */ + uint32_t payload[3]; + + uint32_t can_enable_guardband; +}; + struct ilo_rasterizer_state { struct pipe_rasterizer_state state; + + struct ilo_rasterizer_clip clip; }; struct ilo_dsa_state { @@ -253,6 +262,19 @@ void ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev, struct ilo_scissor_state *scissor); +void +ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info *dev, + const struct pipe_rasterizer_state *state, + struct ilo_rasterizer_clip *clip); + +static inline void +ilo_gpe_init_rasterizer(const struct ilo_dev_info *dev, + const struct pipe_rasterizer_state *state, + struct ilo_rasterizer_state *rasterizer) +{ + ilo_gpe_init_rasterizer_clip(dev, state, &rasterizer->clip); +} + void ilo_gpe_init_dsa(const struct ilo_dev_info *dev, const struct pipe_depth_stencil_alpha_state *state, diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen6.c b/src/gallium/drivers/ilo/ilo_gpe_gen6.c index 77a5cb6cabe..ebb6d86c4ba 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen6.c +++ b/src/gallium/drivers/ilo/ilo_gpe_gen6.c @@ -1350,31 +1350,15 @@ gen6_emit_3DSTATE_GS(const struct ilo_dev_info *dev, ilo_cp_end(cp); } -static void -gen6_emit_3DSTATE_CLIP(const struct ilo_dev_info *dev, - const struct pipe_rasterizer_state *rasterizer, - bool has_linear_interp, - bool enable_guardband, - int num_viewports, - struct ilo_cp *cp) +void +ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info *dev, + const struct pipe_rasterizer_state *state, + struct ilo_rasterizer_clip *clip) { - const uint32_t cmd = ILO_GPE_CMD(0x3, 0x0, 0x12); - const uint8_t cmd_len = 4; uint32_t dw1, dw2, dw3; ILO_GPE_VALID_GEN(dev, 6, 7); - if (!rasterizer) { - ilo_cp_begin(cp, cmd_len); - ilo_cp_write(cp, cmd | (cmd_len - 2)); - ilo_cp_write(cp, 0); - ilo_cp_write(cp, 0); - ilo_cp_write(cp, 0); - ilo_cp_end(cp); - - return; - } - dw1 = GEN6_CLIP_STATISTICS_ENABLE; if (dev->gen >= ILO_GEN(7)) { @@ -1390,10 +1374,10 @@ gen6_emit_3DSTATE_CLIP(const struct ilo_dev_info *dev, dw1 |= 0 << 19 | GEN7_CLIP_EARLY_CULL; - if (rasterizer->front_ccw) + if (state->front_ccw) dw1 |= GEN7_CLIP_WINDING_CCW; - switch (rasterizer->cull_face) { + switch (state->cull_face) { case PIPE_FACE_NONE: dw1 |= GEN7_CLIP_CULLMODE_NONE; break; @@ -1411,53 +1395,81 @@ gen6_emit_3DSTATE_CLIP(const struct ilo_dev_info *dev, dw2 = GEN6_CLIP_ENABLE | GEN6_CLIP_XY_TEST | - rasterizer->clip_plane_enable << GEN6_USER_CLIP_CLIP_DISTANCES_SHIFT | + state->clip_plane_enable << GEN6_USER_CLIP_CLIP_DISTANCES_SHIFT | GEN6_CLIP_MODE_NORMAL; - if (rasterizer->clip_halfz) + if (state->clip_halfz) dw2 |= GEN6_CLIP_API_D3D; else dw2 |= GEN6_CLIP_API_OGL; - if (rasterizer->depth_clip) + if (state->depth_clip) dw2 |= GEN6_CLIP_Z_TEST; + if (state->flatshade_first) { + dw2 |= 0 << GEN6_CLIP_TRI_PROVOKE_SHIFT | + 0 << GEN6_CLIP_LINE_PROVOKE_SHIFT | + 1 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT; + } + else { + dw2 |= 2 << GEN6_CLIP_TRI_PROVOKE_SHIFT | + 1 << GEN6_CLIP_LINE_PROVOKE_SHIFT | + 2 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT; + } + + dw3 = 0x1 << GEN6_CLIP_MIN_POINT_WIDTH_SHIFT | + 0x7ff << GEN6_CLIP_MAX_POINT_WIDTH_SHIFT; + + clip->payload[0] = dw1; + clip->payload[1] = dw2; + clip->payload[2] = dw3; + + clip->can_enable_guardband = true; + /* * There are several reasons that guard band test should be disabled * - * - when the renderer does not perform 2D clipping * - GL wide points (to avoid partially visibie object) * - GL wide or AA lines (to avoid partially visibie object) */ - if (enable_guardband && true /* API_GL */) { - if (rasterizer->point_size_per_vertex || rasterizer->point_size > 1.0f) - enable_guardband = false; - if (rasterizer->line_smooth || rasterizer->line_width > 1.0f) - enable_guardband = false; - } + if (state->point_size_per_vertex || state->point_size > 1.0f) + clip->can_enable_guardband = false; + if (state->line_smooth || state->line_width > 1.0f) + clip->can_enable_guardband = false; +} + +static void +gen6_emit_3DSTATE_CLIP(const struct ilo_dev_info *dev, + const struct ilo_rasterizer_state *rasterizer, + bool has_linear_interp, + bool enable_guardband, + int num_viewports, + struct ilo_cp *cp) +{ + const uint32_t cmd = ILO_GPE_CMD(0x3, 0x0, 0x12); + const uint8_t cmd_len = 4; + uint32_t dw1, dw2, dw3; - if (enable_guardband) - dw2 |= GEN6_CLIP_GB_TEST; + if (rasterizer) { + dw1 = rasterizer->clip.payload[0]; + dw2 = rasterizer->clip.payload[1]; + dw3 = rasterizer->clip.payload[2]; - if (has_linear_interp) - dw2 |= GEN6_CLIP_NON_PERSPECTIVE_BARYCENTRIC_ENABLE; + if (enable_guardband && rasterizer->clip.can_enable_guardband) + dw2 |= GEN6_CLIP_GB_TEST; - if (rasterizer->flatshade_first) { - dw2 |= 0 << GEN6_CLIP_TRI_PROVOKE_SHIFT | - 0 << GEN6_CLIP_LINE_PROVOKE_SHIFT | - 1 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT; + if (has_linear_interp) + dw2 |= GEN6_CLIP_NON_PERSPECTIVE_BARYCENTRIC_ENABLE; + + dw3 |= GEN6_CLIP_FORCE_ZERO_RTAINDEX | + (num_viewports - 1); } else { - dw2 |= 2 << GEN6_CLIP_TRI_PROVOKE_SHIFT | - 1 << GEN6_CLIP_LINE_PROVOKE_SHIFT | - 2 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT; + dw1 = 0; + dw2 = 0; + dw3 = 0; } - dw3 = 0x1 << GEN6_CLIP_MIN_POINT_WIDTH_SHIFT | - 0x7ff << GEN6_CLIP_MAX_POINT_WIDTH_SHIFT | - GEN6_CLIP_FORCE_ZERO_RTAINDEX | - (num_viewports - 1); - ilo_cp_begin(cp, cmd_len); ilo_cp_write(cp, cmd | (cmd_len - 2)); ilo_cp_write(cp, dw1); diff --git a/src/gallium/drivers/ilo/ilo_gpe_gen6.h b/src/gallium/drivers/ilo/ilo_gpe_gen6.h index 615671f3178..146ed12652a 100644 --- a/src/gallium/drivers/ilo/ilo_gpe_gen6.h +++ b/src/gallium/drivers/ilo/ilo_gpe_gen6.h @@ -247,7 +247,7 @@ typedef void typedef void (*ilo_gpe_gen6_3DSTATE_CLIP)(const struct ilo_dev_info *dev, - const struct pipe_rasterizer_state *rasterizer, + const struct ilo_rasterizer_state *rasterizer, bool has_linear_interp, bool enable_guardband, int num_viewports, diff --git a/src/gallium/drivers/ilo/ilo_state.c b/src/gallium/drivers/ilo/ilo_state.c index 15eb1228ace..a2ec664c304 100644 --- a/src/gallium/drivers/ilo/ilo_state.c +++ b/src/gallium/drivers/ilo/ilo_state.c @@ -303,12 +303,14 @@ static void * ilo_create_rasterizer_state(struct pipe_context *pipe, const struct pipe_rasterizer_state *state) { + struct ilo_context *ilo = ilo_context(pipe); struct ilo_rasterizer_state *rast; rast = MALLOC_STRUCT(ilo_rasterizer_state); assert(rast); rast->state = *state; + ilo_gpe_init_rasterizer(ilo->dev, state, rast); return rast; } -- cgit v1.2.3