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

Brian Paul brian.e.paul at gmail.com
Wed Jul 13 08:53:22 PDT 2011


On Fri, Jun 24, 2011 at 7:20 AM, Brian Paul <brianp at vmware.com> wrote:
> On 06/23/2011 11:22 PM, Dave Airlie wrote:
>>
>> 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);
>> +}
>
> How about:
>
> if (*ptr != prog)
>   __mesa_reference_program(ctx, ptr, prog);
>
>
> Otherwise, Reviewed-by: Brian Paul <brianp at vmware.com>

Dave, were you going to commit this patch?

-Brian


More information about the mesa-dev mailing list