lima: add layer_stride field to lima_resource struct
[mesa.git] / src / compiler / spirv / spirv2nir.c
index c837186bdfce56605dcb26cdc0d3b25dd0e11446..48d2694c96351ddcf5e37e172bd1df0c6be4d6ca 100644 (file)
 #include <sys/types.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#define WORD_SIZE 4
 
 int main(int argc, char **argv)
 {
    int fd = open(argv[1], O_RDONLY);
+   if (fd < 0)
+   {
+      fprintf(stderr, "Failed to open %s\n", argv[1]);
+      return 1;
+   }
+
    off_t len = lseek(fd, 0, SEEK_END);
+   if (len % WORD_SIZE != 0)
+   {
+      fprintf(stderr, "File length isn't a multiple of the word size\n");
+      fprintf(stderr, "Are you sure this is a valid SPIR-V shader?\n");
+      close(fd);
+      return 1;
+   }
 
-   assert(len % 4 == 0);
-   size_t word_count = len / 4;
+   size_t word_count = len / WORD_SIZE;
 
    const void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
-   assert(map != NULL);
+   if (map == MAP_FAILED)
+   {
+      fprintf(stderr, "Failed to mmap the file: errno=%d, %s\n",
+              errno, strerror(errno));
+      close(fd);
+      return 1;
+   }
+
+   struct spirv_to_nir_options spirv_opts = {};
+
+   nir_shader *nir = spirv_to_nir(map, word_count, NULL, 0,
+                                  MESA_SHADER_FRAGMENT, "main",
+                                  &spirv_opts, NULL);
+   nir_print_shader(nir, stderr);
 
-   nir_function *func = spirv_to_nir(map, word_count, NULL, 0,
-                                     MESA_SHADER_FRAGMENT, "main", NULL);
-   nir_print_shader(func->shader, stderr);
+   return 0;
 }