[Mesa-dev] [PATCH] mesa/program: split reference program into hot/cold paths.

Dave Airlie airlied at gmail.com
Thu Jun 23 22:22:00 PDT 2011


From: Dave Airlie <airlied at redhat.com>

inline the hotpath of the reference remaining the same, this shouldn't
penalise the slow path at all but improve the hot path so we don't have
to jump to the function.

It also moves some assert checks under an #ifndef NDEBUG.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/program/program.c |    8 ++++----
 src/mesa/program/program.h |   12 +++++++++++-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index 78efca9..b419058 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -423,10 +423,11 @@ _mesa_lookup_program(struct gl_context *ctx, GLuint id)
  * Reference counting for vertex/fragment programs
  */
 void
-_mesa_reference_program(struct gl_context *ctx,
+__mesa_reference_program(struct gl_context *ctx,
                         struct gl_program **ptr,
                         struct gl_program *prog)
 {
+#ifndef NDEBUG
    assert(ptr);
    if (*ptr && prog) {
       /* sanity check */
@@ -438,9 +439,8 @@ _mesa_reference_program(struct gl_context *ctx,
       else if ((*ptr)->Target == MESA_GEOMETRY_PROGRAM)
          ASSERT(prog->Target == MESA_GEOMETRY_PROGRAM);
    }
-   if (*ptr == prog) {
-      return;  /* no change */
-   }
+#endif
+
    if (*ptr) {
       GLboolean deleteFlag;
 
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index ce37b95..c093afa 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -89,11 +89,21 @@ extern struct gl_program *
 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
 
 extern void
-_mesa_reference_program(struct gl_context *ctx,
+__mesa_reference_program(struct gl_context *ctx,
                         struct gl_program **ptr,
                         struct gl_program *prog);
 
 static INLINE void
+_mesa_reference_program(struct gl_context *ctx,
+                        struct gl_program **ptr,
+                        struct gl_program *prog)
+{
+   if (*ptr == prog)
+     return;
+   __mesa_reference_program(ctx, ptr, prog);
+}
+
+static INLINE void
 _mesa_reference_vertprog(struct gl_context *ctx,
                          struct gl_vertex_program **ptr,
                          struct gl_vertex_program *prog)
-- 
1.7.1



More information about the mesa-dev mailing list