[Mesa-dev] [PATCH 5/5] mesa: Use functions to convert gl_shader_stage to PROGRAM enum or pipe target.

Emil Velikov emil.l.velikov at gmail.com
Wed Jan 8 12:21:01 PST 2014


On 08/01/14 19:20, Paul Berry wrote:
> Suggested-by: Brian Paul <brianp at vmware.com>
> ---
>  src/mesa/program/ir_to_mesa.cpp            | 17 +------------
>  src/mesa/program/program.h                 | 18 ++++++++++++++
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 40 +++++++++++++++---------------
>  3 files changed, 39 insertions(+), 36 deletions(-)
> 
> diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> index 7988248..f6c229c 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -2799,26 +2799,11 @@ get_mesa_program(struct gl_context *ctx,
>     ir_instruction **mesa_instruction_annotation;
>     int i;
>     struct gl_program *prog;
> -   GLenum target;
> +   GLenum target = _mesa_shader_stage_to_program(shader->Stage);
>     const char *target_string = _mesa_shader_stage_to_string(shader->Stage);
>     struct gl_shader_compiler_options *options =
>           &ctx->ShaderCompilerOptions[shader->Stage];
>  
> -   switch (shader->Stage) {
> -   case MESA_SHADER_VERTEX:
> -      target = GL_VERTEX_PROGRAM_ARB;
> -      break;
> -   case MESA_SHADER_FRAGMENT:
> -      target = GL_FRAGMENT_PROGRAM_ARB;
> -      break;
> -   case MESA_SHADER_GEOMETRY:
> -      target = GL_GEOMETRY_PROGRAM_NV;
> -      break;
> -   default:
> -      assert(!"should not be reached");
> -      return NULL;
> -   }
> -
>     validate_ir_tree(shader->ir);
>  
>     prog = ctx->Driver.NewProgram(ctx, target, shader_program->Name);
> diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
> index 4015b4c..648233c 100644
> --- a/src/mesa/program/program.h
> +++ b/src/mesa/program/program.h
> @@ -207,6 +207,24 @@ _mesa_program_enum_to_shader_stage(GLenum v)
>     }
>  }
>  
> +
> +static inline GLenum
> +_mesa_shader_stage_to_program(gl_shader_stage stage)
> +{
> +   switch (stage) {
> +   case MESA_SHADER_VERTEX:
> +      return GL_VERTEX_PROGRAM_ARB;
> +   case MESA_SHADER_FRAGMENT:
> +      return GL_FRAGMENT_PROGRAM_ARB;
> +   case MESA_SHADER_GEOMETRY:
> +      return GL_GEOMETRY_PROGRAM_NV;
> +   }
> +
> +   ASSERT(0);
Hi Paul

Can you use a normal assert that prints a somewhat informative message -
similar to what you did in shader_stage_to_ptarget()?

Thanks
Emil

> +   return GL_VERTEX_PROGRAM_ARB;
> +}
> +
> +
>  static inline GLenum
>  _mesa_program_index_to_target(GLuint i)
>  {
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 4b6fd2d..73c39eb 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -5023,6 +5023,24 @@ out:
>  }
>  /* ----------------------------- End TGSI code ------------------------------ */
>  
> +
> +static unsigned
> +shader_stage_to_ptarget(gl_shader_stage stage)
> +{
> +   switch (stage) {
> +   case MESA_SHADER_VERTEX:
> +      return PIPE_SHADER_VERTEX;
> +   case MESA_SHADER_FRAGMENT:
> +      return PIPE_SHADER_FRAGMENT;
> +   case MESA_SHADER_GEOMETRY:
> +      return PIPE_SHADER_GEOMETRY;
> +   }
> +
> +   assert(!"should not be reached");
> +   return PIPE_SHADER_VERTEX;
> +}
> +
> +
>  /**
>   * Convert a shader's GLSL IR into a Mesa gl_program, although without 
>   * generating Mesa IR.
> @@ -5034,30 +5052,12 @@ get_mesa_program(struct gl_context *ctx,
>  {
>     glsl_to_tgsi_visitor* v;
>     struct gl_program *prog;
> -   GLenum target;
> +   GLenum target = _mesa_shader_stage_to_program(shader->Stage);
>     bool progress;
>     struct gl_shader_compiler_options *options =
>           &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)];
>     struct pipe_screen *pscreen = ctx->st->pipe->screen;
> -   unsigned ptarget;
> -
> -   switch (shader->Type) {
> -   case GL_VERTEX_SHADER:
> -      target = GL_VERTEX_PROGRAM_ARB;
> -      ptarget = PIPE_SHADER_VERTEX;
> -      break;
> -   case GL_FRAGMENT_SHADER:
> -      target = GL_FRAGMENT_PROGRAM_ARB;
> -      ptarget = PIPE_SHADER_FRAGMENT;
> -      break;
> -   case GL_GEOMETRY_SHADER:
> -      target = GL_GEOMETRY_PROGRAM_NV;
> -      ptarget = PIPE_SHADER_GEOMETRY;
> -      break;
> -   default:
> -      assert(!"should not be reached");
> -      return NULL;
> -   }
> +   unsigned ptarget = shader_stage_to_ptarget(shader->Stage);
>  
>     validate_ir_tree(shader->ir);
>  
> 



More information about the mesa-dev mailing list