program: convert _mesa_init_gl_program() to take struct gl_program *
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 13 Oct 2015 10:26:09 +0000 (11:26 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 15 Oct 2015 12:30:52 +0000 (13:30 +0100)
Rather than accepting a void pointer, only to down and up cast around
it, convert the function to take the base (struct gl_program) pointer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/drivers/dri/i915/i915_fragprog.c
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp
src/mesa/drivers/dri/i965/test_vec4_copy_propagation.cpp
src/mesa/drivers/dri/i965/test_vec4_register_coalesce.cpp
src/mesa/drivers/dri/r200/r200_vertprog.c
src/mesa/program/program.c
src/mesa/program/program.h
src/mesa/state_tracker/st_cb_program.c

index 237d219289b8a5584a3be23c924001425265eea7..59d795998c62ee97e8e43c7ee18a7937b5d5dd20 100644 (file)
@@ -1315,9 +1315,10 @@ static struct gl_program *
 i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id)
 {
    switch (target) {
-   case GL_VERTEX_PROGRAM_ARB:
-      return _mesa_init_gl_program(CALLOC_STRUCT(gl_vertex_program),
-                                   target, id);
+   case GL_VERTEX_PROGRAM_ARB: {
+      struct gl_vertex_program *prog = CALLOC_STRUCT(gl_vertex_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
 
    case GL_FRAGMENT_PROGRAM_ARB:{
          struct i915_fragment_program *prog =
@@ -1325,7 +1326,7 @@ i915NewProgram(struct gl_context * ctx, GLenum target, GLuint id)
          if (prog) {
             i915_init_program(I915_CONTEXT(ctx), prog);
 
-            return _mesa_init_gl_program(prog, target, id);
+            return _mesa_init_gl_program(&prog->FragProg.Base, target, id);
          }
          else
             return NULL;
index 164c3d76c998a2fe63330e47f438484379f2d7e4..b547d07f0cae819f4a41198c4e81d57bd7021914 100644 (file)
@@ -69,7 +69,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
         prog->id = get_new_program_id(brw->intelScreen);
 
-        return _mesa_init_gl_program(&prog->program, target, id);
+        return _mesa_init_gl_program(&prog->program.Base, target, id);
       }
       else
         return NULL;
@@ -80,7 +80,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
         prog->id = get_new_program_id(brw->intelScreen);
 
-        return _mesa_init_gl_program(&prog->program, target, id);
+        return _mesa_init_gl_program(&prog->program.Base, target, id);
       }
       else
         return NULL;
@@ -102,7 +102,7 @@ static struct gl_program *brwNewProgram( struct gl_context *ctx,
       if (prog) {
          prog->id = get_new_program_id(brw->intelScreen);
 
-         return _mesa_init_gl_program(&prog->program, target, id);
+         return _mesa_init_gl_program(&prog->program.Base, target, id);
       } else {
          return NULL;
       }
index 7eee42630a6aecf428549446dd988c0c6d03dcf4..5f80f90a91db7d7a14403d553b0321bba4c2d534 100644 (file)
@@ -66,7 +66,7 @@ void cmod_propagation_test::SetUp()
 
    v = new cmod_propagation_fs_visitor(compiler, prog_data, shader);
 
-   _mesa_init_gl_program(&fp->program, GL_FRAGMENT_SHADER, 0);
+   _mesa_init_gl_program(&fp->program.Base, GL_FRAGMENT_SHADER, 0);
 
    devinfo->gen = 4;
 }
index fefde4bb7bf7b9edfc43868f0e5a4c3c4051a1e1..32e8b8f88673a63a0df6da4dabe8f57f81172148 100644 (file)
@@ -66,7 +66,7 @@ void saturate_propagation_test::SetUp()
 
    v = new saturate_propagation_fs_visitor(compiler, prog_data, shader);
 
-   _mesa_init_gl_program(&fp->program, GL_FRAGMENT_SHADER, 0);
+   _mesa_init_gl_program(&fp->program.Base, GL_FRAGMENT_SHADER, 0);
 
    devinfo->gen = 4;
 }
index 4a87e6eff96f7dce2e595f8d0a22e1aa0386914d..e80b71b558de92ea43b564d5a912f89374c0637e 100644 (file)
@@ -98,7 +98,7 @@ void copy_propagation_test::SetUp()
 
    v = new copy_propagation_vec4_visitor(compiler, shader);
 
-   _mesa_init_gl_program(&vp->program, GL_VERTEX_SHADER, 0);
+   _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0);
 
    devinfo->gen = 4;
 }
