Mesa (master): mesa: split _mesa_reference_program() into hot/cold paths.

Brian Paul brianp at kemper.freedesktop.org
Thu Jul 14 14:16:32 UTC 2011


Module: Mesa
Branch: master
Commit: 323e4bff799a657632c5777c8be6e306202953af
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=323e4bff799a657632c5777c8be6e306202953af

Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 14 08:09:21 2011 -0600

mesa: split _mesa_reference_program() into hot/cold paths.

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.

Minor clean-ups added by Brian.

Signed-off-by: Dave Airlie <airlied at redhat.com>
Signed-off-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/program/program.c |   14 ++++++++------
 src/mesa/program/program.h |   11 ++++++++++-
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index 78efca9..adca094 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -421,12 +421,15 @@ _mesa_lookup_program(struct gl_context *ctx, GLuint id)
 
 /**
  * Reference counting for vertex/fragment programs
+ * This is normally only called from the _mesa_reference_program() macro
+ * when there's a real pointer change.
  */
 void
-_mesa_reference_program(struct gl_context *ctx,
-                        struct gl_program **ptr,
-                        struct gl_program *prog)
+_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 +441,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..0f32a6a 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -89,9 +89,18 @@ extern struct gl_program *
 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
 
 extern void
+_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);
+                        struct gl_program *prog)
+{
+   if (*ptr != prog)
+      _mesa_reference_program_(ctx, ptr, prog);
+}
 
 static INLINE void
 _mesa_reference_vertprog(struct gl_context *ctx,




More information about the mesa-commit mailing list