glsl: add ARB_texture_cube_map_array support (v2)
authorDave Airlie <airlied@gmail.com>
Sat, 3 Nov 2012 10:43:17 +0000 (20:43 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 9 Nov 2012 00:26:33 +0000 (10:26 +1000)
This adds all the new builtins + the new sampler types,
and hooks them up if the extension is supported.

v2: fix missing signatures for grad/lod
fix missing textureSize clarifications
fix compare vs starts with usage

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
12 files changed:
src/glsl/builtin_types.h
src/glsl/builtins/profiles/ARB_texture_cube_map_array.glsl [new file with mode: 0644]
src/glsl/builtins/tools/generate_builtins.py
src/glsl/builtins/tools/texture_builtins.py
src/glsl/glcpp/glcpp-parse.y
src/glsl/glsl_lexer.ll
src/glsl/glsl_parser.yy
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/glsl/glsl_types.cpp
src/glsl/glsl_types.h
src/glsl/standalone_scaffolding.cpp

index d75c5626157cf81ac8e63344f7909836e96ff0a9..92427d8e7469c1d071c2d6be8f4ccc6422785d5f 100644 (file)
@@ -327,3 +327,18 @@ const glsl_type glsl_type::builtin_OES_EGL_image_external_types[] = {
             GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT, "samplerExternalOES"),
 };
 /*@}*/
+
+/** \name Sampler types added by GL_ARB_texture_cube_map_array
+ */
+/*@{*/
+const glsl_type glsl_type::builtin_ARB_texture_cube_map_array_types[] = {
+   glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY,
+            GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_FLOAT, "samplerCubeArray"),
+   glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW,
+            GLSL_SAMPLER_DIM_CUBE, 1, 1, GLSL_TYPE_FLOAT, "samplerCubeArrayShadow"),
+   glsl_type(GL_INT_SAMPLER_CUBE_MAP_ARRAY,
+            GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_INT, "isamplerCubeArray"),
+   glsl_type(GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY,
+            GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT, "usamplerCubeArray"),
+};
+/*@}*/
diff --git a/src/glsl/builtins/profiles/ARB_texture_cube_map_array.glsl b/src/glsl/builtins/profiles/ARB_texture_cube_map_array.glsl
new file mode 100644 (file)
index 0000000..0f53212
--- /dev/null
@@ -0,0 +1,19 @@
+#version 130
+#extension GL_ARB_texture_cube_map_array : enable
+
+ivec3 textureSize(samplerCubeArray sampler, int lod);
+ivec3 textureSize(isamplerCubeArray sampler, int lod);
+ivec3 textureSize(usamplerCubeArray sampler, int lod);
+ivec3 textureSize(samplerCubeArrayShadow sampler, int lod);
+
+ vec4 texture( samplerCubeArray sampler, vec4 coord);
+ vec4 texture( samplerCubeArray sampler, vec4 coord, float bias);
+float texture( samplerCubeArrayShadow sampler, vec4 P, float compare);
+
+ vec4 textureGrad( samplerCubeArray sampler, vec4 P, vec3 dPdx, vec3 dPdy);
+ivec4 textureGrad( isamplerCubeArray sampler, vec4 P, vec3 dPdx, vec3 dPdy);
+uvec4 textureGrad( usamplerCubeArray sampler, vec4 P, vec3 dPdx, vec3 dPdy);
+
+ vec4 textureLod( samplerCubeArray sampler, vec4 P, float lod);
+ivec4 textureLod( isamplerCubeArray sampler, vec4 P, float lod);
+uvec4 textureLod( usamplerCubeArray sampler, vec4 P, float lod);
index 9dc3279dfcc3fa8a55938ec379f70139c247f472..7eccb7dca91f6c72ce3ff64a4c9a39d67e1419c1 100755 (executable)
@@ -187,6 +187,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne
    st->EXT_texture_array_enable = true;
    st->OES_EGL_image_external_enable = true;
    st->ARB_shader_bit_encoding_enable = true;
+   st->ARB_texture_cube_map_array_enable = true;
    _mesa_glsl_initialize_types(st);
 
    sh->ir = new(sh) exec_list;
