[Mesa-dev] [PATCH 07/17] mesa: add & use a new driver flag for UBO updates instead of _NEW_BUFFER_OBJECT

Marek Olšák maraeo at gmail.com
Wed May 1 20:42:58 PDT 2013


---
 src/mesa/drivers/dri/i965/brw_context.c           |    1 +
 src/mesa/drivers/dri/i965/brw_context.h           |    2 ++
 src/mesa/drivers/dri/i965/brw_state_upload.c      |    1 +
 src/mesa/drivers/dri/i965/brw_vs_surface_state.c  |    5 ++---
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c  |    5 ++---
 src/mesa/drivers/dri/intel/intel_buffer_objects.c |   12 ++++++++++++
 src/mesa/main/bufferobj.c                         |    3 ++-
 src/mesa/main/mtypes.h                            |    6 ++++++
 src/mesa/main/uniforms.c                          |    4 +++-
 src/mesa/state_tracker/st_atom_constbuf.c         |    9 ++++-----
 src/mesa/state_tracker/st_cb_bufferobjects.c      |    4 +++-
 src/mesa/state_tracker/st_context.c               |    1 +
 src/mesa/state_tracker/st_context.h               |    1 +
 13 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 3ca4bd6..99b68a0 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -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;
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index c682501..9baf57b 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -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 */
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index 270b3f4..cdc2657 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -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}
 };
 
diff --git a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
index 968cc03..cbad071 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c
@@ -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,
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index ee2c9f1..485e027 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -1469,9 +1469,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,
diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index 996518b..f941c56 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -39,6 +39,10 @@
 #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);
 
@@ -160,6 +164,14 @@ intel_bufferobj_data(struct gl_context * ctx,
 	 drm_intel_bo_subdata(intel_obj->buffer, 0, size, data);
    }
 
+#ifndef I915
+   /* BufferData may change a uniform buffer, need to update it */
+   {
+      struct brw_context *brw = brw_context(ctx);
+      brw->state.dirty.brw |= BRW_NEW_UNIFORM_BUFFER;
+   }
+#endif
+
    return true;
 }
 
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index e482c91..1566cb4 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -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;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index deecdf5..0098392 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3328,6 +3328,12 @@ struct gl_driver_flags
 
    /** gl_context::RasterDiscard */
    GLbitfield NewRasterizerDiscard;
+
+   /**
+    * gl_context::UniformBufferBindings
+    * gl_shader_program::UniformBlocks
+    */
+   GLbitfield NewUniformBuffer;
 };
 
 struct gl_uniform_buffer_binding
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index a53e8e1..f0d80f0 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -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++) {
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index ed69166..ef208bc 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -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
 };
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 8ff32c8..d166fe6 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -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;
 }
 
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 25e895b..dccf87b 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -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,
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 451217f..ab89b49 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -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 {
-- 
1.7.10.4



More information about the mesa-dev mailing list