ilo: make ilo_render_emit_draw() direct
authorChia-I Wu <olvaffe@gmail.com>
Thu, 25 Sep 2014 04:02:33 +0000 (12:02 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 26 Sep 2014 13:15:55 +0000 (21:15 +0800)
Remove emit_draw() and ILO_RENDER_DRAW indirections.  With all emit functions
being direct now, ilo_render_estimate_size() and more can also be removed.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
src/gallium/drivers/ilo/Makefile.sources
src/gallium/drivers/ilo/ilo_draw.c
src/gallium/drivers/ilo/ilo_render.c
src/gallium/drivers/ilo/ilo_render.h
src/gallium/drivers/ilo/ilo_render_gen.h
src/gallium/drivers/ilo/ilo_render_gen6.c
src/gallium/drivers/ilo/ilo_render_gen7.c
src/gallium/drivers/ilo/ilo_render_gen7.h [deleted file]

index 2bb81baf90df0d87866ba5b8e3a70b2481af862d..52f4ff25987d4aca24b726650dc067772a140acb 100644 (file)
@@ -40,7 +40,6 @@ C_SOURCES := \
        ilo_render_dynamic.c \
        ilo_render_gen6.c \
        ilo_render_gen7.c \
-       ilo_render_gen7.h \
        ilo_render_surface.c \
        ilo_screen.c \
        ilo_screen.h \
index 8e01f6d3d6f46698b2eb3e463e0dd1915817442a..1c9c4226650ea36d9349a99cd8be990e81139029 100644 (file)
@@ -320,8 +320,7 @@ draw_vbo(struct ilo_context *ilo, const struct ilo_state_vector *vec)
    ilo_draw_set_owner(ilo);
 
    /* make sure there is enough room first */
-   max_len = ilo_render_estimate_size(ilo->render,
-         ILO_RENDER_DRAW, vec);
+   max_len = ilo_render_get_draw_len(ilo->render, vec);
    if (need_flush)
       max_len += ilo_render_get_flush_len(ilo->render);
 
index 4f78cf59eadf9c624e6d5f093236ca038f5684c5..2b8412a348f33332178f08fc7af9d2707c122772 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include "genhw/genhw.h"
+#include "util/u_prim.h"
 #include "intel_winsys.h"
 
 #include "ilo_builder.h"
@@ -33,7 +34,6 @@
 #include "ilo_builder_render.h"
 #include "ilo_query.h"
 #include "ilo_render_gen.h"
-#include "ilo_render_gen7.h"
 #include "ilo_render.h"
 
 /* in U0.4 */
@@ -77,21 +77,6 @@ ilo_render_create(struct ilo_builder *builder)
    render->dev = builder->dev;
    render->builder = builder;
 
-   switch (ilo_dev_gen(render->dev)) {
-   case ILO_GEN(6):
-      ilo_render_init_gen6(render);
-      break;
-   case ILO_GEN(7):
-   case ILO_GEN(7.5):
-      ilo_render_init_gen7(render);
-      break;
-   default:
-      assert(!"unsupported GEN");
-      FREE(render);
-      return NULL;
-      break;
-   }
-
    render->workaround_bo = intel_winsys_alloc_buffer(builder->winsys,
          "PIPE_CONTROL workaround", 4096, false);
    if (!render->workaround_bo) {
@@ -388,3 +373,84 @@ ilo_render_emit_rectlist(struct ilo_render *render,
    ilo_render_emit_rectlist_dynamic_states(render, blitter);
    ilo_render_emit_rectlist_commands(render, blitter);
 }
+
+int
+ilo_render_get_draw_len(const struct ilo_render *render,
+                        const struct ilo_state_vector *vec)
+{
+   ILO_DEV_ASSERT(render->dev, 6, 7.5);
+
+   return ilo_render_get_draw_dynamic_states_len(render, vec) +
+          ilo_render_get_draw_surface_states_len(render, vec) +
+          ilo_render_get_draw_commands_len(render, vec);
+}
+
+static void
+gen6_draw_prepare(struct ilo_render *render,
+                  const struct ilo_state_vector *vec,
+                  struct gen6_draw_session *session)
+{
+   memset(session, 0, sizeof(*session));
+   session->pipe_dirty = vec->dirty;
+   session->reduced_prim = u_reduced_prim(vec->draw->mode);
+
+   if (render->hw_ctx_changed) {
+      /* these should be enough to make everything uploaded */
+      render->batch_bo_changed = true;
+      render->state_bo_changed = true;
+      render->instruction_bo_changed = true;
+
+      session->prim_changed = true;
+      session->primitive_restart_changed = true;
+   } else {
+      session->prim_changed =
+         (render->state.reduced_prim != session->reduced_prim);
+      session->primitive_restart_changed =
+         (render->state.primitive_restart != vec->draw->primitive_restart);
+   }
+}
+
+static void
+gen6_draw_end(struct ilo_render *render,
+              const struct ilo_state_vector *vec,
+              struct gen6_draw_session *session)
+{
+   render->hw_ctx_changed = false;
+
+   render->batch_bo_changed = false;
+   render->state_bo_changed = false;
+   render->instruction_bo_changed = false;
+
+   render->state.reduced_prim = session->reduced_prim;
+   render->state.primitive_restart = vec->draw->primitive_restart;
+}
+
+void
+ilo_render_emit_draw(struct ilo_render *render,
+                     const struct ilo_state_vector *vec)
+{
+   struct gen6_draw_session session;
+
+   ILO_DEV_ASSERT(render->dev, 6, 7.5);
+
+   gen6_draw_prepare(render, vec, &session);
+
+   /* force all states to be uploaded if the state bo changed */
+   if (render->state_bo_changed)
+      session.pipe_dirty = ILO_DIRTY_ALL;
+   else
+      session.pipe_dirty = vec->dirty;
+
+   ilo_render_emit_draw_dynamic_states(render, vec, &session);
+   ilo_render_emit_draw_surface_states(render, vec, &session);
+
+   /* force all commands to be uploaded if the HW context changed */
+   if (render->hw_ctx_changed)
+      session.pipe_dirty = ILO_DIRTY_ALL;
+   else
+      session.pipe_dirty = vec->dirty;
+
+   ilo_render_emit_draw_commands(render, vec, &session);
+
+   gen6_draw_end(render, vec, &session);
+}
index dd4c3c0f95a863e11092a370c215189956cb3982..60e3769e0dc4ddedfd63d2db6927ffe334445ecd 100644 (file)
@@ -37,10 +37,6 @@ struct ilo_cp;
 struct ilo_query;
 struct ilo_state_vector;
 
-enum ilo_render_action {
-   ILO_RENDER_DRAW,
-};
-
 /**
  * Render Engine.
  */
@@ -54,13 +50,6 @@ struct ilo_render {
    uint32_t packed_sample_position_4x;
    uint32_t packed_sample_position_8x[2];
 
-   int (*estimate_size)(struct ilo_render *render,
-                        enum ilo_render_action action,
-                        const void *arg);
-
-   void (*emit_draw)(struct ilo_render *render,
-                     const struct ilo_state_vector *vec);
-
    bool hw_ctx_changed;
 
    /*
@@ -143,24 +132,6 @@ ilo_render_destroy(struct ilo_render *render);
 /**
  * Estimate the size of an action.
  */
-static inline int
-ilo_render_estimate_size(struct ilo_render *render,
-                         enum ilo_render_action action,
-                         const void *arg)
-{
-   return render->estimate_size(render, action, arg);
-}
-
-/**
- * Emit context states and 3DPRIMITIVE.
- */
-static inline void
-ilo_render_emit_draw(struct ilo_render *render,
-                     const struct ilo_state_vector *vec)
-{
-   render->emit_draw(render, vec);
-}
-
 void
 ilo_render_get_sample_position(const struct ilo_render *render,
                                unsigned sample_count,
@@ -195,4 +166,12 @@ void
 ilo_render_emit_rectlist(struct ilo_render *render,
                          const struct ilo_blitter *blitter);
 
+int
+ilo_render_get_draw_len(const struct ilo_render *render,
+                        const struct ilo_state_vector *vec);
+
+void
+ilo_render_emit_draw(struct ilo_render *render,
+                     const struct ilo_state_vector *vec);
+
 #endif /* ILO_RENDER_H */
index 80e51cab31d23baf070395c57897433c1ffcc662..ffddaa87f67c64c6c0d297d7069bd629d6f411c9 100644 (file)
@@ -45,10 +45,6 @@ struct gen6_draw_session {
    bool prim_changed;
    bool primitive_restart_changed;
 
-   void (*emit_draw_commands)(struct ilo_render *render,
-                              const struct ilo_state_vector *ilo,
-                              struct gen6_draw_session *session);
-
    /* dynamic states */
    bool viewport_changed;
    bool scissor_changed;
@@ -73,6 +69,50 @@ struct gen6_draw_session {
    int num_surfaces[PIPE_SHADER_TYPES];
 };
 
+int
+ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
+                                      const struct ilo_state_vector *vec);
+
+int
+ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
+                                      const struct ilo_state_vector *vec);
+
+static inline int
+ilo_render_get_draw_commands_len(const struct ilo_render *render,
+                                 const struct ilo_state_vector *vec)
+{
+   if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
+      return ilo_render_get_draw_commands_len_gen7(render, vec);
+   else
+      return ilo_render_get_draw_commands_len_gen6(render, vec);
+}
+
+void
+ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
+                                   const struct ilo_state_vector *vec,
+                                   struct gen6_draw_session *session);
+
+void
+ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
+                                   const struct ilo_state_vector *vec,
+                                   struct gen6_draw_session *session);
+
+static inline void
+ilo_render_emit_draw_commands(struct ilo_render *render,
+                              const struct ilo_state_vector *vec,
+                              struct gen6_draw_session *session)
+{
+   const unsigned batch_used = ilo_builder_batch_used(render->builder);
+
+   if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
+      ilo_render_emit_draw_commands_gen7(render, vec, session);
+   else
+      ilo_render_emit_draw_commands_gen6(render, vec, session);
+
+   assert(ilo_builder_batch_used(render->builder) <= batch_used +
+         ilo_render_get_draw_commands_len(render, vec));
+}
+
 int
 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
                                           const struct ilo_blitter *blitter);
