[Mesa-dev] [PATCH v2 6/6] mesa: Make a function is_transform_feedback_active_and_unpaused.

Paul Berry stereotype441 at gmail.com
Sat Dec 15 22:09:25 PST 2012


The rather unweildy logic for determining this condition was repeated
in a large number of places.  This patch consolidates it to a single
inline function.

Cc: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/common/meta.c             |  3 +--
 src/mesa/drivers/dri/i965/brw_draw.c       |  4 ++--
 src/mesa/drivers/dri/i965/brw_gs.c         |  4 ++--
 src/mesa/drivers/dri/i965/gen6_sol.c       |  2 +-
 src/mesa/drivers/dri/i965/gen7_sol_state.c |  5 ++---
 src/mesa/main/api_validate.c               | 20 +++++++-------------
 src/mesa/main/shaderapi.c                  |  8 +++-----
 src/mesa/main/transformfeedback.c          |  5 ++---
 src/mesa/main/transformfeedback.h          |  9 +++++++++
 9 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index ac036ea..4c4e348 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -474,8 +474,7 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
     * able to change other state.
     */
    save->TransformFeedbackNeedsResume =
-      ctx->TransformFeedback.CurrentObject->Active &&
-      !ctx->TransformFeedback.CurrentObject->Paused;
+      is_transform_feedback_active_and_unpaused(ctx);
    if (save->TransformFeedbackNeedsResume)
       _mesa_PauseTransformFeedback();
 
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 1ba839c..7042cb4 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -34,6 +34,7 @@
 #include "main/state.h"
 #include "main/enums.h"
 #include "main/macros.h"
+#include "main/transformfeedback.h"
 #include "tnl/tnl.h"
 #include "vbo/vbo_context.h"
 #include "swrast/swrast.h"
