etnaviv: fix standalone compiler to work without a tgsi backend
authorItalo Nicola <italonicola@collabora.com>
Fri, 29 Jul 2022 20:34:02 +0000 (17:34 -0300)
committerMarge Bot <emma+marge@anholt.net>
Thu, 11 Aug 2022 17:46:32 +0000 (17:46 +0000)
Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17810>

src/gallium/drivers/etnaviv/etnaviv_compiler_cmdline.c

index 0bfb39e..202147d 100644 (file)
@@ -35,6 +35,8 @@
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_text.h"
 
+#include "nir/tgsi_to_nir.h"
+
 #include "etnaviv_compiler.h"
 #include "etnaviv_debug.h"
 #include "etnaviv_internal.h"
@@ -102,17 +104,10 @@ main(int argc, char **argv)
    const char *filename;
    struct tgsi_token toks[65536];
    struct tgsi_parse_context parse;
-   struct etna_shader s = {};
    struct etna_shader_key key = {};
    void *ptr;
    size_t size;
 
-   struct etna_shader_variant *v = CALLOC_STRUCT(etna_shader_variant);
-   if (!v) {
-      fprintf(stderr, "malloc failed!\n");
-      return 1;
-   }
-
    etna_mesa_debug = ETNA_DBG_MSGS | ETNA_DBG_NOCACHE;
 
    while (n < argc) {
@@ -152,11 +147,19 @@ main(int argc, char **argv)
 
    tgsi_parse_init(&parse, toks);
 
-   s.specs = &specs_gc2000;
-   s.tokens = toks;
+   struct etna_compiler *compiler = etna_compiler_create(NULL, &specs_gc2000);
 
-   v->shader = &s;
-   v->key = key;
+   struct etna_shader shader = {};
+   shader.nir = tgsi_to_nir_noscreen(toks, &compiler->options);
+   shader.specs = &specs_gc2000;
+   shader.compiler = compiler;
+
+   struct util_debug_callback debug = {}; // TODO: proper debug callback
+   struct etna_shader_variant *v = etna_shader_variant(&shader, key, &debug);
+   if (!v) {
+      fprintf(stderr, "shader variant creation failed!\n");
+      return 1;
+   }
 
    if (!etna_compile_shader(v)) {
       fprintf(stderr, "compiler failed!\n");