nir: Add a foreach_block_reverse function
[mesa.git] / src / glsl / nir / nir_lower_variables_scalar.c
index 63c55c0969426cc6b5e5321df4e78d56679fcb9a..0b7263c88de40e4adbc6cbf9dabbf393592e16c2 100644 (file)
@@ -75,7 +75,7 @@ type_size(const struct glsl_type *type)
  */
 
 static void
-assign_var_locations(struct hash_table *ht)
+assign_var_locations(struct hash_table *ht, unsigned *size)
 {
    unsigned location = 0;
 
@@ -93,14 +93,16 @@ assign_var_locations(struct hash_table *ht)
       var->data.driver_location = location;
       location += type_size(var->type);
    }
+
+   *size = location;
 }
 
 static void
 assign_var_locations_shader(nir_shader *shader)
 {
-   assign_var_locations(shader->inputs);
-   assign_var_locations(shader->outputs);
-   assign_var_locations(shader->uniforms);
+   assign_var_locations(shader->inputs, &shader->num_inputs);
+   assign_var_locations(shader->outputs, &shader->num_outputs);
+   assign_var_locations(shader->uniforms, &shader->num_uniforms);
 }
 
 static void
@@ -350,13 +352,26 @@ get_deref_tail(nir_deref *deref)
 /* helper for reg_const_load which emits a single instruction */
 static void
 reg_const_load_single_instr(nir_reg_dest reg, nir_constant *constant,
+                            enum glsl_base_type base_type,
                             unsigned num_components, unsigned offset,
                             nir_function_impl *impl, void *mem_ctx)
 {
    nir_load_const_instr *instr = nir_load_const_instr_create(mem_ctx);
    instr->num_components = num_components;
    for (unsigned i = 0; i < num_components; i++) {
-      instr->value.u[i] = constant->value.u[i + offset];
+      switch (base_type) {
+      case GLSL_TYPE_FLOAT:
+      case GLSL_TYPE_INT:
+      case GLSL_TYPE_UINT:
+         instr->value.u[i] = constant->value.u[i + offset];
+         break;
+      case GLSL_TYPE_BOOL:
+         instr->value.u[i] = constant->value.u[i + offset] ?
+                             NIR_TRUE : NIR_FALSE;
+         break;
+      default:
+         unreachable("Invalid immediate type");
+      }
    }
    instr->dest.reg = reg;
    instr->dest.reg.base_offset += offset;
@@ -374,20 +389,21 @@ reg_const_load(nir_reg_dest reg, nir_constant *constant,
    const struct glsl_type *subtype;
    unsigned subtype_size;
 
-   switch (glsl_get_base_type(type)) {
+   enum glsl_base_type base_type = glsl_get_base_type(type);
+   switch (base_type) {
       case GLSL_TYPE_FLOAT:
       case GLSL_TYPE_INT:
       case GLSL_TYPE_UINT:
       case GLSL_TYPE_BOOL:
          if (glsl_type_is_matrix(type)) {
             for (unsigned i = 0; i < glsl_get_matrix_columns(type); i++) {
-               reg_const_load_single_instr(reg, constant,
+               reg_const_load_single_instr(reg, constant, base_type,
                                            glsl_get_vector_elements(type),
                                            i * glsl_get_vector_elements(type),
                                            impl, mem_ctx);
             }
          } else {
-            reg_const_load_single_instr(reg, constant,
+            reg_const_load_single_instr(reg, constant, base_type,
                                         glsl_get_vector_elements(type), 0,
                                         impl, mem_ctx);
          }