[Mesa-dev] [PATCH] mesa: Use get_local_param_pointer in glProgramLocalParameters4fvEXT().

Brian Paul brianp at vmware.com
Mon Jan 6 09:13:41 PST 2014


On 01/05/2014 09:10 PM, Kenneth Graunke wrote:
> Using the get_local_param_pointer helper ensures that the LocalParams
> arrays have actually been allocated before attempting to use them.
>
> glProgramLocalParameters4fvEXT needs to do a bit of extra checking,
> but it can be simplified since the helper has already validated the
> target.
>
> Fixes crashes in programs that use Cg (such as Awesomenauts) since
> commit e5885c119de1e508099cc1111e1c9f8ff00fab88 (mesa: Dynamically
> allocate the storage for program local parameters.).
>
> Bugzilla: https://urldefense.proofpoint.com/v1/url?u=https://bugs.freedesktop.org/show_bug.cgi?id%3D73136&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=gW5OVHtORWDtOYenBA%2FvNgvhol2aPx9mdsARthkvza8%3D%0A&s=9820bb2ade5ab45808e872046b14d1fbd24aca1ff1fb29a6686a5a538d37400d
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> Cc: Eric Anholt <eric at anholt.net>
> ---
>   src/mesa/main/arbprogram.c | 30 +++++++++++-------------------
>   1 file changed, 11 insertions(+), 19 deletions(-)
>
> diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
> index 8bd3f0b..bf2a5f8 100644
> --- a/src/mesa/main/arbprogram.c
> +++ b/src/mesa/main/arbprogram.c
> @@ -527,28 +527,20 @@ _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
>         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
>      }
>
> -   if (target == GL_FRAGMENT_PROGRAM_ARB
> -       && ctx->Extensions.ARB_fragment_program) {
> -      if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
> -         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
> -         return;
> -      }
> -      dest = ctx->FragmentProgram.Current->Base.LocalParams[index];
> -   }
> -   else if (target == GL_VERTEX_PROGRAM_ARB
> -            && ctx->Extensions.ARB_vertex_program) {
> -      if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
> -         _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
> +   if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
> +                               target, index, &dest)) {
> +      GLuint maxParams = target == GL_FRAGMENT_PROGRAM_ARB ?
> +         ctx->Const.FragmentProgram.MaxLocalParams :
> +         ctx->Const.VertexProgram.MaxLocalParams;
> +
> +      if ((index + count) > maxParams) {
> +         _mesa_error(ctx, GL_INVALID_VALUE,
> +                     "glProgramLocalParameters4fvEXT(index + count)");
>            return;
>         }
> -      dest = ctx->VertexProgram.Current->Base.LocalParams[index];
> -   }
> -   else {
> -      _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
> -      return;
> -   }
>
> -   memcpy(dest, params, count * 4 * sizeof(GLfloat));
> +      memcpy(dest, params, count * 4 * sizeof(GLfloat));
> +   }
>   }
>
>
>

Reviewed-by: Brian Paul <brianp at vmware.com>




More information about the mesa-dev mailing list