index 94971bc69f836a85a62590bd69b1eb532606bcec..654eb06c888c42a7d78b935b8d27deec5e138ea2 100755 (executable)
@@ -42,6 +42,8 @@ def get_coord_dim(sampler_type):
 # Get the number of extra vector components (i.e. shadow comparitor)
 def get_extra_dim(sampler_type, use_proj, unused_fields):
     extra_dim = unused_fields
+    if sampler_type == "CubeArrayShadow":
+        return 0
     if sampler_type.find("Shadow") != -1:
         extra_dim += 1
     if use_proj:
@@ -49,6 +51,8 @@ def get_extra_dim(sampler_type, use_proj, unused_fields):
     return extra_dim
 
 def get_txs_dim(sampler_type):
+    if sampler_type.startswith("CubeArray"):
+        return 3
     if sampler_type.startswith("Cube"):
         return 2
     return get_coord_dim(sampler_type)
@@ -79,6 +83,8 @@ def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
         grad_type = vec_type("", sampler_dim)
         print "\n       (declare (in) " + grad_type + " dPdx)",
         print "\n       (declare (in) " + grad_type + " dPdy)",
+    if sampler_type == "CubeArrayShadow" and tex_inst == "tex":
+        print "\n       (declare (in) float compare)",
 
     if variant & Offset:
         print "\n       (declare (const_in) " + vec_type("i", sampler_dim) + " offset)",
@@ -107,7 +113,9 @@ def generate_sigs(g, tex_inst, sampler_type, variant = 0, unused_fields = 0):
             print "1",
 
         # Shadow comparitor
-        if sampler_type == "2DArrayShadow" or sampler_type == "CubeShadow": # a special case:
+        if sampler_type == "CubeArrayShadow": # a special case
+            print "(var_ref compare)",
+        elif sampler_type == "2DArrayShadow" or sampler_type == "CubeShadow": # a special case:
             print "(swiz w (var_ref P))",   # ...array layer is z; shadow is w
         elif sampler_type.endswith("Shadow"):
             print "(swiz z (var_ref P))",
@@ -163,6 +171,8 @@ def generate_texture_functions(fs):
     generate_fiu_sigs("txs", "2DRect")
     generate_sigs("", "txs", "2DRectShadow")
     generate_fiu_sigs("txs", "Buffer")
+    generate_fiu_sigs("txs", "CubeArray")
+    generate_sigs("", "txs", "CubeArrayShadow")
     end_function(fs, "textureSize")
 
     start_function("texture")
@@ -179,6 +189,9 @@ def generate_texture_functions(fs):
     generate_sigs("", "tex", "2DArrayShadow", Single);
     generate_fiu_sigs("tex", "2DRect")
     generate_sigs("", "tex", "2DRectShadow", Single);
+    # ARB_texture_cube_map_array extension
+    generate_fiu_sigs("tex", "CubeArray")
+    generate_sigs("", "tex", "CubeArrayShadow", Single);
 
     generate_fiu_sigs("txb", "1D")
     generate_fiu_sigs("txb", "2D")
@@ -186,6 +199,7 @@ def generate_texture_functions(fs):
     generate_fiu_sigs("txb", "Cube")
     generate_fiu_sigs("txb", "1DArray")
     generate_fiu_sigs("txb", "2DArray")
+    generate_fiu_sigs("txb", "CubeArray")
     generate_sigs("", "txb", "1DShadow", Single, 1);
     generate_sigs("", "txb", "2DShadow", Single);
     generate_sigs("", "txb", "CubeShadow", Single);
@@ -224,6 +238,8 @@ def generate_texture_functions(fs):
     generate_sigs("", "txl", "1DShadow", Single, 1);
     generate_sigs("", "txl", "2DShadow", Single);
     generate_sigs("", "txl", "1DArrayShadow", Single);
+    # ARB_texture_cube_map_array extension
+    generate_fiu_sigs("txl", "CubeArray")
     end_function(fs, "textureLod")
 
     start_function("textureLodOffset")
