spirv: Stop counting inputs in entry_point_wrapper
[mesa.git] / src / compiler / spirv / spirv_to_nir.c
index 6f29ab624841950396d56d0ba9772f442a10d1e3..1660611066731fb1de3f2c31bb33d72f2552e61c 100644 (file)
@@ -1131,6 +1131,21 @@ struct_member_matrix_stride_cb(struct vtn_builder *b,
    ctx->fields[member].type = ctx->type->members[member]->type;
 }
 
+static void
+struct_packed_decoration_cb(struct vtn_builder *b,
+                            struct vtn_value *val, int member,
+                            const struct vtn_decoration *dec, void *void_ctx)
+{
+   vtn_assert(val->type->base_type == vtn_base_type_struct);
+   if (dec->decoration == SpvDecorationCPacked) {
+      if (b->shader->info.stage != MESA_SHADER_KERNEL) {
+         vtn_warn("Decoration only allowed for CL-style kernels: %s",
+                  spirv_decoration_to_string(dec->decoration));
+      }
+      val->type->packed = true;
+   }
+}
+
 static void
 struct_block_decoration_cb(struct vtn_builder *b,
                            struct vtn_value *val, int member,
@@ -1229,11 +1244,7 @@ type_decoration_cb(struct vtn_builder *b,
       break;
 
    case SpvDecorationCPacked:
-      if (b->shader->info.stage != MESA_SHADER_KERNEL)
-         vtn_warn("Decoration only allowed for CL-style kernels: %s",
-                  spirv_decoration_to_string(dec->decoration));
-      else
-         type->packed = true;
+      /* Handled when parsing a struct type, nothing to do here. */
       break;
 
    case SpvDecorationSaturatedConversion:
@@ -1457,10 +1468,13 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
          };
       }
 
+      vtn_foreach_decoration(b, val, struct_packed_decoration_cb, NULL);
+
       if (b->shader->info.stage == MESA_SHADER_KERNEL) {
          unsigned offset = 0;
          for (unsigned i = 0; i < num_fields; i++) {
-            offset = align(offset, glsl_get_cl_alignment(fields[i].type));
+            if (!val->type->packed)
+               offset = align(offset, glsl_get_cl_alignment(fields[i].type));
             fields[i].offset = offset;
             offset += glsl_get_cl_size(fields[i].type);
          }
@@ -1488,7 +1502,8 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
                                                name ? name : "block");
       } else {
          val->type->type = glsl_struct_type(fields, num_fields,
-                                            name ? name : "struct", false);
+                                            name ? name : "struct",
+                                            val->type->packed);
       }
       break;
    }
@@ -5559,8 +5574,6 @@ vtn_emit_kernel_entry_point_wrapper(struct vtn_builder *b,
    const char *func_name =
       ralloc_asprintf(b->shader, "__wrapped_%s", entry_point->name);
 
-   /* we shouldn't have any inputs yet */
-   vtn_assert(!entry_point->shader->num_inputs);
    vtn_assert(b->shader->info.stage == MESA_SHADER_KERNEL);
 
    nir_function *main_entry_point = nir_function_create(b->shader, func_name);
@@ -5603,7 +5616,6 @@ vtn_emit_kernel_entry_point_wrapper(struct vtn_builder *b,
          in_var->type = param_type->type;
 
       nir_shader_add_variable(b->nb.shader, in_var);
-      b->nb.shader->num_inputs++;
 
       /* we have to copy the entire variable into function memory */
       if (is_by_val) {