compiler/types: Remove unused GLSL_TYPE_FUNCTION and related functions
authorCaio Oliveira <caio.oliveira@intel.com>
Fri, 1 Sep 2023 17:50:31 +0000 (10:50 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 23:18:12 +0000 (23:18 +0000)
GLSL doesn't use that type.  SPIR-V used for a while but later started
relying on its own data structures and stopped using it.
See ca62e849d3c ("nir/spirv: Stop using glsl_type for function types")

If we were ever to add this one again, would be better to have a way to
grab a key for lookup that did not require allocations, right now that's
needed to inject return type as the first element in params array.

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25160>

src/compiler/glsl/ast_to_hir.cpp
src/compiler/glsl/gl_nir_link_uniform_initializers.c
src/compiler/glsl/ir_clone.cpp
src/compiler/glsl_types.cpp
src/compiler/glsl_types.h
src/compiler/nir/nir.c
src/compiler/nir_types.cpp
src/compiler/nir_types.h
src/intel/compiler/brw_shader.cpp
src/intel/compiler/brw_vec4_visitor.cpp
src/mesa/main/uniform_query.cpp

index 2092fce..b6d2601 100644 (file)
@@ -1187,7 +1187,6 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
    case GLSL_TYPE_INTERFACE:
    case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_SUBROUTINE:
-   case GLSL_TYPE_FUNCTION:
       /* I assume a comparison of a struct containing a sampler just
        * ignores the sampler present in the type.
        */
index 51a5d4f..74e52d8 100644 (file)
@@ -158,7 +158,6 @@ copy_constant_to_storage(union gl_constant_value *storage,
          case GLSL_TYPE_INTERFACE:
          case GLSL_TYPE_VOID:
          case GLSL_TYPE_SUBROUTINE:
-         case GLSL_TYPE_FUNCTION:
          case GLSL_TYPE_ERROR:
          case GLSL_TYPE_UINT16:
          case GLSL_TYPE_INT16:
index 877db52..5a38447 100644 (file)
@@ -368,7 +368,6 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
    case GLSL_TYPE_ERROR:
    case GLSL_TYPE_SUBROUTINE:
    case GLSL_TYPE_INTERFACE:
-   case GLSL_TYPE_FUNCTION:
       assert(!"Should not get here.");
       break;
    }
index 464e1ed..1f49aae 100644 (file)
@@ -169,40 +169,6 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
    this->fields.structure = copied_struct;
 }
 
-glsl_type::glsl_type(const glsl_type *return_type,
-                     const glsl_function_param *params, unsigned num_params) :
-   gl_type(0),
-   base_type(GLSL_TYPE_FUNCTION), sampled_type(GLSL_TYPE_VOID),
-   sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
-   interface_packing(0), interface_row_major(0), packed(0),
-   vector_elements(0), matrix_columns(0),
-   length(num_params), explicit_stride(0), explicit_alignment(0)
-{
-   unsigned int i;
-
-   this->mem_ctx = ralloc_context(NULL);
-   assert(this->mem_ctx != NULL);
-
-   this->name = "";
-
-   struct glsl_function_param *copied_params =
-      rzalloc_array(this->mem_ctx, glsl_function_param, num_params + 1);
-
-   /* We store the return type as the first parameter */
-   copied_params[0].type = return_type;
-   copied_params[0].in = false;
-   copied_params[0].out = true;
-
-   /* We store the i'th parameter in slot i+1 */
-   for (i = 0; i < length; i++) {
-      copied_params[i + 1].type = params[i].type;
-      copied_params[i + 1].in = params[i].in;
-      copied_params[i + 1].out = params[i].out;
-   }
-
-   this->fields.parameters = copied_params;
-}
-
 glsl_type::glsl_type(const char *subroutine_name) :
    gl_type(0),
    base_type(GLSL_TYPE_SUBROUTINE), sampled_type(GLSL_TYPE_VOID),
@@ -444,7 +410,6 @@ const glsl_type *glsl_type::get_bare_type() const
    case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_SUBROUTINE:
-   case GLSL_TYPE_FUNCTION:
    case GLSL_TYPE_ERROR:
       return this;
    }
@@ -1589,62 +1554,6 @@ glsl_type::get_subroutine_instance(const char *subroutine_name)
    return t;
 }
 
