[Mesa-dev] [RFC PATCH 08/26] glsl: add support for ARB_texture_multisample

Ian Romanick idr at freedesktop.org
Fri Jan 4 13:37:47 PST 2013


On 12/29/2012 04:35 AM, Chris Forbes wrote:
> V2: emit `sample` parameter properly for multisample texelFetch()
>
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>

Other than the trivial nit below, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>   src/glsl/builtin_types.h                            | 19 +++++++++++++++++++
>   .../builtins/profiles/ARB_texture_multisample.glsl  | 18 ++++++++++++++++++
>   src/glsl/builtins/tools/generate_builtins.py        |  1 +
>   src/glsl/builtins/tools/texture_builtins.py         | 21 +++++++++++++++++++--
>   src/glsl/glcpp/glcpp-parse.y                        |  4 ++++
>   src/glsl/glsl_lexer.ll                              | 16 ++++++++++------
>   src/glsl/glsl_parser.yy                             | 11 +++++++++--
>   src/glsl/glsl_parser_extras.cpp                     |  1 +
>   src/glsl/glsl_parser_extras.h                       |  2 ++
>   src/glsl/glsl_types.cpp                             | 17 +++++++++++++++++
>   src/glsl/glsl_types.h                               |  5 ++++-
>   src/glsl/standalone_scaffolding.cpp                 |  1 +
>   12 files changed, 105 insertions(+), 11 deletions(-)
>   create mode 100644 src/glsl/builtins/profiles/ARB_texture_multisample.glsl
>
> diff --git a/src/glsl/builtin_types.h b/src/glsl/builtin_types.h
> index a4c995f..7c18a98 100644
> --- a/src/glsl/builtin_types.h
> +++ b/src/glsl/builtin_types.h
> @@ -347,3 +347,22 @@ const glsl_type glsl_type::builtin_ARB_texture_cube_map_array_types[] = {
>   	     GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT, "usamplerCubeArray"),
>   };
>   /*@}*/
> +
> +/** \name Sampler types added by GL_ARB_texture_multisample
> + */
> +/*@{*/
> +const glsl_type glsl_type::builtin_ARB_texture_multisample_types[] = {
> +   glsl_type(GL_SAMPLER_2D_MULTISAMPLE,
> +            GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_FLOAT, "sampler2DMS"),
> +   glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE,
> +            GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_INT, "isampler2DMS"),
> +   glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE,
> +            GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_UINT, "usampler2DMS"),
> +   glsl_type(GL_SAMPLER_2D_MULTISAMPLE_ARRAY,
> +            GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_FLOAT, "sampler2DMSArray"),
> +   glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
> +            GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_INT, "isampler2DMSArray"),
> +   glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
> +            GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_UINT, "usampler2DMSArray"),
> +};
> +/*@}*/
> diff --git a/src/glsl/builtins/profiles/ARB_texture_multisample.glsl b/src/glsl/builtins/profiles/ARB_texture_multisample.glsl
> new file mode 100644
> index 0000000..4fa67e9
> --- /dev/null
> +++ b/src/glsl/builtins/profiles/ARB_texture_multisample.glsl
> @@ -0,0 +1,18 @@
> +#version 130
> +#extension GL_ARB_texture_multisample : enable
> +
> +ivec2 textureSize( sampler2DMS sampler);
> +ivec2 textureSize(isampler2DMS sampler);
> +ivec2 textureSize(usampler2DMS sampler);
> +
> +ivec3 textureSize( sampler2DMSArray sampler);
> +ivec3 textureSize(isampler2DMSArray sampler);
> +ivec3 textureSize(usampler2DMSArray sampler);
> +
> + vec4 texelFetch( sampler2DMS sampler, ivec2 P, int sample);
> +ivec4 texelFetch(isampler2DMS sampler, ivec2 P, int sample);
> +uvec4 texelFetch(usampler2DMS sampler, ivec2 P, int sample);
> +
> + vec4 texelFetch( sampler2DMSArray sampler, ivec3 P, int sample);
> +ivec4 texelFetch(isampler2DMSArray sampler, ivec3 P, int sample);
> +uvec4 texelFetch(usampler2DMSArray sampler, ivec3 P, int sample);
> diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
> index 2cfb1a3..2b2a691 100755
> --- a/src/glsl/builtins/tools/generate_builtins.py
> +++ b/src/glsl/builtins/tools/generate_builtins.py
> @@ -189,6 +189,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne
>      st->OES_EGL_image_external_enable = true;
>      st->ARB_shader_bit_encoding_enable = true;
>      st->ARB_texture_cube_map_array_enable = true;
> +   st->ARB_texture_multisample_enable = true;
>      _mesa_glsl_initialize_types(st);
>
>      sh->ir = new(sh) exec_list;
> diff --git a/src/glsl/builtins/tools/texture_builtins.py b/src/glsl/builtins/tools/texture_builtins.py
> index 654eb06..54c7e45 100755
> --- a/src/glsl/builtins/tools/texture_builtins.py
> +++ b/src/glsl/builtins/tools/texture_builtins.py
> @@ -57,6 +57,15 @@ def get_txs_dim(sampler_type):
>           return 2
>       return get_coord_dim(sampler_type)
>
> +def has_lod(sampler_type):
> +    if 'Buffer' in sampler_type: return False
> +    if 'Rect' in sampler_type: return False
> +    if 'MS' in sampler_type: return False
> +    return True
> +
> +def has_sample(sampler_type):
> +    return 'MS' in sampler_type
> +
>   def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
>       coord_dim = get_coord_dim(sampler_type)
>       extra_dim = get_extra_dim(sampler_type, variant & Proj, unused_fields)
> @@ -77,8 +86,10 @@ def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
>           print "\n       (declare (in) " + vec_type("i" if tex_inst == "txf" else "", coord_dim + extra_dim) + " P)",
>       if tex_inst == "txl":
>           print "\n       (declare (in) float lod)",
> -    elif ((tex_inst == "txf" or tex_inst == "txs") and "Buffer" not in sampler_type and "Rect" not in sampler_type):
> +    elif ((tex_inst == "txf" or tex_inst == "txs") and has_lod(sampler_type)):
>           print "\n       (declare (in) int lod)",
> +    elif tex_inst == "txf" and has_sample(sampler_type):
> +          print "\n       (declare (in) int sample)",
>       elif tex_inst == "txd":
>           grad_type = vec_type("", sampler_dim)
>           print "\n       (declare (in) " + grad_type + " dPdx)",
> @@ -126,8 +137,10 @@ def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
>       if tex_inst == "txb":
>           print "(var_ref bias)",
>       elif tex_inst == "txs" or tex_inst == "txf":
> -        if "Rect" not in sampler_type and "Buffer" not in sampler_type:
> +        if has_lod(sampler_type):
>               print "(var_ref lod)",
> +        elif tex_inst == 'txf' and has_sample(sampler_type):
> +            print "(var_ref sample)",
>           else:
>               print "(constant int (0))"
>       elif tex_inst == "txl":
> @@ -173,6 +186,8 @@ def generate_texture_functions(fs):
>       generate_fiu_sigs("txs", "Buffer")
>       generate_fiu_sigs("txs", "CubeArray")
>       generate_sigs("", "txs", "CubeArrayShadow")
> +    generate_fiu_sigs("txs", "2DMS")
> +    generate_fiu_sigs("txs", "2DMSArray")
>       end_function(fs, "textureSize")
>
>       start_function("texture")
> @@ -283,6 +298,8 @@ def generate_texture_functions(fs):
>       generate_fiu_sigs("txf", "1DArray")
>       generate_fiu_sigs("txf", "2DArray")
>       generate_fiu_sigs("txf", "Buffer")
> +    generate_fiu_sigs("txf", "2DMS")
> +    generate_fiu_sigs("txf", "2DMSArray")
>       end_function(fs, "texelFetch")
>
>       start_function("texelFetchOffset")
> diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
> index 380a1d9..f8bd97a 100644
> --- a/src/glsl/glcpp/glcpp-parse.y
> +++ b/src/glsl/glcpp/glcpp-parse.y
> @@ -1222,6 +1222,10 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
>
>   	      if (extensions->ARB_texture_cube_map_array)
>   	         add_builtin_define(parser, "GL_ARB_texture_cube_map_array", 1);
> +
> +	      if (extensions->ARB_texture_multisample)
> +	         add_builtin_define(parser, "GL_ARB_texture_multisample", 1);
> +
>   	   }
>   	}
>
> diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
> index 2f66c58..daf5b23 100644
> --- a/src/glsl/glsl_lexer.ll
> +++ b/src/glsl/glsl_lexer.ll
> @@ -315,6 +315,15 @@ usamplerCube		KEYWORD(130, 300, 130, 300, USAMPLERCUBE);
>   usampler1DArray		KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY);
>   usampler2DArray		KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY);
>
> +   /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
> +   /* these are reserved but not defined in GLSL 3.00 */
> +sampler2DMS        KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS);
> +isampler2DMS       KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS);
> +usampler2DMS       KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS);
> +sampler2DMSArray   KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMSARRAY);
> +isampler2DMSArray  KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMSARRAY);
> +usampler2DMSArray  KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMSARRAY);
> +
>   samplerCubeArray	{
>   			  if (yyextra->ARB_texture_cube_map_array_enable)
>   			     return SAMPLERCUBEARRAY;
> @@ -340,6 +349,7 @@ samplerCubeArrayShadow	{
>   			     return IDENTIFIER;
>   		}
>
> +
>   samplerExternalOES		{
>   			  if (yyextra->OES_EGL_image_external_enable)
>   			     return SAMPLEREXTERNALOES;

Spurious whitespace change.

> @@ -531,12 +541,6 @@ atomic_uint	KEYWORD(0, 300, 0, 0, ATOMIC_UINT);
>   patch		KEYWORD(0, 300, 0, 0, PATCH);
>   sample		KEYWORD(0, 300, 0, 0, SAMPLE);
>   subroutine	KEYWORD(0, 300, 0, 0, SUBROUTINE);
> -sampler2DMS	KEYWORD(0, 300, 0, 0, SAMPLER2DMS);
> -isampler2DMS	KEYWORD(0, 300, 0, 0, ISAMPLER2DMS);
> -usampler2DMS	KEYWORD(0, 300, 0, 0, USAMPLER2DMS);
> -sampler2DMSArray KEYWORD(0, 300, 0, 0, SAMPLER2DMSARRAY);
> -isampler2DMSArray KEYWORD(0, 300, 0, 0, ISAMPLER2DMSARRAY);
> -usampler2DMSArray KEYWORD(0, 300, 0, 0, USAMPLER2DMSARRAY);
>
>
>   [_a-zA-Z][_a-zA-Z0-9]*	{
> diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
> index d849466..97c6b82 100644
> --- a/src/glsl/glsl_parser.yy
> +++ b/src/glsl/glsl_parser.yy
> @@ -108,6 +108,8 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
>   %token USAMPLER2DARRAY USAMPLERCUBEARRAY
>   %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
>   %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
> +%token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
> +%token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
>   %token SAMPLEREXTERNALOES
>   %token STRUCT VOID_TOK WHILE
>   %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
> @@ -138,8 +140,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
>   %token SAMPLER3DRECT
>   %token SIZEOF CAST NAMESPACE USING
>   %token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
> -%token SUBROUTINE SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS SAMPLER2DMSARRAY
> -%token ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
> +%token SUBROUTINE
>
>   %token ERROR_TOK
>
> @@ -1459,6 +1460,12 @@ basic_type_specifier_nonarray:
>   	| USAMPLER2DARRAY	{ $$ = "usampler2DArray"; }
>   	| USAMPLERBUFFER	{ $$ = "usamplerBuffer"; }
>   	| USAMPLERCUBEARRAY	{ $$ = "usamplerCubeArray"; }
> +	| SAMPLER2DMS		{ $$ = "sampler2DMS"; }
> +	| ISAMPLER2DMS		{ $$ = "isampler2DMS"; }
> +	| USAMPLER2DMS		{ $$ = "usampler2DMS"; }
> +	| SAMPLER2DMSARRAY	{ $$ = "sampler2DMSArray"; }
> +	| ISAMPLER2DMSARRAY	{ $$ = "isampler2DMSArray"; }
> +	| USAMPLER2DMSARRAY	{ $$ = "usampler2DMSArray"; }
>   	;
>
>   precision_qualifier:
> diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
> index b460c86..408fe04 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -462,6 +462,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
>      EXT(ARB_uniform_buffer_object,      true,  false, true,  true,  false,     ARB_uniform_buffer_object),
>      EXT(OES_standard_derivatives,       false, false, true,  false,  true,     OES_standard_derivatives),
>      EXT(ARB_texture_cube_map_array,     true,  false, true,  true,  false,     ARB_texture_cube_map_array),
> +   EXT(ARB_texture_multisample,        true,  false, true,  true,  false,     ARB_texture_multisample),
>   };
>
>   #undef EXT
> diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
> index 46e0784..dbe9f76 100644
> --- a/src/glsl/glsl_parser_extras.h
> +++ b/src/glsl/glsl_parser_extras.h
> @@ -272,6 +272,8 @@ struct _mesa_glsl_parse_state {
>      bool OES_standard_derivatives_warn;
>      bool ARB_texture_cube_map_array_enable;
>      bool ARB_texture_cube_map_array_warn;
> +   bool ARB_texture_multisample_enable;
> +   bool ARB_texture_multisample_warn;
>      /*@}*/
>
>      /** Extensions supported by the OpenGL implementation. */
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> index 71b1850..0fc9c6d 100644
> --- a/src/glsl/glsl_types.cpp
> +++ b/src/glsl/glsl_types.cpp
> @@ -154,6 +154,8 @@ glsl_type::sampler_index() const
>         return TEXTURE_BUFFER_INDEX;
>      case GLSL_SAMPLER_DIM_EXTERNAL:
>         return TEXTURE_EXTERNAL_INDEX;
> +   case GLSL_SAMPLER_DIM_MS:
> +      return (t->sampler_array) ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX: TEXTURE_2D_MULTISAMPLE_INDEX;
>      default:
>         assert(!"Should not get here.");
>         return TEXTURE_BUFFER_INDEX;
> @@ -301,6 +303,16 @@ glsl_type::generate_ARB_texture_cube_map_array_types(glsl_symbol_table *symtab,
>   }
>
>   void
> +glsl_type::generate_ARB_texture_multisample_types(glsl_symbol_table *symtab,
> +                                                  bool warn)
> +{
> +   bool skip_1d = false;
> +   add_types_to_symbol_table(symtab, builtin_ARB_texture_multisample_types,
> +                             Elements(builtin_ARB_texture_multisample_types),
> +                             warn, skip_1d);
> +}
> +
> +void
>   _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
>   {
>      if (state->es_shader) {
> @@ -368,6 +380,11 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
>         glsl_type::generate_ARB_texture_cube_map_array_types(state->symbols,
>   				       state->ARB_texture_cube_map_array_warn);
>      }
> +
> +   if (state->ARB_texture_multisample_enable) {
> +      glsl_type::generate_ARB_texture_multisample_types(state->symbols,
> +         state->ARB_texture_multisample_warn);
> +   }
>   }
>
>
> diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
> index d6f5c10..8f35c8d 100644
> --- a/src/glsl/glsl_types.h
> +++ b/src/glsl/glsl_types.h
> @@ -66,7 +66,8 @@ enum glsl_sampler_dim {
>      GLSL_SAMPLER_DIM_CUBE,
>      GLSL_SAMPLER_DIM_RECT,
>      GLSL_SAMPLER_DIM_BUF,
> -   GLSL_SAMPLER_DIM_EXTERNAL
> +   GLSL_SAMPLER_DIM_EXTERNAL,
> +   GLSL_SAMPLER_DIM_MS
>   };
>
>   #ifdef __cplusplus
> @@ -523,6 +524,7 @@ private:
>      static const glsl_type builtin_EXT_texture_buffer_object_types[];
>      static const glsl_type builtin_OES_EGL_image_external_types[];
>      static const glsl_type builtin_ARB_texture_cube_map_array_types[];
> +   static const glsl_type builtin_ARB_texture_multisample_types[];
>      /*@}*/
>
>      /**
> @@ -548,6 +550,7 @@ private:
>      static void generate_OES_texture_3D_types(glsl_symbol_table *, bool);
>      static void generate_OES_EGL_image_external_types(glsl_symbol_table *, bool);
>      static void generate_ARB_texture_cube_map_array_types(glsl_symbol_table *, bool);
> +   static void generate_ARB_texture_multisample_types(glsl_symbol_table *, bool);
>      /*@}*/
>
>      /**
> diff --git a/src/glsl/standalone_scaffolding.cpp b/src/glsl/standalone_scaffolding.cpp
> index 33d3804..25b46e9 100644
> --- a/src/glsl/standalone_scaffolding.cpp
> +++ b/src/glsl/standalone_scaffolding.cpp
> @@ -83,6 +83,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
>      ctx->Extensions.ARB_shader_bit_encoding = true;
>      ctx->Extensions.OES_standard_derivatives = true;
>      ctx->Extensions.ARB_texture_cube_map_array = true;
> +   ctx->Extensions.ARB_texture_multisample = true;
>
>      ctx->Const.GLSLVersion = 120;
>
>



More information about the mesa-dev mailing list