@@ -136,21 +176,6 @@ ilo_render_emit_draw_surface_states(struct ilo_render *render,
 void
 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
 
-void
-gen6_draw_prepare(struct ilo_render *r,
-                  const struct ilo_state_vector *ilo,
-                  struct gen6_draw_session *session);
-
-void
-gen6_draw_emit(struct ilo_render *r,
-               const struct ilo_state_vector *ilo,
-               struct gen6_draw_session *session);
-
-void
-gen6_draw_end(struct ilo_render *r,
-              const struct ilo_state_vector *ilo,
-              struct gen6_draw_session *session);
-
 void
 gen6_draw_common_select(struct ilo_render *r,
                         const struct ilo_state_vector *ilo,
@@ -196,7 +221,4 @@ gen6_draw_wm_raster(struct ilo_render *r,
                     const struct ilo_state_vector *ilo,
                     struct gen6_draw_session *session);
 
-void
-ilo_render_init_gen6(struct ilo_render *render);
-
 #endif /* ILO_RENDER_GEN_H */
index 2173746c83bff6d2400f05ffb42a5d838b3d02d5..f2b876cf046fbbf2d0841dee3e3886f143f85b74 100644 (file)
@@ -834,11 +834,13 @@ gen6_draw_wm_raster(struct ilo_render *r,
 
 #undef DIRTY
 
-static void
-gen6_draw_commands(struct ilo_render *render,
-                   const struct ilo_state_vector *vec,
-                   struct gen6_draw_session *session)
+void
+ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
+                                   const struct ilo_state_vector *vec,
+                                   struct gen6_draw_session *session)
 {
+   ILO_DEV_ASSERT(render->dev, 6, 6);
+
    /*
     * We try to keep the order of the commands match, as closely as possible,
     * that of the classic i965 driver.  It allows us to compare the command
@@ -866,83 +868,6 @@ gen6_draw_commands(struct ilo_render *render,
    gen6_draw_vf_draw(render, vec, session);
 }
 
-void
-gen6_draw_prepare(struct ilo_render *render,
-                  const struct ilo_state_vector *vec,
-                  struct gen6_draw_session *session)
-{
-   memset(session, 0, sizeof(*session));
-   session->pipe_dirty = vec->dirty;
-   session->reduced_prim = u_reduced_prim(vec->draw->mode);
-
-   if (render->hw_ctx_changed) {
-      /* these should be enough to make everything uploaded */
-      render->batch_bo_changed = true;
-      render->state_bo_changed = true;
-      render->instruction_bo_changed = true;
-
-      session->prim_changed = true;
-      session->primitive_restart_changed = true;
-   } else {
-      session->prim_changed =
-         (render->state.reduced_prim != session->reduced_prim);
-      session->primitive_restart_changed =
-         (render->state.primitive_restart != vec->draw->primitive_restart);
-   }
-}
-
-void
-gen6_draw_emit(struct ilo_render *render,
-               const struct ilo_state_vector *vec,
-               struct gen6_draw_session *session)
-{
-   /* force all states to be uploaded if the state bo changed */
-   if (render->state_bo_changed)
-      session->pipe_dirty = ILO_DIRTY_ALL;
-   else
-      session->pipe_dirty = vec->dirty;
-
-   ilo_render_emit_draw_dynamic_states(render, vec, session);
-   ilo_render_emit_draw_surface_states(render, vec, session);
-
-   /* force all commands to be uploaded if the HW context changed */
-   if (render->hw_ctx_changed)
-      session->pipe_dirty = ILO_DIRTY_ALL;
-   else
-      session->pipe_dirty = vec->dirty;
-
-   session->emit_draw_commands(render, vec, session);
-}
-
-void
-gen6_draw_end(struct ilo_render *render,
-              const struct ilo_state_vector *vec,
-              struct gen6_draw_session *session)
-{
-   render->hw_ctx_changed = false;
-
-   render->batch_bo_changed = false;
-   render->state_bo_changed = false;
-   render->instruction_bo_changed = false;
-
-   render->state.reduced_prim = session->reduced_prim;
-   render->state.primitive_restart = vec->draw->primitive_restart;
-}
-
-static void
-ilo_render_emit_draw_gen6(struct ilo_render *render,
-                          const struct ilo_state_vector *vec)
-{
-   struct gen6_draw_session session;
-
-   gen6_draw_prepare(render, vec, &session);
-
-   session.emit_draw_commands = gen6_draw_commands;
-
-   gen6_draw_emit(render, vec, &session);
-   gen6_draw_end(render, vec, &session);
-}
-
 static void
 gen6_rectlist_vs_to_sf(struct ilo_render *r,
                        const struct ilo_blitter *blitter)
@@ -1085,17 +1010,20 @@ ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
    gen6_3DPRIMITIVE(r->builder, &blitter->draw, NULL);
 }
 