@@ -385,8 +386,7 @@ brw_update_primitive_count(struct brw_context *brw,
       = vbo_count_tessellated_primitives(prim->mode, prim->count,
                                          prim->num_instances);
    brw->sol.primitives_generated += count;
-   if (brw->intel.ctx.TransformFeedback.CurrentObject->Active &&
-       !brw->intel.ctx.TransformFeedback.CurrentObject->Paused) {
+   if (is_transform_feedback_active_and_unpaused(&brw->intel.ctx)) {
       /* Update brw->sol.svbi_0_max_index to reflect the amount by which the
        * hardware is going to increment SVBI 0 when this drawing operation
        * occurs.  This is necessary because the kernel does not (yet) save and
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 9ba53ec..291a63d 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -32,6 +32,7 @@
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/enums.h"
+#include "main/transformfeedback.h"
 
 #include "intel_batchbuffer.h"
 
@@ -189,8 +190,7 @@ static void populate_key( struct brw_context *brw,
    } else if (intel->gen == 6) {
       /* On Gen6, GS is used for transform feedback. */
       /* _NEW_TRANSFORM_FEEDBACK */
-      if (ctx->TransformFeedback.CurrentObject->Active &&
-          !ctx->TransformFeedback.CurrentObject->Paused) {
+      if (is_transform_feedback_active_and_unpaused(ctx)) {
          const struct gl_shader_program *shaderprog =
             ctx->Shader.CurrentVertexProgram;
          const struct gl_transform_feedback_info *linked_xfb_info =
diff --git a/src/mesa/drivers/dri/i965/gen6_sol.c b/src/mesa/drivers/dri/i965/gen6_sol.c
index 7aa6140..0cd030b 100644
--- a/src/mesa/drivers/dri/i965/gen6_sol.c
+++ b/src/mesa/drivers/dri/i965/gen6_sol.c
@@ -49,7 +49,7 @@ gen6_update_sol_surfaces(struct brw_context *brw)
 
    for (i = 0; i < BRW_MAX_SOL_BINDINGS; ++i) {
       const int surf_index = SURF_INDEX_SOL_BINDING(i);
-      if (xfb_obj->Active && !xfb_obj->Paused &&
+      if (is_transform_feedback_active_and_unpaused(ctx) &&
           i < linked_xfb_info->NumOutputs) {
          unsigned buffer = linked_xfb_info->Outputs[i].OutputBuffer;
          unsigned buffer_offset =
diff --git a/src/mesa/drivers/dri/i965/gen7_sol_state.c b/src/mesa/drivers/dri/i965/gen7_sol_state.c
index 1a89503..c2536df 100644
--- a/src/mesa/drivers/dri/i965/gen7_sol_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sol_state.c
@@ -33,6 +33,7 @@
 #include "brw_defines.h"
 #include "intel_batchbuffer.h"
 #include "intel_buffer_objects.h"
+#include "main/transformfeedback.h"
 
 static void
 upload_3dstate_so_buffers(struct brw_context *brw)
@@ -236,9 +237,7 @@ upload_sol_state(struct brw_context *brw)
    struct intel_context *intel = &brw->intel;
    struct gl_context *ctx = &intel->ctx;
    /* _NEW_TRANSFORM_FEEDBACK */
-   struct gl_transform_feedback_object *xfb_obj =
-      ctx->TransformFeedback.CurrentObject;
-   bool active = xfb_obj->Active && !xfb_obj->Paused;
+   bool active = is_transform_feedback_active_and_unpaused(ctx);
 
    if (active) {
       upload_3dstate_so_buffers(brw);
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 1606282..1bdf75f 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -32,6 +32,7 @@
 #include "mtypes.h"
 #include "enums.h"
 #include "vbo/vbo.h"
+#include "transformfeedback.h"
 #include <stdbool.h>
 
 
@@ -252,8 +253,7 @@ _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name)
     *        current transform feedback state as given by table X.1.
     *
     */
-   if (ctx->TransformFeedback.CurrentObject->Active &&
-       !ctx->TransformFeedback.CurrentObject->Paused) {
+   if (is_transform_feedback_active_and_unpaused(ctx)) {
       GLboolean pass = GL_TRUE;
 
       switch (mode) {
@@ -313,8 +313,6 @@ _mesa_validate_DrawElements(struct gl_context *ctx,
 			    GLenum mode, GLsizei count, GLenum type,
 			    const GLvoid *indices, GLint basevertex)
 {
-   struct gl_transform_feedback_object *xfb_obj
-      = ctx->TransformFeedback.CurrentObject;
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
    FLUSH_CURRENT(ctx, 0);
 
@@ -325,7 +323,7 @@ _mesa_validate_DrawElements(struct gl_context *ctx,
     *   DrawElementsInstanced, and DrawRangeElements while transform feedback
     *   is active and not paused, regardless of mode.
     */
-   if (_mesa_is_gles3(ctx) && xfb_obj->Active && !xfb_obj->Paused) {
+   if (_mesa_is_gles3(ctx) && is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glDrawElements(transform feedback active)");
       return GL_FALSE;
@@ -446,8 +444,6 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
 				 GLsizei count, GLenum type,
 				 const GLvoid *indices, GLint basevertex)
 {
-   struct gl_transform_feedback_object *xfb_obj
-      = ctx->TransformFeedback.CurrentObject;
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
    FLUSH_CURRENT(ctx, 0);
 
@@ -458,7 +454,7 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
     *   DrawElementsInstanced, and DrawRangeElements while transform feedback
     *   is active and not paused, regardless of mode.
     */
-   if (_mesa_is_gles3(ctx) && xfb_obj->Active && !xfb_obj->Paused) {
+   if (_mesa_is_gles3(ctx) && is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glDrawElements(transform feedback active)");
       return GL_FALSE;
@@ -552,7 +548,7 @@ _mesa_validate_DrawArrays(struct gl_context *ctx,
     * This is in contrast to the behaviour of desktop GL, where the extra
     * primitives are silently dropped from the transform feedback buffer.
     */
-   if (_mesa_is_gles3(ctx) && xfb_obj->Active && !xfb_obj->Paused) {
+   if (_mesa_is_gles3(ctx) && is_transform_feedback_active_and_unpaused(ctx)) {
       size_t prim_count = vbo_count_tessellated_primitives(mode, count, 1);
       if (xfb_obj->GlesRemainingPrims < prim_count) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -620,7 +616,7 @@ _mesa_validate_DrawArraysInstanced(struct gl_context *ctx, GLenum mode, GLint fi
     * This is in contrast to the behaviour of desktop GL, where the extra
     * primitives are silently dropped from the transform feedback buffer.
     */
-   if (_mesa_is_gles3(ctx) && xfb_obj->Active && !xfb_obj->Paused) {
+   if (_mesa_is_gles3(ctx) && is_transform_feedback_active_and_unpaused(ctx)) {
       size_t prim_count
          = vbo_count_tessellated_primitives(mode, count, numInstances);
       if (xfb_obj->GlesRemainingPrims < prim_count) {
@@ -641,8 +637,6 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
                                      const GLvoid *indices, GLsizei numInstances,
                                      GLint basevertex)
 {
-   struct gl_transform_feedback_object *xfb_obj
-      = ctx->TransformFeedback.CurrentObject;
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
    FLUSH_CURRENT(ctx, 0);
 
@@ -653,7 +647,7 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
     *   DrawElementsInstanced, and DrawRangeElements while transform feedback
     *   is active and not paused, regardless of mode.
     */
-   if (_mesa_is_gles3(ctx) && xfb_obj->Active && !xfb_obj->Paused) {
+   if (_mesa_is_gles3(ctx) && is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glDrawElements(transform feedback active)");
       return GL_FALSE;
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 53e9d04..a722d8c 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -45,6 +45,7 @@
 #include "main/mtypes.h"
 #include "main/shaderapi.h"
 #include "main/shaderobj.h"
+#include "main/transformfeedback.h"
 #include "main/uniforms.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
@@ -1383,12 +1384,10 @@ _mesa_UseProgram(GLhandleARB program)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_shader_program *shProg;
-   struct gl_transform_feedback_object *obj =
-      ctx->TransformFeedback.CurrentObject;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (obj->Active && !obj->Paused) {
+   if (is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glUseProgram(transform feedback active)");
       return;
@@ -1590,8 +1589,7 @@ _mesa_UseShaderProgramEXT(GLenum type, GLuint program)
       return;
    }
 
-   if (ctx->TransformFeedback.CurrentObject->Active &&
-       !ctx->TransformFeedback.CurrentObject->Paused) {
+   if (is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glUseShaderProgramEXT(transform feedback is active)");
       return;
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index dd03038..01ea470 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -818,8 +818,7 @@ _mesa_BindTransformFeedback(GLenum target, GLuint name)
       return;
    }
 
-   if (ctx->TransformFeedback.CurrentObject->Active &&
-       !ctx->TransformFeedback.CurrentObject->Paused) {
+   if (is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
               "glBindTransformFeedback(transform is active, or not paused)");
       return;
@@ -889,7 +888,7 @@ _mesa_PauseTransformFeedback(void)
 
    obj = ctx->TransformFeedback.CurrentObject;
 
-   if (!obj->Active || obj->Paused) {
+   if (!is_transform_feedback_active_and_unpaused(ctx)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
            "glPauseTransformFeedback(feedback not active or already paused)");
       return;
diff --git a/src/mesa/main/transformfeedback.h b/src/mesa/main/transformfeedback.h
index 3c03b7a..0b3b6b3 100644
--- a/src/mesa/main/transformfeedback.h
+++ b/src/mesa/main/transformfeedback.h
@@ -25,9 +25,11 @@
 #ifndef TRANSFORM_FEEDBACK_H
 #define TRANSFORM_FEEDBACK_H
 
+#include <stdbool.h>
 #include "compiler.h"
 #include "glheader.h"
 #include "mfeatures.h"
+#include "mtypes.h"
 
 struct _glapi_table;
 struct dd_function_table;
@@ -111,4 +113,11 @@ _mesa_PauseTransformFeedback(void);
 extern void GLAPIENTRY
 _mesa_ResumeTransformFeedback(void);
 
+static inline bool
+is_transform_feedback_active_and_unpaused(struct gl_context *ctx)
+{
+   return ctx->TransformFeedback.CurrentObject->Active &&
+      !ctx->TransformFeedback.CurrentObject->Paused;
+}
+
 #endif /* TRANSFORM_FEEDBACK_H */
-- 
1.8.0.2



More information about the mesa-dev mailing list