mesa: add & use a new driver flag for UBO updates instead of _NEW_BUFFER_OBJECT
authorMarek Olšák <maraeo@gmail.com>
Fri, 26 Apr 2013 12:21:09 +0000 (14:21 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sat, 11 May 2013 21:45:01 +0000 (23:45 +0200)
v2: move the flagging from intel_bufferobj_data to intel_bufferobj_alloc_buffer

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
13 files changed:
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/brw_vs_surface_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_buffer_objects.c
src/mesa/main/bufferobj.c
src/mesa/main/mtypes.h
src/mesa/main/uniforms.c
src/mesa/state_tracker/st_atom_constbuf.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h

index a676415dde077be0e7a742fb134f31cee6172b39..745a1172772d8cceeafe8056be98779b3cba87ee 100644 (file)
@@ -152,6 +152,7 @@ brwCreateContext(int api,
 
    ctx->DriverFlags.NewTransformFeedback = BRW_NEW_TRANSFORM_FEEDBACK;
    ctx->DriverFlags.NewRasterizerDiscard = BRW_NEW_RASTERIZER_DISCARD;
+   ctx->DriverFlags.NewUniformBuffer = BRW_NEW_UNIFORM_BUFFER;
 
    ctx->Const.MaxDualSourceDrawBuffers = 1;
    ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
index c6825018ddcf18061f9ffd295fc475469cf98053..9baf57bc05ce64b6e31a3a5ca904f4d5ac91d5cd 100644 (file)
@@ -153,6 +153,7 @@ enum brw_state_id {
    BRW_STATE_TRANSFORM_FEEDBACK,
    BRW_STATE_RASTERIZER_DISCARD,
    BRW_STATE_STATS_WM,
+   BRW_STATE_UNIFORM_BUFFER
 };
 
 #define BRW_NEW_URB_FENCE               (1 << BRW_STATE_URB_FENCE)
@@ -184,6 +185,7 @@ enum brw_state_id {
 #define BRW_NEW_TRANSFORM_FEEDBACK     (1 << BRW_STATE_TRANSFORM_FEEDBACK)
 #define BRW_NEW_RASTERIZER_DISCARD     (1 << BRW_STATE_RASTERIZER_DISCARD)
 #define BRW_NEW_STATS_WM               (1 << BRW_STATE_STATS_WM)
+#define BRW_NEW_UNIFORM_BUFFER          (1 << BRW_STATE_UNIFORM_BUFFER)
 
 struct brw_state_flags {
    /** State update flags signalled by mesa internals */
index 270b3f46b8be67099ecaf843cb05f3f9506d979f..cdc26574910584cea39135b62d604a151d01e971 100644 (file)
@@ -372,6 +372,7 @@ static struct dirty_bit_map brw_bits[] = {
    DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT),
    DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK),
    DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD),
+   DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER),
    {0, 0, 0}
 };
 
