[Mesa-dev] [PATCH 05/14] mesa, i965: use NewDriverState to communicate TFB state changes with the driver

Marek Olšák maraeo at gmail.com
Mon Apr 15 06:17:30 PDT 2013


_NEW_TRANSFORM_FEEDBACK is not used by core Mesa, so it can be removed.
Instead, an new private flag is added to i965 to serve the same purpose.

If you're new to this:

* When creating a context. you can set private dirty flags
  in gl_context::DriverFlags, eg.:
    ctx->DriverFlags.NewStateX = BRW_NEW_STATE_X;

* When StateX is changed, core Mesa does:
    ctx->NewDriverState |= ctx->DriverFlags.NewStateX;

* When you have to draw, read and clear ctx->NewDriverState.

* Pros: not touching NewState, the driver decides the mapping between
  GL states and hw state groups, unlimited number of flags in core Mesa
  (still limited number of flags in the driver though)
---
 src/mesa/drivers/dri/i965/brw_context.c      |    2 ++
 src/mesa/drivers/dri/i965/brw_context.h      |    2 ++
 src/mesa/drivers/dri/i965/brw_gs.c           |    6 +++---
 src/mesa/drivers/dri/i965/brw_state_upload.c |    4 +++-
 src/mesa/drivers/dri/i965/gen6_sol.c         |    7 ++++---
 src/mesa/drivers/dri/i965/gen7_sol_state.c   |   14 +++++++-------
 src/mesa/main/mtypes.h                       |    8 ++++++--
 src/mesa/main/transformfeedback.c            |   20 ++++++++++++++------
 8 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index ceaf325..04d6943 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -153,6 +153,8 @@ brwCreateContext(int api,
    if (tnl)
       tnl->Driver.RunPipeline = _tnl_run_pipeline;
 
+   ctx->DriverFlags.NewTransformFeedback = BRW_NEW_TRANSFORM_FEEDBACK;
+
    ctx->Const.MaxDualSourceDrawBuffers = 1;
    ctx->Const.MaxDrawBuffers = BRW_MAX_DRAW_BUFFERS;
    ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT;
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 114c369..e4fd071 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -150,6 +150,7 @@ enum brw_state_id {
    BRW_STATE_STATE_BASE_ADDRESS,
    BRW_STATE_SOL_INDICES,
    BRW_STATE_VUE_MAP_GEOM_OUT,
+   BRW_STATE_TRANSFORM_FEEDBACK,
 };
 
 #define BRW_NEW_URB_FENCE               (1 << BRW_STATE_URB_FENCE)
@@ -178,6 +179,7 @@ enum brw_state_id {
 #define BRW_NEW_STATE_BASE_ADDRESS	(1 << BRW_STATE_STATE_BASE_ADDRESS)
 #define BRW_NEW_SOL_INDICES		(1 << BRW_STATE_SOL_INDICES)
 #define BRW_NEW_VUE_MAP_GEOM_OUT	(1 << BRW_STATE_VUE_MAP_GEOM_OUT)
+#define BRW_NEW_TRANSFORM_FEEDBACK	(1 << BRW_STATE_TRANSFORM_FEEDBACK)
 
 struct brw_state_flags {
    /** State update flags signalled by mesa internals */
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index caa3b3e..59053d4 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -186,7 +186,7 @@ static void populate_key( struct brw_context *brw,
       key->need_gs_prog = false;
    } else if (intel->gen == 6) {
       /* On Gen6, GS is used for transform feedback. */
-      /* _NEW_TRANSFORM_FEEDBACK */
+      /* BRW_NEW_TRANSFORM_FEEDBACK */
       if (_mesa_is_xfb_active_and_unpaused(ctx)) {
          const struct gl_shader_program *shaderprog =
             ctx->Shader.CurrentVertexProgram;
@@ -258,9 +258,9 @@ brw_upload_gs_prog(struct brw_context *brw)
 const struct brw_tracked_state brw_gs_prog = {
    .dirty = {
       .mesa  = (_NEW_LIGHT |
-                _NEW_TRANSFORM_FEEDBACK |
                 _NEW_RASTERIZER_DISCARD),
-      .brw   = BRW_NEW_PRIMITIVE,
+      .brw   = (BRW_NEW_PRIMITIVE |
+                BRW_NEW_TRANSFORM_FEEDBACK),
       .cache = CACHE_NEW_VS_PROG
    },
    .emit = brw_upload_gs_prog
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index 8c56245..083b619 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -345,7 +345,6 @@ static struct dirty_bit_map mesa_bits[] = {
    DEFINE_BIT(_NEW_PROGRAM_CONSTANTS),
    DEFINE_BIT(_NEW_BUFFER_OBJECT),
    DEFINE_BIT(_NEW_FRAG_CLAMP),
-   DEFINE_BIT(_NEW_TRANSFORM_FEEDBACK),
    DEFINE_BIT(_NEW_VARYING_VP_INPUTS),
    {0, 0, 0}
 };
@@ -440,6 +439,9 @@ void brw_upload_state(struct brw_context *brw)
    state->mesa |= brw->intel.NewGLState;
    brw->intel.NewGLState = 0;
 
+   state->brw |= ctx->NewDriverState;
+   ctx->NewDriverState = 0;
+
    if (brw->emit_state_always) {
       state->mesa |= ~0;
       state->brw |= ~0;
diff --git a/src/mesa/drivers/dri/i965/gen6_sol.c b/src/mesa/drivers/dri/i965/gen6_sol.c
index cf7a60d..3cbf28e 100644
--- a/src/mesa/drivers/dri/i965/gen6_sol.c
+++ b/src/mesa/drivers/dri/i965/gen6_sol.c
@@ -37,7 +37,7 @@ static void
 gen6_update_sol_surfaces(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
    /* BRW_NEW_VERTEX_PROGRAM */
@@ -69,9 +69,10 @@ gen6_update_sol_surfaces(struct brw_context *brw)
 
 const struct brw_tracked_state gen6_sol_surface = {
    .dirty = {
-      .mesa = _NEW_TRANSFORM_FEEDBACK,
+      .mesa = 0,
       .brw = (BRW_NEW_BATCH |
-              BRW_NEW_VERTEX_PROGRAM),
+              BRW_NEW_VERTEX_PROGRAM |
+              BRW_NEW_TRANSFORM_FEEDBACK),
       .cache = 0
    },
    .emit = gen6_update_sol_surfaces,
diff --git a/src/mesa/drivers/dri/i965/gen7_sol_state.c b/src/mesa/drivers/dri/i965/gen7_sol_state.c
index 03709ea..a404e2b 100644
--- a/src/mesa/drivers/dri/i965/gen7_sol_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sol_state.c
@@ -45,7 +45,7 @@ upload_3dstate_so_buffers(struct brw_context *brw)
       ctx->Shader.CurrentVertexProgram;
    const struct gl_transform_feedback_info *linked_xfb_info =
       &vs_prog->LinkedTransformFeedback;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
    int i;
@@ -116,7 +116,7 @@ upload_3dstate_so_decl_list(struct brw_context *brw,
    /* BRW_NEW_VERTEX_PROGRAM */
    const struct gl_shader_program *vs_prog =
       ctx->Shader.CurrentVertexProgram;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    const struct gl_transform_feedback_info *linked_xfb_info =
       &vs_prog->LinkedTransformFeedback;
    int i;
@@ -189,7 +189,7 @@ upload_3dstate_streamout(struct brw_context *brw, bool active,
 {
    struct intel_context *intel = &brw->intel;
    struct gl_context *ctx = &intel->ctx;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
    uint32_t dw1 = 0, dw2 = 0;
@@ -238,7 +238,7 @@ upload_sol_state(struct brw_context *brw)
 {
    struct intel_context *intel = &brw->intel;
    struct gl_context *ctx = &intel->ctx;
-   /* _NEW_TRANSFORM_FEEDBACK */
+   /* BRW_NEW_TRANSFORM_FEEDBACK */
    bool active = _mesa_is_xfb_active_and_unpaused(ctx);
 
    if (active) {
@@ -264,11 +264,11 @@ upload_sol_state(struct brw_context *brw)
 const struct brw_tracked_state gen7_sol_state = {
    .dirty = {
       .mesa  = (_NEW_RASTERIZER_DISCARD |
-		_NEW_LIGHT |
-		_NEW_TRANSFORM_FEEDBACK),
+		_NEW_LIGHT),
       .brw   = (BRW_NEW_BATCH |
 		BRW_NEW_VERTEX_PROGRAM |
-                BRW_NEW_VUE_MAP_GEOM_OUT)
+                BRW_NEW_VUE_MAP_GEOM_OUT |
+                BRW_NEW_TRANSFORM_FEEDBACK)
    },
    .emit = upload_sol_state,
 };
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index e46fa39..04eaea8 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3149,7 +3149,7 @@ struct gl_matrix_stack
 #define _NEW_PROGRAM_CONSTANTS (1 << 27)
 #define _NEW_BUFFER_OBJECT     (1 << 28)
 #define _NEW_FRAG_CLAMP        (1 << 29)
-#define _NEW_TRANSFORM_FEEDBACK (1 << 30) /**< gl_context::TransformFeedback */
+/* gap, re-use for core Mesa state only; use ctx->DriverFlags otherwise */
 #define _NEW_VARYING_VP_INPUTS (1 << 31) /**< gl_context::varying_vp_inputs */
 #define _NEW_ALL ~0
 
@@ -3353,7 +3353,11 @@ typedef enum
  */
 struct gl_driver_flags
 {
-   GLbitfield NewArray;             /**< Vertex array state */
+   /** gl_context::Array::_DrawArrays (vertex array state) */
+   GLbitfield NewArray;
+
+   /** gl_context::TransformFeedback::CurrentObject */
+   GLbitfield NewTransformFeedback;
 };
 
 struct gl_uniform_buffer_binding
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index fd4718d..d688266 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -385,7 +385,9 @@ _mesa_BeginTransformFeedback(GLenum mode)
       }
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
+
    obj->Active = GL_TRUE;
    ctx->TransformFeedback.Mode = mode;
 
@@ -422,7 +424,9 @@ _mesa_EndTransformFeedback(void)
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
+
    ctx->TransformFeedback.CurrentObject->Active = GL_FALSE;
    ctx->TransformFeedback.CurrentObject->Paused = GL_FALSE;
    ctx->TransformFeedback.CurrentObject->EndedAnytime = GL_TRUE;
@@ -443,7 +447,7 @@ bind_buffer_range(struct gl_context *ctx, GLuint index,
    struct gl_transform_feedback_object *obj =
       ctx->TransformFeedback.CurrentObject;
 
-   /* Note: no need to FLUSH_VERTICES or flag _NEW_TRANSFORM_FEEDBACK, because
+   /* Note: no need to FLUSH_VERTICES or flag NewTransformFeedback, because
     * transform feedback buffers can't be changed while transform feedback is
     * active.
     */
@@ -687,7 +691,7 @@ _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
 
    shProg->TransformFeedback.BufferMode = bufferMode;
 
-   /* No need to set _NEW_TRANSFORM_FEEDBACK (or invoke FLUSH_VERTICES) since
+   /* No need to invoke FLUSH_VERTICES or flag NewTransformFeedback since
     * the varyings won't be used until shader link time.
     */
 }
@@ -898,7 +902,9 @@ _mesa_PauseTransformFeedback(void)
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
+
    obj->Paused = GL_TRUE;
 
    assert(ctx->Driver.PauseTransformFeedback);
@@ -924,7 +930,9 @@ _mesa_ResumeTransformFeedback(void)
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TRANSFORM_FEEDBACK);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewTransformFeedback;
+
    obj->Paused = GL_FALSE;
 
    assert(ctx->Driver.ResumeTransformFeedback);
-- 
1.7.10.4



More information about the mesa-dev mailing list