glsl/linker: add check for compute shared memory size
[mesa.git] / src / compiler / glsl / ir_print_visitor.cpp
index e06acce782a23136f3125dbc8e110c7087de6609..ea14cdeb6c7b9057c06183a2914f9dc36eca22b4 100644 (file)
@@ -21,6 +21,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <inttypes.h> /* for PRIx64 macro */
 #include "ir_print_visitor.h"
 #include "compiler/glsl_types.h"
 #include "glsl_parser_extras.h"
@@ -130,26 +131,25 @@ ir_print_visitor::unique_name(ir_variable *var)
 
    /* If there's no conflict, just use the original name */
    const char* name = NULL;
-   if (_mesa_symbol_table_find_symbol(this->symbols, -1, var->name) == NULL) {
+   if (_mesa_symbol_table_find_symbol(this->symbols, var->name) == NULL) {
       name = var->name;
    } else {
       static unsigned i = 1;
       name = ralloc_asprintf(this->mem_ctx, "%s@%u", var->name, ++i);
    }
    _mesa_hash_table_insert(this->printable_names, var, (void *) name);
-   _mesa_symbol_table_add_symbol(this->symbols, -1, name, var);
+   _mesa_symbol_table_add_symbol(this->symbols, name, var);
    return name;
 }
 
 static void
 print_type(FILE *f, const glsl_type *t)
 {
-   if (t->base_type == GLSL_TYPE_ARRAY) {
+   if (t->is_array()) {
       fprintf(f, "(array ");
       print_type(f, t->fields.array);
       fprintf(f, " %u)", t->length);
-   } else if ((t->base_type == GLSL_TYPE_STRUCT)
-              && !is_gl_identifier(t->name)) {
+   } else if (t->is_record() && !is_gl_identifier(t->name)) {
       fprintf(f, "%s@%p", t->name, (void *) t);
    } else {
       fprintf(f, "%s", t->name);
@@ -165,27 +165,61 @@ void ir_print_visitor::visit(ir_variable *ir)
 {
    fprintf(f, "(declare ");
 
-   char loc[256] = {0};
+   char binding[32] = {0};
+   if (ir->data.binding)
+      snprintf(binding, sizeof(binding), "binding=%i ", ir->data.binding);
+
+   char loc[32] = {0};
    if (ir->data.location != -1)
       snprintf(loc, sizeof(loc), "location=%i ", ir->data.location);
 
+   char component[32] = {0};
+   if (ir->data.explicit_component || ir->data.location_frac != 0)
+      snprintf(component, sizeof(component), "component=%i ", ir->data.location_frac);
+
+   char stream[32] = {0};
+   if (ir->data.stream & (1u << 31)) {
+      if (ir->data.stream & ~(1u << 31)) {
+         snprintf(stream, sizeof(stream), "stream(%u,%u,%u,%u) ",
+                  ir->data.stream & 3, (ir->data.stream >> 2) & 3,
+                  (ir->data.stream >> 4) & 3, (ir->data.stream >> 6) & 3);
+      }
+   } else if (ir->data.stream) {
+      snprintf(stream, sizeof(stream), "stream%u ", ir->data.stream);
+   }
+
+   char image_format[32] = {0};
+   if (ir->data.image_format) {
+      snprintf(image_format, sizeof(image_format), "format=%x ",
+               ir->data.image_format);
+   }
+
    const char *const cent = (ir->data.centroid) ? "centroid " : "";
    const char *const samp = (ir->data.sample) ? "sample " : "";
    const char *const patc = (ir->data.patch) ? "patch " : "";
    const char *const inv = (ir->data.invariant) ? "invariant " : "";
    const char *const prec = (ir->data.precise) ? "precise " : "";
+   const char *const bindless = (ir->data.bindless) ? "bindless " : "";
+   const char *const bound = (ir->data.bound) ? "bound " : "";
+   const char *const memory_read_only = (ir->data.memory_read_only) ? "readonly " : "";
+   const char *const memory_write_only = (ir->data.memory_write_only) ? "writeonly " : "";
+   const char *const memory_coherent = (ir->data.memory_coherent) ? "coherent " : "";
+   const char *const memory_volatile = (ir->data.memory_volatile) ? "volatile " : "";
+   const char *const memory_restrict = (ir->data.memory_restrict) ? "restrict " : "";
    const char *const mode[] = { "", "uniform ", "shader_storage ",
                                 "shader_shared ", "shader_in ", "shader_out ",
                                 "in ", "out ", "inout ",
                                "const_in ", "sys ", "temporary " };
    STATIC_ASSERT(ARRAY_SIZE(mode) == ir_var_mode_count);
-   const char *const stream [] = {"", "stream1 ", "stream2 ", "stream3 "};
    const char *const interp[] = { "", "smooth", "flat", "noperspective" };
-   STATIC_ASSERT(ARRAY_SIZE(interp) == INTERP_QUALIFIER_COUNT);
-
-   fprintf(f, "(%s%s%s%s%s%s%s%s%s) ",
-           loc, cent, samp, patc, inv, prec, mode[ir->data.mode],
-           stream[ir->data.stream],
+   STATIC_ASSERT(ARRAY_SIZE(interp) == INTERP_MODE_COUNT);
+
+   fprintf(f, "(%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s) ",
+           binding, loc, component, cent, bindless, bound,
+           image_format, memory_read_only, memory_write_only,
+           memory_coherent, memory_volatile, memory_restrict,
+           samp, patc, inv, prec, mode[ir->data.mode],
+           stream,
            interp[ir->data.interpolation]);
 
    print_type(f, ir->type);
@@ -255,9 +289,9 @@ void ir_print_visitor::visit(ir_expression *ir)
 
    print_type(f, ir->type);
 
-   fprintf(f, " %s ", ir->operator_string());
+   fprintf(f, " %s ", ir_expression_operation_strings[ir->operation]);
 
-   for (unsigned i = 0; i < ir->get_num_operands(); i++) {
+   for (unsigned i = 0; i < ir->num_operands; i++) {
       ir->operands[i]->accept(this);
    }
 
@@ -306,9 +340,9 @@ void ir_print_visitor::visit(ir_texture *ir)
       else
         fprintf(f, "1");
 
-      if (ir->shadow_comparitor) {
+      if (ir->shadow_comparator) {
         fprintf(f, " ");
-        ir->shadow_comparitor->accept(this);
+        ir->shadow_comparator->accept(this);
       } else {
         fprintf(f, " ()");
       }
@@ -344,7 +378,7 @@ void ir_print_visitor::visit(ir_texture *ir)
       ir->lod_info.component->accept(this);
       break;
    case ir_samples_identical:
-      unreachable(!"ir_samples_identical was already handled");
+      unreachable("ir_samples_identical was already handled");
    };
    fprintf(f, ")");
 }
@@ -389,7 +423,10 @@ void ir_print_visitor::visit(ir_dereference_record *ir)
 {
    fprintf(f, "(record_ref ");
    ir->record->accept(this);
-   fprintf(f, " %s) ", ir->field);
+
+   const char *field_name =
+      ir->record->type->fields.structure[ir->field_idx].name;
+   fprintf(f, " %s) ", field_name);
 }
 
 
@@ -432,13 +469,10 @@ void ir_print_visitor::visit(ir_constant *ir)
       for (unsigned i = 0; i < ir->type->length; i++)
         ir->get_array_element(i)->accept(this);
    } else if (ir->type->is_record()) {
-      ir_constant *value = (ir_constant *) ir->components.get_head();
       for (unsigned i = 0; i < ir->type->length; i++) {
         fprintf(f, "(%s ", ir->type->fields.structure[i].name);
-        value->accept(this);
+         ir->get_record_field(i)->accept(this);
         fprintf(f, ")");
-
-        value = (ir_constant *) value->next;
       }
    } else {
       for (unsigned i = 0; i < ir->type->components(); i++) {
@@ -458,6 +492,12 @@ void ir_print_visitor::visit(ir_constant *ir)
             else
                fprintf(f, "%f", ir->value.f[i]);
             break;
+        case GLSL_TYPE_SAMPLER:
+        case GLSL_TYPE_IMAGE:
+        case GLSL_TYPE_UINT64:
+            fprintf(f, "%" PRIu64, ir->value.u64[i]);
+            break;
+        case GLSL_TYPE_INT64: fprintf(f, "%" PRIi64, ir->value.i64[i]); break;
         case GLSL_TYPE_BOOL:  fprintf(f, "%d", ir->value.b[i]); break;
         case GLSL_TYPE_DOUBLE:
             if (ir->value.d[i] == 0.0)
@@ -470,7 +510,8 @@ void ir_print_visitor::visit(ir_constant *ir)
             else
                fprintf(f, "%f", ir->value.d[i]);
             break;
-        default: assert(0);
+        default:
+            unreachable("Invalid constant type");
         }
       }
    }