index 968cc0336f7d4806981602a9e1a656022db5c260..cbad0713bdedf29f577c93d07f2ec24f24e3acf1 100644 (file)
@@ -122,9 +122,8 @@ brw_upload_vs_ubo_surfaces(struct brw_context *brw)
 
 const struct brw_tracked_state brw_vs_ubo_surfaces = {
    .dirty = {
-      .mesa = (_NEW_PROGRAM |
-              _NEW_BUFFER_OBJECT),
-      .brw = BRW_NEW_BATCH,
+      .mesa = _NEW_PROGRAM,
+      .brw = BRW_NEW_BATCH | BRW_NEW_UNIFORM_BUFFER,
       .cache = 0,
    },
    .emit = brw_upload_vs_ubo_surfaces,
index b067f6db9e8b8d680d7ccfecb126895a85d5179f..046c4e8c4ee854a85921ac40b40cb18a1803f5c6 100644 (file)
@@ -1564,9 +1564,8 @@ brw_upload_wm_ubo_surfaces(struct brw_context *brw)
 
 const struct brw_tracked_state brw_wm_ubo_surfaces = {
    .dirty = {
-      .mesa = (_NEW_PROGRAM |
-              _NEW_BUFFER_OBJECT),
-      .brw = BRW_NEW_BATCH,
+      .mesa = _NEW_PROGRAM,
+      .brw = BRW_NEW_BATCH | BRW_NEW_UNIFORM_BUFFER,
       .cache = 0,
    },
    .emit = brw_upload_wm_ubo_surfaces,
index 996518b4e92b09ad99d9ef7597c7a59ca92477a7..f568864f4b4c38b73dbc6a7055a8bccbd169cf87 100644 (file)
 #include "intel_mipmap_tree.h"
 #include "intel_regions.h"
 
+#ifndef I915
+#include "brw_context.h"
+#endif
+
 static GLboolean
 intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj);
 
@@ -49,6 +53,15 @@ intel_bufferobj_alloc_buffer(struct intel_context *intel,
 {
    intel_obj->buffer = drm_intel_bo_alloc(intel->bufmgr, "bufferobj",
                                          intel_obj->Base.Size, 64);
+
+#ifndef I915
+   /* the buffer might be bound as a uniform buffer, need to update it
+    */
+   {
+      struct brw_context *brw = brw_context(&intel->ctx);
+      brw->state.dirty.brw |= BRW_NEW_UNIFORM_BUFFER;
+   }
+#endif
 }
 
 static void
index e482c91cd0ad81fa6d3f48c345e0769d19477e11..1566cb4c509271fff9695bbb9831c801aee134cc 100644 (file)
@@ -2060,7 +2060,8 @@ set_ubo_binding(struct gl_context *ctx,
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
 
    _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
    binding->Offset = offset;
index 137f0e3df0a50305f1d4c58e6216e23edc947e41..9e6ea8aed4bc0edc11d4632190ce78218bab1b41 100644 (file)
@@ -3333,6 +3333,12 @@ struct gl_driver_flags
 
    /** gl_context::RasterDiscard */
    GLbitfield NewRasterizerDiscard;
+
+   /**
+    * gl_context::UniformBufferBindings
+    * gl_shader_program::UniformBlocks
+    */
+   GLbitfield NewUniformBuffer;
 };
 
 struct gl_uniform_buffer_binding
index a53e8e112c98809d1f0c3b7853e16f4819674a47..f0d80f0c81212d247bbd6cbeb6c615f96dfd3d19 100644 (file)
@@ -631,7 +631,9 @@ _mesa_UniformBlockBinding(GLuint program,
        uniformBlockBinding) {
       int i;
 
-      FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+      FLUSH_VERTICES(ctx, 0);
+      ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
+
       shProg->UniformBlocks[uniformBlockIndex].Binding = uniformBlockBinding;
 
       for (i = 0; i < MESA_SHADER_TYPES; i++) {
index ed69166f6b58aac4ef6805d36284b83d21bcc92d..ef208bc36fa1479b5580e5ccdf2daaf9654a6dd7 100644 (file)
@@ -217,8 +217,8 @@ static void bind_vs_ubos(struct st_context *st)
 const struct st_tracked_state st_bind_vs_ubos = {
    "st_bind_vs_ubos",
    {
-      (_NEW_PROGRAM | _NEW_BUFFER_OBJECT),
-      ST_NEW_VERTEX_PROGRAM,
+      _NEW_PROGRAM,
+      ST_NEW_VERTEX_PROGRAM | ST_NEW_UNIFORM_BUFFER,
    },
    bind_vs_ubos
 };
@@ -231,14 +231,13 @@ static void bind_fs_ubos(struct st_context *st)
       return;
 
    st_bind_ubos(st, prog->_LinkedShaders[MESA_SHADER_FRAGMENT], PIPE_SHADER_FRAGMENT);
-
 }
 
 const struct st_tracked_state st_bind_fs_ubos = {
    "st_bind_fs_ubos",
    {
-      (_NEW_PROGRAM | _NEW_BUFFER_OBJECT),
-      ST_NEW_FRAGMENT_PROGRAM,
+      _NEW_PROGRAM,
+      ST_NEW_FRAGMENT_PROGRAM | ST_NEW_UNIFORM_BUFFER,
    },
    bind_fs_ubos
 };
index 8ff32c8429186dd250866ea0a7b3691236bf6deb..d166fe644148d7af8996216b3e73f80c24f8e467 100644 (file)
@@ -247,9 +247,11 @@ st_bufferobj_data(struct gl_context *ctx,
 
       if (data)
          pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
-      return GL_TRUE;
    }
 
+   /* BufferData may change a uniform buffer, need to update it */
+   st->dirty.st |= ST_NEW_UNIFORM_BUFFER;
+
    return GL_TRUE;
 }
 
index 25e895b4a9da19a43ee9f985bdcda45941344d1c..dccf87bc326281518f85f914164472ccabe4a5b2 100644 (file)
@@ -209,6 +209,7 @@ static void st_init_driver_flags(struct gl_driver_flags *f)
 {
    f->NewArray = ST_NEW_VERTEX_ARRAYS;
    f->NewRasterizerDiscard = ST_NEW_RASTERIZER;
+   f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER;
 }
 
 struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
index 451217ff69e61419cd35691e27b372fe28c16823..ab89b49473cc156267f54b04966b31673ce4406a 100644 (file)
@@ -51,6 +51,7 @@ struct u_upload_mgr;
 #define ST_NEW_GEOMETRY_PROGRAM        (1 << 5)
 #define ST_NEW_VERTEX_ARRAYS           (1 << 6)
 #define ST_NEW_RASTERIZER              (1 << 7)
+#define ST_NEW_UNIFORM_BUFFER          (1 << 8)
 
 
 struct st_state_flags {