OSDN Git Service

ilo: construct 3DSTATE_CLIP in create_rasterizer_state()
authorChia-I Wu <olvaffe@gmail.com>
Tue, 4 Jun 2013 10:37:23 +0000 (18:37 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 7 Jun 2013 03:13:16 +0000 (11:13 +0800)
Add ilo_rasterizer_clip and initialize it in create_rasterizer_state().

src/gallium/drivers/ilo/ilo_3d_pipeline_gen6.c
src/gallium/drivers/ilo/ilo_gpe.h
src/gallium/drivers/ilo/ilo_gpe_gen6.c
src/gallium/drivers/ilo/ilo_gpe_gen6.h
src/gallium/drivers/ilo/ilo_state.c

index c53e5b8..04e88bd 100644 (file)
@@ -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);
    }
index b31dbf2..2b8152a 100644 (file)
@@ -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 {
@@ -254,6 +263,19 @@ 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,
                  struct ilo_dsa_state *dsa);
index 77a5cb6..ebb6d86 100644 (file)
@@ -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);
index 615671f..146ed12 100644 (file)
@@ -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,
index 15eb122..a2ec664 100644 (file)
@@ -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;
 }