-
-static bool
-function_key_compare(const void *a, const void *b)
-{
-   const glsl_type *const key1 = (glsl_type *) a;
-   const glsl_type *const key2 = (glsl_type *) b;
-
-   if (key1->length != key2->length)
-      return false;
-
-   return memcmp(key1->fields.parameters, key2->fields.parameters,
-                 (key1->length + 1) * sizeof(*key1->fields.parameters)) == 0;
-}
-
-
-static uint32_t
-function_key_hash(const void *a)
-{
-   const glsl_type *const key = (glsl_type *) a;
-   return _mesa_hash_data(key->fields.parameters,
-                          (key->length + 1) * sizeof(*key->fields.parameters));
-}
-
-const glsl_type *
-glsl_type::get_function_instance(const glsl_type *return_type,
-                                 const glsl_function_param *params,
-                                 unsigned num_params)
-{
-   const glsl_type key(return_type, params, num_params);
-   const uint32_t key_hash = function_key_hash(&key);
-
-   simple_mtx_lock(&glsl_type::hash_mutex);
-   assert(glsl_type_users > 0);
-
-   if (function_types == NULL) {
-      function_types = _mesa_hash_table_create(NULL, function_key_hash,
-                                               function_key_compare);
-   }
-
-   struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(function_types, key_hash, &key);
-   if (entry == NULL) {
-      const glsl_type *t = new glsl_type(return_type, params, num_params);
-
-      entry = _mesa_hash_table_insert_pre_hashed(function_types, key_hash, t, (void *) t);
-   }
-
-   auto t = (const glsl_type *)entry->data;
-   simple_mtx_unlock(&glsl_type::hash_mutex);
-
-   assert(t->base_type == GLSL_TYPE_FUNCTION);
-   assert(t->length == num_params);
-
-   return t;
-}
-
-
 const glsl_type *
 glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
 {
@@ -1785,7 +1694,6 @@ glsl_type::component_slots() const
    case GLSL_TYPE_SUBROUTINE:
       return 1;
 
-   case GLSL_TYPE_FUNCTION:
    case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
@@ -1852,7 +1760,6 @@ glsl_type::component_slots_aligned(unsigned offset) const
    case GLSL_TYPE_SUBROUTINE:
       return 1;
 
-   case GLSL_TYPE_FUNCTION:
    case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
@@ -2930,7 +2837,6 @@ glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const
    case GLSL_TYPE_SUBROUTINE:
       return 1;
 
-   case GLSL_TYPE_FUNCTION:
    case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
@@ -2987,7 +2893,6 @@ glsl_type::count_dword_slots(bool is_bindless) const
       return 1;
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_FUNCTION:
    default:
       unreachable("invalid type in st_glsl_type_dword_size()");
    }
index a5c4fff..a451ea4 100644 (file)
@@ -86,7 +86,6 @@ enum glsl_base_type {
    GLSL_TYPE_ARRAY,
    GLSL_TYPE_VOID,
    GLSL_TYPE_SUBROUTINE,
-   GLSL_TYPE_FUNCTION,
    GLSL_TYPE_ERROR
 };
 
@@ -363,7 +362,6 @@ public:
     */
    union {
       const struct glsl_type *array;            /**< Type of array elements. */
-      const struct glsl_function_param *parameters;   /**< Parameters to function. */
       const struct glsl_struct_field *structure;      /**< List of struct fields. */
    } fields;
 
@@ -495,13 +493,6 @@ public:
    static const glsl_type *get_subroutine_instance(const char *subroutine_name);
 
    /**
-    * Get the instance of a function type
-    */
-   static const glsl_type *get_function_instance(const struct glsl_type *return_type,
-                                                 const glsl_function_param *parameters,
-                                                 unsigned num_params);
-
-   /**
     * Get the type resulting from a multiplication of \p type_a * \p type_b
     */
    static const glsl_type *get_mul_type(const glsl_type *type_a,
@@ -1267,10 +1258,6 @@ private:
             enum glsl_interface_packing packing,
             bool row_major, const char *name);
 
-   /** Constructor for interface types */
-   glsl_type(const glsl_type *return_type,
-             const glsl_function_param *params, unsigned num_params);
-
    /** Constructors for array types */
    glsl_type(const glsl_type *array, unsigned length, unsigned explicit_stride);
 
@@ -1463,11 +1450,4 @@ struct glsl_struct_field {
 #endif
 };
 
