[Mesa-dev] [PATCH 6/9] st/mesa: make user constant buffers optional

Marek Olšák maraeo at gmail.com
Tue Apr 24 14:56:27 PDT 2012


---
 src/mesa/state_tracker/st_atom_constbuf.c |   19 +++++++++++++------
 src/mesa/state_tracker/st_context.c       |   13 +++++++++++++
 src/mesa/state_tracker/st_context.h       |    2 +-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 87bb515..eb98161 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -38,6 +38,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
+#include "util/u_upload_mgr.h"
 
 #include "st_debug.h"
 #include "st_context.h"
@@ -77,15 +78,21 @@ void st_upload_constants( struct st_context *st,
        * avoid gratuitous rendering synchronization.
        * Let's use a user buffer to avoid an unnecessary copy.
        */
-      cb.buffer = pipe_user_buffer_create(pipe->screen,
-                                          params->ParameterValues,
-                                          paramBytes,
-                                          PIPE_BIND_CONSTANT_BUFFER);
-      cb.buffer_offset = 0;
+      if (st->constbuf_uploader) {
+         cb.buffer = NULL;
+         u_upload_data(st->constbuf_uploader, 0, paramBytes,
+                       params->ParameterValues, &cb.buffer_offset, &cb.buffer);
+      } else {
+         cb.buffer = pipe_user_buffer_create(pipe->screen,
+                                             params->ParameterValues,
+                                             paramBytes,
+                                             PIPE_BIND_CONSTANT_BUFFER);
+         cb.buffer_offset = 0;
+      }
       cb.buffer_size = paramBytes;
 
       if (ST_DEBUG & DEBUG_CONSTANTS) {
-	 debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", 
+         debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
                       __FUNCTION__, shader_type, params->NumParameters,
                       params->StateFlags);
          _mesa_print_parameter_list(params);
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 164cc45..d4907db 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -139,6 +139,7 @@ static struct st_context *
 st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe )
 {
    uint i;
+   struct pipe_screen *screen = pipe->screen;
    struct st_context *st = ST_CALLOC_STRUCT( st_context );
    
    ctx->st = st;
@@ -158,6 +159,15 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe )
    st->uploader = u_upload_create(st->pipe, 128 * 1024, 4,
                                   PIPE_BIND_VERTEX_BUFFER |
                                   PIPE_BIND_INDEX_BUFFER);
+
+   if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) {
+      unsigned alignment =
+         screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT);
+
+      st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, alignment,
+                                              PIPE_BIND_CONSTANT_BUFFER);
+   }
+
    st->cso_context = cso_create_context(pipe);
 
    st_init_vbuf(st);
@@ -265,6 +275,9 @@ static void st_destroy_context_priv( struct st_context *st )
    }
 
    u_upload_destroy(st->uploader);
+   if (st->constbuf_uploader) {
+      u_upload_destroy(st->constbuf_uploader);
+   }
    free( st );
 }
 
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index ffd36e6..1af0d14 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -73,7 +73,7 @@ struct st_context
 
    struct pipe_context *pipe;
 
-   struct u_upload_mgr *uploader;
+   struct u_upload_mgr *uploader, *constbuf_uploader;
    struct u_vbuf *vbuf;
 
    struct draw_context *draw;  /**< For selection/feedback/rastpos only */
-- 
1.7.5.4



More information about the mesa-dev mailing list