@@ -333,6 +349,8 @@ def generate_texture_functions(fs):
     generate_sigs("", "txd", "CubeShadow", Single);
     generate_sigs("", "txd", "1DArrayShadow", Single);
     generate_sigs("", "txd", "2DArrayShadow", Single);
+    # ARB_texture_cube_map_array extension
+    generate_fiu_sigs("txd", "CubeArray")
     end_function(fs, "textureGrad")
 
     start_function("textureGradOffset")
index ffb48e330b0235d62ffd716dbd2a9209344b803e..40c43c63efd1b60f41b65b098933d289c7147dd7 100644 (file)
@@ -1187,6 +1187,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
 
           if (extensions->ARB_uniform_buffer_object)
              add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1);
+
+          if (extensions->ARB_texture_cube_map_array)
+             add_builtin_define(parser, "GL_ARB_texture_cube_map_array", 1);
        }
 
        language_version = 110;
index 24cda0c45eae6242792474a6ce29ca7e1d9037d0..c538d7d8e309c23a0450fc7eaa41a9ab88950f7c 100644 (file)
@@ -296,12 +296,37 @@ usamplerCube              KEYWORD(130, 130, USAMPLERCUBE);
 usampler1DArray                KEYWORD(130, 130, USAMPLER1DARRAY);
 usampler2DArray                KEYWORD(130, 130, USAMPLER2DARRAY);
 
-samplerExternalOES     {
+samplerCubeArray       {
+                         if (yyextra->ARB_texture_cube_map_array_enable)
+                            return SAMPLERCUBEARRAY;
+                         else
+                            return IDENTIFIER;
+               }
+isamplerCubeArray      {
+                         if (yyextra->ARB_texture_cube_map_array_enable)
+                            return ISAMPLERCUBEARRAY;
+                         else
+                            return IDENTIFIER;
+               }
+usamplerCubeArray      {
+                         if (yyextra->ARB_texture_cube_map_array_enable)
+                            return USAMPLERCUBEARRAY;
+                         else
+                            return IDENTIFIER;
+               }
+samplerCubeArrayShadow {
+                         if (yyextra->ARB_texture_cube_map_array_enable)
+                            return SAMPLERCUBEARRAYSHADOW;
+                         else
+                            return IDENTIFIER;
+               }
+
+samplerExternalOES             {
                          if (yyextra->OES_EGL_image_external_enable)
                             return SAMPLEREXTERNALOES;
                          else
                             return IDENTIFIER;
-                       }
+               }
 
 
 struct         return STRUCT;
index ee6a67288e845f41efb19279adeb5b88268a7642..a0665067d74348f363edf9d30da557c11836aae8 100644 (file)
@@ -101,9 +101,11 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %token MAT4X2 MAT4X3 MAT4X4
 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
-%token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
-%token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
-%token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
+%token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
+%token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
+%token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
+%token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
+%token USAMPLER2DARRAY USAMPLERCUBEARRAY
 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
 %token SAMPLEREXTERNALOES
@@ -1467,6 +1469,8 @@ basic_type_specifier_nonarray:
        | SAMPLER1DARRAYSHADOW  { $$ = "sampler1DArrayShadow"; }
        | SAMPLER2DARRAYSHADOW  { $$ = "sampler2DArrayShadow"; }
        | SAMPLERBUFFER         { $$ = "samplerBuffer"; }
+       | SAMPLERCUBEARRAY      { $$ = "samplerCubeArray"; }
+       | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
        | ISAMPLER1D            { $$ = "isampler1D"; }
        | ISAMPLER2D            { $$ = "isampler2D"; }
        | ISAMPLER2DRECT        { $$ = "isampler2DRect"; }
@@ -1475,6 +1479,7 @@ basic_type_specifier_nonarray:
        | ISAMPLER1DARRAY       { $$ = "isampler1DArray"; }
        | ISAMPLER2DARRAY       { $$ = "isampler2DArray"; }
        | ISAMPLERBUFFER        { $$ = "isamplerBuffer"; }
+       | ISAMPLERCUBEARRAY     { $$ = "isamplerCubeArray"; }
        | USAMPLER1D            { $$ = "usampler1D"; }
        | USAMPLER2D            { $$ = "usampler2D"; }
        | USAMPLER2DRECT        { $$ = "usampler2DRect"; }
