mesa: remove support for GL_APPLE_client_storage extension
[mesa.git] / src / glsl / ir_reader.cpp
index af85e06ae0e4a2cda026c84b5aca30b7476d2373..2d0bccb78cd2dabad15a3810e64bba406a18e7fe 100644 (file)
@@ -482,19 +482,21 @@ ir_reader::read_return(s_expression *expr)
 {
    s_expression *s_retval;
 
-   s_pattern pat[] = { "return", s_retval};
-   if (!MATCH(expr, pat)) {
-      ir_read_error(expr, "expected (return <rvalue>)");
-      return NULL;
-   }
-
-   ir_rvalue *retval = read_rvalue(s_retval);
-   if (retval == NULL) {
-      ir_read_error(NULL, "when reading return value");
+   s_pattern return_value_pat[] = { "return", s_retval};
+   s_pattern return_void_pat[] = { "return" };
+   if (MATCH(expr, return_value_pat)) {
+      ir_rvalue *retval = read_rvalue(s_retval);
+      if (retval == NULL) {
+         ir_read_error(NULL, "when reading return value");
+         return NULL;
+      }
+      return new(mem_ctx) ir_return(retval);
+   } else if (MATCH(expr, return_void_pat)) {
+      return new(mem_ctx) ir_return;
+   } else {
+      ir_read_error(expr, "expected (return <rvalue>) or (return)");
       return NULL;
    }
-
-   return new(mem_ctx) ir_return(retval);
 }
 
 
@@ -775,7 +777,7 @@ ir_reader::read_constant(s_expression *expr)
    ir_constant_data data = { { 0 } };
 
    // Read in list of values (at most 16).
-   int k = 0;
+   unsigned k = 0;
    foreach_iter(exec_list_iterator, it, values->subexpressions) {
       if (k >= 16) {
         ir_read_error(values, "expected at most 16 numbers");
@@ -818,6 +820,11 @@ ir_reader::read_constant(s_expression *expr)
       }
       ++k;
    }
+   if (k != type->components()) {
+      ir_read_error(values, "expected %u constant values, found %u",
+                   type->components(), k);
+      return NULL;
+   }
 
    return new(mem_ctx) ir_constant(type, &data);
 }
@@ -869,6 +876,7 @@ ir_texture *
 ir_reader::read_texture(s_expression *expr)
 {
    s_symbol *tag = NULL;
+   s_expression *s_type = NULL;
    s_expression *s_sampler = NULL;
    s_expression *s_coord = NULL;
    s_expression *s_offset = NULL;
@@ -879,16 +887,20 @@ ir_reader::read_texture(s_expression *expr)
    ir_texture_opcode op = ir_tex; /* silence warning */
 
    s_pattern tex_pattern[] =
-      { "tex", s_sampler, s_coord, s_offset, s_proj, s_shadow };
+      { "tex", s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow };
    s_pattern txf_pattern[] =
-      { "txf", s_sampler, s_coord, s_offset, s_lod };
+      { "txf", s_type, s_sampler, s_coord, s_offset, s_lod };
+   s_pattern txs_pattern[] =
+      { "txs", s_type, s_sampler, s_lod };
    s_pattern other_pattern[] =
-      { tag, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
+      { tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
 
    if (MATCH(expr, tex_pattern)) {
       op = ir_tex;
    } else if (MATCH(expr, txf_pattern)) {
       op = ir_txf;
+   } else if (MATCH(expr, txs_pattern)) {
+      op = ir_txs;
    } else if (MATCH(expr, other_pattern)) {
       op = ir_texture::get_opcode(tag->value());
       if (op == -1)
@@ -900,34 +912,44 @@ ir_reader::read_texture(s_expression *expr)
 
    ir_texture *tex = new(mem_ctx) ir_texture(op);
 
-   // Read sampler (must be a deref)
-   ir_dereference *sampler = read_dereference(s_sampler);
-   if (sampler == NULL) {
-      ir_read_error(NULL, "when reading sampler in (%s ...)",
+   // Read return type
+   const glsl_type *type = read_type(s_type);
+   if (type == NULL) {
+      ir_read_error(NULL, "when reading type in (%s ...)",
                    tex->opcode_string());
       return NULL;
    }
-   tex->set_sampler(sampler);
 
-   // Read coordinate (any rvalue)
-   tex->coordinate = read_rvalue(s_coord);
-   if (tex->coordinate == NULL) {
-      ir_read_error(NULL, "when reading coordinate in (%s ...)",
+   // Read sampler (must be a deref)
+   ir_dereference *sampler = read_dereference(s_sampler);
+   if (sampler == NULL) {
+      ir_read_error(NULL, "when reading sampler in (%s ...)",
                    tex->opcode_string());
       return NULL;
    }
+   tex->set_sampler(sampler, type);
 
-   // Read texel offset - either 0 or an rvalue.
-   s_int *si_offset = SX_AS_INT(s_offset);
-   if (si_offset == NULL || si_offset->value() != 0) {
-      tex->offset = read_rvalue(s_offset);
-      if (tex->offset == NULL) {
-        ir_read_error(s_offset, "expected 0 or an expression");
+   if (op != ir_txs) {
+      // Read coordinate (any rvalue)
+      tex->coordinate = read_rvalue(s_coord);
+      if (tex->coordinate == NULL) {
+        ir_read_error(NULL, "when reading coordinate in (%s ...)",
+                      tex->opcode_string());
         return NULL;
       }
+
+      // Read texel offset - either 0 or an rvalue.
+      s_int *si_offset = SX_AS_INT(s_offset);
+      if (si_offset == NULL || si_offset->value() != 0) {
+        tex->offset = read_rvalue(s_offset);
+        if (tex->offset == NULL) {
+           ir_read_error(s_offset, "expected 0 or an expression");
+           return NULL;
+        }
+      }
    }
 
-   if (op != ir_txf) {
+   if (op != ir_txf && op != ir_txs) {
       s_int *proj_as_int = SX_AS_INT(s_proj);
       if (proj_as_int && proj_as_int->value() == 1) {
         tex->projector = NULL;
@@ -962,6 +984,7 @@ ir_reader::read_texture(s_expression *expr)
       break;
    case ir_txl:
    case ir_txf:
+   case ir_txs:
       tex->lod_info.lod = read_rvalue(s_lod);
       if (tex->lod_info.lod == NULL) {
         ir_read_error(NULL, "when reading LOD in (%s ...)",