[Mesa-dev] Mesa (master): glsl: add support for system values and GL_ARB_draw_instanced

Ian Romanick idr at freedesktop.org
Mon Jan 17 14:38:11 PST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/15/2011 09:25 AM, Brian Paul wrote:

> diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp
> index 6b9b294..4d10540 100644
> --- a/src/glsl/ir_variable.cpp
> +++ b/src/glsl/ir_variable.cpp
> @@ -30,6 +30,11 @@ static void generate_ARB_draw_buffers_variables(exec_list *,
>  						struct _mesa_glsl_parse_state *,
>  						bool, _mesa_glsl_parser_targets);
>  
> +static void
> +generate_ARB_draw_instanced_variables(exec_list *,
> +                                      struct _mesa_glsl_parse_state *,
> +                                      bool, _mesa_glsl_parser_targets);
> +
>  static ir_variable *
>  add_variable(const char *name, enum ir_variable_mode mode, int slot,
>  	     const glsl_type *type, exec_list *instructions,
> @@ -41,6 +46,7 @@ add_variable(const char *name, enum ir_variable_mode mode, int slot,
>     case ir_var_auto:
>     case ir_var_in:
>     case ir_var_uniform:
> +   case ir_var_system_value:
>        var->read_only = true;
>        break;
>     case ir_var_inout:
> @@ -324,8 +330,13 @@ initialize_vs_variables(exec_list *instructions,
>        generate_130_vs_variables(instructions, state);
>        break;
>     }
> +
> +   if (state->ARB_draw_instanced_enable)
> +      generate_ARB_draw_instanced_variables(instructions, state, false,
> +                                            vertex_shader);

Have you verified this against other implementations?  The
GL_ARB_draw_instanced spec say:

   "If EXT_gpu_shader4 or OpenGL 3.0 is not supported, all references to
   gl_InstanceIDARB are deleted.  Note that if EXT_gpu_shader4 is
   available, the gl_InstanceIDARB and gl_InstanceID values are the
   same."

Is gl_InstanceIDARB available in 1.10 or 1.20 vertex shaders on other
implementations?

This bit of weirdness in the spec is part of the reason I hadn't already
implemented this extension.  It's not 100% clear to me why this
dependency exists.  My only guess is that GLSL 1.20 and earlier allow
integer variables to be stored in floats, and that's kind of weird for
the instance ID.

>  }
>  
> +
>  /* This function should only be called for ES, not desktop GL. */
>  static void
>  generate_100ES_fs_variables(exec_list *instructions,
> @@ -422,6 +433,27 @@ generate_ARB_draw_buffers_variables(exec_list *instructions,
>     }
>  }
>  
> +
> +static void
> +generate_ARB_draw_instanced_variables(exec_list *instructions,
> +                                      struct _mesa_glsl_parse_state *state,
> +                                      bool warn,
> +                                      _mesa_glsl_parser_targets target)
> +{
> +   /* gl_InstanceIDARB is only available in the vertex shader.
> +    */
> +   if (target == vertex_shader) {
> +      ir_variable *const inst =
> +         add_variable("gl_InstanceIDARB", ir_var_system_value,
> +                      SYSTEM_VALUE_INSTANCE_ID,
> +                      glsl_type::int_type, instructions, state->symbols);
> +
> +      if (warn)
> +         inst->warn_extension = "GL_ARB_draw_instanced";
> +   }
> +}
> +
> +
>  static void
>  generate_ARB_shader_stencil_export_variables(exec_list *instructions,
>  					     struct _mesa_glsl_parse_state *state,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk00xNMACgkQX1gOwKyEAw8ILwCdHGlHHaEF3TCvMsGF2mEYP83r
GfIAn3vZ11dOexyDzy6kHhPE1IR4f8mg
=hw3l
-----END PGP SIGNATURE-----


More information about the mesa-dev mailing list