[Mesa-dev] [PATCH 09/11] st/mesa: use the common uploader (v2)

Marek Olšák maraeo at gmail.com
Thu Feb 9 00:11:10 UTC 2017


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

v2: use const_uploader

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com> (v1)
Tested-by: Edmondo Tommasina <edmondo.tommasina at gmail.com> (v1)
---
 src/mesa/state_tracker/st_atom_constbuf.c |  6 +++---
 src/mesa/state_tracker/st_cb_bitmap.c     |  4 ++--
 src/mesa/state_tracker/st_cb_drawtex.c    |  4 ++--
 src/mesa/state_tracker/st_context.c       | 28 ++++------------------------
 src/mesa/state_tracker/st_context.h       |  4 ++--
 src/mesa/state_tracker/st_draw.c          | 13 +++++++------
 src/mesa/state_tracker/st_pbo.c           | 10 +++++-----
 7 files changed, 25 insertions(+), 44 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 6ab4ca9..d16f92e 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -93,27 +93,27 @@ void st_upload_constants( struct st_context *st,
        */
       if (params->StateFlags)
          _mesa_load_state_parameters(st->ctx, params);
 
       _mesa_shader_write_subroutine_indices(st->ctx, stage);
 
       /* We always need to get a new buffer, to keep the drivers simple and
        * avoid gratuitous rendering synchronization.
        * Let's use a user buffer to avoid an unnecessary copy.
        */
-      if (st->constbuf_uploader) {
+      if (!st->has_user_constbuf) {
          cb.buffer = NULL;
          cb.user_buffer = NULL;
-         u_upload_data(st->constbuf_uploader, 0, paramBytes,
+         u_upload_data(st->pipe->const_uploader, 0, paramBytes,
                        st->ctx->Const.UniformBufferOffsetAlignment,
                        params->ParameterValues, &cb.buffer_offset, &cb.buffer);
-         u_upload_unmap(st->constbuf_uploader);
+         u_upload_unmap(st->pipe->const_uploader);
       } else {
          cb.buffer = NULL;
          cb.user_buffer = params->ParameterValues;
          cb.buffer_offset = 0;
       }
       cb.buffer_size = paramBytes;
 
       if (ST_DEBUG & DEBUG_CONSTANTS) {
          debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
                       __func__, shader_type, params->NumParameters,
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 457c416..b2e2608 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -710,21 +710,21 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
    sv = st_create_texture_sampler_view(pipe, stObj->pt);
    if (!sv) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCallLists(bitmap text)");
       return;
    }
 
    setup_render_state(ctx, sv, color, true);
 
    vb.stride = sizeof(struct st_util_vertex);
 
-   u_upload_alloc(st->uploader, 0, num_vert_bytes, 4,
+   u_upload_alloc(pipe->stream_uploader, 0, num_vert_bytes, 4,
                   &vb.buffer_offset, &vb.buffer, (void **) &verts);
 
    /* build quads vertex data */
    for (i = 0; i < count; i++) {
       const GLfloat epsilon = 0.0001F;
       const struct gl_bitmap_glyph *g = &atlas->glyphs[ids[i]];
       const float xmove = g->xmove, ymove = g->ymove;
       const float xorig = g->xorig, yorig = g->yorig;
       const float s0 = g->x, t0 = g->y;
       const float s1 = s0 + g->w, t1 = t0 + g->h;
@@ -782,21 +782,21 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
       verts->a = color[3];
       verts->s = s0;
       verts->t = t1;
       verts++;
 
       /* Update the raster position */
       ctx->Current.RasterPos[0] += xmove;
       ctx->Current.RasterPos[1] += ymove;
    }
 
-   u_upload_unmap(st->uploader);
+   u_upload_unmap(pipe->stream_uploader);
 
    cso_set_vertex_buffers(st->cso_context,
                           cso_get_aux_vertex_buffer_slot(st->cso_context),
                           1, &vb);
 
    cso_draw_arrays(st->cso_context, PIPE_PRIM_QUADS, 0, num_verts);
 
    restore_render_state(ctx);
 
    pipe_resource_reference(&vb.buffer, NULL);
diff --git a/src/mesa/state_tracker/st_cb_drawtex.c b/src/mesa/state_tracker/st_cb_drawtex.c
index 85f9a53..01c5757 100644
--- a/src/mesa/state_tracker/st_cb_drawtex.c
+++ b/src/mesa/state_tracker/st_cb_drawtex.c
@@ -149,21 +149,21 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
          vbuf[k + 0] = X;                                               \
          vbuf[k + 1] = Y;                                               \
          vbuf[k + 2] = Z;                                               \
          vbuf[k + 3] = W;                                               \
       } while (0)
 
       const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
       GLfloat *vbuf = NULL;
       GLuint tex_attr;
 
-      u_upload_alloc(st->uploader, 0,
+      u_upload_alloc(pipe->stream_uploader, 0,
                      numAttribs * 4 * 4 * sizeof(GLfloat), 4,
                      &offset, &vbuffer, (void **) &vbuf);
       if (!vbuffer) {
          return;
       }
 
       z = CLAMP(z, 0.0f, 1.0f);
 
       /* positions (in clip coords) */
       {
@@ -221,21 +221,21 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
 
             semantic_names[tex_attr] = st->needs_texcoord_semantic ?
                TGSI_SEMANTIC_TEXCOORD : TGSI_SEMANTIC_GENERIC;
             /* XXX: should this use semantic index i instead of 0 ? */
             semantic_indexes[tex_attr] = 0;
 
             tex_attr++;
          }
       }
 
-      u_upload_unmap(st->uploader);
+      u_upload_unmap(pipe->stream_uploader);
 
 #undef SET_ATTRIB
    }
 
    cso_save_state(cso, (CSO_BIT_VIEWPORT |
                         CSO_BIT_STREAM_OUTPUTS |
                         CSO_BIT_VERTEX_SHADER |
                         CSO_BIT_TESSCTRL_SHADER |
                         CSO_BIT_TESSEVAL_SHADER |
                         CSO_BIT_GEOMETRY_SHADER |
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 5523734..3d0455f 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -291,28 +291,20 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
    st_destroy_perfmon(st);
    st_destroy_pbo_helpers(st);
 
    for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) {
       for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
          pipe_sampler_view_release(st->pipe,
                                    &st->state.sampler_views[shader][i]);
       }
    }
 
-   u_upload_destroy(st->uploader);
-   if (st->indexbuf_uploader) {
-      u_upload_destroy(st->indexbuf_uploader);
-   }
-   if (st->constbuf_uploader) {
-      u_upload_destroy(st->constbuf_uploader);
-   }
-
    /* free glDrawPixels cache data */
    free(st->drawpix_cache.image);
    pipe_resource_reference(&st->drawpix_cache.texture, NULL);
 
    /* free glReadPixels cache data */
    st_invalidate_readpix_cache(st);
 
    cso_destroy_context(st->cso_context);
 
    if (st->pipe && destroy_pipe)
@@ -338,36 +330,24 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
    st->pipe = pipe;
 
    /* XXX: this is one-off, per-screen init: */
    st_debug_init();
    
    /* state tracker needs the VBO module */
    _vbo_CreateContext(ctx);
 
    st->dirty = ST_ALL_STATES_MASK;
 
-   /* Create upload manager for vertex data for glBitmap, glDrawPixels,
-    * glClear, etc.
-    */
-   st->uploader = u_upload_create(pipe, 65536, PIPE_BIND_VERTEX_BUFFER,
-                                  PIPE_USAGE_STREAM);
-
-   if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) {
-      st->indexbuf_uploader = u_upload_create(pipe, 128 * 1024,
-                                              PIPE_BIND_INDEX_BUFFER,
-                                              PIPE_USAGE_STREAM);
-   }
-
-   if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS))
-      st->constbuf_uploader = u_upload_create(pipe, 128 * 1024,
-                                              PIPE_BIND_CONSTANT_BUFFER,
-                                              PIPE_USAGE_STREAM);
+   st->has_user_indexbuf =
+      screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS);
+   st->has_user_constbuf =
+      screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS);
 
    st->cso_context = cso_create_context(pipe);
 
    st_init_atoms( st );
    st_init_clear(st);
    st_init_draw( st );
    st_init_pbo_helpers(st);
 
    /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */
    if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index b3478ea..942fdd7 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -61,38 +61,38 @@ struct st_util_vertex
 
 
 struct st_context
 {
    struct st_context_iface iface;
 
    struct gl_context *ctx;
 
    struct pipe_context *pipe;
 
-   struct u_upload_mgr *uploader, *indexbuf_uploader, *constbuf_uploader;
-
    struct draw_context *draw;  /**< For selection/feedback/rastpos only */
    struct draw_stage *feedback_stage;  /**< For GL_FEEDBACK rendermode */
    struct draw_stage *selection_stage;  /**< For GL_SELECT rendermode */
    struct draw_stage *rastpos_stage;  /**< For glRasterPos */
    GLboolean clamp_frag_color_in_shader;
    GLboolean clamp_vert_color_in_shader;
    boolean has_stencil_export; /**< can do shader stencil export? */
    boolean has_time_elapsed;
    boolean has_shader_model3;
    boolean has_etc1;
    boolean has_etc2;
    boolean prefer_blit_based_texture_transfer;
    boolean force_persample_in_shader;
    boolean has_shareable_shaders;
    boolean has_half_float_packing;
    boolean has_multi_draw_indirect;
+   boolean has_user_constbuf;
+   boolean has_user_indexbuf;
 
    /**
     * If a shader can be created when we get its source.
     * This means it has only 1 variant, not counting glBitmap and
     * glDrawPixels.
     */
    boolean shader_has_one_variant[MESA_SHADER_STAGES];
 
    boolean needs_texcoord_semantic;
    boolean apply_texture_swizzle_to_border_color;
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index c1a1d2d..8d54732 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -98,30 +98,30 @@ setup_index_buffer(struct st_context *st,
    struct gl_buffer_object *bufobj = ib->obj;
 
    ibuffer->index_size = vbo_sizeof_ib_type(ib->type);
 
    /* get/create the index buffer object */
    if (_mesa_is_bufferobj(bufobj)) {
       /* indices are in a real VBO */
       ibuffer->buffer = st_buffer_object(bufobj)->buffer;
       ibuffer->offset = pointer_to_offset(ib->ptr);
    }
-   else if (st->indexbuf_uploader) {
+   else if (!st->has_user_indexbuf) {
       /* upload indexes from user memory into a real buffer */
-      u_upload_data(st->indexbuf_uploader, 0,
+      u_upload_data(st->pipe->stream_uploader, 0,
                     ib->count * ibuffer->index_size, 4, ib->ptr,
                     &ibuffer->offset, &ibuffer->buffer);
       if (!ibuffer->buffer) {
          /* out of memory */
          return FALSE;
       }
-      u_upload_unmap(st->indexbuf_uploader);
+      u_upload_unmap(st->pipe->stream_uploader);
    }
    else {
       /* indices are in user space memory */
       ibuffer->user_buffer = ib->ptr;
    }
 
    cso_set_index_buffer(st->cso_context, ibuffer);
    return TRUE;
 }
 
@@ -270,21 +270,21 @@ st_draw_vbo(struct gl_context *ctx,
       }
       else if (info.primitive_restart) {
          /* don't trim, restarts might be inside index list */
          cso_draw_vbo(st->cso_context, &info);
       }
       else if (u_trim_pipe_prim(prims[i].mode, &info.count)) {
          cso_draw_vbo(st->cso_context, &info);
       }
    }
 
-   if (ib && st->indexbuf_uploader && !_mesa_is_bufferobj(ib->obj)) {
+   if (ib && !st->has_user_indexbuf && !_mesa_is_bufferobj(ib->obj)) {
       pipe_resource_reference(&ibuffer.buffer, NULL);
    }
 }
 
 static void
 st_indirect_draw_vbo(struct gl_context *ctx,
                      GLuint mode,
                      struct gl_buffer_object *indirect_data,
                      GLsizeiptr indirect_offset,
                      unsigned draw_count,
@@ -411,21 +411,22 @@ st_draw_quad(struct st_context *st,
              float x0, float y0, float x1, float y1, float z,
              float s0, float t0, float s1, float t1,
              const float *color,
              unsigned num_instances)
 {
    struct pipe_vertex_buffer vb = {0};
    struct st_util_vertex *verts;
 
    vb.stride = sizeof(struct st_util_vertex);
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(struct st_util_vertex), 4,
+   u_upload_alloc(st->pipe->stream_uploader, 0,
+                  4 * sizeof(struct st_util_vertex), 4,
                   &vb.buffer_offset, &vb.buffer, (void **) &verts);
    if (!vb.buffer) {
       return false;
    }
 
    /* lower-left */
    verts[0].x = x0;
    verts[0].y = y1;
    verts[0].z = z;
    verts[0].r = color[0];
@@ -461,21 +462,21 @@ st_draw_quad(struct st_context *st,
    verts[3].x = x0;
    verts[3].y = y0;
    verts[3].z = z;
    verts[3].r = color[0];
    verts[3].g = color[1];
    verts[3].b = color[2];
    verts[3].a = color[3];
    verts[3].s = s0;
    verts[3].t = t1;
 
-   u_upload_unmap(st->uploader);
+   u_upload_unmap(st->pipe->stream_uploader);
 
    /* At the time of writing, cso_get_aux_vertex_buffer_slot() always returns
     * zero.  If that ever changes we need to audit the calls to that function
     * and make sure the slot number is used consistently everywhere.
     */
    assert(cso_get_aux_vertex_buffer_slot(st->cso_context) == 0);
 
    cso_set_vertex_buffers(st->cso_context,
                           cso_get_aux_vertex_buffer_slot(st->cso_context),
                           1, &vb);
diff --git a/src/mesa/state_tracker/st_pbo.c b/src/mesa/state_tracker/st_pbo.c
index a9ea6ea..2c63c09 100644
--- a/src/mesa/state_tracker/st_pbo.c
+++ b/src/mesa/state_tracker/st_pbo.c
@@ -222,62 +222,62 @@ st_pbo_draw(struct st_context *st, const struct st_pbo_addresses *addr,
       float y0 = (float) addr->yoffset / surface_height * 2.0f - 1.0f;
       float x1 = (float) (addr->xoffset + addr->width) / surface_width * 2.0f - 1.0f;
       float y1 = (float) (addr->yoffset + addr->height) / surface_height * 2.0f - 1.0f;
 
       float *verts = NULL;
 
       vbo.user_buffer = NULL;
       vbo.buffer = NULL;
       vbo.stride = 2 * sizeof(float);
 
-      u_upload_alloc(st->uploader, 0, 8 * sizeof(float), 4,
+      u_upload_alloc(st->pipe->stream_uploader, 0, 8 * sizeof(float), 4,
                      &vbo.buffer_offset, &vbo.buffer, (void **) &verts);
       if (!verts)
          return false;
 
       verts[0] = x0;
       verts[1] = y0;
       verts[2] = x0;
       verts[3] = y1;
       verts[4] = x1;
       verts[5] = y0;
       verts[6] = x1;
       verts[7] = y1;
 
-      u_upload_unmap(st->uploader);
+      u_upload_unmap(st->pipe->stream_uploader);
 
       velem.src_offset = 0;
       velem.instance_divisor = 0;
       velem.vertex_buffer_index = cso_get_aux_vertex_buffer_slot(cso);
       velem.src_format = PIPE_FORMAT_R32G32_FLOAT;
 
       cso_set_vertex_elements(cso, 1, &velem);
 
       cso_set_vertex_buffers(cso, velem.vertex_buffer_index, 1, &vbo);
 
       pipe_resource_reference(&vbo.buffer, NULL);
    }
 
    /* Upload constants */
    {
       struct pipe_constant_buffer cb;
 
-      if (st->constbuf_uploader) {
+      if (!st->has_user_constbuf) {
          cb.buffer = NULL;
          cb.user_buffer = NULL;
-         u_upload_data(st->constbuf_uploader, 0, sizeof(addr->constants),
+         u_upload_data(st->pipe->const_uploader, 0, sizeof(addr->constants),
                        st->ctx->Const.UniformBufferOffsetAlignment,
                        &addr->constants, &cb.buffer_offset, &cb.buffer);
          if (!cb.buffer)
             return false;
 
-         u_upload_unmap(st->constbuf_uploader);
+         u_upload_unmap(st->pipe->const_uploader);
       } else {
          cb.buffer = NULL;
          cb.user_buffer = &addr->constants;
          cb.buffer_offset = 0;
       }
       cb.buffer_size = sizeof(addr->constants);
 
       cso_set_constant_buffer(cso, PIPE_SHADER_FRAGMENT, 0, &cb);
 
       pipe_resource_reference(&cb.buffer, NULL);
-- 
2.7.4



More information about the mesa-dev mailing list