draw/gs: make sure geometry shaders don't overflow
[mesa.git] / src / glsl / glsl_types.cpp
index 4a2c8790790ca65a6650c722aceb13270e8b4d35..df9c5d36f0b0b1dea091d4a15644e7f2cb6c00f7 100644 (file)
@@ -57,6 +57,7 @@ glsl_type::glsl_type(GLenum gl_type,
    length(0)
 {
    init_ralloc_type_ctx();
+   assert(name != NULL);
    this->name = ralloc_strdup(this->mem_ctx, name);
    /* Neither dimension is zero or both dimensions are zero.
     */
@@ -75,12 +76,14 @@ glsl_type::glsl_type(GLenum gl_type,
    length(0)
 {
    init_ralloc_type_ctx();
+   assert(name != NULL);
    this->name = ralloc_strdup(this->mem_ctx, name);
    memset(& fields, 0, sizeof(fields));
 }
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
                     const char *name) :
+   gl_type(0),
    base_type(GLSL_TYPE_STRUCT),
    sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
    sampler_type(0), interface_packing(0),
@@ -90,6 +93,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
    unsigned int i;
 
    init_ralloc_type_ctx();
+   assert(name != NULL);
    this->name = ralloc_strdup(this->mem_ctx, name);
    this->fields.structure = ralloc_array(this->mem_ctx,
                                         glsl_struct_field, length);
@@ -103,6 +107,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
 
 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
                     enum glsl_interface_packing packing, const char *name) :
+   gl_type(0),
    base_type(GLSL_TYPE_INTERFACE),
    sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
    sampler_type(0), interface_packing((unsigned) packing),
@@ -112,6 +117,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
    unsigned int i;
 
    init_ralloc_type_ctx();
+   assert(name != NULL);
    this->name = ralloc_strdup(this->mem_ctx, name);
    this->fields.structure = ralloc_array(this->mem_ctx,
                                         glsl_struct_field, length);
@@ -156,6 +162,24 @@ glsl_type::contains_sampler() const
    }
 }
 
+
+bool
+glsl_type::contains_integer() const
+{
+   if (this->is_array()) {
+      return this->fields.array->contains_integer();
+   } else if (this->is_record()) {
+      for (unsigned int i = 0; i < this->length; i++) {
+        if (this->fields.structure[i].type->contains_integer())
+           return true;
+      }
+      return false;
+   } else {
+      return this->is_integer();
+   }
+}
+
+
 gl_texture_index
 glsl_type::sampler_index() const
 {
@@ -178,6 +202,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;
@@ -269,6 +295,14 @@ glsl_type::generate_140_types(glsl_symbol_table *symtab)
 }
 
 
+void
+glsl_type::generate_150_types(glsl_symbol_table *symtab)
+{
+   generate_140_types(symtab);
+   generate_ARB_texture_multisample_types(symtab, false);
+}
+
+
 void
 glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab,
                                                bool warn)
@@ -324,6 +358,16 @@ glsl_type::generate_ARB_texture_cube_map_array_types(glsl_symbol_table *symtab,
                             warn, skip_1d);
 }
 
+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)
 {
@@ -355,6 +399,9 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
       case 140:
          glsl_type::generate_140_types(state->symbols);
          break;
+      case 150:
+         glsl_type::generate_150_types(state->symbols);
+         break;
       default:
          assert(!"Unexpected language version");
          break;
@@ -392,6 +439,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);
+   }
 }
 
 
@@ -428,6 +480,8 @@ const glsl_type *glsl_type::get_scalar_type() const
       return int_type;
    case GLSL_TYPE_FLOAT:
       return float_type;
+   case GLSL_TYPE_BOOL:
+      return bool_type;
    default:
       /* Handle everything else */
       return type;