[Mesa-dev] [PATCH 2/3] st/mesa: unify common code in st_draw_vbo functions

Marek Olšák maraeo at gmail.com
Mon May 8 17:09:09 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_draw.c | 48 ++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 78aabb0..15c5b80 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -117,20 +117,37 @@ translate_prim(const struct gl_context *ctx, unsigned prim)
 {
    /* GL prims should match Gallium prims, spot-check a few */
    STATIC_ASSERT(GL_POINTS == PIPE_PRIM_POINTS);
    STATIC_ASSERT(GL_QUADS == PIPE_PRIM_QUADS);
    STATIC_ASSERT(GL_TRIANGLE_STRIP_ADJACENCY == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
    STATIC_ASSERT(GL_PATCHES == PIPE_PRIM_PATCHES);
 
    return prim;
 }
 
+static inline void
+prepare_draw(struct st_context *st, struct gl_context *ctx)
+{
+   /* Mesa core state should have been validated already */
+   assert(ctx->NewState == 0x0);
+
+   if (unlikely(!st->bitmap.cache.empty))
+      st_flush_bitmap_cache(st);
+
+   st_invalidate_readpix_cache(st);
+
+   /* Validate state. */
+   if ((st->dirty | ctx->NewDriverState) & ST_PIPELINE_RENDER_STATE_MASK ||
+       st->gfx_shaders_may_be_dirty) {
+      st_validate_state(st, ST_PIPELINE_RENDER);
+   }
+}
 
 /**
  * This function gets plugged into the VBO module and is called when
  * we have something to render.
  * Basically, translate the information into the format expected by gallium.
  */
 static void
 st_draw_vbo(struct gl_context *ctx,
             const struct _mesa_prim *prims,
             GLuint nr_prims,
@@ -141,37 +158,24 @@ st_draw_vbo(struct gl_context *ctx,
             struct gl_transform_feedback_object *tfb_vertcount,
             unsigned stream,
             struct gl_buffer_object *indirect)
 {
    struct st_context *st = st_context(ctx);
    struct pipe_draw_info info;
    const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
    unsigned i;
    unsigned start = 0;
 
-   /* Mesa core state should have been validated already */
-   assert(ctx->NewState == 0x0);
-
-   if (unlikely(!st->bitmap.cache.empty))
-      st_flush_bitmap_cache(st);
-
-   st_invalidate_readpix_cache(st);
-
-   /* Validate state. */
-   if ((st->dirty | ctx->NewDriverState) & ST_PIPELINE_RENDER_STATE_MASK ||
-       st->gfx_shaders_may_be_dirty) {
-      st_validate_state(st, ST_PIPELINE_RENDER);
-   }
+   prepare_draw(st, ctx);
 
-   if (st->vertex_array_out_of_memory) {
+   if (st->vertex_array_out_of_memory)
       return;
-   }
 
    /* Initialize pipe_draw_info. */
    info.primitive_restart = false;
    info.vertices_per_patch = ctx->TessCtrlProgram.patch_vertices;
    info.indirect = NULL;
    info.count_from_stream_output = NULL;
 
    if (ib) {
       struct gl_buffer_object *bufobj = ib->obj;
 
@@ -246,35 +250,25 @@ st_indirect_draw_vbo(struct gl_context *ctx,
                      unsigned draw_count,
                      unsigned stride,
                      struct gl_buffer_object *indirect_params,
                      GLsizeiptr indirect_params_offset,
                      const struct _mesa_index_buffer *ib)
 {
    struct st_context *st = st_context(ctx);
    struct pipe_draw_info info;
    struct pipe_draw_indirect_info indirect;
 
-   /* Mesa core state should have been validated already */
-   assert(ctx->NewState == 0x0);
    assert(stride);
+   prepare_draw(st, ctx);
 
-   st_invalidate_readpix_cache(st);
-
-   /* Validate state. */
-   if ((st->dirty | ctx->NewDriverState) & ST_PIPELINE_RENDER_STATE_MASK ||
-       st->gfx_shaders_may_be_dirty) {
-      st_validate_state(st, ST_PIPELINE_RENDER);
-   }
-
-   if (st->vertex_array_out_of_memory) {
+   if (st->vertex_array_out_of_memory)
       return;
-   }
 
    memset(&indirect, 0, sizeof(indirect));
    util_draw_init_info(&info);
    info.start = 0; /* index offset / index size */
 
    if (ib) {
       struct gl_buffer_object *bufobj = ib->obj;
 
       /* indices are always in a real VBO */
       assert(_mesa_is_bufferobj(bufobj));
-- 
2.7.4



More information about the mesa-dev mailing list