[Mesa-dev] [PATCH 04/27] glsl: add basic arb_gpu_shader_int64 types

Dave Airlie airlied at gmail.com
Mon Jun 20 05:06:50 UTC 2016


From: Dave Airlie <airlied at redhat.com>

This adds the builtins and the lexer support.

To avoid too many warnings, it adds basic
support to the type in a few other places
in mesa, mostly in the trivial places.

It also adds a query to be used later for
if a type is an integer 32 or 64.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/compiler/builtin_type_macros.h              | 10 ++++++
 src/compiler/glsl/ast_to_hir.cpp                |  2 ++
 src/compiler/glsl/builtin_types.cpp             | 12 +++++++
 src/compiler/glsl/glsl_lexer.ll                 | 10 ++++++
 src/compiler/glsl/glsl_parser.yy                |  9 +++++
 src/compiler/glsl/ir_clone.cpp                  |  2 ++
 src/compiler/glsl/link_uniform_initializers.cpp |  2 ++
 src/compiler/glsl_types.cpp                     | 45 +++++++++++++++++++++++++
 src/compiler/glsl_types.h                       | 19 +++++++++--
 src/mesa/program/ir_to_mesa.cpp                 | 14 ++++++++
 src/mesa/state_tracker/st_glsl_types.cpp        |  6 ++++
 11 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/src/compiler/builtin_type_macros.h b/src/compiler/builtin_type_macros.h
index da3f19e..1986684 100644
--- a/src/compiler/builtin_type_macros.h
+++ b/src/compiler/builtin_type_macros.h
@@ -78,6 +78,16 @@ DECL_TYPE(dmat3x4, GL_DOUBLE_MAT3x4, GLSL_TYPE_DOUBLE, 4, 3)
 DECL_TYPE(dmat4x2, GL_DOUBLE_MAT4x2, GLSL_TYPE_DOUBLE, 2, 4)
 DECL_TYPE(dmat4x3, GL_DOUBLE_MAT4x3, GLSL_TYPE_DOUBLE, 3, 4)
 
+DECL_TYPE(int64_t,  GL_INT64_ARB,          GLSL_TYPE_INT64,   1, 1)
+DECL_TYPE(i64vec2,  GL_INT64_VEC2_ARB,     GLSL_TYPE_INT64,   2, 1)
+DECL_TYPE(i64vec3,  GL_INT64_VEC3_ARB,     GLSL_TYPE_INT64,   3, 1)
+DECL_TYPE(i64vec4,  GL_INT64_VEC4_ARB,     GLSL_TYPE_INT64,   4, 1)
+
+DECL_TYPE(uint64_t, GL_UNSIGNED_INT64_ARB,      GLSL_TYPE_UINT64, 1, 1)
+DECL_TYPE(u64vec2,  GL_UNSIGNED_INT64_VEC2_ARB, GLSL_TYPE_UINT64, 2, 1)
+DECL_TYPE(u64vec3,  GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1)
+DECL_TYPE(u64vec4,  GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1)
+
 DECL_TYPE(sampler,           GL_SAMPLER_1D,                   GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D,   0, 0, GLSL_TYPE_VOID)
 DECL_TYPE(sampler1D,         GL_SAMPLER_1D,                   GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D,   0, 0, GLSL_TYPE_FLOAT)
 DECL_TYPE(sampler2D,         GL_SAMPLER_2D,                   GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D,   0, 0, GLSL_TYPE_FLOAT)
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 7da734c..29514a5 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -1089,6 +1089,8 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
    case GLSL_TYPE_INT:
    case GLSL_TYPE_BOOL:
    case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
       return new(mem_ctx) ir_expression(operation, op0, op1);
 
    case GLSL_TYPE_ARRAY: {
diff --git a/src/compiler/glsl/builtin_types.cpp b/src/compiler/glsl/builtin_types.cpp
index 5f208f8..1a9292a 100644
--- a/src/compiler/glsl/builtin_types.cpp
+++ b/src/compiler/glsl/builtin_types.cpp
@@ -402,5 +402,17 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
       add_type(symbols, glsl_type::dmat4x2_type);
       add_type(symbols, glsl_type::dmat4x3_type);
    }
+
+   if (state->ARB_gpu_shader_int64_enable) {
+      add_type(symbols, glsl_type::int64_t_type);
+      add_type(symbols, glsl_type::i64vec2_type);
+      add_type(symbols, glsl_type::i64vec3_type);
+      add_type(symbols, glsl_type::i64vec4_type);
+
+      add_type(symbols, glsl_type::uint64_t_type);
+      add_type(symbols, glsl_type::u64vec2_type);
+      add_type(symbols, glsl_type::u64vec3_type);
+      add_type(symbols, glsl_type::u64vec4_type);
+   }
 }
 /** @} */
diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll
index 11711ee..9c6d943 100644
--- a/src/compiler/glsl/glsl_lexer.ll
+++ b/src/compiler/glsl/glsl_lexer.ll
@@ -587,6 +587,16 @@ resource	KEYWORD(420, 300, 0, 0, RESOURCE);
 sample		KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE);
 subroutine	KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE);
 
+    /* Additional words for ARB_gpu_shader_int64 */
+int64_t		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, INT64);
+i64vec2		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC2);
+i64vec3		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC3);
+i64vec4		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC4);
+
+uint64_t	KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, UINT64);
+u64vec2		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC2);
+u64vec3		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC3);
+u64vec4		KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC4);
 
 [_a-zA-Z][_a-zA-Z0-9]*	{
 			    struct _mesa_glsl_parse_state *state = yyextra;
diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index 3885688..2cd4ed8 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -136,6 +136,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
 %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
+%token INT64 UINT64 I64VEC2 I64VEC3 I64VEC4 U64VEC2 U64VEC3 U64VEC4
 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
 %token NOPERSPECTIVE FLAT SMOOTH
 %token MAT2X2 MAT2X3 MAT2X4
@@ -2178,6 +2179,14 @@ basic_type_specifier_nonarray:
    | UIMAGE2DMS             { $$ = "uimage2DMS"; }
    | UIMAGE2DMSARRAY        { $$ = "uimage2DMSArray"; }
    | ATOMIC_UINT            { $$ = "atomic_uint"; }
+   | INT64                  { $$ = "int64_t";	   }
+   | I64VEC2                { $$ = "i64vec2";	   }
+   | I64VEC3                { $$ = "i64vec3";	   }
+   | I64VEC4                { $$ = "i64vec4";	   }
+   | UINT64                 { $$ = "uint64_t";	   }
+   | U64VEC2                { $$ = "u64vec2";	   }
+   | U64VEC3                { $$ = "u64vec3";	   }
+   | U64VEC4                { $$ = "u64vec4";	   }
    ;
 
 precision_qualifier:
diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp
index 60d1526..509eabf 100644
--- a/src/compiler/glsl/ir_clone.cpp
+++ b/src/compiler/glsl/ir_clone.cpp
@@ -338,6 +338,8 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
    case GLSL_TYPE_FLOAT:
    case GLSL_TYPE_DOUBLE:
    case GLSL_TYPE_BOOL:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
       return new(mem_ctx) ir_constant(this->type, &this->value);
 
    case GLSL_TYPE_STRUCT: {
diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index acf8222..bec2dae 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -71,6 +71,8 @@ copy_constant_to_storage(union gl_constant_value *storage,
       case GLSL_TYPE_BOOL:
 	 storage[i].b = val->value.b[i] ? boolean_true : 0;
 	 break;
+      case GLSL_TYPE_INT64:
+      case GLSL_TYPE_UINT64:
       case GLSL_TYPE_ARRAY:
       case GLSL_TYPE_STRUCT:
       case GLSL_TYPE_IMAGE:
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 884f311..2b4a265 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -378,6 +378,10 @@ const glsl_type *glsl_type::get_base_type() const
       return double_type;
    case GLSL_TYPE_BOOL:
       return bool_type;
+   case GLSL_TYPE_UINT64:
+      return uint64_t_type;
+   case GLSL_TYPE_INT64:
+      return int64_t_type;
    default:
       return error_type;
    }
@@ -404,6 +408,10 @@ const glsl_type *glsl_type::get_scalar_type() const
       return double_type;
    case GLSL_TYPE_BOOL:
       return bool_type;
+   case GLSL_TYPE_UINT64:
+      return uint64_t_type;
+   case GLSL_TYPE_INT64:
+      return int64_t_type;
    default:
       /* Handle everything else */
       return type;
@@ -544,6 +552,31 @@ glsl_type::bvec(unsigned components)
 
 
 const glsl_type *
+glsl_type::i64vec(unsigned components)
+{
+   if (components == 0 || components > 4)
+      return error_type;
+
+   static const glsl_type *const ts[] = {
+      int64_t_type, i64vec2_type, i64vec3_type, i64vec4_type
+   };
+   return ts[components - 1];
+}
+
+
+const glsl_type *
+glsl_type::u64vec(unsigned components)
+{
+   if (components == 0 || components > 4)
+      return error_type;
+
+   static const glsl_type *const ts[] = {
+      uint64_t_type, u64vec2_type, u64vec3_type, u64vec4_type
+   };
+   return ts[components - 1];
+}
+
+const glsl_type *
 glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
 {
    if (base_type == GLSL_TYPE_VOID)
@@ -566,6 +599,10 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
          return dvec(rows);
       case GLSL_TYPE_BOOL:
          return bvec(rows);
+      case GLSL_TYPE_UINT64:
+         return u64vec(rows);
+      case GLSL_TYPE_INT64:
+         return i64vec(rows);
       default:
          return error_type;
       }
@@ -1250,6 +1287,8 @@ glsl_type::component_slots() const
       return this->components();
 
    case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
       return 2 * this->components();
 
    case GLSL_TYPE_STRUCT:
@@ -1332,6 +1371,8 @@ glsl_type::uniform_locations() const
    case GLSL_TYPE_INT:
    case GLSL_TYPE_FLOAT:
    case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
    case GLSL_TYPE_BOOL:
    case GLSL_TYPE_SAMPLER:
    case GLSL_TYPE_IMAGE:
@@ -1361,6 +1402,8 @@ glsl_type::varying_count() const
    case GLSL_TYPE_FLOAT:
    case GLSL_TYPE_DOUBLE:
    case GLSL_TYPE_BOOL:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
       return 1;
 
    case GLSL_TYPE_STRUCT:
@@ -1931,6 +1974,8 @@ glsl_type::count_attribute_slots(bool is_vertex_input) const
    case GLSL_TYPE_BOOL:
       return this->matrix_columns;
    case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
       if (this->vector_elements > 2 && !is_vertex_input)
          return this->matrix_columns * 2;
       else
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index c3a0185..cb53ea7 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -51,6 +51,8 @@ enum glsl_base_type {
    GLSL_TYPE_INT,
    GLSL_TYPE_FLOAT,
    GLSL_TYPE_DOUBLE,
+   GLSL_TYPE_UINT64,
+   GLSL_TYPE_INT64,
    GLSL_TYPE_BOOL,
    GLSL_TYPE_SAMPLER,
    GLSL_TYPE_IMAGE,
@@ -66,7 +68,9 @@ enum glsl_base_type {
 
 static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
 {
-   return type == GLSL_TYPE_DOUBLE;
+   return type == GLSL_TYPE_DOUBLE ||
+      type == GLSL_TYPE_UINT64 ||
+      type == GLSL_TYPE_INT64;
 }
 
 enum glsl_sampler_dim {
@@ -219,6 +223,8 @@ struct glsl_type {
    static const glsl_type *ivec(unsigned components);
    static const glsl_type *uvec(unsigned components);
    static const glsl_type *bvec(unsigned components);
+   static const glsl_type *i64vec(unsigned components);
+   static const glsl_type *u64vec(unsigned components);
    /**@}*/
 
    /**
@@ -455,7 +461,7 @@ struct glsl_type {
     */
    bool is_numeric() const
    {
-      return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
+      return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_INT64);
    }
 
    /**
@@ -467,6 +473,15 @@ struct glsl_type {
    }
 
    /**
+    * Query whether or not a type is a 32-bit or 64-bit integer
+    */
+   bool is_integer_32_64() const
+   {
+      return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT) ||
+             (base_type == GLSL_TYPE_UINT64) || (base_type == GLSL_TYPE_INT64);
+   }
+
+   /**
     * Query whether or not type is an integral type, or for struct and array
     * types, contains an integral type.
     */
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 3a5f058..94a6ca3 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -532,6 +532,12 @@ type_size(const struct glsl_type *type)
             return 1;
       }
       break;
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
+      if (type->vector_elements > 2)
+         return 2;
+      else
+         return 1;
    case GLSL_TYPE_ARRAY:
       assert(type->length > 0);
       return type_size(type->fields.array) * type->length;
@@ -2521,11 +2527,19 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
 	 unsigned columns = 0;
 	 int dmul = 4 * sizeof(float);
 	 switch (storage->type->base_type) {
+         case GLSL_TYPE_UINT64:
+	    if (storage->type->vector_elements > 2)
+               dmul *= 2;
+	    /* fallthrough */
 	 case GLSL_TYPE_UINT:
 	    assert(ctx->Const.NativeIntegers);
 	    format = uniform_native;
 	    columns = 1;
 	    break;
+         case GLSL_TYPE_INT64:
+	    if (storage->type->vector_elements > 2)
+               dmul *= 2;
+	    /* fallthrough */
 	 case GLSL_TYPE_INT:
 	    format =
 	       (ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
diff --git a/src/mesa/state_tracker/st_glsl_types.cpp b/src/mesa/state_tracker/st_glsl_types.cpp
index 857e143..37c3164 100644
--- a/src/mesa/state_tracker/st_glsl_types.cpp
+++ b/src/mesa/state_tracker/st_glsl_types.cpp
@@ -67,6 +67,12 @@ st_glsl_attrib_type_size(const struct glsl_type *type, bool is_vs_input)
             return 2;
       }
       break;
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_INT64:
+      if (type->vector_elements <= 2 || is_vs_input)
+         return 1;
+      else
+         return 2;
    case GLSL_TYPE_ARRAY:
       assert(type->length > 0);
       return st_glsl_attrib_type_size(type->fields.array, is_vs_input) * type->length;
-- 
2.5.5



More information about the mesa-dev mailing list