@@ -1483,6 +1488,7 @@ basic_type_specifier_nonarray:
        | USAMPLER1DARRAY       { $$ = "usampler1DArray"; }
        | USAMPLER2DARRAY       { $$ = "usampler2DArray"; }
        | USAMPLERBUFFER        { $$ = "usamplerBuffer"; }
+       | USAMPLERCUBEARRAY     { $$ = "usamplerCubeArray"; }
        ;
 
 precision_qualifier:
index 872fcda71c8e4799868113ae381e67704f3042d5..f1fdd3a475219b760221b3cf7e5e799543798cde 100644 (file)
@@ -289,6 +289,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
    EXT(ARB_shader_bit_encoding,        true,  true,  true,  true,  false,     ARB_shader_bit_encoding),
    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),
 };
 
 #undef EXT
index c8c40ab5a71775673001a790afed43e0c8853bca..0b208f6ca9464bd7a4101b2fe01bcc918af5e99e 100644 (file)
@@ -205,6 +205,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_uniform_buffer_object_warn;
    bool OES_standard_derivatives_enable;
    bool OES_standard_derivatives_warn;
+   bool ARB_texture_cube_map_array_enable;
+   bool ARB_texture_cube_map_array_warn;
    /*@}*/
 
    /** Extensions supported by the OpenGL implementation. */
index 2aa51f0b3861aa02d0815fd419e174f19c0ce9fa..3940a12a5cdef10a9e1d16a912f439c0c35744fc 100644 (file)
@@ -142,7 +142,7 @@ glsl_type::sampler_index() const
    case GLSL_SAMPLER_DIM_3D:
       return TEXTURE_3D_INDEX;
    case GLSL_SAMPLER_DIM_CUBE:
-      return TEXTURE_CUBE_INDEX;
+      return (t->sampler_array) ? TEXTURE_CUBE_ARRAY_INDEX : TEXTURE_CUBE_INDEX;
    case GLSL_SAMPLER_DIM_RECT:
       return TEXTURE_RECT_INDEX;
    case GLSL_SAMPLER_DIM_BUF:
@@ -255,6 +255,15 @@ glsl_type::generate_OES_EGL_image_external_types(glsl_symbol_table *symtab,
                             warn);
 }
 
+void
+glsl_type::generate_ARB_texture_cube_map_array_types(glsl_symbol_table *symtab,
+                                                    bool warn)
+{
+   add_types_to_symbol_table(symtab, builtin_ARB_texture_cube_map_array_types,
+                            Elements(builtin_ARB_texture_cube_map_array_types),
+                            warn);
+}
+
 void
 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
 {
@@ -304,6 +313,11 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
       glsl_type::generate_OES_EGL_image_external_types(state->symbols,
                                               state->OES_EGL_image_external_warn);
    }
+
+   if (state->ARB_texture_cube_map_array_enable) {
+      glsl_type::generate_ARB_texture_cube_map_array_types(state->symbols,
+                                      state->ARB_texture_cube_map_array_warn);
+   }
 }
 
 
index 915d1a22b246516d9b7dea59d41ec58c2a14ab5a..cf954a256d391976c7372980322787f613afde5f 100644 (file)
@@ -521,6 +521,7 @@ private:
    static const glsl_type builtin_EXT_texture_array_types[];
    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[];
    /*@}*/
 
    /**
@@ -541,6 +542,7 @@ private:
    static void generate_EXT_texture_array_types(glsl_symbol_table *, bool);
    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);
    /*@}*/
 
    /**
index 7e37be5786011fe808f87b870a9bc8a5369992b7..120ee953471f7a828a8b05f821630100b84d1e44 100644 (file)
@@ -81,6 +81,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
    ctx->Extensions.OES_EGL_image_external = true;
    ctx->Extensions.ARB_shader_bit_encoding = true;
    ctx->Extensions.OES_standard_derivatives = true;
+   ctx->Extensions.ARB_texture_cube_map_array = true;
 
    ctx->Const.GLSLVersion = 120;