intel / DRI2: When available, use DRI2GetBuffersWithFormat
[mesa.git] / src / mesa / state_tracker / st_atom_constbuf.c
index 21416da2e012c702338adca6cd67a1134532c95f..3ba7b2692856bda0defeadf6736a7a1d869b98c6 100644 (file)
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_winsys.h"
 #include "pipe/p_inlines.h"
 
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_atom_constbuf.h"
 #include "st_program.h"
-
+#include "st_inlines.h"
 
 /**
  * Pass the given program parameters to the graphics pipe as a
@@ -54,7 +53,7 @@ void st_upload_constants( struct st_context *st,
                           struct gl_program_parameter_list *params,
                           unsigned id)
 {
-   struct pipe_winsys *ws = st->pipe->winsys;
+   struct pipe_context *pipe = st->pipe;
    struct pipe_constant_buffer *cbuf = &st->state.constants[id];
 
    assert(id == PIPE_SHADER_VERTEX || id == PIPE_SHADER_FRAGMENT);
@@ -63,20 +62,14 @@ void st_upload_constants( struct st_context *st,
    if (params && params->NumParameters) {
       const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
 
-      /* Update our own dependency flags.  This works because this
-       * function will also be called whenever the program changes.
-       */
-      st->constants.tracked_state[id].dirty.mesa = params->StateFlags;
-
       _mesa_load_state_parameters(st->ctx, params);
 
-      if (cbuf->buffer && cbuf->size != paramBytes)
-        pipe_buffer_reference( ws, &cbuf->buffer, NULL );
-
-      if (!cbuf->buffer) {
-         cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT,
-                                          paramBytes);
-      }
+      /* We always need to get a new buffer, to keep the drivers simple and
+       * avoid gratuitous rendering synchronization.
+       */
+      pipe_buffer_reference(&cbuf->buffer, NULL );
+      cbuf->buffer = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT,
+                                       paramBytes );
 
       if (0)
       {
@@ -86,13 +79,10 @@ void st_upload_constants( struct st_context *st,
       }
 
       /* load Mesa constants into the constant buffer */
-      if (cbuf->buffer) {
-         memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
-                params->ParameterValues, paramBytes);
-         ws->buffer_unmap(ws, cbuf->buffer);
-      }
-
-      cbuf->size = paramBytes;
+      if (cbuf->buffer)
+         st_no_flush_pipe_buffer_write(st, cbuf->buffer,
+                                      0, paramBytes,
+                                      params->ParameterValues);
 
       st->pipe->set_constant_buffer(st->pipe, id, 0, cbuf);
    }
@@ -113,12 +103,12 @@ static void update_vs_constants(struct st_context *st )
 }
 
 const struct st_tracked_state st_update_vs_constants = {
-   .name = "st_update_vs_constants",
-   .dirty = {
-      .mesa  = 0, 
-      .st   = ST_NEW_VERTEX_PROGRAM,
+   "st_update_vs_constants",                           /* name */
+   {                                                   /* dirty */
+      (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS),          /* mesa */
+      ST_NEW_VERTEX_PROGRAM,                           /* st */
    },
-   .update = update_vs_constants
+   update_vs_constants                                 /* update */
 };
 
 /* Fragment shader:
@@ -132,11 +122,11 @@ static void update_fs_constants(struct st_context *st )
 }
 
 const struct st_tracked_state st_update_fs_constants = {
-   .name = "st_update_fs_constants",
-   .dirty = {
-      .mesa  = 0, 
-      .st   = ST_NEW_FRAGMENT_PROGRAM,
+   "st_update_fs_constants",                           /* name */
+   {                                                   /* dirty */
+      (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS),          /* mesa */
+      ST_NEW_FRAGMENT_PROGRAM,                         /* st */
    },
-   .update = update_fs_constants
+   update_fs_constants                                 /* update */
 };