-struct glsl_function_param {
-   const struct glsl_type *type;
-
-   bool in;
-   bool out;
-};
-
 #endif /* GLSL_TYPES_H */
index 8b8aeaf..31f9f99 100644 (file)
@@ -2753,7 +2753,6 @@ nir_get_nir_type_for_glsl_base_type(enum glsl_base_type base_type)
    case GLSL_TYPE_ARRAY:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_SUBROUTINE:
-   case GLSL_TYPE_FUNCTION:
    case GLSL_TYPE_ERROR:
       return nir_type_invalid;
    }
index 6de9401..15fd71a 100644 (file)
@@ -101,18 +101,6 @@ glsl_get_explicit_stride(const struct glsl_type *type)
 }
 
 const glsl_type *
-glsl_get_function_return_type(const glsl_type *type)
-{
-   return type->fields.parameters[0].type;
-}
-
-const glsl_function_param *
-glsl_get_function_param(const glsl_type *type, unsigned index)
-{
-   return &type->fields.parameters[index + 1];
-}
-
-const glsl_type *
 glsl_texture_type_to_sampler(const glsl_type *type, bool is_shadow)
 {
    assert(glsl_type_is_texture(type));
@@ -715,13 +703,6 @@ glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
 }
 
 const glsl_type *
-glsl_function_type(const glsl_type *return_type,
-                   const glsl_function_param *params, unsigned num_params)
-{
-   return glsl_type::get_function_instance(return_type, params, num_params);
-}
-
-const glsl_type *
 glsl_transposed_type(const struct glsl_type *type)
 {
    assert(glsl_type_is_matrix(type));
@@ -872,7 +853,6 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type,
    case GLSL_TYPE_SUBROUTINE:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_FUNCTION:
       unreachable("type does not have a natural size");
    }
 }
@@ -926,7 +906,6 @@ glsl_get_vec4_size_align_bytes(const struct glsl_type *type,
    case GLSL_TYPE_SUBROUTINE:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_FUNCTION:
       unreachable("type does not make sense for glsl_get_vec4_size_align_bytes()");
    }
 }
index 11f32f3..877c8cf 100644 (file)
@@ -72,12 +72,6 @@ const struct glsl_type *glsl_get_bare_type(const struct glsl_type *type);
 const struct glsl_type *glsl_get_column_type(const struct glsl_type *type);
 
 const struct glsl_type *
-glsl_get_function_return_type(const struct glsl_type *type);
-
-const struct glsl_function_param *
-glsl_get_function_param(const struct glsl_type *type, unsigned index);
-
-const struct glsl_type *
 glsl_texture_type_to_sampler(const struct glsl_type *type, bool is_shadow);
 const struct glsl_type *
 glsl_sampler_type_to_texture(const struct glsl_type *type);
@@ -228,9 +222,6 @@ const struct glsl_type *glsl_texture_type(enum glsl_sampler_dim dim,
 const struct glsl_type *glsl_image_type(enum glsl_sampler_dim dim,
                                         bool is_array,
                                         enum glsl_base_type base_type);
-const struct glsl_type * glsl_function_type(const struct glsl_type *return_type,
-                                            const struct glsl_function_param *params,
-                                            unsigned num_params);
 
 const struct glsl_type *glsl_transposed_type(const struct glsl_type *type);
 
index 0cd756c..0648bdf 100644 (file)
@@ -74,7 +74,6 @@ brw_type_for_base_type(const struct glsl_type *type)
       return BRW_REGISTER_TYPE_Q;
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_FUNCTION:
       unreachable("not reached");
    }
 
index 9f31c5f..d20d8ff 100644 (file)
@@ -622,7 +622,6 @@ type_size_xvec4(const struct glsl_type *type, bool as_vec4, bool bindless)
       return bindless ? 1 : DIV_ROUND_UP(BRW_IMAGE_PARAM_SIZE, 4);
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
-   case GLSL_TYPE_FUNCTION:
       unreachable("not reached");
    }
 
index ebf1f0d..f90d197 100644 (file)
@@ -1011,7 +1011,6 @@ associate_uniform_storage(struct gl_context *ctx,
          case GLSL_TYPE_STRUCT:
          case GLSL_TYPE_ERROR:
          case GLSL_TYPE_INTERFACE:
-         case GLSL_TYPE_FUNCTION:
             assert(!"Should not get here.");
             break;
          }