index 92d75e798378aaa89aa682b81d0b7c97d9f9570e..2f8246174549c1828d9a81ad037cf82f8109f916 100644 (file)
@@ -101,7 +101,7 @@ void register_coalesce_test::SetUp()
 
    v = new register_coalesce_vec4_visitor(compiler, shader);
 
-   _mesa_init_gl_program(&vp->program, GL_VERTEX_SHADER, 0);
+   _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0);
 
    devinfo->gen = 4;
 }
index d173605d1103c8ed5029d9094591607c69db67fd..628c5708090a53ac2f1874ca9bb2ed0c8f3e3eb4 100644 (file)
@@ -1200,18 +1200,19 @@ r200BindProgram(struct gl_context *ctx, GLenum target, struct gl_program *prog)
 static struct gl_program *
 r200NewProgram(struct gl_context *ctx, GLenum target, GLuint id)
 {
-   struct r200_vertex_program *vp;
-
    switch(target){
-   case GL_VERTEX_PROGRAM_ARB:
-      vp = CALLOC_STRUCT(r200_vertex_program);
-      return _mesa_init_gl_program(&vp->mesa_program, target, id);
-   case GL_FRAGMENT_PROGRAM_ARB:
-      return _mesa_init_gl_program(CALLOC_STRUCT(gl_fragment_program), target, id);
+   case GL_VERTEX_PROGRAM_ARB: {
+      struct r200_vertex_program *vp = CALLOC_STRUCT(r200_vertex_program);
+      return _mesa_init_gl_program(&vp->mesa_program.Base, target, id);
+   }
+   case GL_FRAGMENT_PROGRAM_ARB: {
+      struct gl_fragment_program *prog = CALLOC_STRUCT(gl_fragment_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
    default:
       _mesa_problem(ctx, "Bad target in r200NewProgram");
+      return NULL;
    }
-   return NULL;        
 }
 
 
index 86de5e965f17d81e5cd67e38d44a60c0e54a7fab..0e78e6ab25de558247f8dd6ca7b9d0779e0c7cdc 100644 (file)
@@ -176,9 +176,8 @@ _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string)
  * Initialize a new gl_program object.
  */
 struct gl_program *
-_mesa_init_gl_program(void *_prog, GLenum target, GLuint id)
+_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id)
 {
-   struct gl_program *prog = (struct gl_program*)_prog;
    GLuint i;
 
    if (!prog)
@@ -214,38 +213,36 @@ _mesa_init_gl_program(void *_prog, GLenum target, GLuint id)
 struct gl_program *
 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id)
 {
-   struct gl_program *prog;
    switch (target) {
-   case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
-      prog = _mesa_init_gl_program(CALLOC_STRUCT(gl_vertex_program),
-                                   target, id);
-      break;
+   case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
+      struct gl_vertex_program *prog = CALLOC_STRUCT(gl_vertex_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
    case GL_FRAGMENT_PROGRAM_NV:
-   case GL_FRAGMENT_PROGRAM_ARB:
-      prog =_mesa_init_gl_program(CALLOC_STRUCT(gl_fragment_program),
-                                  target, id);
-      break;
-   case GL_GEOMETRY_PROGRAM_NV:
-      prog = _mesa_init_gl_program(CALLOC_STRUCT(gl_geometry_program),
-                                   target, id);
-      break;
-   case GL_TESS_CONTROL_PROGRAM_NV:
-      prog = _mesa_init_gl_program(CALLOC_STRUCT(gl_tess_ctrl_program),
-                                   target, id);
-      break;
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-      prog = _mesa_init_gl_program(CALLOC_STRUCT(gl_tess_eval_program),
-                                   target, id);
-      break;
-   case GL_COMPUTE_PROGRAM_NV:
-      prog = _mesa_init_gl_program(CALLOC_STRUCT(gl_compute_program),
-                                   target, id);
-      break;
+   case GL_FRAGMENT_PROGRAM_ARB: {
+      struct gl_fragment_program *prog = CALLOC_STRUCT(gl_fragment_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_GEOMETRY_PROGRAM_NV: {
+      struct gl_geometry_program *prog = CALLOC_STRUCT(gl_geometry_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_TESS_CONTROL_PROGRAM_NV: {
+      struct gl_tess_ctrl_program *prog = CALLOC_STRUCT(gl_tess_ctrl_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_TESS_EVALUATION_PROGRAM_NV: {
+      struct gl_tess_eval_program *prog = CALLOC_STRUCT(gl_tess_eval_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_COMPUTE_PROGRAM_NV: {
+      struct gl_compute_program *prog = CALLOC_STRUCT(gl_compute_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
    default:
       _mesa_problem(ctx, "bad target in _mesa_new_program");
-      prog = NULL;
+      return NULL;
    }
-   return prog;
 }
 
 
index 51e10a1708b61c455ee7d8bec9f120ceab00b1ac..24e05974dc3294e10ae0c3a7e2ff842a0745693d 100644 (file)
@@ -64,7 +64,7 @@ extern void
 _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
 
 extern struct gl_program *
-_mesa_init_gl_program(void *prog, GLenum target, GLuint id);
+_mesa_init_gl_program(struct gl_program *prog, GLenum target, GLuint id);
 
 extern struct gl_program *
 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
index 40f2af0e550a088b0c22ea2bb999409efc629f4f..26d128abd380d56f894c16f031147da00876816d 100644 (file)
@@ -102,29 +102,31 @@ st_use_program(struct gl_context *ctx, struct gl_shader_program *shProg)
 static struct gl_program *
 st_new_program(struct gl_context *ctx, GLenum target, GLuint id)
 {
-   struct gl_program *prog;
-
    switch (target) {
-   case GL_VERTEX_PROGRAM_ARB:
-      prog = (struct gl_program*)ST_CALLOC_STRUCT(st_vertex_program);
-      break;
-   case GL_FRAGMENT_PROGRAM_ARB:
-      prog = (struct gl_program*)ST_CALLOC_STRUCT(st_fragment_program);
-      break;
-   case GL_GEOMETRY_PROGRAM_NV:
-      prog = (struct gl_program*)ST_CALLOC_STRUCT(st_geometry_program);
-      break;
-   case GL_TESS_CONTROL_PROGRAM_NV:
-      prog = (struct gl_program*)ST_CALLOC_STRUCT(st_tessctrl_program);
-      break;
-   case GL_TESS_EVALUATION_PROGRAM_NV:
-      prog = (struct gl_program*)ST_CALLOC_STRUCT(st_tesseval_program);
-      break;
+   case GL_VERTEX_PROGRAM_ARB: {
+      struct st_vertex_program *prog = ST_CALLOC_STRUCT(st_vertex_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_FRAGMENT_PROGRAM_ARB: {
+      struct st_fragment_program *prog = ST_CALLOC_STRUCT(st_fragment_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_GEOMETRY_PROGRAM_NV: {
+      struct st_geometry_program *prog = ST_CALLOC_STRUCT(st_geometry_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_TESS_CONTROL_PROGRAM_NV: {
+      struct st_tessctrl_program *prog = ST_CALLOC_STRUCT(st_tessctrl_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
+   case GL_TESS_EVALUATION_PROGRAM_NV: {
+      struct st_tesseval_program *prog = ST_CALLOC_STRUCT(st_tesseval_program);
+      return _mesa_init_gl_program(&prog->Base, target, id);
+   }
    default:
       assert(0);
       return NULL;
    }
-   return _mesa_init_gl_program(prog, target, id);
 }