mesa,i965: use NewDriverState to communicate TFB state changes with the driver
authorMarek Olšák <maraeo@gmail.com>
Sun, 14 Apr 2013 22:50:20 +0000 (00:50 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 24 Apr 2013 01:23:23 +0000 (03:23 +0200)
_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)

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_gs.c
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/gen6_sol.c
src/mesa/drivers/dri/i965/gen7_sol_state.c
src/mesa/main/mtypes.h
src/mesa/main/transformfeedback.c

index ceaf325e25b341c772a511deb3ec1f2cf060efab..04d6943352e315b69d371106ad3c61ee4bef2ff0 100644 (file)
@@ -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;
index 114c369f82197c7aaf9023ebbfdec9570c89a371..e4fd0714c33472f3d7d2ad3ac84f07715e773892 100644 (file)
@@ -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 */
index caa3b3efdd6f517fdbe585e74444380718050f5d..59053d4c6c9b93f19c2e2e6d1dcf4af70e91544f 100644 (file)
@@ -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
index 8c562455d8e9f27f62770d7474e0572149bf7934..843324f8c9ffa6c26bc045016c3c6f0d688b7011 100644 (file)
@@ -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}
 };
@@ -372,6 +371,7 @@ static struct dirty_bit_map brw_bits[] = {
    DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS),
    DEFINE_BIT(BRW_NEW_SOL_INDICES),
    DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT),
+   DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK),
    {0, 0, 0}
 };
 
@@ -440,6 +440,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;
index cf7a60db6bea99d2dc0ceb27fd5b07fd8f58c62d..3cbf28e7dc4c50a293647de31f0a0c0c603cc26d 100644 (file)
@@ -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,
index 03709eafba91dab6ff0e909671fa473769367d5f..a404e2be3d475f65461c43967d12df6adb992fc8 100644 (file)
@@ -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,
 };
index 6108a35fd805b8d6d98fb511e0fbcdd9faf34e65..8d8622e9e1b163fcbc3127443c8a0daabd983c47 100644 (file)
@@ -3148,7 +3148,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
 
@@ -3333,7 +3333,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
index d0118c5f7c74d2f1c349dde63fe49b899fcc0075..9967fbf6c8f1dae474eaebb1df80c2441181878b 100644 (file)
@@ -384,7 +384,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;
 
@@ -421,7 +423,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;
@@ -442,7 +446,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.
     */
@@ -686,7 +690,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.
     */
 }
@@ -897,7 +901,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);
@@ -923,7 +929,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);