-static int
-gen6_render_max_command_size(const struct ilo_render *render)
+int
+ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
+                                      const struct ilo_state_vector *vec)
 {
-   static int size;
+   static int len;
+
+   ILO_DEV_ASSERT(render->dev, 6, 6);
 
-   if (!size) {
-      size += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 3;
-      size += GEN6_3DSTATE_GS_SVB_INDEX__SIZE * 4;
-      size += GEN6_PIPE_CONTROL__SIZE * 5;
+   if (!len) {
+      len += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 3;
+      len += GEN6_3DSTATE_GS_SVB_INDEX__SIZE * 4;
+      len += GEN6_PIPE_CONTROL__SIZE * 5;
 
-      size +=
+      len +=
          GEN6_STATE_BASE_ADDRESS__SIZE +
          GEN6_STATE_SIP__SIZE +
          GEN6_3DSTATE_VF_STATISTICS__SIZE +
@@ -1128,38 +1056,5 @@ gen6_render_max_command_size(const struct ilo_render *render)
          GEN6_3DPRIMITIVE__SIZE;
    }
 
-   return size;
-}
-
-static int
-ilo_render_estimate_size_gen6(struct ilo_render *render,
-                              enum ilo_render_action action,
-                              const void *arg)
-{
-   int size;
-
-   switch (action) {
-   case ILO_RENDER_DRAW:
-      {
-         const struct ilo_state_vector *vec = arg;
-
-         size = gen6_render_max_command_size(render) +
-            ilo_render_get_draw_dynamic_states_len(render, vec) +
-            ilo_render_get_draw_surface_states_len(render, vec);
-      }
-      break;
-   default:
-      assert(!"unknown render action");
-      size = 0;
-      break;
-   }
-
-   return size;
-}
-
-void
-ilo_render_init_gen6(struct ilo_render *render)
-{
-   render->estimate_size = ilo_render_estimate_size_gen6;
-   render->emit_draw = ilo_render_emit_draw_gen6;
+   return len;
 }
index 3ec24c823c33e9004eb1175e50265b8f67adf220..888d67810af8e4a52d64061e7a79959f9961ff48 100644 (file)
@@ -35,7 +35,6 @@
 #include "ilo_state.h"
 #include "ilo_render.h"
 #include "ilo_render_gen.h"
-#include "ilo_render_gen7.h"
 
 /**
  * A wrapper for gen6_PIPE_CONTROL().
@@ -652,11 +651,13 @@ gen7_draw_vf_draw(struct ilo_render *r,
    r->state.deferred_pipe_control_dw1 = 0;
 }
 
-static void
-gen7_draw_commands(struct ilo_render *render,
-                   const struct ilo_state_vector *vec,
-                   struct gen6_draw_session *session)
+void
+ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
+                                   const struct ilo_state_vector *vec,
+                                   struct gen6_draw_session *session)
 {
+   ILO_DEV_ASSERT(render->dev, 7, 7.5);
+
    /*
     * We try to keep the order of the commands match, as closely as possible,
     * that of the classic i965 driver.  It allows us to compare the command
@@ -686,20 +687,6 @@ gen7_draw_commands(struct ilo_render *render,
    gen7_draw_vf_draw(render, vec, session);
 }
 
-static void
-ilo_render_emit_draw_gen7(struct ilo_render *render,
-                          const struct ilo_state_vector *vec)
-{
-   struct gen6_draw_session session;
-
-   gen6_draw_prepare(render, vec, &session);
-
-   session.emit_draw_commands = gen7_draw_commands;
-
-   gen6_draw_emit(render, vec, &session);
-   gen6_draw_end(render, vec, &session);
-}
-
 static void
 gen7_rectlist_pcb_alloc(struct ilo_render *r,
                         const struct ilo_blitter *blitter)
@@ -887,20 +874,23 @@ ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
    gen7_3DPRIMITIVE(r->builder, &blitter->draw, NULL);
 }
 
-static int
-gen7_render_max_command_size(const struct ilo_render *render)
+int
+ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
+                                      const struct ilo_state_vector *vec)
 {
-   static int size;
+   static int len;
 
-   if (!size) {
-      size += GEN7_3DSTATE_URB_ANY__SIZE * 4;
-      size += GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE * 5;
-      size += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 5;
-      size += GEN7_3DSTATE_POINTERS_ANY__SIZE * (5 + 5 + 4);
-      size += GEN7_3DSTATE_SO_BUFFER__SIZE * 4;
-      size += GEN6_PIPE_CONTROL__SIZE * 5;
+   ILO_DEV_ASSERT(render->dev, 7, 7.5);
 
-      size +=
+   if (!len) {
+      len += GEN7_3DSTATE_URB_ANY__SIZE * 4;
+      len += GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE * 5;
+      len += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 5;
+      len += GEN7_3DSTATE_POINTERS_ANY__SIZE * (5 + 5 + 4);
+      len += GEN7_3DSTATE_SO_BUFFER__SIZE * 4;
+      len += GEN6_PIPE_CONTROL__SIZE * 5;
+
+      len +=
          GEN6_STATE_BASE_ADDRESS__SIZE +
          GEN6_STATE_SIP__SIZE +
          GEN6_3DSTATE_VF_STATISTICS__SIZE +
@@ -935,38 +925,5 @@ gen7_render_max_command_size(const struct ilo_render *render)
          GEN6_3DPRIMITIVE__SIZE;
    }
 
-   return size;
-}
-
-static int
-ilo_render_estimate_size_gen7(struct ilo_render *render,
-                              enum ilo_render_action action,
-                              const void *arg)
-{
-   int size;
-
-   switch (action) {
-   case ILO_RENDER_DRAW:
-      {
-         const struct ilo_state_vector *vec = arg;
-
-         size = gen7_render_max_command_size(render) +
-            ilo_render_get_draw_dynamic_states_len(render, vec) +
-            ilo_render_get_draw_surface_states_len(render, vec);
-      }
-      break;
-   default:
-      assert(!"unknown render action");
-      size = 0;
-      break;
-   }
-
-   return size;
-}
-
-void
-ilo_render_init_gen7(struct ilo_render *render)
-{
-   render->estimate_size = ilo_render_estimate_size_gen7;
-   render->emit_draw = ilo_render_emit_draw_gen7;
+   return len;
 }
diff --git a/src/gallium/drivers/ilo/ilo_render_gen7.h b/src/gallium/drivers/ilo/ilo_render_gen7.h
deleted file mode 100644 (file)
index 5721ce2..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2013 LunarG, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Chia-I Wu <olv@lunarg.com>
- */
-
-#ifndef ILO_RENDER_GEN7_H
-#define ILO_RENDER_GEN7_H
-
-#include "ilo_common.h"
-
-struct ilo_render;
-
-void
-ilo_render_init_gen7(struct ilo_render *render);
-
-#endif /* ILO_RENDER_GEN7_H */